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" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 39 | #include "p2p/base/fake_ice_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 40 | #include "p2p/base/mock_async_resolver.h" |
| 41 | #include "p2p/base/p2p_constants.h" |
| 42 | #include "p2p/base/port_interface.h" |
| 43 | #include "p2p/base/test_stun_server.h" |
| 44 | #include "p2p/base/test_turn_customizer.h" |
| 45 | #include "p2p/base/test_turn_server.h" |
| 46 | #include "p2p/client/basic_port_allocator.h" |
| 47 | #include "pc/dtmf_sender.h" |
| 48 | #include "pc/local_audio_source.h" |
| 49 | #include "pc/media_session.h" |
| 50 | #include "pc/peer_connection.h" |
| 51 | #include "pc/peer_connection_factory.h" |
| 52 | #include "pc/rtp_media_utils.h" |
| 53 | #include "pc/session_description.h" |
| 54 | #include "pc/test/fake_audio_capture_module.h" |
| 55 | #include "pc/test/fake_periodic_video_track_source.h" |
| 56 | #include "pc/test/fake_rtc_certificate_generator.h" |
| 57 | #include "pc/test/fake_video_track_renderer.h" |
| 58 | #include "pc/test/mock_peer_connection_observers.h" |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 59 | #include "rtc_base/fake_clock.h" |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 60 | #include "rtc_base/fake_mdns_responder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 61 | #include "rtc_base/fake_network.h" |
| 62 | #include "rtc_base/firewall_socket_server.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 63 | #include "rtc_base/gunit.h" |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 64 | #include "rtc_base/numerics/safe_conversions.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 65 | #include "rtc_base/test_certificate_verifier.h" |
| 66 | #include "rtc_base/time_utils.h" |
| 67 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 68 | #include "system_wrappers/include/metrics.h" |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 69 | #include "test/field_trial.h" |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 70 | #include "test/gmock.h" |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 71 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 72 | namespace webrtc { |
| 73 | namespace { |
| 74 | |
| 75 | using ::cricket::ContentInfo; |
| 76 | using ::cricket::StreamParams; |
| 77 | using ::rtc::SocketAddress; |
| 78 | using ::testing::_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 79 | using ::testing::Combine; |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 80 | using ::testing::Contains; |
Mirko Bonadei | e46f5db | 2019-03-26 20:14:46 +0100 | [diff] [blame] | 81 | using ::testing::DoAll; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 82 | using ::testing::ElementsAre; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 83 | using ::testing::NiceMock; |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 84 | using ::testing::Return; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 85 | using ::testing::SetArgPointee; |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 86 | using ::testing::UnorderedElementsAreArray; |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 87 | using ::testing::Values; |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 88 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 89 | |
| 90 | static const int kDefaultTimeout = 10000; |
| 91 | static const int kMaxWaitForStatsMs = 3000; |
| 92 | static const int kMaxWaitForActivationMs = 5000; |
| 93 | static const int kMaxWaitForFramesMs = 10000; |
| 94 | // Default number of audio/video frames to wait for before considering a test |
| 95 | // successful. |
| 96 | static const int kDefaultExpectedAudioFrameCount = 3; |
| 97 | static const int kDefaultExpectedVideoFrameCount = 3; |
| 98 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 99 | static const char kDataChannelLabel[] = "data_channel"; |
| 100 | |
| 101 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 102 | // default changes. |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 103 | static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_80; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 104 | static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; |
| 105 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 106 | static const SocketAddress kDefaultLocalAddress("192.168.1.1", 0); |
| 107 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 108 | // Helper function for constructing offer/answer options to initiate an ICE |
| 109 | // restart. |
| 110 | PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() { |
| 111 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 112 | options.ice_restart = true; |
| 113 | return options; |
| 114 | } |
| 115 | |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 116 | // Remove all stream information (SSRCs, track IDs, etc.) and "msid-semantic" |
| 117 | // attribute from received SDP, simulating a legacy endpoint. |
| 118 | void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) { |
| 119 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 120 | content.media_description()->mutable_streams().clear(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 121 | } |
| 122 | desc->set_msid_supported(false); |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 123 | desc->set_msid_signaling(0); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 126 | // Removes all stream information besides the stream ids, simulating an |
| 127 | // endpoint that only signals a=msid lines to convey stream_ids. |
| 128 | void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc) { |
| 129 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 130 | std::string track_id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 131 | std::vector<std::string> stream_ids; |
| 132 | if (!content.media_description()->streams().empty()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 133 | const StreamParams& first_stream = |
| 134 | content.media_description()->streams()[0]; |
| 135 | track_id = first_stream.id; |
| 136 | stream_ids = first_stream.stream_ids(); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 137 | } |
| 138 | content.media_description()->mutable_streams().clear(); |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 139 | StreamParams new_stream; |
| 140 | new_stream.id = track_id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 141 | new_stream.set_stream_ids(stream_ids); |
| 142 | content.media_description()->AddStream(new_stream); |
| 143 | } |
| 144 | } |
| 145 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 146 | int FindFirstMediaStatsIndexByKind( |
| 147 | const std::string& kind, |
| 148 | const std::vector<const webrtc::RTCMediaStreamTrackStats*>& |
| 149 | media_stats_vec) { |
| 150 | for (size_t i = 0; i < media_stats_vec.size(); i++) { |
| 151 | if (media_stats_vec[i]->kind.ValueToString() == kind) { |
| 152 | return i; |
| 153 | } |
| 154 | } |
| 155 | return -1; |
| 156 | } |
| 157 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 158 | class SignalingMessageReceiver { |
| 159 | public: |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 160 | virtual void ReceiveSdpMessage(SdpType type, const std::string& msg) = 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 161 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 162 | int sdp_mline_index, |
| 163 | const std::string& msg) = 0; |
| 164 | |
| 165 | protected: |
| 166 | SignalingMessageReceiver() {} |
| 167 | virtual ~SignalingMessageReceiver() {} |
| 168 | }; |
| 169 | |
| 170 | class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { |
| 171 | public: |
| 172 | explicit MockRtpReceiverObserver(cricket::MediaType media_type) |
| 173 | : expected_media_type_(media_type) {} |
| 174 | |
| 175 | void OnFirstPacketReceived(cricket::MediaType media_type) override { |
| 176 | ASSERT_EQ(expected_media_type_, media_type); |
| 177 | first_packet_received_ = true; |
| 178 | } |
| 179 | |
| 180 | bool first_packet_received() const { return first_packet_received_; } |
| 181 | |
| 182 | virtual ~MockRtpReceiverObserver() {} |
| 183 | |
| 184 | private: |
| 185 | bool first_packet_received_ = false; |
| 186 | cricket::MediaType expected_media_type_; |
| 187 | }; |
| 188 | |
| 189 | // Helper class that wraps a peer connection, observes it, and can accept |
| 190 | // signaling messages from another wrapper. |
| 191 | // |
| 192 | // Uses a fake network, fake A/V capture, and optionally fake |
| 193 | // encoders/decoders, though they aren't used by default since they don't |
| 194 | // advertise support of any codecs. |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 195 | // TODO(steveanton): See how this could become a subclass of |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 196 | // PeerConnectionWrapper defined in peerconnectionwrapper.h. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 197 | class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 198 | public SignalingMessageReceiver { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 199 | public: |
| 200 | // Different factory methods for convenience. |
| 201 | // TODO(deadbeef): Could use the pattern of: |
| 202 | // |
| 203 | // PeerConnectionWrapper = |
| 204 | // WrapperBuilder.WithConfig(...).WithOptions(...).build(); |
| 205 | // |
| 206 | // To reduce some code duplication. |
| 207 | static PeerConnectionWrapper* CreateWithDtlsIdentityStore( |
| 208 | const std::string& debug_name, |
| 209 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 210 | rtc::Thread* network_thread, |
| 211 | rtc::Thread* worker_thread) { |
| 212 | PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 213 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 214 | dependencies.cert_generator = std::move(cert_generator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 215 | if (!client->Init(nullptr, nullptr, std::move(dependencies), network_thread, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 216 | worker_thread, nullptr, |
| 217 | /*media_transport_factory=*/nullptr)) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 218 | delete client; |
| 219 | return nullptr; |
| 220 | } |
| 221 | return client; |
| 222 | } |
| 223 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 224 | webrtc::PeerConnectionFactoryInterface* pc_factory() const { |
| 225 | return peer_connection_factory_.get(); |
| 226 | } |
| 227 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 228 | webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); } |
| 229 | |
| 230 | // If a signaling message receiver is set (via ConnectFakeSignaling), this |
| 231 | // will set the whole offer/answer exchange in motion. Just need to wait for |
| 232 | // the signaling state to reach "stable". |
| 233 | void CreateAndSetAndSignalOffer() { |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 234 | auto offer = CreateOfferAndWait(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 235 | ASSERT_NE(nullptr, offer); |
| 236 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(offer))); |
| 237 | } |
| 238 | |
| 239 | // Sets the options to be used when CreateAndSetAndSignalOffer is called, or |
| 240 | // when a remote offer is received (via fake signaling) and an answer is |
| 241 | // generated. By default, uses default options. |
| 242 | void SetOfferAnswerOptions( |
| 243 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 244 | offer_answer_options_ = options; |
| 245 | } |
| 246 | |
| 247 | // Set a callback to be invoked when SDP is received via the fake signaling |
| 248 | // channel, which provides an opportunity to munge (modify) the SDP. This is |
| 249 | // used to test SDP being applied that a PeerConnection would normally not |
| 250 | // generate, but a non-JSEP endpoint might. |
| 251 | void SetReceivedSdpMunger( |
| 252 | std::function<void(cricket::SessionDescription*)> munger) { |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 253 | received_sdp_munger_ = std::move(munger); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 254 | } |
| 255 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 256 | // 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] | 257 | // generated. |
| 258 | void SetGeneratedSdpMunger( |
| 259 | std::function<void(cricket::SessionDescription*)> munger) { |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 260 | generated_sdp_munger_ = std::move(munger); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 263 | // Set a callback to be invoked when a remote offer is received via the fake |
| 264 | // signaling channel. This provides an opportunity to change the |
| 265 | // PeerConnection state before an answer is created and sent to the caller. |
| 266 | void SetRemoteOfferHandler(std::function<void()> handler) { |
| 267 | remote_offer_handler_ = std::move(handler); |
| 268 | } |
| 269 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 270 | void SetRemoteAsyncResolver(rtc::MockAsyncResolver* resolver) { |
| 271 | remote_async_resolver_ = resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 274 | // Every ICE connection state in order that has been seen by the observer. |
| 275 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 276 | ice_connection_state_history() const { |
| 277 | return ice_connection_state_history_; |
| 278 | } |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 279 | void clear_ice_connection_state_history() { |
| 280 | ice_connection_state_history_.clear(); |
| 281 | } |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 282 | |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 283 | // Every standardized ICE connection state in order that has been seen by the |
| 284 | // observer. |
| 285 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 286 | standardized_ice_connection_state_history() const { |
| 287 | return standardized_ice_connection_state_history_; |
| 288 | } |
| 289 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 290 | // Every PeerConnection state in order that has been seen by the observer. |
| 291 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 292 | peer_connection_state_history() const { |
| 293 | return peer_connection_state_history_; |
| 294 | } |
| 295 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 296 | // Every ICE gathering state in order that has been seen by the observer. |
| 297 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 298 | ice_gathering_state_history() const { |
| 299 | return ice_gathering_state_history_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 300 | } |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 301 | std::vector<cricket::CandidatePairChangeEvent> |
| 302 | ice_candidate_pair_change_history() const { |
| 303 | return ice_candidate_pair_change_history_; |
| 304 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 305 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 306 | // Every PeerConnection signaling state in order that has been seen by the |
| 307 | // observer. |
| 308 | std::vector<PeerConnectionInterface::SignalingState> |
| 309 | peer_connection_signaling_state_history() const { |
| 310 | return peer_connection_signaling_state_history_; |
| 311 | } |
| 312 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 313 | void AddAudioVideoTracks() { |
| 314 | AddAudioTrack(); |
| 315 | AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 318 | rtc::scoped_refptr<RtpSenderInterface> AddAudioTrack() { |
| 319 | return AddTrack(CreateLocalAudioTrack()); |
| 320 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 321 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 322 | rtc::scoped_refptr<RtpSenderInterface> AddVideoTrack() { |
| 323 | return AddTrack(CreateLocalVideoTrack()); |
| 324 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 325 | |
| 326 | rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack() { |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 327 | cricket::AudioOptions options; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 328 | // 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] | 329 | options.highpass_filter = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 330 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 331 | peer_connection_factory_->CreateAudioSource(options); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 332 | // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 333 | // always use the default input. |
deadbeef | b1a15d7 | 2017-09-07 14:12:05 -0700 | [diff] [blame] | 334 | return peer_connection_factory_->CreateAudioTrack(rtc::CreateRandomUuid(), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 335 | source); |
| 336 | } |
| 337 | |
| 338 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack() { |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 339 | webrtc::FakePeriodicVideoSource::Config config; |
| 340 | config.timestamp_offset_ms = rtc::TimeMillis(); |
| 341 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 345 | CreateLocalVideoTrackWithConfig( |
| 346 | webrtc::FakePeriodicVideoSource::Config config) { |
| 347 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
| 351 | CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) { |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 352 | webrtc::FakePeriodicVideoSource::Config config; |
| 353 | config.rotation = rotation; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 354 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 355 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 358 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 359 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 360 | const std::vector<std::string>& stream_ids = {}) { |
| 361 | auto result = pc()->AddTrack(track, stream_ids); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 362 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 363 | return result.MoveValue(); |
| 364 | } |
| 365 | |
| 366 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceiversOfType( |
| 367 | cricket::MediaType media_type) { |
| 368 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 369 | for (const auto& receiver : pc()->GetReceivers()) { |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 370 | if (receiver->media_type() == media_type) { |
| 371 | receivers.push_back(receiver); |
| 372 | } |
| 373 | } |
| 374 | return receivers; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 377 | rtc::scoped_refptr<RtpTransceiverInterface> GetFirstTransceiverOfType( |
| 378 | cricket::MediaType media_type) { |
| 379 | for (auto transceiver : pc()->GetTransceivers()) { |
| 380 | if (transceiver->receiver()->media_type() == media_type) { |
| 381 | return transceiver; |
| 382 | } |
| 383 | } |
| 384 | return nullptr; |
| 385 | } |
| 386 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 387 | bool SignalingStateStable() { |
| 388 | return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable; |
| 389 | } |
| 390 | |
| 391 | void CreateDataChannel() { CreateDataChannel(nullptr); } |
| 392 | |
| 393 | void CreateDataChannel(const webrtc::DataChannelInit* init) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 394 | CreateDataChannel(kDataChannelLabel, init); |
| 395 | } |
| 396 | |
| 397 | void CreateDataChannel(const std::string& label, |
| 398 | const webrtc::DataChannelInit* init) { |
| 399 | data_channel_ = pc()->CreateDataChannel(label, init); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 400 | ASSERT_TRUE(data_channel_.get() != nullptr); |
| 401 | data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
| 402 | } |
| 403 | |
| 404 | DataChannelInterface* data_channel() { return data_channel_; } |
| 405 | const MockDataChannelObserver* data_observer() const { |
| 406 | return data_observer_.get(); |
| 407 | } |
| 408 | |
| 409 | int audio_frames_received() const { |
| 410 | return fake_audio_capture_module_->frames_received(); |
| 411 | } |
| 412 | |
| 413 | // Takes minimum of video frames received for each track. |
| 414 | // |
| 415 | // Can be used like: |
| 416 | // EXPECT_GE(expected_frames, min_video_frames_received_per_track()); |
| 417 | // |
| 418 | // To ensure that all video tracks received at least a certain number of |
| 419 | // frames. |
| 420 | int min_video_frames_received_per_track() const { |
| 421 | int min_frames = INT_MAX; |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 422 | if (fake_video_renderers_.empty()) { |
| 423 | return 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 424 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 425 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 426 | for (const auto& pair : fake_video_renderers_) { |
| 427 | min_frames = std::min(min_frames, pair.second->num_rendered_frames()); |
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 | return min_frames; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | // Returns a MockStatsObserver in a state after stats gathering finished, |
| 433 | // which can be used to access the gathered stats. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 434 | rtc::scoped_refptr<MockStatsObserver> OldGetStatsForTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 435 | webrtc::MediaStreamTrackInterface* track) { |
| 436 | rtc::scoped_refptr<MockStatsObserver> observer( |
| 437 | new rtc::RefCountedObject<MockStatsObserver>()); |
| 438 | EXPECT_TRUE(peer_connection_->GetStats( |
| 439 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
| 440 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 441 | return observer; |
| 442 | } |
| 443 | |
| 444 | // Version that doesn't take a track "filter", and gathers all stats. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 445 | rtc::scoped_refptr<MockStatsObserver> OldGetStats() { |
| 446 | return OldGetStatsForTrack(nullptr); |
| 447 | } |
| 448 | |
| 449 | // Synchronously gets stats and returns them. If it times out, fails the test |
| 450 | // and returns null. |
| 451 | rtc::scoped_refptr<const webrtc::RTCStatsReport> NewGetStats() { |
| 452 | rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback( |
| 453 | new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>()); |
| 454 | peer_connection_->GetStats(callback); |
| 455 | EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout); |
| 456 | return callback->report(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | int rendered_width() { |
| 460 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 461 | return fake_video_renderers_.empty() |
| 462 | ? 0 |
| 463 | : fake_video_renderers_.begin()->second->width(); |
| 464 | } |
| 465 | |
| 466 | int rendered_height() { |
| 467 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 468 | return fake_video_renderers_.empty() |
| 469 | ? 0 |
| 470 | : fake_video_renderers_.begin()->second->height(); |
| 471 | } |
| 472 | |
| 473 | double rendered_aspect_ratio() { |
| 474 | if (rendered_height() == 0) { |
| 475 | return 0.0; |
| 476 | } |
| 477 | return static_cast<double>(rendered_width()) / rendered_height(); |
| 478 | } |
| 479 | |
| 480 | webrtc::VideoRotation rendered_rotation() { |
| 481 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 482 | return fake_video_renderers_.empty() |
| 483 | ? webrtc::kVideoRotation_0 |
| 484 | : fake_video_renderers_.begin()->second->rotation(); |
| 485 | } |
| 486 | |
| 487 | int local_rendered_width() { |
| 488 | return local_video_renderer_ ? local_video_renderer_->width() : 0; |
| 489 | } |
| 490 | |
| 491 | int local_rendered_height() { |
| 492 | return local_video_renderer_ ? local_video_renderer_->height() : 0; |
| 493 | } |
| 494 | |
| 495 | double local_rendered_aspect_ratio() { |
| 496 | if (local_rendered_height() == 0) { |
| 497 | return 0.0; |
| 498 | } |
| 499 | return static_cast<double>(local_rendered_width()) / |
| 500 | local_rendered_height(); |
| 501 | } |
| 502 | |
| 503 | size_t number_of_remote_streams() { |
| 504 | if (!pc()) { |
| 505 | return 0; |
| 506 | } |
| 507 | return pc()->remote_streams()->count(); |
| 508 | } |
| 509 | |
| 510 | StreamCollectionInterface* remote_streams() const { |
| 511 | if (!pc()) { |
| 512 | ADD_FAILURE(); |
| 513 | return nullptr; |
| 514 | } |
| 515 | return pc()->remote_streams(); |
| 516 | } |
| 517 | |
| 518 | StreamCollectionInterface* local_streams() { |
| 519 | if (!pc()) { |
| 520 | ADD_FAILURE(); |
| 521 | return nullptr; |
| 522 | } |
| 523 | return pc()->local_streams(); |
| 524 | } |
| 525 | |
| 526 | webrtc::PeerConnectionInterface::SignalingState signaling_state() { |
| 527 | return pc()->signaling_state(); |
| 528 | } |
| 529 | |
| 530 | webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
| 531 | return pc()->ice_connection_state(); |
| 532 | } |
| 533 | |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 534 | webrtc::PeerConnectionInterface::IceConnectionState |
| 535 | standardized_ice_connection_state() { |
| 536 | return pc()->standardized_ice_connection_state(); |
| 537 | } |
| 538 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 539 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 540 | return pc()->ice_gathering_state(); |
| 541 | } |
| 542 | |
| 543 | // Returns a MockRtpReceiverObserver for each RtpReceiver returned by |
| 544 | // GetReceivers. They're updated automatically when a remote offer/answer |
| 545 | // from the fake signaling channel is applied, or when |
| 546 | // ResetRtpReceiverObservers below is called. |
| 547 | const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& |
| 548 | rtp_receiver_observers() { |
| 549 | return rtp_receiver_observers_; |
| 550 | } |
| 551 | |
| 552 | void ResetRtpReceiverObservers() { |
| 553 | rtp_receiver_observers_.clear(); |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 554 | for (const rtc::scoped_refptr<RtpReceiverInterface>& receiver : |
| 555 | pc()->GetReceivers()) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 556 | std::unique_ptr<MockRtpReceiverObserver> observer( |
| 557 | new MockRtpReceiverObserver(receiver->media_type())); |
| 558 | receiver->SetObserver(observer.get()); |
| 559 | rtp_receiver_observers_.push_back(std::move(observer)); |
| 560 | } |
| 561 | } |
| 562 | |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 563 | rtc::FakeNetworkManager* network_manager() const { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 564 | return fake_network_manager_.get(); |
| 565 | } |
| 566 | cricket::PortAllocator* port_allocator() const { return port_allocator_; } |
| 567 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 568 | webrtc::FakeRtcEventLogFactory* event_log_factory() const { |
| 569 | return event_log_factory_; |
| 570 | } |
| 571 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 572 | const cricket::Candidate& last_candidate_gathered() const { |
| 573 | return last_candidate_gathered_; |
| 574 | } |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 575 | const cricket::IceCandidateErrorEvent& error_event() const { |
| 576 | return error_event_; |
| 577 | } |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 578 | |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 579 | // Sets the mDNS responder for the owned fake network manager and keeps a |
| 580 | // reference to the responder. |
| 581 | void SetMdnsResponder( |
| 582 | std::unique_ptr<webrtc::FakeMdnsResponder> mdns_responder) { |
| 583 | RTC_DCHECK(mdns_responder != nullptr); |
| 584 | mdns_responder_ = mdns_responder.get(); |
| 585 | network_manager()->set_mdns_responder(std::move(mdns_responder)); |
| 586 | } |
| 587 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 588 | // Returns null on failure. |
| 589 | std::unique_ptr<SessionDescriptionInterface> CreateOfferAndWait() { |
| 590 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 591 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 592 | pc()->CreateOffer(observer, offer_answer_options_); |
| 593 | return WaitForDescriptionFromObserver(observer); |
| 594 | } |
| 595 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 596 | private: |
| 597 | explicit PeerConnectionWrapper(const std::string& debug_name) |
| 598 | : debug_name_(debug_name) {} |
| 599 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 600 | bool Init( |
| 601 | const PeerConnectionFactory::Options* options, |
| 602 | const PeerConnectionInterface::RTCConfiguration* config, |
| 603 | webrtc::PeerConnectionDependencies dependencies, |
| 604 | rtc::Thread* network_thread, |
| 605 | rtc::Thread* worker_thread, |
| 606 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 607 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 608 | // There's an error in this test code if Init ends up being called twice. |
| 609 | RTC_DCHECK(!peer_connection_); |
| 610 | RTC_DCHECK(!peer_connection_factory_); |
| 611 | |
| 612 | fake_network_manager_.reset(new rtc::FakeNetworkManager()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 613 | fake_network_manager_->AddInterface(kDefaultLocalAddress); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 614 | |
| 615 | std::unique_ptr<cricket::PortAllocator> port_allocator( |
| 616 | new cricket::BasicPortAllocator(fake_network_manager_.get())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 617 | port_allocator_ = port_allocator.get(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 618 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 619 | if (!fake_audio_capture_module_) { |
| 620 | return false; |
| 621 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 622 | rtc::Thread* const signaling_thread = rtc::Thread::Current(); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 623 | |
| 624 | webrtc::PeerConnectionFactoryDependencies pc_factory_dependencies; |
| 625 | pc_factory_dependencies.network_thread = network_thread; |
| 626 | pc_factory_dependencies.worker_thread = worker_thread; |
| 627 | pc_factory_dependencies.signaling_thread = signaling_thread; |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 628 | pc_factory_dependencies.task_queue_factory = |
| 629 | webrtc::CreateDefaultTaskQueueFactory(); |
| 630 | cricket::MediaEngineDependencies media_deps; |
| 631 | media_deps.task_queue_factory = |
| 632 | pc_factory_dependencies.task_queue_factory.get(); |
| 633 | media_deps.adm = fake_audio_capture_module_; |
| 634 | webrtc::SetMediaEngineDefaults(&media_deps); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 635 | pc_factory_dependencies.media_engine = |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 636 | cricket::CreateMediaEngine(std::move(media_deps)); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 637 | pc_factory_dependencies.call_factory = webrtc::CreateCallFactory(); |
| 638 | if (event_log_factory) { |
| 639 | event_log_factory_ = event_log_factory.get(); |
| 640 | pc_factory_dependencies.event_log_factory = std::move(event_log_factory); |
| 641 | } else { |
| 642 | pc_factory_dependencies.event_log_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 643 | std::make_unique<webrtc::RtcEventLogFactory>( |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 644 | pc_factory_dependencies.task_queue_factory.get()); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 645 | } |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 646 | if (media_transport_factory) { |
| 647 | pc_factory_dependencies.media_transport_factory = |
| 648 | std::move(media_transport_factory); |
| 649 | } |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 650 | peer_connection_factory_ = webrtc::CreateModularPeerConnectionFactory( |
| 651 | std::move(pc_factory_dependencies)); |
| 652 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 653 | if (!peer_connection_factory_) { |
| 654 | return false; |
| 655 | } |
| 656 | if (options) { |
| 657 | peer_connection_factory_->SetOptions(*options); |
| 658 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 659 | if (config) { |
| 660 | sdp_semantics_ = config->sdp_semantics; |
| 661 | } |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 662 | |
| 663 | dependencies.allocator = std::move(port_allocator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 664 | peer_connection_ = CreatePeerConnection(config, std::move(dependencies)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 665 | return peer_connection_.get() != nullptr; |
| 666 | } |
| 667 | |
| 668 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 669 | const PeerConnectionInterface::RTCConfiguration* config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 670 | webrtc::PeerConnectionDependencies dependencies) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 671 | PeerConnectionInterface::RTCConfiguration modified_config; |
| 672 | // If |config| is null, this will result in a default configuration being |
| 673 | // used. |
| 674 | if (config) { |
| 675 | modified_config = *config; |
| 676 | } |
| 677 | // Disable resolution adaptation; we don't want it interfering with the |
| 678 | // test results. |
| 679 | // TODO(deadbeef): Do something more robust. Since we're testing for aspect |
| 680 | // ratios and not specific resolutions, is this even necessary? |
| 681 | modified_config.set_cpu_adaptation(false); |
| 682 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 683 | dependencies.observer = this; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 684 | return peer_connection_factory_->CreatePeerConnection( |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 685 | modified_config, std::move(dependencies)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | void set_signaling_message_receiver( |
| 689 | SignalingMessageReceiver* signaling_message_receiver) { |
| 690 | signaling_message_receiver_ = signaling_message_receiver; |
| 691 | } |
| 692 | |
| 693 | void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; } |
| 694 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 695 | void set_signal_ice_candidates(bool signal) { |
| 696 | signal_ice_candidates_ = signal; |
| 697 | } |
| 698 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 699 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrackInternal( |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 700 | webrtc::FakePeriodicVideoSource::Config config) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 701 | // Set max frame rate to 10fps to reduce the risk of test flakiness. |
| 702 | // TODO(deadbeef): Do something more robust. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 703 | config.frame_interval_ms = 100; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 704 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 705 | video_track_sources_.emplace_back( |
Niels Möller | 0f40582 | 2018-05-17 09:16:41 +0200 | [diff] [blame] | 706 | new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>( |
| 707 | config, false /* remote */)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 708 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track( |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 709 | peer_connection_factory_->CreateVideoTrack( |
| 710 | rtc::CreateRandomUuid(), video_track_sources_.back())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 711 | if (!local_video_renderer_) { |
| 712 | local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track)); |
| 713 | } |
| 714 | return track; |
| 715 | } |
| 716 | |
| 717 | void HandleIncomingOffer(const std::string& msg) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 718 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingOffer"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 719 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 720 | webrtc::CreateSessionDescription(SdpType::kOffer, msg); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 721 | if (received_sdp_munger_) { |
| 722 | received_sdp_munger_(desc->description()); |
| 723 | } |
| 724 | |
| 725 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 726 | // Setting a remote description may have changed the number of receivers, |
| 727 | // so reset the receiver observers. |
| 728 | ResetRtpReceiverObservers(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 729 | if (remote_offer_handler_) { |
| 730 | remote_offer_handler_(); |
| 731 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 732 | auto answer = CreateAnswer(); |
| 733 | ASSERT_NE(nullptr, answer); |
| 734 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer))); |
| 735 | } |
| 736 | |
| 737 | void HandleIncomingAnswer(const std::string& msg) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 738 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 739 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 740 | webrtc::CreateSessionDescription(SdpType::kAnswer, msg); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 741 | if (received_sdp_munger_) { |
| 742 | received_sdp_munger_(desc->description()); |
| 743 | } |
| 744 | |
| 745 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 746 | // Set the RtpReceiverObserver after receivers are created. |
| 747 | ResetRtpReceiverObservers(); |
| 748 | } |
| 749 | |
| 750 | // Returns null on failure. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 751 | std::unique_ptr<SessionDescriptionInterface> CreateAnswer() { |
| 752 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 753 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 754 | pc()->CreateAnswer(observer, offer_answer_options_); |
| 755 | return WaitForDescriptionFromObserver(observer); |
| 756 | } |
| 757 | |
| 758 | std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver( |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 759 | MockCreateSessionDescriptionObserver* observer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 760 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
| 761 | if (!observer->result()) { |
| 762 | return nullptr; |
| 763 | } |
| 764 | auto description = observer->MoveDescription(); |
| 765 | if (generated_sdp_munger_) { |
| 766 | generated_sdp_munger_(description->description()); |
| 767 | } |
| 768 | return description; |
| 769 | } |
| 770 | |
| 771 | // Setting the local description and sending the SDP message over the fake |
| 772 | // signaling channel are combined into the same method because the SDP |
| 773 | // message needs to be sent as soon as SetLocalDescription finishes, without |
| 774 | // waiting for the observer to be called. This ensures that ICE candidates |
| 775 | // don't outrace the description. |
| 776 | bool SetLocalDescriptionAndSendSdpMessage( |
| 777 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 778 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 779 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 780 | RTC_LOG(LS_INFO) << debug_name_ << ": SetLocalDescriptionAndSendSdpMessage"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 781 | SdpType type = desc->GetType(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 782 | std::string sdp; |
| 783 | EXPECT_TRUE(desc->ToString(&sdp)); |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 784 | RTC_LOG(LS_INFO) << debug_name_ << ": local SDP contents=\n" << sdp; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 785 | pc()->SetLocalDescription(observer, desc.release()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 786 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 787 | RemoveUnusedVideoRenderers(); |
| 788 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 789 | // As mentioned above, we need to send the message immediately after |
| 790 | // SetLocalDescription. |
| 791 | SendSdpMessage(type, sdp); |
| 792 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) { |
| 797 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 798 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 799 | RTC_LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 800 | pc()->SetRemoteDescription(observer, desc.release()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 801 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 802 | RemoveUnusedVideoRenderers(); |
| 803 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 804 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 805 | return observer->result(); |
| 806 | } |
| 807 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 808 | // This is a work around to remove unused fake_video_renderers from |
| 809 | // transceivers that have either stopped or are no longer receiving. |
| 810 | void RemoveUnusedVideoRenderers() { |
| 811 | auto transceivers = pc()->GetTransceivers(); |
| 812 | for (auto& transceiver : transceivers) { |
| 813 | if (transceiver->receiver()->media_type() != cricket::MEDIA_TYPE_VIDEO) { |
| 814 | continue; |
| 815 | } |
| 816 | // Remove fake video renderers from any stopped transceivers. |
| 817 | if (transceiver->stopped()) { |
| 818 | auto it = |
| 819 | fake_video_renderers_.find(transceiver->receiver()->track()->id()); |
| 820 | if (it != fake_video_renderers_.end()) { |
| 821 | fake_video_renderers_.erase(it); |
| 822 | } |
| 823 | } |
| 824 | // Remove fake video renderers from any transceivers that are no longer |
| 825 | // receiving. |
| 826 | if ((transceiver->current_direction() && |
| 827 | !webrtc::RtpTransceiverDirectionHasRecv( |
| 828 | *transceiver->current_direction()))) { |
| 829 | auto it = |
| 830 | fake_video_renderers_.find(transceiver->receiver()->track()->id()); |
| 831 | if (it != fake_video_renderers_.end()) { |
| 832 | fake_video_renderers_.erase(it); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 838 | // Simulate sending a blob of SDP with delay |signaling_delay_ms_| (0 by |
| 839 | // default). |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 840 | void SendSdpMessage(SdpType type, const std::string& msg) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 841 | if (signaling_delay_ms_ == 0) { |
| 842 | RelaySdpMessageIfReceiverExists(type, msg); |
| 843 | } else { |
| 844 | invoker_.AsyncInvokeDelayed<void>( |
| 845 | RTC_FROM_HERE, rtc::Thread::Current(), |
| 846 | rtc::Bind(&PeerConnectionWrapper::RelaySdpMessageIfReceiverExists, |
| 847 | this, type, msg), |
| 848 | signaling_delay_ms_); |
| 849 | } |
| 850 | } |
| 851 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 852 | void RelaySdpMessageIfReceiverExists(SdpType type, const std::string& msg) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 853 | if (signaling_message_receiver_) { |
| 854 | signaling_message_receiver_->ReceiveSdpMessage(type, msg); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | // Simulate trickling an ICE candidate with delay |signaling_delay_ms_| (0 by |
| 859 | // default). |
| 860 | void SendIceMessage(const std::string& sdp_mid, |
| 861 | int sdp_mline_index, |
| 862 | const std::string& msg) { |
| 863 | if (signaling_delay_ms_ == 0) { |
| 864 | RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, msg); |
| 865 | } else { |
| 866 | invoker_.AsyncInvokeDelayed<void>( |
| 867 | RTC_FROM_HERE, rtc::Thread::Current(), |
| 868 | rtc::Bind(&PeerConnectionWrapper::RelayIceMessageIfReceiverExists, |
| 869 | this, sdp_mid, sdp_mline_index, msg), |
| 870 | signaling_delay_ms_); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | void RelayIceMessageIfReceiverExists(const std::string& sdp_mid, |
| 875 | int sdp_mline_index, |
| 876 | const std::string& msg) { |
| 877 | if (signaling_message_receiver_) { |
| 878 | signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index, |
| 879 | msg); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | // SignalingMessageReceiver callbacks. |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 884 | void ReceiveSdpMessage(SdpType type, const std::string& msg) override { |
| 885 | if (type == SdpType::kOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 886 | HandleIncomingOffer(msg); |
| 887 | } else { |
| 888 | HandleIncomingAnswer(msg); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | void ReceiveIceMessage(const std::string& sdp_mid, |
| 893 | int sdp_mline_index, |
| 894 | const std::string& msg) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 895 | RTC_LOG(LS_INFO) << debug_name_ << ": ReceiveIceMessage"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 896 | std::unique_ptr<webrtc::IceCandidateInterface> candidate( |
| 897 | webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr)); |
| 898 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 899 | } |
| 900 | |
| 901 | // PeerConnectionObserver callbacks. |
| 902 | void OnSignalingChange( |
| 903 | webrtc::PeerConnectionInterface::SignalingState new_state) override { |
| 904 | EXPECT_EQ(pc()->signaling_state(), new_state); |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 905 | peer_connection_signaling_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 906 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 907 | void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, |
| 908 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 909 | streams) override { |
| 910 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 911 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
| 912 | static_cast<VideoTrackInterface*>(receiver->track().get())); |
| 913 | ASSERT_TRUE(fake_video_renderers_.find(video_track->id()) == |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 914 | fake_video_renderers_.end()); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 915 | fake_video_renderers_[video_track->id()] = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 916 | std::make_unique<FakeVideoTrackRenderer>(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 917 | } |
| 918 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 919 | void OnRemoveTrack( |
| 920 | rtc::scoped_refptr<RtpReceiverInterface> receiver) override { |
| 921 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 922 | auto it = fake_video_renderers_.find(receiver->track()->id()); |
| 923 | RTC_DCHECK(it != fake_video_renderers_.end()); |
| 924 | fake_video_renderers_.erase(it); |
| 925 | } |
| 926 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 927 | void OnRenegotiationNeeded() override {} |
| 928 | void OnIceConnectionChange( |
| 929 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 930 | EXPECT_EQ(pc()->ice_connection_state(), new_state); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 931 | ice_connection_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 932 | } |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 933 | void OnStandardizedIceConnectionChange( |
| 934 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 935 | standardized_ice_connection_state_history_.push_back(new_state); |
| 936 | } |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 937 | void OnConnectionChange( |
| 938 | webrtc::PeerConnectionInterface::PeerConnectionState new_state) override { |
| 939 | peer_connection_state_history_.push_back(new_state); |
| 940 | } |
| 941 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 942 | void OnIceGatheringChange( |
| 943 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 944 | EXPECT_EQ(pc()->ice_gathering_state(), new_state); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 945 | ice_gathering_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 946 | } |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 947 | |
| 948 | void OnIceSelectedCandidatePairChanged( |
| 949 | const cricket::CandidatePairChangeEvent& event) { |
| 950 | ice_candidate_pair_change_history_.push_back(event); |
| 951 | } |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 952 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 953 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 954 | RTC_LOG(LS_INFO) << debug_name_ << ": OnIceCandidate"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 955 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 956 | if (remote_async_resolver_) { |
| 957 | const auto& local_candidate = candidate->candidate(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 958 | if (local_candidate.address().IsUnresolvedIP()) { |
| 959 | RTC_DCHECK(local_candidate.type() == cricket::LOCAL_PORT_TYPE); |
| 960 | rtc::SocketAddress resolved_addr(local_candidate.address()); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 961 | const auto resolved_ip = mdns_responder_->GetMappedAddressForName( |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 962 | local_candidate.address().hostname()); |
| 963 | RTC_DCHECK(!resolved_ip.IsNil()); |
| 964 | resolved_addr.SetResolvedIP(resolved_ip); |
| 965 | EXPECT_CALL(*remote_async_resolver_, GetResolvedAddress(_, _)) |
| 966 | .WillOnce(DoAll(SetArgPointee<1>(resolved_addr), Return(true))); |
| 967 | EXPECT_CALL(*remote_async_resolver_, Destroy(_)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 968 | } |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 969 | } |
| 970 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 971 | std::string ice_sdp; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 972 | EXPECT_TRUE(candidate->ToString(&ice_sdp)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 973 | if (signaling_message_receiver_ == nullptr || !signal_ice_candidates_) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 974 | // Remote party may be deleted. |
| 975 | return; |
| 976 | } |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 977 | SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 978 | last_candidate_gathered_ = candidate->candidate(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 979 | } |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 980 | void OnIceCandidateError(const std::string& host_candidate, |
| 981 | const std::string& url, |
| 982 | int error_code, |
| 983 | const std::string& error_text) override { |
| 984 | error_event_ = cricket::IceCandidateErrorEvent(host_candidate, url, |
| 985 | error_code, error_text); |
| 986 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 987 | void OnDataChannel( |
| 988 | rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 989 | RTC_LOG(LS_INFO) << debug_name_ << ": OnDataChannel"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 990 | data_channel_ = data_channel; |
| 991 | data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 992 | } |
| 993 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 994 | std::string debug_name_; |
| 995 | |
| 996 | std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 997 | // Reference to the mDNS responder owned by |fake_network_manager_| after set. |
| 998 | webrtc::FakeMdnsResponder* mdns_responder_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 999 | |
| 1000 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 1001 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 1002 | peer_connection_factory_; |
| 1003 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1004 | cricket::PortAllocator* port_allocator_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1005 | // Needed to keep track of number of frames sent. |
| 1006 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
| 1007 | // Needed to keep track of number of frames received. |
| 1008 | std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1009 | fake_video_renderers_; |
| 1010 | // Needed to ensure frames aren't received for removed tracks. |
| 1011 | std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1012 | removed_fake_video_renderers_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1013 | |
| 1014 | // For remote peer communication. |
| 1015 | SignalingMessageReceiver* signaling_message_receiver_ = nullptr; |
| 1016 | int signaling_delay_ms_ = 0; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1017 | bool signal_ice_candidates_ = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 1018 | cricket::Candidate last_candidate_gathered_; |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 1019 | cricket::IceCandidateErrorEvent error_event_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1020 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1021 | // 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] | 1022 | // them, if required. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1023 | std::vector<rtc::scoped_refptr<webrtc::VideoTrackSource>> |
| 1024 | video_track_sources_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1025 | // |local_video_renderer_| attached to the first created local video track. |
| 1026 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; |
| 1027 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1028 | SdpSemantics sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1029 | PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; |
| 1030 | std::function<void(cricket::SessionDescription*)> received_sdp_munger_; |
| 1031 | std::function<void(cricket::SessionDescription*)> generated_sdp_munger_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1032 | std::function<void()> remote_offer_handler_; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1033 | rtc::MockAsyncResolver* remote_async_resolver_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1034 | rtc::scoped_refptr<DataChannelInterface> data_channel_; |
| 1035 | std::unique_ptr<MockDataChannelObserver> data_observer_; |
| 1036 | |
| 1037 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
| 1038 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1039 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1040 | ice_connection_state_history_; |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 1041 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1042 | standardized_ice_connection_state_history_; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 1043 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 1044 | peer_connection_state_history_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1045 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 1046 | ice_gathering_state_history_; |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 1047 | std::vector<cricket::CandidatePairChangeEvent> |
| 1048 | ice_candidate_pair_change_history_; |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 1049 | std::vector<PeerConnectionInterface::SignalingState> |
| 1050 | peer_connection_signaling_state_history_; |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1051 | webrtc::FakeRtcEventLogFactory* event_log_factory_; |
| 1052 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1053 | rtc::AsyncInvoker invoker_; |
| 1054 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1055 | friend class PeerConnectionIntegrationBaseTest; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1056 | }; |
| 1057 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 1058 | class MockRtcEventLogOutput : public webrtc::RtcEventLogOutput { |
| 1059 | public: |
| 1060 | virtual ~MockRtcEventLogOutput() = default; |
| 1061 | MOCK_CONST_METHOD0(IsActive, bool()); |
| 1062 | MOCK_METHOD1(Write, bool(const std::string&)); |
| 1063 | }; |
| 1064 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1065 | // This helper object is used for both specifying how many audio/video frames |
| 1066 | // are expected to be received for a caller/callee. It provides helper functions |
| 1067 | // to specify these expectations. The object initially starts in a state of no |
| 1068 | // expectations. |
| 1069 | class MediaExpectations { |
| 1070 | public: |
| 1071 | enum ExpectFrames { |
| 1072 | kExpectSomeFrames, |
| 1073 | kExpectNoFrames, |
| 1074 | kNoExpectation, |
| 1075 | }; |
| 1076 | |
| 1077 | void ExpectBidirectionalAudioAndVideo() { |
| 1078 | ExpectBidirectionalAudio(); |
| 1079 | ExpectBidirectionalVideo(); |
| 1080 | } |
| 1081 | |
| 1082 | void ExpectBidirectionalAudio() { |
| 1083 | CallerExpectsSomeAudio(); |
| 1084 | CalleeExpectsSomeAudio(); |
| 1085 | } |
| 1086 | |
| 1087 | void ExpectNoAudio() { |
| 1088 | CallerExpectsNoAudio(); |
| 1089 | CalleeExpectsNoAudio(); |
| 1090 | } |
| 1091 | |
| 1092 | void ExpectBidirectionalVideo() { |
| 1093 | CallerExpectsSomeVideo(); |
| 1094 | CalleeExpectsSomeVideo(); |
| 1095 | } |
| 1096 | |
| 1097 | void ExpectNoVideo() { |
| 1098 | CallerExpectsNoVideo(); |
| 1099 | CalleeExpectsNoVideo(); |
| 1100 | } |
| 1101 | |
| 1102 | void CallerExpectsSomeAudioAndVideo() { |
| 1103 | CallerExpectsSomeAudio(); |
| 1104 | CallerExpectsSomeVideo(); |
| 1105 | } |
| 1106 | |
| 1107 | void CalleeExpectsSomeAudioAndVideo() { |
| 1108 | CalleeExpectsSomeAudio(); |
| 1109 | CalleeExpectsSomeVideo(); |
| 1110 | } |
| 1111 | |
| 1112 | // Caller's audio functions. |
| 1113 | void CallerExpectsSomeAudio( |
| 1114 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1115 | caller_audio_expectation_ = kExpectSomeFrames; |
| 1116 | caller_audio_frames_expected_ = expected_audio_frames; |
| 1117 | } |
| 1118 | |
| 1119 | void CallerExpectsNoAudio() { |
| 1120 | caller_audio_expectation_ = kExpectNoFrames; |
| 1121 | caller_audio_frames_expected_ = 0; |
| 1122 | } |
| 1123 | |
| 1124 | // Caller's video functions. |
| 1125 | void CallerExpectsSomeVideo( |
| 1126 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1127 | caller_video_expectation_ = kExpectSomeFrames; |
| 1128 | caller_video_frames_expected_ = expected_video_frames; |
| 1129 | } |
| 1130 | |
| 1131 | void CallerExpectsNoVideo() { |
| 1132 | caller_video_expectation_ = kExpectNoFrames; |
| 1133 | caller_video_frames_expected_ = 0; |
| 1134 | } |
| 1135 | |
| 1136 | // Callee's audio functions. |
| 1137 | void CalleeExpectsSomeAudio( |
| 1138 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1139 | callee_audio_expectation_ = kExpectSomeFrames; |
| 1140 | callee_audio_frames_expected_ = expected_audio_frames; |
| 1141 | } |
| 1142 | |
| 1143 | void CalleeExpectsNoAudio() { |
| 1144 | callee_audio_expectation_ = kExpectNoFrames; |
| 1145 | callee_audio_frames_expected_ = 0; |
| 1146 | } |
| 1147 | |
| 1148 | // Callee's video functions. |
| 1149 | void CalleeExpectsSomeVideo( |
| 1150 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1151 | callee_video_expectation_ = kExpectSomeFrames; |
| 1152 | callee_video_frames_expected_ = expected_video_frames; |
| 1153 | } |
| 1154 | |
| 1155 | void CalleeExpectsNoVideo() { |
| 1156 | callee_video_expectation_ = kExpectNoFrames; |
| 1157 | callee_video_frames_expected_ = 0; |
| 1158 | } |
| 1159 | |
| 1160 | ExpectFrames caller_audio_expectation_ = kNoExpectation; |
| 1161 | ExpectFrames caller_video_expectation_ = kNoExpectation; |
| 1162 | ExpectFrames callee_audio_expectation_ = kNoExpectation; |
| 1163 | ExpectFrames callee_video_expectation_ = kNoExpectation; |
| 1164 | int caller_audio_frames_expected_ = 0; |
| 1165 | int caller_video_frames_expected_ = 0; |
| 1166 | int callee_audio_frames_expected_ = 0; |
| 1167 | int callee_video_frames_expected_ = 0; |
| 1168 | }; |
| 1169 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 1170 | class MockIceTransport : public webrtc::IceTransportInterface { |
| 1171 | public: |
| 1172 | MockIceTransport(const std::string& name, int component) |
| 1173 | : internal_(std::make_unique<cricket::FakeIceTransport>( |
| 1174 | name, |
| 1175 | component, |
| 1176 | nullptr /* network_thread */)) {} |
| 1177 | ~MockIceTransport() = default; |
| 1178 | cricket::IceTransportInternal* internal() { return internal_.get(); } |
| 1179 | |
| 1180 | private: |
| 1181 | std::unique_ptr<cricket::FakeIceTransport> internal_; |
| 1182 | }; |
| 1183 | |
| 1184 | class MockIceTransportFactory : public IceTransportFactory { |
| 1185 | public: |
| 1186 | ~MockIceTransportFactory() override = default; |
| 1187 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 1188 | const std::string& transport_name, |
| 1189 | int component, |
| 1190 | IceTransportInit init) { |
| 1191 | RecordIceTransportCreated(); |
| 1192 | return new rtc::RefCountedObject<MockIceTransport>(transport_name, |
| 1193 | component); |
| 1194 | } |
| 1195 | MOCK_METHOD0(RecordIceTransportCreated, void()); |
| 1196 | }; |
| 1197 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1198 | // Tests two PeerConnections connecting to each other end-to-end, using a |
| 1199 | // virtual network, fake A/V capture and fake encoder/decoders. The |
| 1200 | // PeerConnections share the threads/socket servers, but use separate versions |
| 1201 | // of everything else (including "PeerConnectionFactory"s). |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 1202 | class PeerConnectionIntegrationBaseTest : public ::testing::Test { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1203 | public: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1204 | explicit PeerConnectionIntegrationBaseTest(SdpSemantics sdp_semantics) |
| 1205 | : sdp_semantics_(sdp_semantics), |
| 1206 | ss_(new rtc::VirtualSocketServer()), |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1207 | fss_(new rtc::FirewallSocketServer(ss_.get())), |
| 1208 | network_thread_(new rtc::Thread(fss_.get())), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1209 | worker_thread_(rtc::Thread::Create()), |
| 1210 | loopback_media_transports_(network_thread_.get()) { |
Sebastian Jansson | 8a793a0 | 2018-03-13 15:21:48 +0100 | [diff] [blame] | 1211 | network_thread_->SetName("PCNetworkThread", this); |
| 1212 | worker_thread_->SetName("PCWorkerThread", this); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1213 | RTC_CHECK(network_thread_->Start()); |
| 1214 | RTC_CHECK(worker_thread_->Start()); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1215 | webrtc::metrics::Reset(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1218 | ~PeerConnectionIntegrationBaseTest() { |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1219 | // The PeerConnections should deleted before the TurnCustomizers. |
| 1220 | // A TurnPort is created with a raw pointer to a TurnCustomizer. The |
| 1221 | // TurnPort has the same lifetime as the PeerConnection, so it's expected |
| 1222 | // that the TurnCustomizer outlives the life of the PeerConnection or else |
| 1223 | // when Send() is called it will hit a seg fault. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1224 | if (caller_) { |
| 1225 | caller_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1226 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1227 | } |
| 1228 | if (callee_) { |
| 1229 | callee_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1230 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1231 | } |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1232 | |
| 1233 | // If turn servers were created for the test they need to be destroyed on |
| 1234 | // the network thread. |
| 1235 | network_thread()->Invoke<void>(RTC_FROM_HERE, [this] { |
| 1236 | turn_servers_.clear(); |
| 1237 | turn_customizers_.clear(); |
| 1238 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | bool SignalingStateStable() { |
| 1242 | return caller_->SignalingStateStable() && callee_->SignalingStateStable(); |
| 1243 | } |
| 1244 | |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1245 | bool DtlsConnected() { |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1246 | // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS |
| 1247 | // are connected. This is an important distinction. Once we have separate |
| 1248 | // ICE and DTLS state, this check needs to use the DTLS state. |
| 1249 | return (callee()->ice_connection_state() == |
| 1250 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1251 | callee()->ice_connection_state() == |
| 1252 | webrtc::PeerConnectionInterface::kIceConnectionCompleted) && |
| 1253 | (caller()->ice_connection_state() == |
| 1254 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1255 | caller()->ice_connection_state() == |
| 1256 | webrtc::PeerConnectionInterface::kIceConnectionCompleted); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1259 | // When |event_log_factory| is null, the default implementation of the event |
| 1260 | // log factory will be used. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1261 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWrapper( |
| 1262 | const std::string& debug_name, |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1263 | const PeerConnectionFactory::Options* options, |
| 1264 | const RTCConfiguration* config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1265 | webrtc::PeerConnectionDependencies dependencies, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1266 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 1267 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1268 | RTCConfiguration modified_config; |
| 1269 | if (config) { |
| 1270 | modified_config = *config; |
| 1271 | } |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1272 | modified_config.sdp_semantics = sdp_semantics_; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1273 | if (!dependencies.cert_generator) { |
| 1274 | dependencies.cert_generator = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1275 | std::make_unique<FakeRTCCertificateGenerator>(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1276 | } |
| 1277 | std::unique_ptr<PeerConnectionWrapper> client( |
| 1278 | new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1279 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1280 | if (!client->Init(options, &modified_config, std::move(dependencies), |
| 1281 | network_thread_.get(), worker_thread_.get(), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1282 | std::move(event_log_factory), |
| 1283 | std::move(media_transport_factory))) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1284 | return nullptr; |
| 1285 | } |
| 1286 | return client; |
| 1287 | } |
| 1288 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1289 | std::unique_ptr<PeerConnectionWrapper> |
| 1290 | CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1291 | const std::string& debug_name, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1292 | const PeerConnectionFactory::Options* options, |
| 1293 | const RTCConfiguration* config, |
| 1294 | webrtc::PeerConnectionDependencies dependencies) { |
| 1295 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory( |
| 1296 | new webrtc::FakeRtcEventLogFactory(rtc::Thread::Current())); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1297 | return CreatePeerConnectionWrapper(debug_name, options, config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1298 | std::move(dependencies), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1299 | std::move(event_log_factory), |
| 1300 | /*media_transport_factory=*/nullptr); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1303 | bool CreatePeerConnectionWrappers() { |
| 1304 | return CreatePeerConnectionWrappersWithConfig( |
| 1305 | PeerConnectionInterface::RTCConfiguration(), |
| 1306 | PeerConnectionInterface::RTCConfiguration()); |
| 1307 | } |
| 1308 | |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1309 | bool CreatePeerConnectionWrappersWithSdpSemantics( |
| 1310 | SdpSemantics caller_semantics, |
| 1311 | SdpSemantics callee_semantics) { |
| 1312 | // Can't specify the sdp_semantics in the passed-in configuration since it |
| 1313 | // will be overwritten by CreatePeerConnectionWrapper with whatever is |
| 1314 | // stored in sdp_semantics_. So get around this by modifying the instance |
| 1315 | // variable before calling CreatePeerConnectionWrapper for the caller and |
| 1316 | // callee PeerConnections. |
| 1317 | SdpSemantics original_semantics = sdp_semantics_; |
| 1318 | sdp_semantics_ = caller_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1319 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1320 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1321 | nullptr, /*media_transport_factory=*/nullptr); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1322 | sdp_semantics_ = callee_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1323 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1324 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1325 | nullptr, /*media_transport_factory=*/nullptr); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1326 | sdp_semantics_ = original_semantics; |
| 1327 | return caller_ && callee_; |
| 1328 | } |
| 1329 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1330 | bool CreatePeerConnectionWrappersWithConfig( |
| 1331 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1332 | const PeerConnectionInterface::RTCConfiguration& callee_config) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1333 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1334 | "Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1335 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1336 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1337 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1338 | "Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1339 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1340 | /*media_transport_factory=*/nullptr); |
| 1341 | return caller_ && callee_; |
| 1342 | } |
| 1343 | |
| 1344 | bool CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 1345 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1346 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1347 | std::unique_ptr<webrtc::MediaTransportFactory> caller_factory, |
| 1348 | std::unique_ptr<webrtc::MediaTransportFactory> callee_factory) { |
| 1349 | caller_ = |
| 1350 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
| 1351 | webrtc::PeerConnectionDependencies(nullptr), |
| 1352 | nullptr, std::move(caller_factory)); |
| 1353 | callee_ = |
| 1354 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
| 1355 | webrtc::PeerConnectionDependencies(nullptr), |
| 1356 | nullptr, std::move(callee_factory)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1357 | return caller_ && callee_; |
| 1358 | } |
| 1359 | |
| 1360 | bool CreatePeerConnectionWrappersWithConfigAndDeps( |
| 1361 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1362 | webrtc::PeerConnectionDependencies caller_dependencies, |
| 1363 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1364 | webrtc::PeerConnectionDependencies callee_dependencies) { |
| 1365 | caller_ = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1366 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1367 | std::move(caller_dependencies), nullptr, |
| 1368 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1369 | callee_ = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1370 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1371 | std::move(callee_dependencies), nullptr, |
| 1372 | /*media_transport_factory=*/nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1373 | return caller_ && callee_; |
| 1374 | } |
| 1375 | |
| 1376 | bool CreatePeerConnectionWrappersWithOptions( |
| 1377 | const PeerConnectionFactory::Options& caller_options, |
| 1378 | const PeerConnectionFactory::Options& callee_options) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1379 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1380 | "Caller", &caller_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1381 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1382 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1383 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1384 | "Callee", &callee_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1385 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1386 | /*media_transport_factory=*/nullptr); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1387 | return caller_ && callee_; |
| 1388 | } |
| 1389 | |
| 1390 | bool CreatePeerConnectionWrappersWithFakeRtcEventLog() { |
| 1391 | PeerConnectionInterface::RTCConfiguration default_config; |
| 1392 | caller_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1393 | "Caller", nullptr, &default_config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1394 | webrtc::PeerConnectionDependencies(nullptr)); |
| 1395 | callee_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1396 | "Callee", nullptr, &default_config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1397 | webrtc::PeerConnectionDependencies(nullptr)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1398 | return caller_ && callee_; |
| 1399 | } |
| 1400 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1401 | std::unique_ptr<PeerConnectionWrapper> |
| 1402 | CreatePeerConnectionWrapperWithAlternateKey() { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1403 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 1404 | new FakeRTCCertificateGenerator()); |
| 1405 | cert_generator->use_alternate_key(); |
| 1406 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1407 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 1408 | dependencies.cert_generator = std::move(cert_generator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1409 | return CreatePeerConnectionWrapper("New Peer", nullptr, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1410 | std::move(dependencies), nullptr, |
| 1411 | /*media_transport_factory=*/nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1414 | cricket::TestTurnServer* CreateTurnServer( |
| 1415 | rtc::SocketAddress internal_address, |
| 1416 | rtc::SocketAddress external_address, |
| 1417 | cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP, |
| 1418 | const std::string& common_name = "test turn server") { |
| 1419 | rtc::Thread* thread = network_thread(); |
| 1420 | std::unique_ptr<cricket::TestTurnServer> turn_server = |
| 1421 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnServer>>( |
| 1422 | RTC_FROM_HERE, |
| 1423 | [thread, internal_address, external_address, type, common_name] { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1424 | return std::make_unique<cricket::TestTurnServer>( |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1425 | thread, internal_address, external_address, type, |
| 1426 | /*ignore_bad_certs=*/true, common_name); |
| 1427 | }); |
| 1428 | turn_servers_.push_back(std::move(turn_server)); |
| 1429 | // Interactions with the turn server should be done on the network thread. |
| 1430 | return turn_servers_.back().get(); |
| 1431 | } |
| 1432 | |
| 1433 | cricket::TestTurnCustomizer* CreateTurnCustomizer() { |
| 1434 | std::unique_ptr<cricket::TestTurnCustomizer> turn_customizer = |
| 1435 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnCustomizer>>( |
| 1436 | RTC_FROM_HERE, |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1437 | [] { return std::make_unique<cricket::TestTurnCustomizer>(); }); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1438 | turn_customizers_.push_back(std::move(turn_customizer)); |
| 1439 | // Interactions with the turn customizer should be done on the network |
| 1440 | // thread. |
| 1441 | return turn_customizers_.back().get(); |
| 1442 | } |
| 1443 | |
| 1444 | // Checks that the function counters for a TestTurnCustomizer are greater than |
| 1445 | // 0. |
| 1446 | void ExpectTurnCustomizerCountersIncremented( |
| 1447 | cricket::TestTurnCustomizer* turn_customizer) { |
| 1448 | unsigned int allow_channel_data_counter = |
| 1449 | network_thread()->Invoke<unsigned int>( |
| 1450 | RTC_FROM_HERE, [turn_customizer] { |
| 1451 | return turn_customizer->allow_channel_data_cnt_; |
| 1452 | }); |
| 1453 | EXPECT_GT(allow_channel_data_counter, 0u); |
| 1454 | unsigned int modify_counter = network_thread()->Invoke<unsigned int>( |
| 1455 | RTC_FROM_HERE, |
| 1456 | [turn_customizer] { return turn_customizer->modify_cnt_; }); |
| 1457 | EXPECT_GT(modify_counter, 0u); |
| 1458 | } |
| 1459 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1460 | // Once called, SDP blobs and ICE candidates will be automatically signaled |
| 1461 | // between PeerConnections. |
| 1462 | void ConnectFakeSignaling() { |
| 1463 | caller_->set_signaling_message_receiver(callee_.get()); |
| 1464 | callee_->set_signaling_message_receiver(caller_.get()); |
| 1465 | } |
| 1466 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1467 | // Once called, SDP blobs will be automatically signaled between |
| 1468 | // PeerConnections. Note that ICE candidates will not be signaled unless they |
| 1469 | // are in the exchanged SDP blobs. |
| 1470 | void ConnectFakeSignalingForSdpOnly() { |
| 1471 | ConnectFakeSignaling(); |
| 1472 | SetSignalIceCandidates(false); |
| 1473 | } |
| 1474 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1475 | void SetSignalingDelayMs(int delay_ms) { |
| 1476 | caller_->set_signaling_delay_ms(delay_ms); |
| 1477 | callee_->set_signaling_delay_ms(delay_ms); |
| 1478 | } |
| 1479 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1480 | void SetSignalIceCandidates(bool signal) { |
| 1481 | caller_->set_signal_ice_candidates(signal); |
| 1482 | callee_->set_signal_ice_candidates(signal); |
| 1483 | } |
| 1484 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1485 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1486 | // times to avoid test flakiness. |
| 1487 | void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc, |
| 1488 | const std::string& data, |
| 1489 | int retries) { |
| 1490 | for (int i = 0; i < retries; ++i) { |
| 1491 | dc->Send(DataBuffer(data)); |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | rtc::Thread* network_thread() { return network_thread_.get(); } |
| 1496 | |
| 1497 | rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1498 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1499 | webrtc::MediaTransportPair* loopback_media_transports() { |
| 1500 | return &loopback_media_transports_; |
| 1501 | } |
| 1502 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1503 | PeerConnectionWrapper* caller() { return caller_.get(); } |
| 1504 | |
| 1505 | // Set the |caller_| to the |wrapper| passed in and return the |
| 1506 | // original |caller_|. |
| 1507 | PeerConnectionWrapper* SetCallerPcWrapperAndReturnCurrent( |
| 1508 | PeerConnectionWrapper* wrapper) { |
| 1509 | PeerConnectionWrapper* old = caller_.release(); |
| 1510 | caller_.reset(wrapper); |
| 1511 | return old; |
| 1512 | } |
| 1513 | |
| 1514 | PeerConnectionWrapper* callee() { return callee_.get(); } |
| 1515 | |
| 1516 | // Set the |callee_| to the |wrapper| passed in and return the |
| 1517 | // original |callee_|. |
| 1518 | PeerConnectionWrapper* SetCalleePcWrapperAndReturnCurrent( |
| 1519 | PeerConnectionWrapper* wrapper) { |
| 1520 | PeerConnectionWrapper* old = callee_.release(); |
| 1521 | callee_.reset(wrapper); |
| 1522 | return old; |
| 1523 | } |
| 1524 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1525 | void SetPortAllocatorFlags(uint32_t caller_flags, uint32_t callee_flags) { |
| 1526 | network_thread()->Invoke<void>( |
| 1527 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1528 | caller()->port_allocator(), caller_flags)); |
| 1529 | network_thread()->Invoke<void>( |
| 1530 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1531 | callee()->port_allocator(), callee_flags)); |
| 1532 | } |
| 1533 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1534 | rtc::FirewallSocketServer* firewall() const { return fss_.get(); } |
| 1535 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1536 | // Expects the provided number of new frames to be received within |
| 1537 | // kMaxWaitForFramesMs. The new expected frames are specified in |
| 1538 | // |media_expectations|. Returns false if any of the expectations were |
| 1539 | // not met. |
| 1540 | bool ExpectNewFrames(const MediaExpectations& media_expectations) { |
| 1541 | // First initialize the expected frame counts based upon the current |
| 1542 | // frame count. |
| 1543 | int total_caller_audio_frames_expected = caller()->audio_frames_received(); |
| 1544 | if (media_expectations.caller_audio_expectation_ == |
| 1545 | MediaExpectations::kExpectSomeFrames) { |
| 1546 | total_caller_audio_frames_expected += |
| 1547 | media_expectations.caller_audio_frames_expected_; |
| 1548 | } |
| 1549 | int total_caller_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1550 | caller()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1551 | if (media_expectations.caller_video_expectation_ == |
| 1552 | MediaExpectations::kExpectSomeFrames) { |
| 1553 | total_caller_video_frames_expected += |
| 1554 | media_expectations.caller_video_frames_expected_; |
| 1555 | } |
| 1556 | int total_callee_audio_frames_expected = callee()->audio_frames_received(); |
| 1557 | if (media_expectations.callee_audio_expectation_ == |
| 1558 | MediaExpectations::kExpectSomeFrames) { |
| 1559 | total_callee_audio_frames_expected += |
| 1560 | media_expectations.callee_audio_frames_expected_; |
| 1561 | } |
| 1562 | int total_callee_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1563 | callee()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1564 | if (media_expectations.callee_video_expectation_ == |
| 1565 | MediaExpectations::kExpectSomeFrames) { |
| 1566 | total_callee_video_frames_expected += |
| 1567 | media_expectations.callee_video_frames_expected_; |
| 1568 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1569 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1570 | // Wait for the expected frames. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1571 | EXPECT_TRUE_WAIT(caller()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1572 | total_caller_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1573 | caller()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1574 | total_caller_video_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1575 | callee()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1576 | total_callee_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1577 | callee()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1578 | total_callee_video_frames_expected, |
| 1579 | kMaxWaitForFramesMs); |
| 1580 | bool expectations_correct = |
| 1581 | caller()->audio_frames_received() >= |
| 1582 | total_caller_audio_frames_expected && |
| 1583 | caller()->min_video_frames_received_per_track() >= |
| 1584 | total_caller_video_frames_expected && |
| 1585 | callee()->audio_frames_received() >= |
| 1586 | total_callee_audio_frames_expected && |
| 1587 | callee()->min_video_frames_received_per_track() >= |
| 1588 | total_callee_video_frames_expected; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1589 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1590 | // After the combined wait, print out a more detailed message upon |
| 1591 | // failure. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1592 | EXPECT_GE(caller()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1593 | total_caller_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1594 | EXPECT_GE(caller()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1595 | total_caller_video_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1596 | EXPECT_GE(callee()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1597 | total_callee_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1598 | EXPECT_GE(callee()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1599 | total_callee_video_frames_expected); |
| 1600 | |
| 1601 | // We want to make sure nothing unexpected was received. |
| 1602 | if (media_expectations.caller_audio_expectation_ == |
| 1603 | MediaExpectations::kExpectNoFrames) { |
| 1604 | EXPECT_EQ(caller()->audio_frames_received(), |
| 1605 | total_caller_audio_frames_expected); |
| 1606 | if (caller()->audio_frames_received() != |
| 1607 | total_caller_audio_frames_expected) { |
| 1608 | expectations_correct = false; |
| 1609 | } |
| 1610 | } |
| 1611 | if (media_expectations.caller_video_expectation_ == |
| 1612 | MediaExpectations::kExpectNoFrames) { |
| 1613 | EXPECT_EQ(caller()->min_video_frames_received_per_track(), |
| 1614 | total_caller_video_frames_expected); |
| 1615 | if (caller()->min_video_frames_received_per_track() != |
| 1616 | total_caller_video_frames_expected) { |
| 1617 | expectations_correct = false; |
| 1618 | } |
| 1619 | } |
| 1620 | if (media_expectations.callee_audio_expectation_ == |
| 1621 | MediaExpectations::kExpectNoFrames) { |
| 1622 | EXPECT_EQ(callee()->audio_frames_received(), |
| 1623 | total_callee_audio_frames_expected); |
| 1624 | if (callee()->audio_frames_received() != |
| 1625 | total_callee_audio_frames_expected) { |
| 1626 | expectations_correct = false; |
| 1627 | } |
| 1628 | } |
| 1629 | if (media_expectations.callee_video_expectation_ == |
| 1630 | MediaExpectations::kExpectNoFrames) { |
| 1631 | EXPECT_EQ(callee()->min_video_frames_received_per_track(), |
| 1632 | total_callee_video_frames_expected); |
| 1633 | if (callee()->min_video_frames_received_per_track() != |
| 1634 | total_callee_video_frames_expected) { |
| 1635 | expectations_correct = false; |
| 1636 | } |
| 1637 | } |
| 1638 | return expectations_correct; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 1641 | void ClosePeerConnections() { |
| 1642 | caller()->pc()->Close(); |
| 1643 | callee()->pc()->Close(); |
| 1644 | } |
| 1645 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1646 | void TestNegotiatedCipherSuite( |
| 1647 | const PeerConnectionFactory::Options& caller_options, |
| 1648 | const PeerConnectionFactory::Options& callee_options, |
| 1649 | int expected_cipher_suite) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1650 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options, |
| 1651 | callee_options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1652 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1653 | caller()->AddAudioVideoTracks(); |
| 1654 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1655 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1656 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1657 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1658 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1659 | // TODO(bugs.webrtc.org/9456): Fix it. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1660 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1661 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1662 | expected_cipher_suite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1665 | void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled, |
| 1666 | bool remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1667 | bool aes_ctr_enabled, |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1668 | int expected_cipher_suite) { |
| 1669 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1670 | caller_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1671 | local_gcm_enabled; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1672 | caller_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1673 | aes_ctr_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1674 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1675 | callee_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1676 | remote_gcm_enabled; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1677 | callee_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1678 | aes_ctr_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1679 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1680 | expected_cipher_suite); |
| 1681 | } |
| 1682 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1683 | protected: |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1684 | SdpSemantics sdp_semantics_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1685 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1686 | private: |
| 1687 | // |ss_| is used by |network_thread_| so it must be destroyed later. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1688 | std::unique_ptr<rtc::VirtualSocketServer> ss_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1689 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1690 | // |network_thread_| and |worker_thread_| are used by both |
| 1691 | // |caller_| and |callee_| so they must be destroyed |
| 1692 | // later. |
| 1693 | std::unique_ptr<rtc::Thread> network_thread_; |
| 1694 | std::unique_ptr<rtc::Thread> worker_thread_; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1695 | // The turn servers and turn customizers should be accessed & deleted on the |
| 1696 | // network thread to avoid a race with the socket read/write that occurs |
| 1697 | // on the network thread. |
| 1698 | std::vector<std::unique_ptr<cricket::TestTurnServer>> turn_servers_; |
| 1699 | std::vector<std::unique_ptr<cricket::TestTurnCustomizer>> turn_customizers_; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1700 | webrtc::MediaTransportPair loopback_media_transports_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1701 | std::unique_ptr<PeerConnectionWrapper> caller_; |
| 1702 | std::unique_ptr<PeerConnectionWrapper> callee_; |
| 1703 | }; |
| 1704 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1705 | class PeerConnectionIntegrationTest |
| 1706 | : public PeerConnectionIntegrationBaseTest, |
| 1707 | public ::testing::WithParamInterface<SdpSemantics> { |
| 1708 | protected: |
| 1709 | PeerConnectionIntegrationTest() |
| 1710 | : PeerConnectionIntegrationBaseTest(GetParam()) {} |
| 1711 | }; |
| 1712 | |
| 1713 | class PeerConnectionIntegrationTestPlanB |
| 1714 | : public PeerConnectionIntegrationBaseTest { |
| 1715 | protected: |
| 1716 | PeerConnectionIntegrationTestPlanB() |
| 1717 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {} |
| 1718 | }; |
| 1719 | |
| 1720 | class PeerConnectionIntegrationTestUnifiedPlan |
| 1721 | : public PeerConnectionIntegrationBaseTest { |
| 1722 | protected: |
| 1723 | PeerConnectionIntegrationTestUnifiedPlan() |
| 1724 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 1725 | }; |
| 1726 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1727 | // Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This |
| 1728 | // includes testing that the callback is invoked if an observer is connected |
| 1729 | // after the first packet has already been received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1730 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1731 | RtpReceiverObserverOnFirstPacketReceived) { |
| 1732 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1733 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1734 | caller()->AddAudioVideoTracks(); |
| 1735 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1736 | // Start offer/answer exchange and wait for it to complete. |
| 1737 | caller()->CreateAndSetAndSignalOffer(); |
| 1738 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1739 | // Should be one receiver each for audio/video. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1740 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1741 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1742 | // Wait for all "first packet received" callbacks to be fired. |
| 1743 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1744 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1745 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1746 | return o->first_packet_received(); |
| 1747 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1748 | kMaxWaitForFramesMs); |
| 1749 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1750 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1751 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1752 | return o->first_packet_received(); |
| 1753 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1754 | kMaxWaitForFramesMs); |
| 1755 | // If new observers are set after the first packet was already received, the |
| 1756 | // callback should still be invoked. |
| 1757 | caller()->ResetRtpReceiverObservers(); |
| 1758 | callee()->ResetRtpReceiverObservers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1759 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1760 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1761 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1762 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1763 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1764 | return o->first_packet_received(); |
| 1765 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1766 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1767 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1768 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1769 | return o->first_packet_received(); |
| 1770 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 1774 | public: |
| 1775 | DummyDtmfObserver() : completed_(false) {} |
| 1776 | |
| 1777 | // Implements DtmfSenderObserverInterface. |
| 1778 | void OnToneChange(const std::string& tone) override { |
| 1779 | tones_.push_back(tone); |
| 1780 | if (tone.empty()) { |
| 1781 | completed_ = true; |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | const std::vector<std::string>& tones() const { return tones_; } |
| 1786 | bool completed() const { return completed_; } |
| 1787 | |
| 1788 | private: |
| 1789 | bool completed_; |
| 1790 | std::vector<std::string> tones_; |
| 1791 | }; |
| 1792 | |
| 1793 | // Assumes |sender| already has an audio track added and the offer/answer |
| 1794 | // exchange is done. |
| 1795 | void TestDtmfFromSenderToReceiver(PeerConnectionWrapper* sender, |
| 1796 | PeerConnectionWrapper* receiver) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1797 | // We should be able to get a DTMF sender from the local sender. |
| 1798 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender = |
| 1799 | sender->pc()->GetSenders().at(0)->GetDtmfSender(); |
| 1800 | ASSERT_TRUE(dtmf_sender); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1801 | DummyDtmfObserver observer; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1802 | dtmf_sender->RegisterObserver(&observer); |
| 1803 | |
| 1804 | // Test the DtmfSender object just created. |
| 1805 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 1806 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 1807 | |
| 1808 | EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout); |
| 1809 | std::vector<std::string> tones = {"1", "a", ""}; |
| 1810 | EXPECT_EQ(tones, observer.tones()); |
| 1811 | dtmf_sender->UnregisterObserver(); |
| 1812 | // TODO(deadbeef): Verify the tones were actually received end-to-end. |
| 1813 | } |
| 1814 | |
| 1815 | // Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each |
| 1816 | // direction). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1817 | TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1818 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1819 | ConnectFakeSignaling(); |
| 1820 | // Only need audio for DTMF. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1821 | caller()->AddAudioTrack(); |
| 1822 | callee()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1823 | caller()->CreateAndSetAndSignalOffer(); |
| 1824 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1825 | // DTLS must finish before the DTMF sender can be used reliably. |
| 1826 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1827 | TestDtmfFromSenderToReceiver(caller(), callee()); |
| 1828 | TestDtmfFromSenderToReceiver(callee(), caller()); |
| 1829 | } |
| 1830 | |
| 1831 | // Basic end-to-end test, verifying media can be encoded/transmitted/decoded |
| 1832 | // between two connections, using DTLS-SRTP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1833 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1834 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1835 | ConnectFakeSignaling(); |
Harald Alvestrand | 194939b | 2018-01-24 16:04:13 +0100 | [diff] [blame] | 1836 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1837 | // Do normal offer/answer and wait for some frames to be received in each |
| 1838 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1839 | caller()->AddAudioVideoTracks(); |
| 1840 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1841 | caller()->CreateAndSetAndSignalOffer(); |
| 1842 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1843 | MediaExpectations media_expectations; |
| 1844 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1845 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1846 | EXPECT_LE(2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1847 | webrtc::kEnumCounterKeyProtocolDtls)); |
| 1848 | EXPECT_EQ(0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1849 | webrtc::kEnumCounterKeyProtocolSdes)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | // Uses SDES instead of DTLS for key agreement. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1853 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1854 | PeerConnectionInterface::RTCConfiguration sdes_config; |
| 1855 | sdes_config.enable_dtls_srtp.emplace(false); |
| 1856 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config)); |
| 1857 | ConnectFakeSignaling(); |
| 1858 | |
| 1859 | // Do normal offer/answer and wait for some frames to be received in each |
| 1860 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1861 | caller()->AddAudioVideoTracks(); |
| 1862 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1863 | caller()->CreateAndSetAndSignalOffer(); |
| 1864 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1865 | MediaExpectations media_expectations; |
| 1866 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1867 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1868 | EXPECT_LE(2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1869 | webrtc::kEnumCounterKeyProtocolSdes)); |
| 1870 | EXPECT_EQ(0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1871 | webrtc::kEnumCounterKeyProtocolDtls)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Steve Anton | 9a44b2d | 2019-07-12 12:58:30 -0700 | [diff] [blame] | 1874 | // Basic end-to-end test specifying the |enable_encrypted_rtp_header_extensions| |
| 1875 | // option to offer encrypted versions of all header extensions alongside the |
| 1876 | // unencrypted versions. |
| 1877 | TEST_P(PeerConnectionIntegrationTest, |
| 1878 | EndToEndCallWithEncryptedRtpHeaderExtensions) { |
| 1879 | CryptoOptions crypto_options; |
| 1880 | crypto_options.srtp.enable_encrypted_rtp_header_extensions = true; |
| 1881 | PeerConnectionInterface::RTCConfiguration config; |
| 1882 | config.crypto_options = crypto_options; |
| 1883 | // Note: This allows offering >14 RTP header extensions. |
| 1884 | config.offer_extmap_allow_mixed = true; |
| 1885 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 1886 | ConnectFakeSignaling(); |
| 1887 | |
| 1888 | // Do normal offer/answer and wait for some frames to be received in each |
| 1889 | // direction. |
| 1890 | caller()->AddAudioVideoTracks(); |
| 1891 | callee()->AddAudioVideoTracks(); |
| 1892 | caller()->CreateAndSetAndSignalOffer(); |
| 1893 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1894 | MediaExpectations media_expectations; |
| 1895 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1896 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1897 | } |
| 1898 | |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1899 | // Tests that the GetRemoteAudioSSLCertificate method returns the remote DTLS |
| 1900 | // certificate once the DTLS handshake has finished. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1901 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1902 | GetRemoteAudioSSLCertificateReturnsExchangedCertificate) { |
| 1903 | auto GetRemoteAudioSSLCertificate = [](PeerConnectionWrapper* wrapper) { |
| 1904 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1905 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1906 | return pc->GetRemoteAudioSSLCertificate(); |
| 1907 | }; |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1908 | auto GetRemoteAudioSSLCertChain = [](PeerConnectionWrapper* wrapper) { |
| 1909 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1910 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1911 | return pc->GetRemoteAudioSSLCertChain(); |
| 1912 | }; |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1913 | |
| 1914 | auto caller_cert = rtc::RTCCertificate::FromPEM(kRsaPems[0]); |
| 1915 | auto callee_cert = rtc::RTCCertificate::FromPEM(kRsaPems[1]); |
| 1916 | |
| 1917 | // Configure each side with a known certificate so they can be compared later. |
| 1918 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 1919 | caller_config.enable_dtls_srtp.emplace(true); |
| 1920 | caller_config.certificates.push_back(caller_cert); |
| 1921 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 1922 | callee_config.enable_dtls_srtp.emplace(true); |
| 1923 | callee_config.certificates.push_back(callee_cert); |
| 1924 | ASSERT_TRUE( |
| 1925 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 1926 | ConnectFakeSignaling(); |
| 1927 | |
| 1928 | // When first initialized, there should not be a remote SSL certificate (and |
| 1929 | // calling this method should not crash). |
| 1930 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(caller())); |
| 1931 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(callee())); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1932 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(caller())); |
| 1933 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(callee())); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1934 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1935 | caller()->AddAudioTrack(); |
| 1936 | callee()->AddAudioTrack(); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1937 | caller()->CreateAndSetAndSignalOffer(); |
| 1938 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1939 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 1940 | |
| 1941 | // Once DTLS has been connected, each side should return the other's SSL |
| 1942 | // certificate when calling GetRemoteAudioSSLCertificate. |
| 1943 | |
| 1944 | auto caller_remote_cert = GetRemoteAudioSSLCertificate(caller()); |
| 1945 | ASSERT_TRUE(caller_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1946 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1947 | caller_remote_cert->ToPEMString()); |
| 1948 | |
| 1949 | auto callee_remote_cert = GetRemoteAudioSSLCertificate(callee()); |
| 1950 | ASSERT_TRUE(callee_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1951 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1952 | callee_remote_cert->ToPEMString()); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1953 | |
| 1954 | auto caller_remote_cert_chain = GetRemoteAudioSSLCertChain(caller()); |
| 1955 | ASSERT_TRUE(caller_remote_cert_chain); |
| 1956 | ASSERT_EQ(1U, caller_remote_cert_chain->GetSize()); |
| 1957 | auto remote_cert = &caller_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1958 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1959 | remote_cert->ToPEMString()); |
| 1960 | |
| 1961 | auto callee_remote_cert_chain = GetRemoteAudioSSLCertChain(callee()); |
| 1962 | ASSERT_TRUE(callee_remote_cert_chain); |
| 1963 | ASSERT_EQ(1U, callee_remote_cert_chain->GetSize()); |
| 1964 | remote_cert = &callee_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1965 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1966 | remote_cert->ToPEMString()); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1969 | // This test sets up a call between two parties with a source resolution of |
| 1970 | // 1280x720 and verifies that a 16:9 aspect ratio is received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1971 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1972 | Send1280By720ResolutionAndReceive16To9AspectRatio) { |
| 1973 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1974 | ConnectFakeSignaling(); |
| 1975 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1976 | // Add video tracks with 16:9 aspect ratio, size 1280 x 720. |
| 1977 | webrtc::FakePeriodicVideoSource::Config config; |
| 1978 | config.width = 1280; |
| 1979 | config.height = 720; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 1980 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1981 | caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); |
| 1982 | callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1983 | |
| 1984 | // Do normal offer/answer and wait for at least one frame to be received in |
| 1985 | // each direction. |
| 1986 | caller()->CreateAndSetAndSignalOffer(); |
| 1987 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 1988 | callee()->min_video_frames_received_per_track() > 0, |
| 1989 | kMaxWaitForFramesMs); |
| 1990 | |
| 1991 | // Check rendered aspect ratio. |
| 1992 | EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio()); |
| 1993 | EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio()); |
| 1994 | EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio()); |
| 1995 | EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio()); |
| 1996 | } |
| 1997 | |
| 1998 | // This test sets up an one-way call, with media only from caller to |
| 1999 | // callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2000 | TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2001 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2002 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2003 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2004 | caller()->CreateAndSetAndSignalOffer(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2005 | MediaExpectations media_expectations; |
| 2006 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2007 | media_expectations.CallerExpectsNoAudio(); |
| 2008 | media_expectations.CallerExpectsNoVideo(); |
| 2009 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | // This test sets up a audio call initially, with the callee rejecting video |
| 2013 | // initially. Then later the callee decides to upgrade to audio/video, and |
| 2014 | // initiates a new offer/answer exchange. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2015 | TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2016 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2017 | ConnectFakeSignaling(); |
| 2018 | // Initially, offer an audio/video stream from the caller, but refuse to |
| 2019 | // send/receive video on the callee side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2020 | caller()->AddAudioVideoTracks(); |
| 2021 | callee()->AddAudioTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2022 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2023 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2024 | options.offer_to_receive_video = 0; |
| 2025 | callee()->SetOfferAnswerOptions(options); |
| 2026 | } else { |
| 2027 | callee()->SetRemoteOfferHandler([this] { |
| 2028 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2029 | }); |
| 2030 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2031 | // Do offer/answer and make sure audio is still received end-to-end. |
| 2032 | caller()->CreateAndSetAndSignalOffer(); |
| 2033 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2034 | { |
| 2035 | MediaExpectations media_expectations; |
| 2036 | media_expectations.ExpectBidirectionalAudio(); |
| 2037 | media_expectations.ExpectNoVideo(); |
| 2038 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2039 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2040 | // Sanity check that the callee's description has a rejected video section. |
| 2041 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2042 | const ContentInfo* callee_video_content = |
| 2043 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2044 | ASSERT_NE(nullptr, callee_video_content); |
| 2045 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2046 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2047 | // Now negotiate with video and ensure negotiation succeeds, with video |
| 2048 | // frames and additional audio frames being received. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2049 | callee()->AddVideoTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2050 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2051 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2052 | options.offer_to_receive_video = 1; |
| 2053 | callee()->SetOfferAnswerOptions(options); |
| 2054 | } else { |
| 2055 | callee()->SetRemoteOfferHandler(nullptr); |
| 2056 | caller()->SetRemoteOfferHandler([this] { |
| 2057 | // The caller creates a new transceiver to receive video on when receiving |
| 2058 | // the offer, but by default it is send only. |
| 2059 | auto transceivers = caller()->pc()->GetTransceivers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 2060 | ASSERT_EQ(3U, transceivers.size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2061 | ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO, |
| 2062 | transceivers[2]->receiver()->media_type()); |
| 2063 | transceivers[2]->sender()->SetTrack(caller()->CreateLocalVideoTrack()); |
| 2064 | transceivers[2]->SetDirection(RtpTransceiverDirection::kSendRecv); |
| 2065 | }); |
| 2066 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2067 | callee()->CreateAndSetAndSignalOffer(); |
| 2068 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2069 | { |
| 2070 | // Expect additional audio frames to be received after the upgrade. |
| 2071 | MediaExpectations media_expectations; |
| 2072 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2073 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2074 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2077 | // Simpler than the above test; just add an audio track to an established |
| 2078 | // video-only connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2079 | TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) { |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2080 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2081 | ConnectFakeSignaling(); |
| 2082 | // Do initial offer/answer with just a video track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2083 | caller()->AddVideoTrack(); |
| 2084 | callee()->AddVideoTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2085 | caller()->CreateAndSetAndSignalOffer(); |
| 2086 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2087 | // Now add an audio track and do another offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2088 | caller()->AddAudioTrack(); |
| 2089 | callee()->AddAudioTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2090 | caller()->CreateAndSetAndSignalOffer(); |
| 2091 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2092 | // Ensure both audio and video frames are received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2093 | MediaExpectations media_expectations; |
| 2094 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2095 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2098 | // This test sets up a call that's transferred to a new caller with a different |
| 2099 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2100 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2101 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2102 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2103 | caller()->AddAudioVideoTracks(); |
| 2104 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2105 | caller()->CreateAndSetAndSignalOffer(); |
| 2106 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2107 | |
| 2108 | // Keep the original peer around which will still send packets to the |
| 2109 | // receiving client. These SRTP packets will be dropped. |
| 2110 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2111 | SetCallerPcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2112 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2113 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2114 | // directly above. |
| 2115 | original_peer->pc()->Close(); |
| 2116 | |
| 2117 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2118 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2119 | caller()->CreateAndSetAndSignalOffer(); |
| 2120 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2121 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2122 | MediaExpectations media_expectations; |
| 2123 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2124 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | // This test sets up a call that's transferred to a new callee with a different |
| 2128 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2129 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2130 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2131 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2132 | caller()->AddAudioVideoTracks(); |
| 2133 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2134 | caller()->CreateAndSetAndSignalOffer(); |
| 2135 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2136 | |
| 2137 | // Keep the original peer around which will still send packets to the |
| 2138 | // receiving client. These SRTP packets will be dropped. |
| 2139 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2140 | SetCalleePcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2141 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2142 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2143 | // directly above. |
| 2144 | original_peer->pc()->Close(); |
| 2145 | |
| 2146 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2147 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2148 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2149 | caller()->CreateAndSetAndSignalOffer(); |
| 2150 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2151 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2152 | MediaExpectations media_expectations; |
| 2153 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2154 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | // This test sets up a non-bundled call and negotiates bundling at the same |
| 2158 | // time as starting an ICE restart. When bundling is in effect in the restart, |
| 2159 | // the DTLS-SRTP context should be successfully reset. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2160 | TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2161 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2162 | ConnectFakeSignaling(); |
| 2163 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2164 | caller()->AddAudioVideoTracks(); |
| 2165 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2166 | // Remove the bundle group from the SDP received by the callee. |
| 2167 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2168 | desc->RemoveGroupByName("BUNDLE"); |
| 2169 | }); |
| 2170 | caller()->CreateAndSetAndSignalOffer(); |
| 2171 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2172 | { |
| 2173 | MediaExpectations media_expectations; |
| 2174 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2175 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2176 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2177 | // Now stop removing the BUNDLE group, and trigger an ICE restart. |
| 2178 | callee()->SetReceivedSdpMunger(nullptr); |
| 2179 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2180 | caller()->CreateAndSetAndSignalOffer(); |
| 2181 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2182 | |
| 2183 | // Expect additional frames to be received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2184 | { |
| 2185 | MediaExpectations media_expectations; |
| 2186 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2187 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2188 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | // Test CVO (Coordination of Video Orientation). If a video source is rotated |
| 2192 | // and both peers support the CVO RTP header extension, the actual video frames |
| 2193 | // don't need to be encoded in different resolutions, since the rotation is |
| 2194 | // communicated through the RTP header extension. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2195 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2196 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2197 | ConnectFakeSignaling(); |
| 2198 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2199 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2200 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2201 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2202 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2203 | |
| 2204 | // Wait for video frames to be received by both sides. |
| 2205 | caller()->CreateAndSetAndSignalOffer(); |
| 2206 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2207 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2208 | callee()->min_video_frames_received_per_track() > 0, |
| 2209 | kMaxWaitForFramesMs); |
| 2210 | |
| 2211 | // Ensure that the aspect ratio is unmodified. |
| 2212 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2213 | // not just assumed. |
| 2214 | EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio()); |
| 2215 | EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio()); |
| 2216 | EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio()); |
| 2217 | EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio()); |
| 2218 | // Ensure that the CVO bits were surfaced to the renderer. |
| 2219 | EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation()); |
| 2220 | EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation()); |
| 2221 | } |
| 2222 | |
| 2223 | // Test that when the CVO extension isn't supported, video is rotated the |
| 2224 | // old-fashioned way, by encoding rotated frames. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2225 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2226 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2227 | ConnectFakeSignaling(); |
| 2228 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2229 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2230 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2231 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2232 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2233 | |
| 2234 | // Remove the CVO extension from the offered SDP. |
| 2235 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2236 | cricket::VideoContentDescription* video = |
| 2237 | GetFirstVideoContentDescription(desc); |
| 2238 | video->ClearRtpHeaderExtensions(); |
| 2239 | }); |
| 2240 | // Wait for video frames to be received by both sides. |
| 2241 | caller()->CreateAndSetAndSignalOffer(); |
| 2242 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2243 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2244 | callee()->min_video_frames_received_per_track() > 0, |
| 2245 | kMaxWaitForFramesMs); |
| 2246 | |
| 2247 | // Expect that the aspect ratio is inversed to account for the 90/270 degree |
| 2248 | // rotation. |
| 2249 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2250 | // not just assumed. |
| 2251 | EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio()); |
| 2252 | EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio()); |
| 2253 | EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio()); |
| 2254 | EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio()); |
| 2255 | // Expect that each endpoint is unaware of the rotation of the other endpoint. |
| 2256 | EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation()); |
| 2257 | EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation()); |
| 2258 | } |
| 2259 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2260 | // Test that if the answerer rejects the audio m= section, no audio is sent or |
| 2261 | // received, but video still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2262 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2263 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2264 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2265 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2266 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2267 | // Only add video track for callee, and set offer_to_receive_audio to 0, so |
| 2268 | // it will reject the audio m= section completely. |
| 2269 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2270 | options.offer_to_receive_audio = 0; |
| 2271 | callee()->SetOfferAnswerOptions(options); |
| 2272 | } else { |
| 2273 | // Stopping the audio RtpTransceiver will cause the media section to be |
| 2274 | // rejected in the answer. |
| 2275 | callee()->SetRemoteOfferHandler([this] { |
| 2276 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)->Stop(); |
| 2277 | }); |
| 2278 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2279 | callee()->AddTrack(callee()->CreateLocalVideoTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2280 | // Do offer/answer and wait for successful end-to-end video frames. |
| 2281 | caller()->CreateAndSetAndSignalOffer(); |
| 2282 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2283 | MediaExpectations media_expectations; |
| 2284 | media_expectations.ExpectBidirectionalVideo(); |
| 2285 | media_expectations.ExpectNoAudio(); |
| 2286 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2287 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2288 | // Sanity check that the callee's description has a rejected audio section. |
| 2289 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2290 | const ContentInfo* callee_audio_content = |
| 2291 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2292 | ASSERT_NE(nullptr, callee_audio_content); |
| 2293 | EXPECT_TRUE(callee_audio_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2294 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2295 | // The caller's transceiver should have stopped after receiving the answer. |
| 2296 | EXPECT_TRUE(caller() |
| 2297 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO) |
| 2298 | ->stopped()); |
| 2299 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | // Test that if the answerer rejects the video m= section, no video is sent or |
| 2303 | // received, but audio still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2304 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2305 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2306 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2307 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2308 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2309 | // Only add audio track for callee, and set offer_to_receive_video to 0, so |
| 2310 | // it will reject the video m= section completely. |
| 2311 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2312 | options.offer_to_receive_video = 0; |
| 2313 | callee()->SetOfferAnswerOptions(options); |
| 2314 | } else { |
| 2315 | // Stopping the video RtpTransceiver will cause the media section to be |
| 2316 | // rejected in the answer. |
| 2317 | callee()->SetRemoteOfferHandler([this] { |
| 2318 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2319 | }); |
| 2320 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2321 | callee()->AddTrack(callee()->CreateLocalAudioTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2322 | // Do offer/answer and wait for successful end-to-end audio frames. |
| 2323 | caller()->CreateAndSetAndSignalOffer(); |
| 2324 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2325 | MediaExpectations media_expectations; |
| 2326 | media_expectations.ExpectBidirectionalAudio(); |
| 2327 | media_expectations.ExpectNoVideo(); |
| 2328 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2329 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2330 | // Sanity check that the callee's description has a rejected video section. |
| 2331 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2332 | const ContentInfo* callee_video_content = |
| 2333 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2334 | ASSERT_NE(nullptr, callee_video_content); |
| 2335 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2336 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2337 | // The caller's transceiver should have stopped after receiving the answer. |
| 2338 | EXPECT_TRUE(caller() |
| 2339 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 2340 | ->stopped()); |
| 2341 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | // Test that if the answerer rejects both audio and video m= sections, nothing |
| 2345 | // bad happens. |
| 2346 | // TODO(deadbeef): Test that a data channel still works. Currently this doesn't |
| 2347 | // test anything but the fact that negotiation succeeds, which doesn't mean |
| 2348 | // much. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2349 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2350 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2351 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2352 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2353 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2354 | // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it |
| 2355 | // will reject both audio and video m= sections. |
| 2356 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2357 | options.offer_to_receive_audio = 0; |
| 2358 | options.offer_to_receive_video = 0; |
| 2359 | callee()->SetOfferAnswerOptions(options); |
| 2360 | } else { |
| 2361 | callee()->SetRemoteOfferHandler([this] { |
| 2362 | // Stopping all transceivers will cause all media sections to be rejected. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2363 | for (const auto& transceiver : callee()->pc()->GetTransceivers()) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2364 | transceiver->Stop(); |
| 2365 | } |
| 2366 | }); |
| 2367 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2368 | // Do offer/answer and wait for stable signaling state. |
| 2369 | caller()->CreateAndSetAndSignalOffer(); |
| 2370 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2371 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2372 | // Sanity check that the callee's description has rejected m= sections. |
| 2373 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2374 | const ContentInfo* callee_audio_content = |
| 2375 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2376 | ASSERT_NE(nullptr, callee_audio_content); |
| 2377 | EXPECT_TRUE(callee_audio_content->rejected); |
| 2378 | const ContentInfo* callee_video_content = |
| 2379 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2380 | ASSERT_NE(nullptr, callee_video_content); |
| 2381 | EXPECT_TRUE(callee_video_content->rejected); |
| 2382 | } |
| 2383 | |
| 2384 | // This test sets up an audio and video call between two parties. After the |
| 2385 | // call runs for a while, the caller sends an updated offer with video being |
| 2386 | // rejected. Once the re-negotiation is done, the video flow should stop and |
| 2387 | // the audio flow should continue. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2388 | TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2389 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2390 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2391 | caller()->AddAudioVideoTracks(); |
| 2392 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2393 | caller()->CreateAndSetAndSignalOffer(); |
| 2394 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2395 | { |
| 2396 | MediaExpectations media_expectations; |
| 2397 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2398 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2399 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2400 | // Renegotiate, rejecting the video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2401 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2402 | caller()->SetGeneratedSdpMunger( |
| 2403 | [](cricket::SessionDescription* description) { |
| 2404 | for (cricket::ContentInfo& content : description->contents()) { |
| 2405 | if (cricket::IsVideoContent(&content)) { |
| 2406 | content.rejected = true; |
| 2407 | } |
| 2408 | } |
| 2409 | }); |
| 2410 | } else { |
| 2411 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2412 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2413 | caller()->CreateAndSetAndSignalOffer(); |
| 2414 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2415 | |
| 2416 | // Sanity check that the caller's description has a rejected video section. |
| 2417 | ASSERT_NE(nullptr, caller()->pc()->local_description()); |
| 2418 | const ContentInfo* caller_video_content = |
| 2419 | GetFirstVideoContent(caller()->pc()->local_description()->description()); |
| 2420 | ASSERT_NE(nullptr, caller_video_content); |
| 2421 | EXPECT_TRUE(caller_video_content->rejected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2422 | // Wait for some additional audio frames to be received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2423 | { |
| 2424 | MediaExpectations media_expectations; |
| 2425 | media_expectations.ExpectBidirectionalAudio(); |
| 2426 | media_expectations.ExpectNoVideo(); |
| 2427 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2428 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Taylor Brandstetter | 60c8dc8 | 2018-04-11 15:20:27 -0700 | [diff] [blame] | 2431 | // Do one offer/answer with audio, another that disables it (rejecting the m= |
| 2432 | // section), and another that re-enables it. Regression test for: |
| 2433 | // bugs.webrtc.org/6023 |
| 2434 | TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) { |
| 2435 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2436 | ConnectFakeSignaling(); |
| 2437 | |
| 2438 | // Add audio track, do normal offer/answer. |
| 2439 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 2440 | caller()->CreateLocalAudioTrack(); |
| 2441 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
| 2442 | caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2443 | caller()->CreateAndSetAndSignalOffer(); |
| 2444 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2445 | |
| 2446 | // Remove audio track, and set offer_to_receive_audio to false to cause the |
| 2447 | // m= section to be completely disabled, not just "recvonly". |
| 2448 | caller()->pc()->RemoveTrack(sender); |
| 2449 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2450 | options.offer_to_receive_audio = 0; |
| 2451 | caller()->SetOfferAnswerOptions(options); |
| 2452 | caller()->CreateAndSetAndSignalOffer(); |
| 2453 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2454 | |
| 2455 | // Add the audio track again, expecting negotiation to succeed and frames to |
| 2456 | // flow. |
| 2457 | sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2458 | options.offer_to_receive_audio = 1; |
| 2459 | caller()->SetOfferAnswerOptions(options); |
| 2460 | caller()->CreateAndSetAndSignalOffer(); |
| 2461 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2462 | |
| 2463 | MediaExpectations media_expectations; |
| 2464 | media_expectations.CalleeExpectsSomeAudio(); |
| 2465 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2466 | } |
| 2467 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2468 | // Basic end-to-end test, but without SSRC/MSID signaling. This functionality |
| 2469 | // is needed to support legacy endpoints. |
| 2470 | // TODO(deadbeef): When we support the MID extension and demuxing on MID, also |
| 2471 | // add a test for an end-to-end test without MID signaling either (basically, |
| 2472 | // the minimum acceptable SDP). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2473 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2474 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2475 | ConnectFakeSignaling(); |
| 2476 | // 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] | 2477 | caller()->AddAudioVideoTracks(); |
| 2478 | callee()->AddAudioVideoTracks(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2479 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2480 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2481 | caller()->CreateAndSetAndSignalOffer(); |
| 2482 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2483 | MediaExpectations media_expectations; |
| 2484 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2485 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 2488 | // Basic end-to-end test, without SSRC signaling. This means that the track |
| 2489 | // was created properly and frames are delivered when the MSIDs are communicated |
| 2490 | // with a=msid lines and no a=ssrc lines. |
| 2491 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2492 | EndToEndCallWithoutSsrcSignaling) { |
| 2493 | const char kStreamId[] = "streamId"; |
| 2494 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2495 | ConnectFakeSignaling(); |
| 2496 | // Add just audio tracks. |
| 2497 | caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId}); |
| 2498 | callee()->AddAudioTrack(); |
| 2499 | |
| 2500 | // Remove SSRCs from the received offer SDP. |
| 2501 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids); |
| 2502 | caller()->CreateAndSetAndSignalOffer(); |
| 2503 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2504 | MediaExpectations media_expectations; |
| 2505 | media_expectations.ExpectBidirectionalAudio(); |
| 2506 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2507 | } |
| 2508 | |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2509 | // Tests that video flows between multiple video tracks when SSRCs are not |
| 2510 | // signaled. This exercises the MID RTP header extension which is needed to |
| 2511 | // demux the incoming video tracks. |
| 2512 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2513 | EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) { |
| 2514 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2515 | ConnectFakeSignaling(); |
| 2516 | caller()->AddVideoTrack(); |
| 2517 | caller()->AddVideoTrack(); |
| 2518 | callee()->AddVideoTrack(); |
| 2519 | callee()->AddVideoTrack(); |
| 2520 | |
| 2521 | caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2522 | callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2523 | caller()->CreateAndSetAndSignalOffer(); |
| 2524 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2525 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 2526 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 2527 | |
| 2528 | // Expect video to be received in both directions on both tracks. |
| 2529 | MediaExpectations media_expectations; |
| 2530 | media_expectations.ExpectBidirectionalVideo(); |
| 2531 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2532 | } |
| 2533 | |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 2534 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLinePresent) { |
| 2535 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2536 | ConnectFakeSignaling(); |
| 2537 | caller()->AddAudioTrack(); |
| 2538 | caller()->AddVideoTrack(); |
| 2539 | caller()->CreateAndSetAndSignalOffer(); |
| 2540 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2541 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2542 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2543 | EXPECT_TRUE(callee_receivers[0]->stream_ids().empty()); |
| 2544 | EXPECT_TRUE(callee_receivers[1]->stream_ids().empty()); |
| 2545 | } |
| 2546 | |
| 2547 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLineMissing) { |
| 2548 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2549 | ConnectFakeSignaling(); |
| 2550 | caller()->AddAudioTrack(); |
| 2551 | caller()->AddVideoTrack(); |
| 2552 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2553 | caller()->CreateAndSetAndSignalOffer(); |
| 2554 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2555 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2556 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2557 | ASSERT_EQ(1u, callee_receivers[0]->stream_ids().size()); |
| 2558 | ASSERT_EQ(1u, callee_receivers[1]->stream_ids().size()); |
| 2559 | EXPECT_EQ(callee_receivers[0]->stream_ids()[0], |
| 2560 | callee_receivers[1]->stream_ids()[0]); |
| 2561 | EXPECT_EQ(callee_receivers[0]->streams()[0], |
| 2562 | callee_receivers[1]->streams()[0]); |
| 2563 | } |
| 2564 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2565 | // Test that if two video tracks are sent (from caller to callee, in this test), |
| 2566 | // they're transmitted correctly end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2567 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2568 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2569 | ConnectFakeSignaling(); |
| 2570 | // Add one audio/video stream, and one video-only stream. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2571 | caller()->AddAudioVideoTracks(); |
| 2572 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2573 | caller()->CreateAndSetAndSignalOffer(); |
| 2574 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2575 | ASSERT_EQ(3u, callee()->pc()->GetReceivers().size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2576 | |
| 2577 | MediaExpectations media_expectations; |
| 2578 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2579 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) { |
| 2583 | bool first = true; |
| 2584 | for (cricket::ContentInfo& content : desc->contents()) { |
| 2585 | if (first) { |
| 2586 | first = false; |
| 2587 | continue; |
| 2588 | } |
| 2589 | content.bundle_only = true; |
| 2590 | } |
| 2591 | first = true; |
| 2592 | for (cricket::TransportInfo& transport : desc->transport_infos()) { |
| 2593 | if (first) { |
| 2594 | first = false; |
| 2595 | continue; |
| 2596 | } |
| 2597 | transport.description.ice_ufrag.clear(); |
| 2598 | transport.description.ice_pwd.clear(); |
| 2599 | transport.description.connection_role = cricket::CONNECTIONROLE_NONE; |
| 2600 | transport.description.identity_fingerprint.reset(nullptr); |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | // Test that if applying a true "max bundle" offer, which uses ports of 0, |
| 2605 | // "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and |
| 2606 | // "a=ice-pwd" for all but the audio "m=" section, negotiation still completes |
| 2607 | // successfully and media flows. |
| 2608 | // TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works. |
| 2609 | // TODO(deadbeef): Won't need this test once we start generating actual |
| 2610 | // standards-compliant SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2611 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2612 | EndToEndCallWithSpecCompliantMaxBundleOffer) { |
| 2613 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2614 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2615 | caller()->AddAudioVideoTracks(); |
| 2616 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2617 | // Do the equivalent of setting the port to 0, adding a=bundle-only, and |
| 2618 | // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all |
| 2619 | // but the first m= section. |
| 2620 | callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer); |
| 2621 | caller()->CreateAndSetAndSignalOffer(); |
| 2622 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2623 | MediaExpectations media_expectations; |
| 2624 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2625 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | // Test that we can receive the audio output level from a remote audio track. |
| 2629 | // TODO(deadbeef): Use a fake audio source and verify that the output level is |
| 2630 | // exactly what the source on the other side was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2631 | TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2632 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2633 | ConnectFakeSignaling(); |
| 2634 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2635 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2636 | caller()->CreateAndSetAndSignalOffer(); |
| 2637 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2638 | |
| 2639 | // Get the audio output level stats. Note that the level is not available |
| 2640 | // until an RTCP packet has been received. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2641 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2642 | kMaxWaitForFramesMs); |
| 2643 | } |
| 2644 | |
| 2645 | // Test that an audio input level is reported. |
| 2646 | // TODO(deadbeef): Use a fake audio source and verify that the input level is |
| 2647 | // exactly what the source was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2648 | TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2649 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2650 | ConnectFakeSignaling(); |
| 2651 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2652 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2653 | caller()->CreateAndSetAndSignalOffer(); |
| 2654 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2655 | |
| 2656 | // Get the audio input level stats. The level should be available very |
| 2657 | // soon after the test starts. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2658 | EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2659 | kMaxWaitForStatsMs); |
| 2660 | } |
| 2661 | |
| 2662 | // 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] | 2663 | TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2664 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2665 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2666 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2667 | // Do offer/answer, wait for the callee to receive some frames. |
| 2668 | caller()->CreateAndSetAndSignalOffer(); |
| 2669 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2670 | |
| 2671 | MediaExpectations media_expectations; |
| 2672 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2673 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2674 | |
| 2675 | // Get a handle to the remote tracks created, so they can be used as GetStats |
| 2676 | // filters. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2677 | for (const auto& receiver : callee()->pc()->GetReceivers()) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2678 | // We received frames, so we definitely should have nonzero "received bytes" |
| 2679 | // stats at this point. |
| 2680 | EXPECT_GT(callee()->OldGetStatsForTrack(receiver->track())->BytesReceived(), |
| 2681 | 0); |
| 2682 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | // 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] | 2686 | TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2687 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2688 | ConnectFakeSignaling(); |
| 2689 | auto audio_track = caller()->CreateLocalAudioTrack(); |
| 2690 | auto video_track = caller()->CreateLocalVideoTrack(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2691 | caller()->AddTrack(audio_track); |
| 2692 | caller()->AddTrack(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2693 | // Do offer/answer, wait for the callee to receive some frames. |
| 2694 | caller()->CreateAndSetAndSignalOffer(); |
| 2695 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2696 | MediaExpectations media_expectations; |
| 2697 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2698 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2699 | |
| 2700 | // The callee received frames, so we definitely should have nonzero "sent |
| 2701 | // bytes" stats at this point. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2702 | EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0); |
| 2703 | EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0); |
| 2704 | } |
| 2705 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2706 | // Test that we can get capture start ntp time. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2707 | TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) { |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2708 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2709 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2710 | caller()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2711 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2712 | callee()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2713 | |
| 2714 | // Do offer/answer, wait for the callee to receive some frames. |
| 2715 | caller()->CreateAndSetAndSignalOffer(); |
| 2716 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2717 | |
| 2718 | // Get the remote audio track created on the receiver, so they can be used as |
| 2719 | // GetStats filters. |
Steve Anton | fc85371 | 2018-03-01 13:48:58 -0800 | [diff] [blame] | 2720 | auto receivers = callee()->pc()->GetReceivers(); |
| 2721 | ASSERT_EQ(1u, receivers.size()); |
| 2722 | auto remote_audio_track = receivers[0]->track(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2723 | |
| 2724 | // Get the audio output level stats. Note that the level is not available |
| 2725 | // until an RTCP packet has been received. |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 2726 | EXPECT_TRUE_WAIT( |
| 2727 | callee()->OldGetStatsForTrack(remote_audio_track)->CaptureStartNtpTime() > |
| 2728 | 0, |
| 2729 | 2 * kMaxWaitForFramesMs); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2730 | } |
| 2731 | |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 2732 | // Test that the track ID is associated with all local and remote SSRC stats |
| 2733 | // using the old GetStats() and more than 1 audio and more than 1 video track. |
| 2734 | // This is a regression test for crbug.com/906988 |
| 2735 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2736 | OldGetStatsAssociatesTrackIdForManyMediaSections) { |
| 2737 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2738 | ConnectFakeSignaling(); |
| 2739 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 2740 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 2741 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 2742 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 2743 | caller()->CreateAndSetAndSignalOffer(); |
| 2744 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2745 | |
| 2746 | MediaExpectations media_expectations; |
| 2747 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2748 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 2749 | |
| 2750 | std::vector<std::string> track_ids = { |
| 2751 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 2752 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 2753 | |
| 2754 | auto caller_stats = caller()->OldGetStats(); |
| 2755 | EXPECT_THAT(caller_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 2756 | auto callee_stats = callee()->OldGetStats(); |
| 2757 | EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 2758 | } |
| 2759 | |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2760 | // Test that the new GetStats() returns stats for all outgoing/incoming streams |
| 2761 | // with the correct track IDs if there are more than one audio and more than one |
| 2762 | // video senders/receivers. |
| 2763 | TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) { |
| 2764 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2765 | ConnectFakeSignaling(); |
| 2766 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 2767 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 2768 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 2769 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 2770 | caller()->CreateAndSetAndSignalOffer(); |
| 2771 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2772 | |
| 2773 | MediaExpectations media_expectations; |
| 2774 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2775 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 2776 | |
| 2777 | std::vector<std::string> track_ids = { |
| 2778 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 2779 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 2780 | |
| 2781 | rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report = |
| 2782 | caller()->NewGetStats(); |
| 2783 | ASSERT_TRUE(caller_report); |
| 2784 | auto outbound_stream_stats = |
| 2785 | caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>(); |
| 2786 | ASSERT_EQ(4u, outbound_stream_stats.size()); |
| 2787 | std::vector<std::string> outbound_track_ids; |
| 2788 | for (const auto& stat : outbound_stream_stats) { |
| 2789 | ASSERT_TRUE(stat->bytes_sent.is_defined()); |
| 2790 | EXPECT_LT(0u, *stat->bytes_sent); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 2791 | if (*stat->kind == "video") { |
| 2792 | ASSERT_TRUE(stat->key_frames_encoded.is_defined()); |
| 2793 | EXPECT_GT(*stat->key_frames_encoded, 0u); |
| 2794 | ASSERT_TRUE(stat->frames_encoded.is_defined()); |
| 2795 | EXPECT_GE(*stat->frames_encoded, *stat->key_frames_encoded); |
| 2796 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2797 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 2798 | const auto* track_stat = |
| 2799 | caller_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 2800 | ASSERT_TRUE(track_stat); |
| 2801 | outbound_track_ids.push_back(*track_stat->track_identifier); |
| 2802 | } |
| 2803 | EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 2804 | |
| 2805 | rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report = |
| 2806 | callee()->NewGetStats(); |
| 2807 | ASSERT_TRUE(callee_report); |
| 2808 | auto inbound_stream_stats = |
| 2809 | callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2810 | ASSERT_EQ(4u, inbound_stream_stats.size()); |
| 2811 | std::vector<std::string> inbound_track_ids; |
| 2812 | for (const auto& stat : inbound_stream_stats) { |
| 2813 | ASSERT_TRUE(stat->bytes_received.is_defined()); |
| 2814 | EXPECT_LT(0u, *stat->bytes_received); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 2815 | if (*stat->kind == "video") { |
| 2816 | ASSERT_TRUE(stat->key_frames_decoded.is_defined()); |
| 2817 | EXPECT_GT(*stat->key_frames_decoded, 0u); |
| 2818 | ASSERT_TRUE(stat->frames_decoded.is_defined()); |
| 2819 | EXPECT_GE(*stat->frames_decoded, *stat->key_frames_decoded); |
| 2820 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2821 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 2822 | const auto* track_stat = |
| 2823 | callee_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 2824 | ASSERT_TRUE(track_stat); |
| 2825 | inbound_track_ids.push_back(*track_stat->track_identifier); |
| 2826 | } |
| 2827 | EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 2828 | } |
| 2829 | |
| 2830 | // Test that we can get stats (using the new stats implementation) for |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2831 | // unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in |
| 2832 | // SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2833 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2834 | GetStatsForUnsignaledStreamWithNewStatsApi) { |
| 2835 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2836 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2837 | caller()->AddAudioTrack(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2838 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2839 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2840 | caller()->CreateAndSetAndSignalOffer(); |
| 2841 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2842 | MediaExpectations media_expectations; |
| 2843 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2844 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2845 | |
| 2846 | // We received a frame, so we should have nonzero "bytes received" stats for |
| 2847 | // the unsignaled stream, if stats are working for it. |
| 2848 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2849 | callee()->NewGetStats(); |
| 2850 | ASSERT_NE(nullptr, report); |
| 2851 | auto inbound_stream_stats = |
| 2852 | report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2853 | ASSERT_EQ(1U, inbound_stream_stats.size()); |
| 2854 | ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined()); |
| 2855 | ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2856 | ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined()); |
| 2857 | } |
| 2858 | |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 2859 | // Same as above but for the legacy stats implementation. |
| 2860 | TEST_P(PeerConnectionIntegrationTest, |
| 2861 | GetStatsForUnsignaledStreamWithOldStatsApi) { |
| 2862 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2863 | ConnectFakeSignaling(); |
| 2864 | caller()->AddAudioTrack(); |
| 2865 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2866 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2867 | caller()->CreateAndSetAndSignalOffer(); |
| 2868 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2869 | |
| 2870 | // Note that, since the old stats implementation associates SSRCs with tracks |
| 2871 | // using SDP, when SSRCs aren't signaled in SDP these stats won't have an |
| 2872 | // associated track ID. So we can't use the track "selector" argument. |
| 2873 | // |
| 2874 | // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to |
| 2875 | // 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] | 2876 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0, |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 2877 | kDefaultTimeout); |
| 2878 | } |
| 2879 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2880 | // Test that we can successfully get the media related stats (audio level |
| 2881 | // etc.) for the unsignaled stream. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2882 | TEST_P(PeerConnectionIntegrationTest, |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2883 | GetMediaStatsForUnsignaledStreamWithNewStatsApi) { |
| 2884 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2885 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2886 | caller()->AddAudioVideoTracks(); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2887 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2888 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2889 | caller()->CreateAndSetAndSignalOffer(); |
| 2890 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2891 | MediaExpectations media_expectations; |
| 2892 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2893 | media_expectations.CalleeExpectsSomeVideo(1); |
| 2894 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2895 | |
| 2896 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2897 | callee()->NewGetStats(); |
| 2898 | ASSERT_NE(nullptr, report); |
| 2899 | |
| 2900 | auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2901 | auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats); |
| 2902 | ASSERT_GE(audio_index, 0); |
| 2903 | EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2906 | // Helper for test below. |
| 2907 | void ModifySsrcs(cricket::SessionDescription* desc) { |
| 2908 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2909 | for (StreamParams& stream : |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2910 | content.media_description()->mutable_streams()) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2911 | for (uint32_t& ssrc : stream.ssrcs) { |
| 2912 | ssrc = rtc::CreateRandomId(); |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | // Test that the "RTCMediaSteamTrackStats" object is updated correctly when |
| 2919 | // SSRCs are unsignaled, and the SSRC of the received (audio) stream changes. |
| 2920 | // This should result in two "RTCInboundRTPStreamStats", but only one |
| 2921 | // "RTCMediaStreamTrackStats", whose counters go up continuously rather than |
| 2922 | // being reset to 0 once the SSRC change occurs. |
| 2923 | // |
| 2924 | // Regression test for this bug: |
| 2925 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8158 |
| 2926 | // |
| 2927 | // The bug causes the track stats to only represent one of the two streams: |
| 2928 | // whichever one has the higher SSRC. So with this bug, there was a 50% chance |
| 2929 | // that the track stat counters would reset to 0 when the new stream is |
| 2930 | // received, and a 50% chance that they'll stop updating (while |
| 2931 | // "concealed_samples" continues increasing, due to silence being generated for |
| 2932 | // the inactive stream). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2933 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2934 | TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2935 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2936 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2937 | caller()->AddAudioTrack(); |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2938 | // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint |
| 2939 | // that doesn't signal SSRCs (from the callee's perspective). |
| 2940 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2941 | caller()->CreateAndSetAndSignalOffer(); |
| 2942 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2943 | // 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] | 2944 | { |
| 2945 | MediaExpectations media_expectations; |
| 2946 | media_expectations.CalleeExpectsSomeAudio(50); |
| 2947 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2948 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2949 | // Some audio frames were received, so we should have nonzero "samples |
| 2950 | // received" for the track. |
| 2951 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2952 | callee()->NewGetStats(); |
| 2953 | ASSERT_NE(nullptr, report); |
| 2954 | auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2955 | ASSERT_EQ(1U, track_stats.size()); |
| 2956 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 2957 | ASSERT_GT(*track_stats[0]->total_samples_received, 0U); |
| 2958 | // uint64_t prev_samples_received = *track_stats[0]->total_samples_received; |
| 2959 | |
| 2960 | // Create a new offer and munge it to cause the caller to use a new SSRC. |
| 2961 | caller()->SetGeneratedSdpMunger(ModifySsrcs); |
| 2962 | caller()->CreateAndSetAndSignalOffer(); |
| 2963 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2964 | // Wait for 25 more audio frames (250ms of audio) to be received, from the new |
| 2965 | // SSRC. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2966 | { |
| 2967 | MediaExpectations media_expectations; |
| 2968 | media_expectations.CalleeExpectsSomeAudio(25); |
| 2969 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2970 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2971 | |
| 2972 | report = callee()->NewGetStats(); |
| 2973 | ASSERT_NE(nullptr, report); |
| 2974 | track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2975 | ASSERT_EQ(1U, track_stats.size()); |
| 2976 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 2977 | // The "total samples received" stat should only be greater than it was |
| 2978 | // before. |
| 2979 | // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed. |
| 2980 | // Right now, the new SSRC will cause the counters to reset to 0. |
| 2981 | // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received); |
| 2982 | |
| 2983 | // Additionally, the percentage of concealed samples (samples generated to |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2984 | // 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] | 2985 | // good sign that we're seeing stats from the old stream that's no longer |
| 2986 | // receiving packets, and is generating concealed samples of silence. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2987 | constexpr double kAcceptableConcealedSamplesPercentage = 0.50; |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2988 | ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined()); |
| 2989 | EXPECT_LT(*track_stats[0]->concealed_samples, |
| 2990 | *track_stats[0]->total_samples_received * |
| 2991 | kAcceptableConcealedSamplesPercentage); |
| 2992 | |
| 2993 | // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a |
| 2994 | // sanity check that the SSRC really changed. |
| 2995 | // TODO(deadbeef): This isn't working right now, because we're not returning |
| 2996 | // *any* stats for the inactive stream. Uncomment when the bug is completely |
| 2997 | // fixed. |
| 2998 | // auto inbound_stream_stats = |
| 2999 | // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 3000 | // ASSERT_EQ(2U, inbound_stream_stats.size()); |
| 3001 | } |
| 3002 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3003 | // 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] | 3004 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3005 | PeerConnectionFactory::Options dtls_10_options; |
| 3006 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3007 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 3008 | dtls_10_options)); |
| 3009 | ConnectFakeSignaling(); |
| 3010 | // Do normal offer/answer and wait for some frames to be received in each |
| 3011 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3012 | caller()->AddAudioVideoTracks(); |
| 3013 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3014 | caller()->CreateAndSetAndSignalOffer(); |
| 3015 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3016 | MediaExpectations media_expectations; |
| 3017 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3018 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | // 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] | 3022 | TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3023 | PeerConnectionFactory::Options dtls_10_options; |
| 3024 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3025 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 3026 | dtls_10_options)); |
| 3027 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3028 | caller()->AddAudioVideoTracks(); |
| 3029 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3030 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3031 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3032 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3033 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3034 | kDefaultTimeout); |
| 3035 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3036 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3037 | // TODO(bugs.webrtc.org/9456): Fix it. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 3038 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3039 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 3040 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | // 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] | 3044 | TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3045 | PeerConnectionFactory::Options dtls_12_options; |
| 3046 | dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3047 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options, |
| 3048 | dtls_12_options)); |
| 3049 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3050 | caller()->AddAudioVideoTracks(); |
| 3051 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3052 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3053 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3054 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3055 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3056 | kDefaultTimeout); |
| 3057 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3058 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3059 | // TODO(bugs.webrtc.org/9456): Fix it. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 3060 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3061 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 3062 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | // Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the |
| 3066 | // callee only supports 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3067 | TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3068 | PeerConnectionFactory::Options caller_options; |
| 3069 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3070 | PeerConnectionFactory::Options callee_options; |
| 3071 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3072 | ASSERT_TRUE( |
| 3073 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 3074 | ConnectFakeSignaling(); |
| 3075 | // Do normal offer/answer and wait for some frames to be received in each |
| 3076 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3077 | caller()->AddAudioVideoTracks(); |
| 3078 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3079 | caller()->CreateAndSetAndSignalOffer(); |
| 3080 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3081 | MediaExpectations media_expectations; |
| 3082 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3083 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | // Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the |
| 3087 | // callee supports 1.2. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3088 | TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3089 | PeerConnectionFactory::Options caller_options; |
| 3090 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3091 | PeerConnectionFactory::Options callee_options; |
| 3092 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3093 | ASSERT_TRUE( |
| 3094 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 3095 | ConnectFakeSignaling(); |
| 3096 | // Do normal offer/answer and wait for some frames to be received in each |
| 3097 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3098 | caller()->AddAudioVideoTracks(); |
| 3099 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3100 | caller()->CreateAndSetAndSignalOffer(); |
| 3101 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3102 | MediaExpectations media_expectations; |
| 3103 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3104 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3107 | // The three tests below verify that "enable_aes128_sha1_32_crypto_cipher" |
| 3108 | // works as expected; the cipher should only be used if enabled by both sides. |
| 3109 | TEST_P(PeerConnectionIntegrationTest, |
| 3110 | Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) { |
| 3111 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3112 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3113 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3114 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3115 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3116 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3117 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3118 | expected_cipher_suite); |
| 3119 | } |
| 3120 | |
| 3121 | TEST_P(PeerConnectionIntegrationTest, |
| 3122 | Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) { |
| 3123 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3124 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3125 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3126 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3127 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3128 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3129 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3130 | expected_cipher_suite); |
| 3131 | } |
| 3132 | |
| 3133 | TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) { |
| 3134 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3135 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3136 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3137 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3138 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_32; |
| 3139 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3140 | expected_cipher_suite); |
| 3141 | } |
| 3142 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3143 | // 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] | 3144 | TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3145 | bool local_gcm_enabled = false; |
| 3146 | bool remote_gcm_enabled = false; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3147 | bool aes_ctr_enabled = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3148 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 3149 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3150 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3153 | // Test that a GCM cipher is used if both ends support it and non-GCM is |
| 3154 | // disabled. |
| 3155 | TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenOnlyGcmSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3156 | bool local_gcm_enabled = true; |
| 3157 | bool remote_gcm_enabled = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3158 | bool aes_ctr_enabled = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3159 | int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm; |
| 3160 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3161 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3164 | // Verify that media can be transmitted end-to-end when GCM crypto suites are |
| 3165 | // enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported, |
| 3166 | // only verify that a GCM cipher is negotiated, and not necessarily that SRTP |
| 3167 | // works with it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3168 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3169 | PeerConnectionFactory::Options gcm_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3170 | gcm_options.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3171 | gcm_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = false; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3172 | ASSERT_TRUE( |
| 3173 | CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options)); |
| 3174 | ConnectFakeSignaling(); |
| 3175 | // Do normal offer/answer and wait for some frames to be received in each |
| 3176 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3177 | caller()->AddAudioVideoTracks(); |
| 3178 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3179 | caller()->CreateAndSetAndSignalOffer(); |
| 3180 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3181 | MediaExpectations media_expectations; |
| 3182 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3183 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3186 | // This test sets up a call between two parties with audio, video and an RTP |
| 3187 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3188 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithRtpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3189 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3190 | rtc_config.enable_rtp_data_channel = true; |
| 3191 | rtc_config.enable_dtls_srtp = false; |
| 3192 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3193 | ConnectFakeSignaling(); |
| 3194 | // Expect that data channel created on caller side will show up for callee as |
| 3195 | // well. |
| 3196 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3197 | caller()->AddAudioVideoTracks(); |
| 3198 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3199 | caller()->CreateAndSetAndSignalOffer(); |
| 3200 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3201 | // 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] | 3202 | MediaExpectations media_expectations; |
| 3203 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3204 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3205 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3206 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3207 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3208 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3209 | |
| 3210 | // Ensure data can be sent in both directions. |
| 3211 | std::string data = "hello world"; |
| 3212 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3213 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3214 | kDefaultTimeout); |
| 3215 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3216 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3217 | kDefaultTimeout); |
| 3218 | } |
| 3219 | |
| 3220 | // Ensure that an RTP data channel is signaled as closed for the caller when |
| 3221 | // the callee rejects it in a subsequent offer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3222 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3223 | RtpDataChannelSignaledClosedInCalleeOffer) { |
| 3224 | // Same procedure as above test. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3225 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3226 | rtc_config.enable_rtp_data_channel = true; |
| 3227 | rtc_config.enable_dtls_srtp = false; |
| 3228 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3229 | ConnectFakeSignaling(); |
| 3230 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3231 | caller()->AddAudioVideoTracks(); |
| 3232 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3233 | caller()->CreateAndSetAndSignalOffer(); |
| 3234 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3235 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3236 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3237 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3238 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3239 | |
| 3240 | // Close the data channel on the callee, and do an updated offer/answer. |
| 3241 | callee()->data_channel()->Close(); |
| 3242 | callee()->CreateAndSetAndSignalOffer(); |
| 3243 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3244 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3245 | EXPECT_FALSE(callee()->data_observer()->IsOpen()); |
| 3246 | } |
| 3247 | |
| 3248 | // Tests that data is buffered in an RTP data channel until an observer is |
| 3249 | // registered for it. |
| 3250 | // |
| 3251 | // NOTE: RTP data channels can receive data before the underlying |
| 3252 | // transport has detected that a channel is writable and thus data can be |
| 3253 | // received before the data channel state changes to open. That is hard to test |
| 3254 | // but the same buffering is expected to be used in that case. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3255 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3256 | DataBufferedUntilRtpDataChannelObserverRegistered) { |
| 3257 | // Use fake clock and simulated network delay so that we predictably can wait |
| 3258 | // until an SCTP message has been delivered without "sleep()"ing. |
| 3259 | rtc::ScopedFakeClock fake_clock; |
| 3260 | // Some things use a time of "0" as a special value, so we need to start out |
| 3261 | // the fake clock at a nonzero time. |
| 3262 | // TODO(deadbeef): Fix this. |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 3263 | fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3264 | virtual_socket_server()->set_delay_mean(5); // 5 ms per hop. |
| 3265 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3266 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3267 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3268 | rtc_config.enable_rtp_data_channel = true; |
| 3269 | rtc_config.enable_dtls_srtp = false; |
| 3270 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3271 | ConnectFakeSignaling(); |
| 3272 | caller()->CreateDataChannel(); |
| 3273 | caller()->CreateAndSetAndSignalOffer(); |
| 3274 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
| 3275 | ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr, |
| 3276 | kDefaultTimeout, fake_clock); |
| 3277 | ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(), |
| 3278 | kDefaultTimeout, fake_clock); |
| 3279 | ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen, |
| 3280 | callee()->data_channel()->state(), kDefaultTimeout, |
| 3281 | fake_clock); |
| 3282 | |
| 3283 | // Unregister the observer which is normally automatically registered. |
| 3284 | callee()->data_channel()->UnregisterObserver(); |
| 3285 | // Send data and advance fake clock until it should have been received. |
| 3286 | std::string data = "hello world"; |
| 3287 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3288 | SIMULATED_WAIT(false, 50, fake_clock); |
| 3289 | |
| 3290 | // Attach data channel and expect data to be received immediately. Note that |
| 3291 | // EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any |
| 3292 | // further, but data can be received even if the callback is asynchronous. |
| 3293 | MockDataChannelObserver new_observer(callee()->data_channel()); |
| 3294 | EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout, |
| 3295 | fake_clock); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 3296 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 3297 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 3298 | // 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] | 3299 | ClosePeerConnections(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | // This test sets up a call between two parties with audio, video and but only |
| 3303 | // the caller client supports RTP data channels. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3304 | TEST_P(PeerConnectionIntegrationTest, RtpDataChannelsRejectedByCallee) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3305 | PeerConnectionInterface::RTCConfiguration rtc_config_1; |
| 3306 | rtc_config_1.enable_rtp_data_channel = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3307 | // Must disable DTLS to make negotiation succeed. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3308 | rtc_config_1.enable_dtls_srtp = false; |
| 3309 | PeerConnectionInterface::RTCConfiguration rtc_config_2; |
| 3310 | rtc_config_2.enable_dtls_srtp = false; |
| 3311 | rtc_config_2.enable_dtls_srtp = false; |
| 3312 | ASSERT_TRUE( |
| 3313 | CreatePeerConnectionWrappersWithConfig(rtc_config_1, rtc_config_2)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3314 | ConnectFakeSignaling(); |
| 3315 | caller()->CreateDataChannel(); |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 3316 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3317 | caller()->AddAudioVideoTracks(); |
| 3318 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3319 | caller()->CreateAndSetAndSignalOffer(); |
| 3320 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3321 | // The caller should still have a data channel, but it should be closed, and |
| 3322 | // one should ever have been created for the callee. |
| 3323 | EXPECT_TRUE(caller()->data_channel() != nullptr); |
| 3324 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3325 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 3326 | } |
| 3327 | |
| 3328 | // This test sets up a call between two parties with audio, and video. When |
| 3329 | // 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] | 3330 | TEST_P(PeerConnectionIntegrationTest, AddRtpDataChannelInSubsequentOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3331 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3332 | rtc_config.enable_rtp_data_channel = true; |
| 3333 | rtc_config.enable_dtls_srtp = false; |
| 3334 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3335 | ConnectFakeSignaling(); |
| 3336 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3337 | caller()->AddAudioVideoTracks(); |
| 3338 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3339 | caller()->CreateAndSetAndSignalOffer(); |
| 3340 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3341 | // Create data channel and do new offer and answer. |
| 3342 | caller()->CreateDataChannel(); |
| 3343 | caller()->CreateAndSetAndSignalOffer(); |
| 3344 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3345 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3346 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3347 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3348 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3349 | // Ensure data can be sent in both directions. |
| 3350 | std::string data = "hello world"; |
| 3351 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3352 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3353 | kDefaultTimeout); |
| 3354 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3355 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3356 | kDefaultTimeout); |
| 3357 | } |
| 3358 | |
| 3359 | #ifdef HAVE_SCTP |
| 3360 | |
| 3361 | // This test sets up a call between two parties with audio, video and an SCTP |
| 3362 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3363 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3364 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3365 | ConnectFakeSignaling(); |
| 3366 | // Expect that data channel created on caller side will show up for callee as |
| 3367 | // well. |
| 3368 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3369 | caller()->AddAudioVideoTracks(); |
| 3370 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3371 | caller()->CreateAndSetAndSignalOffer(); |
| 3372 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3373 | // 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] | 3374 | MediaExpectations media_expectations; |
| 3375 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3376 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3377 | // Caller data channel should already exist (it created one). Callee data |
| 3378 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3379 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3380 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3381 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3382 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3383 | |
| 3384 | // Ensure data can be sent in both directions. |
| 3385 | std::string data = "hello world"; |
| 3386 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3387 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3388 | kDefaultTimeout); |
| 3389 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3390 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3391 | kDefaultTimeout); |
| 3392 | } |
| 3393 | |
| 3394 | // Ensure that when the callee closes an SCTP data channel, the closing |
| 3395 | // 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] | 3396 | TEST_P(PeerConnectionIntegrationTest, CalleeClosesSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3397 | // Same procedure as above test. |
| 3398 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3399 | ConnectFakeSignaling(); |
| 3400 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3401 | caller()->AddAudioVideoTracks(); |
| 3402 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3403 | caller()->CreateAndSetAndSignalOffer(); |
| 3404 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3405 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3406 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3407 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3408 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3409 | |
| 3410 | // Close the data channel on the callee side, and wait for it to reach the |
| 3411 | // "closed" state on both sides. |
| 3412 | callee()->data_channel()->Close(); |
| 3413 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3414 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3415 | } |
| 3416 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3417 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelConfigSentToOtherSide) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3418 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3419 | ConnectFakeSignaling(); |
| 3420 | webrtc::DataChannelInit init; |
| 3421 | init.id = 53; |
| 3422 | init.maxRetransmits = 52; |
| 3423 | caller()->CreateDataChannel("data-channel", &init); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3424 | caller()->AddAudioVideoTracks(); |
| 3425 | callee()->AddAudioVideoTracks(); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3426 | caller()->CreateAndSetAndSignalOffer(); |
| 3427 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 074dece | 2017-10-24 13:04:12 -0700 | [diff] [blame] | 3428 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3429 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 3430 | // Since "negotiated" is false, the "id" parameter should be ignored. |
| 3431 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3432 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 3433 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 3434 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 3435 | } |
| 3436 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3437 | // Test usrsctp's ability to process unordered data stream, where data actually |
| 3438 | // arrives out of order using simulated delays. Previously there have been some |
| 3439 | // bugs in this area. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3440 | TEST_P(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3441 | // Introduce random network delays. |
| 3442 | // Otherwise it's not a true "unordered" test. |
| 3443 | virtual_socket_server()->set_delay_mean(20); |
| 3444 | virtual_socket_server()->set_delay_stddev(5); |
| 3445 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3446 | // Normal procedure, but with unordered data channel config. |
| 3447 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3448 | ConnectFakeSignaling(); |
| 3449 | webrtc::DataChannelInit init; |
| 3450 | init.ordered = false; |
| 3451 | caller()->CreateDataChannel(&init); |
| 3452 | caller()->CreateAndSetAndSignalOffer(); |
| 3453 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3454 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3455 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3456 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3457 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3458 | |
| 3459 | static constexpr int kNumMessages = 100; |
| 3460 | // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 3461 | static constexpr size_t kMaxMessageSize = 4096; |
| 3462 | // Create and send random messages. |
| 3463 | std::vector<std::string> sent_messages; |
| 3464 | for (int i = 0; i < kNumMessages; ++i) { |
| 3465 | size_t length = |
| 3466 | (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand) |
| 3467 | std::string message; |
| 3468 | ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 3469 | caller()->data_channel()->Send(DataBuffer(message)); |
| 3470 | callee()->data_channel()->Send(DataBuffer(message)); |
| 3471 | sent_messages.push_back(message); |
| 3472 | } |
| 3473 | |
| 3474 | // Wait for all messages to be received. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3475 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3476 | caller()->data_observer()->received_message_count(), |
| 3477 | kDefaultTimeout); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3478 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3479 | callee()->data_observer()->received_message_count(), |
| 3480 | kDefaultTimeout); |
| 3481 | |
| 3482 | // Sort and compare to make sure none of the messages were corrupted. |
| 3483 | std::vector<std::string> caller_received_messages = |
| 3484 | caller()->data_observer()->messages(); |
| 3485 | std::vector<std::string> callee_received_messages = |
| 3486 | callee()->data_observer()->messages(); |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3487 | absl::c_sort(sent_messages); |
| 3488 | absl::c_sort(caller_received_messages); |
| 3489 | absl::c_sort(callee_received_messages); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3490 | EXPECT_EQ(sent_messages, caller_received_messages); |
| 3491 | EXPECT_EQ(sent_messages, callee_received_messages); |
| 3492 | } |
| 3493 | |
| 3494 | // This test sets up a call between two parties with audio, and video. When |
| 3495 | // 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] | 3496 | TEST_P(PeerConnectionIntegrationTest, AddSctpDataChannelInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3497 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3498 | ConnectFakeSignaling(); |
| 3499 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3500 | caller()->AddAudioVideoTracks(); |
| 3501 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3502 | caller()->CreateAndSetAndSignalOffer(); |
| 3503 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3504 | // Create data channel and do new offer and answer. |
| 3505 | caller()->CreateDataChannel(); |
| 3506 | caller()->CreateAndSetAndSignalOffer(); |
| 3507 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3508 | // Caller data channel should already exist (it created one). Callee data |
| 3509 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3510 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3511 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3512 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3513 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3514 | // Ensure data can be sent in both directions. |
| 3515 | std::string data = "hello world"; |
| 3516 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3517 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3518 | kDefaultTimeout); |
| 3519 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3520 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3521 | kDefaultTimeout); |
| 3522 | } |
| 3523 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3524 | // Set up a connection initially just using SCTP data channels, later upgrading |
| 3525 | // to audio/video, ensuring frames are received end-to-end. Effectively the |
| 3526 | // inverse of the test above. |
| 3527 | // This was broken in M57; see https://crbug.com/711243 |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3528 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelToAudioVideoUpgrade) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3529 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3530 | ConnectFakeSignaling(); |
| 3531 | // Do initial offer/answer with just data channel. |
| 3532 | caller()->CreateDataChannel(); |
| 3533 | caller()->CreateAndSetAndSignalOffer(); |
| 3534 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3535 | // Wait until data can be sent over the data channel. |
| 3536 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3537 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3538 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3539 | |
| 3540 | // Do subsequent offer/answer with two-way audio and video. Audio and video |
| 3541 | // 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] | 3542 | caller()->AddAudioVideoTracks(); |
| 3543 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3544 | caller()->CreateAndSetAndSignalOffer(); |
| 3545 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3546 | MediaExpectations media_expectations; |
| 3547 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3548 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3551 | static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) { |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 3552 | cricket::SctpDataContentDescription* dcd_offer = |
| 3553 | GetFirstSctpDataContentDescription(desc); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3554 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3555 | dcd_offer->set_use_sctpmap(false); |
| 3556 | dcd_offer->set_protocol("UDP/DTLS/SCTP"); |
| 3557 | } |
| 3558 | |
| 3559 | // Test that the data channel works when a spec-compliant SCTP m= section is |
| 3560 | // offered (using "a=sctp-port" instead of "a=sctpmap", and using |
| 3561 | // "UDP/DTLS/SCTP" as the protocol). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3562 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3563 | DataChannelWorksWhenSpecCompliantSctpOfferReceived) { |
| 3564 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3565 | ConnectFakeSignaling(); |
| 3566 | caller()->CreateDataChannel(); |
| 3567 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 3568 | caller()->CreateAndSetAndSignalOffer(); |
| 3569 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3570 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3571 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3572 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3573 | |
| 3574 | // Ensure data can be sent in both directions. |
| 3575 | std::string data = "hello world"; |
| 3576 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3577 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3578 | kDefaultTimeout); |
| 3579 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3580 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3581 | kDefaultTimeout); |
| 3582 | } |
| 3583 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 3584 | // Tests that the datagram transport to SCTP fallback works correctly when |
| 3585 | // datagram transport negotiation fails. |
| 3586 | TEST_P(PeerConnectionIntegrationTest, |
| 3587 | DatagramTransportDataChannelFallbackToSctp) { |
| 3588 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3589 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3590 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3591 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3592 | |
| 3593 | // Configure one endpoint to use datagram transport for data channels while |
| 3594 | // the other does not. |
| 3595 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3596 | rtc_config, RTCConfiguration(), |
| 3597 | loopback_media_transports()->first_factory(), nullptr)); |
| 3598 | ConnectFakeSignaling(); |
| 3599 | |
| 3600 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3601 | caller()->CreateDataChannel(); |
| 3602 | caller()->AddAudioVideoTracks(); |
| 3603 | callee()->AddAudioVideoTracks(); |
| 3604 | caller()->CreateAndSetAndSignalOffer(); |
| 3605 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3606 | |
| 3607 | // Negotiation should fallback to SCTP, allowing the data channel to be |
| 3608 | // established. |
| 3609 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3610 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3611 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3612 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3613 | |
| 3614 | // Ensure data can be sent in both directions. |
| 3615 | std::string data = "hello world"; |
| 3616 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3617 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3618 | kDefaultTimeout); |
| 3619 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3620 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3621 | kDefaultTimeout); |
| 3622 | |
| 3623 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 3624 | MediaExpectations media_expectations; |
| 3625 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3626 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3627 | } |
| 3628 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 3629 | // Tests that the data channel transport works correctly when datagram transport |
| 3630 | // negotiation succeeds and does not fall back to SCTP. |
| 3631 | TEST_P(PeerConnectionIntegrationTest, |
| 3632 | DatagramTransportDataChannelDoesNotFallbackToSctp) { |
| 3633 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3634 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3635 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3636 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3637 | |
| 3638 | // Configure one endpoint to use datagram transport for data channels while |
| 3639 | // the other does not. |
| 3640 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3641 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3642 | loopback_media_transports()->second_factory())); |
| 3643 | ConnectFakeSignaling(); |
| 3644 | |
| 3645 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3646 | caller()->CreateDataChannel(); |
| 3647 | caller()->AddAudioVideoTracks(); |
| 3648 | callee()->AddAudioVideoTracks(); |
| 3649 | caller()->CreateAndSetAndSignalOffer(); |
| 3650 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3651 | |
| 3652 | // Ensure that the data channel transport is ready. |
| 3653 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3654 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3655 | |
| 3656 | // Negotiation should succeed, allowing the data channel to be established. |
| 3657 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3658 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3659 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3660 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3661 | |
| 3662 | // Ensure data can be sent in both directions. |
| 3663 | std::string data = "hello world"; |
| 3664 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3665 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3666 | kDefaultTimeout); |
| 3667 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3668 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3669 | kDefaultTimeout); |
| 3670 | |
| 3671 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 3672 | MediaExpectations media_expectations; |
| 3673 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3674 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3675 | } |
| 3676 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 3677 | TEST_P(PeerConnectionIntegrationTest, |
| 3678 | DatagramTransportDataChannelWithMediaOnCaller) { |
| 3679 | // Configure the caller to attempt use of datagram transport for media and |
| 3680 | // data channels. |
| 3681 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3682 | offerer_config.rtcp_mux_policy = |
| 3683 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3684 | offerer_config.bundle_policy = |
| 3685 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3686 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3687 | offerer_config.use_datagram_transport = true; |
| 3688 | |
| 3689 | // Configure the callee to only use datagram transport for data channels. |
| 3690 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3691 | answerer_config.rtcp_mux_policy = |
| 3692 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3693 | answerer_config.bundle_policy = |
| 3694 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3695 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3696 | |
| 3697 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3698 | offerer_config, answerer_config, |
| 3699 | loopback_media_transports()->first_factory(), |
| 3700 | loopback_media_transports()->second_factory())); |
| 3701 | ConnectFakeSignaling(); |
| 3702 | |
| 3703 | // Offer both media and data. |
| 3704 | caller()->AddAudioVideoTracks(); |
| 3705 | callee()->AddAudioVideoTracks(); |
| 3706 | caller()->CreateDataChannel(); |
| 3707 | caller()->CreateAndSetAndSignalOffer(); |
| 3708 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3709 | |
| 3710 | // Ensure that the data channel transport is ready. |
| 3711 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3712 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3713 | |
| 3714 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3715 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3716 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3717 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3718 | |
| 3719 | // Both endpoints should agree to use datagram transport for data channels. |
| 3720 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 3721 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 3722 | |
| 3723 | // Ensure data can be sent in both directions. |
| 3724 | std::string data = "hello world"; |
| 3725 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3726 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3727 | kDefaultTimeout); |
| 3728 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3729 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3730 | kDefaultTimeout); |
| 3731 | |
| 3732 | // Media flow should not be impacted. |
| 3733 | MediaExpectations media_expectations; |
| 3734 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3735 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3736 | } |
| 3737 | |
| 3738 | TEST_P(PeerConnectionIntegrationTest, |
| 3739 | DatagramTransportMediaWithDataChannelOnCaller) { |
| 3740 | // Configure the caller to attempt use of datagram transport for media and |
| 3741 | // data channels. |
| 3742 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3743 | offerer_config.rtcp_mux_policy = |
| 3744 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3745 | offerer_config.bundle_policy = |
| 3746 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3747 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3748 | offerer_config.use_datagram_transport = true; |
| 3749 | |
| 3750 | // Configure the callee to only use datagram transport for media. |
| 3751 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3752 | answerer_config.rtcp_mux_policy = |
| 3753 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3754 | answerer_config.bundle_policy = |
| 3755 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3756 | answerer_config.use_datagram_transport = true; |
| 3757 | |
| 3758 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3759 | offerer_config, answerer_config, |
| 3760 | loopback_media_transports()->first_factory(), |
| 3761 | loopback_media_transports()->second_factory())); |
| 3762 | ConnectFakeSignaling(); |
| 3763 | |
| 3764 | // Offer both media and data. |
| 3765 | caller()->AddAudioVideoTracks(); |
| 3766 | callee()->AddAudioVideoTracks(); |
| 3767 | caller()->CreateDataChannel(); |
| 3768 | caller()->CreateAndSetAndSignalOffer(); |
| 3769 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3770 | |
| 3771 | // Ensure that the data channel transport is ready. |
| 3772 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3773 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3774 | |
| 3775 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3776 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3777 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3778 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3779 | |
| 3780 | // Both endpoints should agree to use SCTP for data channels. |
| 3781 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 3782 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 3783 | |
| 3784 | // Ensure data can be sent in both directions. |
| 3785 | std::string data = "hello world"; |
| 3786 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3787 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3788 | kDefaultTimeout); |
| 3789 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3790 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3791 | kDefaultTimeout); |
| 3792 | |
| 3793 | // Media flow should not be impacted. |
| 3794 | MediaExpectations media_expectations; |
| 3795 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3796 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3797 | } |
| 3798 | |
| 3799 | TEST_P(PeerConnectionIntegrationTest, |
| 3800 | DatagramTransportDataChannelWithMediaOnCallee) { |
| 3801 | // Configure the caller to attempt use of datagram transport for data |
| 3802 | // channels. |
| 3803 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3804 | offerer_config.rtcp_mux_policy = |
| 3805 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3806 | offerer_config.bundle_policy = |
| 3807 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3808 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3809 | |
| 3810 | // Configure the callee to use datagram transport for data channels and media. |
| 3811 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3812 | answerer_config.rtcp_mux_policy = |
| 3813 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3814 | answerer_config.bundle_policy = |
| 3815 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3816 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3817 | answerer_config.use_datagram_transport = true; |
| 3818 | |
| 3819 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3820 | offerer_config, answerer_config, |
| 3821 | loopback_media_transports()->first_factory(), |
| 3822 | loopback_media_transports()->second_factory())); |
| 3823 | ConnectFakeSignaling(); |
| 3824 | |
| 3825 | // Offer both media and data. |
| 3826 | caller()->AddAudioVideoTracks(); |
| 3827 | callee()->AddAudioVideoTracks(); |
| 3828 | caller()->CreateDataChannel(); |
| 3829 | caller()->CreateAndSetAndSignalOffer(); |
| 3830 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3831 | |
| 3832 | // Ensure that the data channel transport is ready. |
| 3833 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3834 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3835 | |
| 3836 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3837 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3838 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3839 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3840 | |
| 3841 | // Both endpoints should agree to use datagram transport for data channels. |
| 3842 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 3843 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 3844 | |
| 3845 | // Ensure data can be sent in both directions. |
| 3846 | std::string data = "hello world"; |
| 3847 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3848 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3849 | kDefaultTimeout); |
| 3850 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3851 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3852 | kDefaultTimeout); |
| 3853 | |
| 3854 | // Media flow should not be impacted. |
| 3855 | MediaExpectations media_expectations; |
| 3856 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3857 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3858 | } |
| 3859 | |
| 3860 | TEST_P(PeerConnectionIntegrationTest, |
| 3861 | DatagramTransportMediaWithDataChannelOnCallee) { |
| 3862 | // Configure the caller to attempt use of datagram transport for media. |
| 3863 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3864 | offerer_config.rtcp_mux_policy = |
| 3865 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3866 | offerer_config.bundle_policy = |
| 3867 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3868 | offerer_config.use_datagram_transport = true; |
| 3869 | |
| 3870 | // Configure the callee to only use datagram transport for media and data |
| 3871 | // channels. |
| 3872 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3873 | answerer_config.rtcp_mux_policy = |
| 3874 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3875 | answerer_config.bundle_policy = |
| 3876 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3877 | answerer_config.use_datagram_transport = true; |
| 3878 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3879 | |
| 3880 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3881 | offerer_config, answerer_config, |
| 3882 | loopback_media_transports()->first_factory(), |
| 3883 | loopback_media_transports()->second_factory())); |
| 3884 | ConnectFakeSignaling(); |
| 3885 | |
| 3886 | // Offer both media and data. |
| 3887 | caller()->AddAudioVideoTracks(); |
| 3888 | callee()->AddAudioVideoTracks(); |
| 3889 | caller()->CreateDataChannel(); |
| 3890 | caller()->CreateAndSetAndSignalOffer(); |
| 3891 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3892 | |
| 3893 | // Ensure that the data channel transport is ready. |
| 3894 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3895 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3896 | |
| 3897 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3898 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3899 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3900 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3901 | |
| 3902 | // Both endpoints should agree to use SCTP for data channels. |
| 3903 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 3904 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 3905 | |
| 3906 | // Ensure data can be sent in both directions. |
| 3907 | std::string data = "hello world"; |
| 3908 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3909 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3910 | kDefaultTimeout); |
| 3911 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3912 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3913 | kDefaultTimeout); |
| 3914 | |
| 3915 | // Media flow should not be impacted. |
| 3916 | MediaExpectations media_expectations; |
| 3917 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3918 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3919 | } |
| 3920 | |
| 3921 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelAndMedia) { |
| 3922 | // Configure the caller to use datagram transport for data channels and media. |
| 3923 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3924 | offerer_config.rtcp_mux_policy = |
| 3925 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3926 | offerer_config.bundle_policy = |
| 3927 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3928 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3929 | offerer_config.use_datagram_transport = true; |
| 3930 | |
| 3931 | // Configure the callee to use datagram transport for data channels and media. |
| 3932 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3933 | answerer_config.rtcp_mux_policy = |
| 3934 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3935 | answerer_config.bundle_policy = |
| 3936 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3937 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3938 | answerer_config.use_datagram_transport = true; |
| 3939 | |
| 3940 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3941 | offerer_config, answerer_config, |
| 3942 | loopback_media_transports()->first_factory(), |
| 3943 | loopback_media_transports()->second_factory())); |
| 3944 | ConnectFakeSignaling(); |
| 3945 | |
| 3946 | // Offer both media and data. |
| 3947 | caller()->AddAudioVideoTracks(); |
| 3948 | callee()->AddAudioVideoTracks(); |
| 3949 | caller()->CreateDataChannel(); |
| 3950 | caller()->CreateAndSetAndSignalOffer(); |
| 3951 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3952 | |
| 3953 | // Ensure that the data channel transport is ready. |
| 3954 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3955 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3956 | |
| 3957 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3958 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3959 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3960 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3961 | |
| 3962 | // Both endpoints should agree to use datagram transport for data channels. |
| 3963 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 3964 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 3965 | |
| 3966 | // Ensure data can be sent in both directions. |
| 3967 | std::string data = "hello world"; |
| 3968 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3969 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3970 | kDefaultTimeout); |
| 3971 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3972 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3973 | kDefaultTimeout); |
| 3974 | |
| 3975 | // Media flow should not be impacted. |
| 3976 | MediaExpectations media_expectations; |
| 3977 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3978 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3979 | } |
| 3980 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 3981 | // Tests that data channels use SCTP instead of datagram transport if datagram |
| 3982 | // transport is configured in receive-only mode on the caller. |
| 3983 | TEST_P(PeerConnectionIntegrationTest, |
| 3984 | DatagramTransportDataChannelReceiveOnlyOnCallerUsesSctp) { |
| 3985 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3986 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3987 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3988 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3989 | rtc_config.use_datagram_transport_for_data_channels_receive_only = true; |
| 3990 | |
| 3991 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3992 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3993 | loopback_media_transports()->second_factory())); |
| 3994 | ConnectFakeSignaling(); |
| 3995 | |
| 3996 | // The caller should offer a data channel using SCTP. |
| 3997 | caller()->CreateDataChannel(); |
| 3998 | caller()->AddAudioVideoTracks(); |
| 3999 | callee()->AddAudioVideoTracks(); |
| 4000 | caller()->CreateAndSetAndSignalOffer(); |
| 4001 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4002 | |
| 4003 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4004 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4005 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4006 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4007 | |
| 4008 | // SCTP transports should be present, since they are in use. |
| 4009 | EXPECT_NE(caller()->pc()->GetSctpTransport(), nullptr); |
| 4010 | EXPECT_NE(callee()->pc()->GetSctpTransport(), nullptr); |
| 4011 | |
| 4012 | // Ensure data can be sent in both directions. |
| 4013 | std::string data = "hello world"; |
| 4014 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4015 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4016 | kDefaultTimeout); |
| 4017 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4018 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4019 | kDefaultTimeout); |
| 4020 | } |
| 4021 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4022 | #endif // HAVE_SCTP |
| 4023 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 4024 | // Tests that a callee configured for receive-only use of datagram transport |
| 4025 | // data channels accepts them on incoming calls. |
| 4026 | TEST_P(PeerConnectionIntegrationTest, |
| 4027 | DatagramTransportDataChannelReceiveOnlyOnCallee) { |
| 4028 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4029 | offerer_config.rtcp_mux_policy = |
| 4030 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4031 | offerer_config.bundle_policy = |
| 4032 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4033 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4034 | |
| 4035 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4036 | answerer_config.rtcp_mux_policy = |
| 4037 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4038 | answerer_config.bundle_policy = |
| 4039 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4040 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4041 | answerer_config.use_datagram_transport_for_data_channels_receive_only = true; |
| 4042 | |
| 4043 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4044 | offerer_config, answerer_config, |
| 4045 | loopback_media_transports()->first_factory(), |
| 4046 | loopback_media_transports()->second_factory())); |
| 4047 | ConnectFakeSignaling(); |
| 4048 | |
| 4049 | caller()->CreateDataChannel(); |
| 4050 | caller()->CreateAndSetAndSignalOffer(); |
| 4051 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4052 | |
| 4053 | // Ensure that the data channel transport is ready. |
| 4054 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4055 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4056 | |
| 4057 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4058 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4059 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4060 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4061 | |
| 4062 | // SCTP transports should not be present, since datagram transport is used. |
| 4063 | EXPECT_EQ(caller()->pc()->GetSctpTransport(), nullptr); |
| 4064 | EXPECT_EQ(callee()->pc()->GetSctpTransport(), nullptr); |
| 4065 | |
| 4066 | // Ensure data can be sent in both directions. |
| 4067 | std::string data = "hello world"; |
| 4068 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4069 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4070 | kDefaultTimeout); |
| 4071 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4072 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4073 | kDefaultTimeout); |
| 4074 | } |
| 4075 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4076 | // This test sets up a call between two parties with a datagram transport data |
| 4077 | // channel. |
| 4078 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelEndToEnd) { |
| 4079 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4080 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4081 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4082 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4083 | rtc_config.enable_dtls_srtp = false; |
| 4084 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4085 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4086 | loopback_media_transports()->second_factory())); |
| 4087 | ConnectFakeSignaling(); |
| 4088 | |
| 4089 | // Expect that data channel created on caller side will show up for callee as |
| 4090 | // well. |
| 4091 | caller()->CreateDataChannel(); |
| 4092 | caller()->CreateAndSetAndSignalOffer(); |
| 4093 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4094 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4095 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4096 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4097 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4098 | |
| 4099 | // Caller data channel should already exist (it created one). Callee data |
| 4100 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4101 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4102 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4103 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4104 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4105 | |
| 4106 | // Ensure data can be sent in both directions. |
| 4107 | std::string data = "hello world"; |
| 4108 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4109 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4110 | kDefaultTimeout); |
| 4111 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4112 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4113 | kDefaultTimeout); |
| 4114 | } |
| 4115 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 4116 | // Tests that 'zero-rtt' data channel transports (which are ready-to-send as |
| 4117 | // soon as they're created) work correctly. |
| 4118 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelZeroRtt) { |
| 4119 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4120 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4121 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4122 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4123 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4124 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4125 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4126 | loopback_media_transports()->second_factory())); |
| 4127 | ConnectFakeSignaling(); |
| 4128 | |
| 4129 | // Ensure that the callee's media transport is ready-to-send immediately. |
| 4130 | // Note that only the callee can become writable in zero RTTs. The caller |
| 4131 | // must wait for the callee's answer. |
| 4132 | loopback_media_transports()->SetSecondStateAfterConnect( |
| 4133 | webrtc::MediaTransportState::kWritable); |
| 4134 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4135 | |
| 4136 | // Expect that data channel created on caller side will show up for callee as |
| 4137 | // well. |
| 4138 | caller()->CreateDataChannel(); |
| 4139 | caller()->CreateAndSetAndSignalOffer(); |
| 4140 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4141 | |
| 4142 | loopback_media_transports()->SetFirstState( |
| 4143 | webrtc::MediaTransportState::kWritable); |
| 4144 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4145 | |
| 4146 | // Caller data channel should already exist (it created one). Callee data |
| 4147 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4148 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4149 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4150 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4151 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4152 | |
| 4153 | // Ensure data can be sent in both directions. |
| 4154 | std::string data = "hello world"; |
| 4155 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4156 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4157 | kDefaultTimeout); |
| 4158 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4159 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4160 | kDefaultTimeout); |
| 4161 | } |
| 4162 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4163 | // Ensures that when the callee closes a datagram transport data channel, the |
| 4164 | // closing procedure results in the data channel being closed for the caller |
| 4165 | // as well. |
| 4166 | TEST_P(PeerConnectionIntegrationTest, |
| 4167 | DatagramTransportDataChannelCalleeCloses) { |
| 4168 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4169 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4170 | rtc_config.enable_dtls_srtp = false; |
| 4171 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4172 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4173 | loopback_media_transports()->second_factory())); |
| 4174 | ConnectFakeSignaling(); |
| 4175 | |
| 4176 | // Create a data channel on the caller and signal it to the callee. |
| 4177 | caller()->CreateDataChannel(); |
| 4178 | caller()->CreateAndSetAndSignalOffer(); |
| 4179 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4180 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4181 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4182 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4183 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4184 | |
| 4185 | // Data channels exist and open on both ends of the connection. |
| 4186 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4187 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4188 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4189 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4190 | |
| 4191 | // Close the data channel on the callee side, and wait for it to reach the |
| 4192 | // "closed" state on both sides. |
| 4193 | callee()->data_channel()->Close(); |
| 4194 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4195 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4196 | } |
| 4197 | |
| 4198 | // Tests that datagram transport data channels can do in-band negotiation. |
| 4199 | TEST_P(PeerConnectionIntegrationTest, |
| 4200 | DatagramTransportDataChannelConfigSentToOtherSide) { |
| 4201 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4202 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4203 | rtc_config.enable_dtls_srtp = false; |
| 4204 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4205 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4206 | loopback_media_transports()->second_factory())); |
| 4207 | ConnectFakeSignaling(); |
| 4208 | |
| 4209 | // Create a data channel with a non-default configuration and signal it to the |
| 4210 | // callee. |
| 4211 | webrtc::DataChannelInit init; |
| 4212 | init.id = 53; |
| 4213 | init.maxRetransmits = 52; |
| 4214 | caller()->CreateDataChannel("data-channel", &init); |
| 4215 | caller()->CreateAndSetAndSignalOffer(); |
| 4216 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4217 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4218 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4219 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4220 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4221 | |
| 4222 | // Ensure that the data channel exists on the callee with the correct |
| 4223 | // configuration. |
| 4224 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4225 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4226 | // Since "negotiate" is false, the "id" parameter is ignored. |
| 4227 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
| 4228 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 4229 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 4230 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 4231 | } |
| 4232 | |
| 4233 | TEST_P(PeerConnectionIntegrationTest, |
| 4234 | DatagramTransportDataChannelRejectedWithNoFallback) { |
| 4235 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4236 | offerer_config.rtcp_mux_policy = |
| 4237 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4238 | offerer_config.bundle_policy = |
| 4239 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4240 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4241 | // Disabling DTLS precludes a fallback to SCTP. |
| 4242 | offerer_config.enable_dtls_srtp = false; |
| 4243 | |
| 4244 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4245 | answerer_config.rtcp_mux_policy = |
| 4246 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4247 | answerer_config.bundle_policy = |
| 4248 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4249 | // Both endpoints must disable DTLS or SetRemoteDescription will fail. |
| 4250 | answerer_config.enable_dtls_srtp = false; |
| 4251 | |
| 4252 | // Configure one endpoint to use datagram transport for data channels while |
| 4253 | // the other does not. |
| 4254 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4255 | offerer_config, answerer_config, |
| 4256 | loopback_media_transports()->first_factory(), nullptr)); |
| 4257 | ConnectFakeSignaling(); |
| 4258 | |
| 4259 | // The caller offers a data channel using either datagram transport or SCTP. |
| 4260 | caller()->CreateDataChannel(); |
| 4261 | caller()->AddAudioVideoTracks(); |
| 4262 | callee()->AddAudioVideoTracks(); |
| 4263 | caller()->CreateAndSetAndSignalOffer(); |
| 4264 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4265 | |
| 4266 | // Caller data channel should already exist (it created one). Callee data |
| 4267 | // channel should not exist, since negotiation happens in-band, not in SDP. |
| 4268 | EXPECT_NE(nullptr, caller()->data_channel()); |
| 4269 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 4270 | |
| 4271 | // The caller's data channel should close when the datagram transport is |
| 4272 | // rejected. |
| 4273 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 4274 | |
| 4275 | // Media flow should not be impacted by the failed data channel. |
| 4276 | MediaExpectations media_expectations; |
| 4277 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4278 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4279 | } |
| 4280 | |
Bjorn Mellem | a2eb0a7 | 2018-11-09 10:13:51 -0800 | [diff] [blame] | 4281 | // This test sets up a call between two parties with a media transport data |
| 4282 | // channel. |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 4283 | TEST_P(PeerConnectionIntegrationTest, MediaTransportDataChannelEndToEnd) { |
| 4284 | PeerConnectionInterface::RTCConfiguration rtc_config; |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 4285 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4286 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 4287 | rtc_config.use_media_transport_for_data_channels = true; |
| 4288 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4289 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4290 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4291 | loopback_media_transports()->second_factory())); |
| 4292 | ConnectFakeSignaling(); |
| 4293 | |
| 4294 | // Expect that data channel created on caller side will show up for callee as |
| 4295 | // well. |
| 4296 | caller()->CreateDataChannel(); |
| 4297 | caller()->CreateAndSetAndSignalOffer(); |
| 4298 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4299 | |
| 4300 | // Ensure that the media transport is ready. |
| 4301 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4302 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4303 | |
| 4304 | // Caller data channel should already exist (it created one). Callee data |
| 4305 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4306 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4307 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4308 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4309 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4310 | |
| 4311 | // Ensure data can be sent in both directions. |
| 4312 | std::string data = "hello world"; |
| 4313 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4314 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4315 | kDefaultTimeout); |
| 4316 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4317 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4318 | kDefaultTimeout); |
| 4319 | } |
| 4320 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 4321 | // Tests that 'zero-rtt' data channel transports (which are ready-to-send as |
| 4322 | // soon as they're created) work correctly. |
| 4323 | TEST_P(PeerConnectionIntegrationTest, MediaTransportDataChannelZeroRtt) { |
| 4324 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4325 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4326 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4327 | rtc_config.use_media_transport_for_data_channels = true; |
| 4328 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4329 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4330 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4331 | loopback_media_transports()->second_factory())); |
| 4332 | ConnectFakeSignaling(); |
| 4333 | |
| 4334 | // Ensure that the callee's media transport is ready-to-send immediately. |
| 4335 | // Note that only the callee can become writable in zero RTTs. The caller |
| 4336 | // must wait for the callee's answer. |
| 4337 | loopback_media_transports()->SetSecondStateAfterConnect( |
| 4338 | webrtc::MediaTransportState::kWritable); |
| 4339 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4340 | |
| 4341 | // Expect that data channel created on caller side will show up for callee as |
| 4342 | // well. |
| 4343 | caller()->CreateDataChannel(); |
| 4344 | caller()->CreateAndSetAndSignalOffer(); |
| 4345 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4346 | |
| 4347 | loopback_media_transports()->SetFirstState( |
| 4348 | webrtc::MediaTransportState::kWritable); |
| 4349 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4350 | |
| 4351 | // Caller data channel should already exist (it created one). Callee data |
| 4352 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4353 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4354 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4355 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4356 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4357 | |
| 4358 | // Ensure data can be sent in both directions. |
| 4359 | std::string data = "hello world"; |
| 4360 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4361 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4362 | kDefaultTimeout); |
| 4363 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4364 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4365 | kDefaultTimeout); |
| 4366 | } |
| 4367 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 4368 | // Ensure that when the callee closes a media transport data channel, the |
| 4369 | // closing procedure results in the data channel being closed for the caller |
| 4370 | // as well. |
| 4371 | TEST_P(PeerConnectionIntegrationTest, MediaTransportDataChannelCalleeCloses) { |
| 4372 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4373 | rtc_config.use_media_transport_for_data_channels = true; |
| 4374 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4375 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4376 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4377 | loopback_media_transports()->second_factory())); |
| 4378 | ConnectFakeSignaling(); |
| 4379 | |
| 4380 | // Create a data channel on the caller and signal it to the callee. |
| 4381 | caller()->CreateDataChannel(); |
| 4382 | caller()->CreateAndSetAndSignalOffer(); |
| 4383 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4384 | |
| 4385 | // Ensure that the media transport is ready. |
| 4386 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4387 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4388 | |
| 4389 | // Data channels exist and open on both ends of the connection. |
| 4390 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4391 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4392 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4393 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4394 | |
| 4395 | // Close the data channel on the callee side, and wait for it to reach the |
| 4396 | // "closed" state on both sides. |
| 4397 | callee()->data_channel()->Close(); |
| 4398 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4399 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4400 | } |
| 4401 | |
| 4402 | TEST_P(PeerConnectionIntegrationTest, |
| 4403 | MediaTransportDataChannelConfigSentToOtherSide) { |
| 4404 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4405 | rtc_config.use_media_transport_for_data_channels = true; |
| 4406 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4407 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4408 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4409 | loopback_media_transports()->second_factory())); |
| 4410 | ConnectFakeSignaling(); |
| 4411 | |
| 4412 | // Create a data channel with a non-default configuration and signal it to the |
| 4413 | // callee. |
| 4414 | webrtc::DataChannelInit init; |
| 4415 | init.id = 53; |
| 4416 | init.maxRetransmits = 52; |
| 4417 | caller()->CreateDataChannel("data-channel", &init); |
| 4418 | caller()->CreateAndSetAndSignalOffer(); |
| 4419 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4420 | |
| 4421 | // Ensure that the media transport is ready. |
| 4422 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4423 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4424 | |
| 4425 | // Ensure that the data channel exists on the callee with the correct |
| 4426 | // configuration. |
| 4427 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4428 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 4429 | // Since "negotiate" is false, the "id" parameter is ignored. |
| 4430 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 4431 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 4432 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 4433 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 4434 | } |
| 4435 | |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 4436 | TEST_P(PeerConnectionIntegrationTest, MediaTransportOfferUpgrade) { |
| 4437 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4438 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4439 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4440 | rtc_config.use_media_transport = true; |
| 4441 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4442 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4443 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4444 | loopback_media_transports()->second_factory())); |
| 4445 | ConnectFakeSignaling(); |
| 4446 | |
| 4447 | // Do initial offer/answer with just a video track. |
| 4448 | caller()->AddVideoTrack(); |
| 4449 | callee()->AddVideoTrack(); |
| 4450 | caller()->CreateAndSetAndSignalOffer(); |
| 4451 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4452 | |
| 4453 | // Ensure that the media transport is ready. |
| 4454 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4455 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4456 | |
| 4457 | // Now add an audio track and do another offer/answer. |
| 4458 | caller()->AddAudioTrack(); |
| 4459 | callee()->AddAudioTrack(); |
| 4460 | caller()->CreateAndSetAndSignalOffer(); |
| 4461 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4462 | |
| 4463 | // Ensure both audio and video frames are received end-to-end. |
| 4464 | MediaExpectations media_expectations; |
| 4465 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4466 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4467 | |
| 4468 | // The second offer should not have generated another media transport. |
| 4469 | // Media transport was kept alive, and was not recreated. |
| 4470 | EXPECT_EQ(1, loopback_media_transports()->first_factory_transport_count()); |
| 4471 | EXPECT_EQ(1, loopback_media_transports()->second_factory_transport_count()); |
| 4472 | } |
| 4473 | |
| 4474 | TEST_P(PeerConnectionIntegrationTest, MediaTransportOfferUpgradeOnTheCallee) { |
| 4475 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4476 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4477 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4478 | rtc_config.use_media_transport = true; |
| 4479 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4480 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4481 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4482 | loopback_media_transports()->second_factory())); |
| 4483 | ConnectFakeSignaling(); |
| 4484 | |
| 4485 | // Do initial offer/answer with just a video track. |
| 4486 | caller()->AddVideoTrack(); |
| 4487 | callee()->AddVideoTrack(); |
| 4488 | caller()->CreateAndSetAndSignalOffer(); |
| 4489 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4490 | |
| 4491 | // Ensure that the media transport is ready. |
| 4492 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4493 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4494 | |
| 4495 | // Now add an audio track and do another offer/answer. |
| 4496 | caller()->AddAudioTrack(); |
| 4497 | callee()->AddAudioTrack(); |
| 4498 | callee()->CreateAndSetAndSignalOffer(); |
| 4499 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4500 | |
| 4501 | // Ensure both audio and video frames are received end-to-end. |
| 4502 | MediaExpectations media_expectations; |
| 4503 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4504 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4505 | |
| 4506 | // The second offer should not have generated another media transport. |
| 4507 | // Media transport was kept alive, and was not recreated. |
| 4508 | EXPECT_EQ(1, loopback_media_transports()->first_factory_transport_count()); |
| 4509 | EXPECT_EQ(1, loopback_media_transports()->second_factory_transport_count()); |
| 4510 | } |
| 4511 | |
Niels Möller | c68d282 | 2018-11-20 14:52:05 +0100 | [diff] [blame] | 4512 | TEST_P(PeerConnectionIntegrationTest, MediaTransportBidirectionalAudio) { |
| 4513 | PeerConnectionInterface::RTCConfiguration rtc_config; |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 4514 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4515 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
Niels Möller | c68d282 | 2018-11-20 14:52:05 +0100 | [diff] [blame] | 4516 | rtc_config.use_media_transport = true; |
| 4517 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4518 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4519 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4520 | loopback_media_transports()->second_factory())); |
| 4521 | ConnectFakeSignaling(); |
| 4522 | |
| 4523 | caller()->AddAudioTrack(); |
| 4524 | callee()->AddAudioTrack(); |
| 4525 | // Start offer/answer exchange and wait for it to complete. |
| 4526 | caller()->CreateAndSetAndSignalOffer(); |
| 4527 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4528 | |
| 4529 | // Ensure that the media transport is ready. |
| 4530 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4531 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4532 | |
| 4533 | MediaExpectations media_expectations; |
| 4534 | media_expectations.ExpectBidirectionalAudio(); |
| 4535 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4536 | |
| 4537 | webrtc::MediaTransportPair::Stats first_stats = |
| 4538 | loopback_media_transports()->FirstStats(); |
| 4539 | webrtc::MediaTransportPair::Stats second_stats = |
| 4540 | loopback_media_transports()->SecondStats(); |
| 4541 | |
| 4542 | EXPECT_GT(first_stats.received_audio_frames, 0); |
| 4543 | EXPECT_GE(second_stats.sent_audio_frames, first_stats.received_audio_frames); |
| 4544 | |
| 4545 | EXPECT_GT(second_stats.received_audio_frames, 0); |
| 4546 | EXPECT_GE(first_stats.sent_audio_frames, second_stats.received_audio_frames); |
| 4547 | } |
| 4548 | |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 4549 | TEST_P(PeerConnectionIntegrationTest, MediaTransportBidirectionalVideo) { |
| 4550 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4551 | rtc_config.use_media_transport = true; |
| 4552 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4553 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4554 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4555 | loopback_media_transports()->second_factory())); |
| 4556 | ConnectFakeSignaling(); |
| 4557 | |
| 4558 | caller()->AddVideoTrack(); |
| 4559 | callee()->AddVideoTrack(); |
| 4560 | // Start offer/answer exchange and wait for it to complete. |
| 4561 | caller()->CreateAndSetAndSignalOffer(); |
| 4562 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4563 | |
| 4564 | // Ensure that the media transport is ready. |
| 4565 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4566 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4567 | |
| 4568 | MediaExpectations media_expectations; |
| 4569 | media_expectations.ExpectBidirectionalVideo(); |
| 4570 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4571 | |
| 4572 | webrtc::MediaTransportPair::Stats first_stats = |
| 4573 | loopback_media_transports()->FirstStats(); |
| 4574 | webrtc::MediaTransportPair::Stats second_stats = |
| 4575 | loopback_media_transports()->SecondStats(); |
| 4576 | |
| 4577 | EXPECT_GT(first_stats.received_video_frames, 0); |
| 4578 | EXPECT_GE(second_stats.sent_video_frames, first_stats.received_video_frames); |
| 4579 | |
| 4580 | EXPECT_GT(second_stats.received_video_frames, 0); |
| 4581 | EXPECT_GE(first_stats.sent_video_frames, second_stats.received_video_frames); |
| 4582 | } |
| 4583 | |
Piotr (Peter) Slatala | 55b91b9 | 2019-01-25 13:31:15 -0800 | [diff] [blame] | 4584 | TEST_P(PeerConnectionIntegrationTest, |
| 4585 | MediaTransportDataChannelUsesRtpBidirectionalVideo) { |
| 4586 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4587 | rtc_config.use_media_transport = false; |
| 4588 | rtc_config.use_media_transport_for_data_channels = true; |
| 4589 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4590 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4591 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4592 | loopback_media_transports()->second_factory())); |
| 4593 | ConnectFakeSignaling(); |
| 4594 | |
| 4595 | caller()->AddVideoTrack(); |
| 4596 | callee()->AddVideoTrack(); |
| 4597 | // Start offer/answer exchange and wait for it to complete. |
| 4598 | caller()->CreateAndSetAndSignalOffer(); |
| 4599 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4600 | |
| 4601 | MediaExpectations media_expectations; |
| 4602 | media_expectations.ExpectBidirectionalVideo(); |
| 4603 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4604 | } |
| 4605 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4606 | // Test that the ICE connection and gathering states eventually reach |
| 4607 | // "complete". |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4608 | TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4609 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4610 | ConnectFakeSignaling(); |
| 4611 | // Do normal offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4612 | caller()->AddAudioVideoTracks(); |
| 4613 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4614 | caller()->CreateAndSetAndSignalOffer(); |
| 4615 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4616 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 4617 | caller()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 4618 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 4619 | callee()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 4620 | // After the best candidate pair is selected and all candidates are signaled, |
| 4621 | // the ICE connection state should reach "complete". |
| 4622 | // TODO(deadbeef): Currently, the ICE "controlled" agent (the |
| 4623 | // answerer/"callee" by default) only reaches "connected". When this is |
| 4624 | // fixed, this test should be updated. |
| 4625 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4626 | caller()->ice_connection_state(), kDefaultTimeout); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4627 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4628 | callee()->ice_connection_state(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4631 | constexpr int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4632 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 4633 | cricket::PORTALLOCATOR_DISABLE_TCP; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4634 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4635 | // Use a mock resolver to resolve the hostname back to the original IP on both |
| 4636 | // sides and check that the ICE connection connects. |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4637 | TEST_P(PeerConnectionIntegrationTest, |
| 4638 | IceStatesReachCompletionWithRemoteHostname) { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4639 | auto caller_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4640 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4641 | auto callee_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4642 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4643 | NiceMock<rtc::MockAsyncResolver> callee_async_resolver; |
| 4644 | NiceMock<rtc::MockAsyncResolver> caller_async_resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4645 | |
| 4646 | // This also verifies that the injected AsyncResolverFactory is used by |
| 4647 | // P2PTransportChannel. |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4648 | EXPECT_CALL(*caller_resolver_factory, Create()) |
| 4649 | .WillOnce(Return(&caller_async_resolver)); |
| 4650 | webrtc::PeerConnectionDependencies caller_deps(nullptr); |
| 4651 | caller_deps.async_resolver_factory = std::move(caller_resolver_factory); |
| 4652 | |
| 4653 | EXPECT_CALL(*callee_resolver_factory, Create()) |
| 4654 | .WillOnce(Return(&callee_async_resolver)); |
| 4655 | webrtc::PeerConnectionDependencies callee_deps(nullptr); |
| 4656 | callee_deps.async_resolver_factory = std::move(callee_resolver_factory); |
| 4657 | |
| 4658 | PeerConnectionInterface::RTCConfiguration config; |
| 4659 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4660 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4661 | |
| 4662 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 4663 | config, std::move(caller_deps), config, std::move(callee_deps))); |
| 4664 | |
| 4665 | caller()->SetRemoteAsyncResolver(&callee_async_resolver); |
| 4666 | callee()->SetRemoteAsyncResolver(&caller_async_resolver); |
| 4667 | |
| 4668 | // Enable hostname candidates with mDNS names. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4669 | caller()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4670 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4671 | callee()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4672 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4673 | |
| 4674 | SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4675 | |
| 4676 | ConnectFakeSignaling(); |
| 4677 | caller()->AddAudioVideoTracks(); |
| 4678 | callee()->AddAudioVideoTracks(); |
| 4679 | caller()->CreateAndSetAndSignalOffer(); |
| 4680 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4681 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4682 | caller()->ice_connection_state(), kDefaultTimeout); |
| 4683 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4684 | callee()->ice_connection_state(), kDefaultTimeout); |
Jeroen de Borst | 833979f | 2018-12-13 08:25:54 -0800 | [diff] [blame] | 4685 | |
| 4686 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
| 4687 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4688 | webrtc::kIceCandidatePairHostNameHostName)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4691 | // Test that firewalling the ICE connection causes the clients to identify the |
| 4692 | // disconnected state and then removing the firewall causes them to reconnect. |
| 4693 | class PeerConnectionIntegrationIceStatesTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4694 | : public PeerConnectionIntegrationBaseTest, |
| 4695 | public ::testing::WithParamInterface< |
| 4696 | std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4697 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4698 | PeerConnectionIntegrationIceStatesTest() |
| 4699 | : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) { |
| 4700 | port_allocator_flags_ = std::get<1>(std::get<1>(GetParam())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | void StartStunServer(const SocketAddress& server_address) { |
| 4704 | stun_server_.reset( |
| 4705 | cricket::TestStunServer::Create(network_thread(), server_address)); |
| 4706 | } |
| 4707 | |
| 4708 | bool TestIPv6() { |
| 4709 | return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 4710 | } |
| 4711 | |
| 4712 | void SetPortAllocatorFlags() { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4713 | PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( |
| 4714 | port_allocator_flags_, port_allocator_flags_); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | std::vector<SocketAddress> CallerAddresses() { |
| 4718 | std::vector<SocketAddress> addresses; |
| 4719 | addresses.push_back(SocketAddress("1.1.1.1", 0)); |
| 4720 | if (TestIPv6()) { |
| 4721 | addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0)); |
| 4722 | } |
| 4723 | return addresses; |
| 4724 | } |
| 4725 | |
| 4726 | std::vector<SocketAddress> CalleeAddresses() { |
| 4727 | std::vector<SocketAddress> addresses; |
| 4728 | addresses.push_back(SocketAddress("2.2.2.2", 0)); |
| 4729 | if (TestIPv6()) { |
| 4730 | addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0)); |
| 4731 | } |
| 4732 | return addresses; |
| 4733 | } |
| 4734 | |
| 4735 | void SetUpNetworkInterfaces() { |
| 4736 | // Remove the default interfaces added by the test infrastructure. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4737 | caller()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
| 4738 | callee()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4739 | |
| 4740 | // Add network addresses for test. |
| 4741 | for (const auto& caller_address : CallerAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4742 | caller()->network_manager()->AddInterface(caller_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4743 | } |
| 4744 | for (const auto& callee_address : CalleeAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4745 | callee()->network_manager()->AddInterface(callee_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | private: |
| 4750 | uint32_t port_allocator_flags_; |
| 4751 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
| 4752 | }; |
| 4753 | |
| 4754 | // Tests that the PeerConnection goes through all the ICE gathering/connection |
| 4755 | // states over the duration of the call. This includes Disconnected and Failed |
| 4756 | // states, induced by putting a firewall between the peers and waiting for them |
| 4757 | // to time out. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4758 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) { |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4759 | rtc::ScopedFakeClock fake_clock; |
| 4760 | // Some things use a time of "0" as a special value, so we need to start out |
| 4761 | // the fake clock at a nonzero time. |
| 4762 | fake_clock.AdvanceTime(TimeDelta::seconds(1)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4763 | |
| 4764 | const SocketAddress kStunServerAddress = |
| 4765 | SocketAddress("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 4766 | StartStunServer(kStunServerAddress); |
| 4767 | |
| 4768 | PeerConnectionInterface::RTCConfiguration config; |
| 4769 | PeerConnectionInterface::IceServer ice_stun_server; |
| 4770 | ice_stun_server.urls.push_back( |
| 4771 | "stun:" + kStunServerAddress.HostAsURIString() + ":" + |
| 4772 | kStunServerAddress.PortAsString()); |
| 4773 | config.servers.push_back(ice_stun_server); |
| 4774 | |
| 4775 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 4776 | ConnectFakeSignaling(); |
| 4777 | SetPortAllocatorFlags(); |
| 4778 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4779 | caller()->AddAudioVideoTracks(); |
| 4780 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4781 | |
| 4782 | // Initial state before anything happens. |
| 4783 | ASSERT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 4784 | caller()->ice_gathering_state()); |
| 4785 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 4786 | caller()->ice_connection_state()); |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4787 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 4788 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4789 | |
| 4790 | // Start the call by creating the offer, setting it as the local description, |
| 4791 | // then sending it to the peer who will respond with an answer. This happens |
| 4792 | // asynchronously so that we can watch the states as it runs in the |
| 4793 | // background. |
| 4794 | caller()->CreateAndSetAndSignalOffer(); |
| 4795 | |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4796 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, |
| 4797 | caller()->ice_connection_state()); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4798 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4799 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4800 | |
| 4801 | // Verify that the observer was notified of the intermediate transitions. |
| 4802 | EXPECT_THAT(caller()->ice_connection_state_history(), |
| 4803 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 4804 | PeerConnectionInterface::kIceConnectionConnected, |
| 4805 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4806 | EXPECT_THAT(caller()->standardized_ice_connection_state_history(), |
| 4807 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 4808 | PeerConnectionInterface::kIceConnectionConnected, |
| 4809 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 4810 | EXPECT_THAT( |
| 4811 | caller()->peer_connection_state_history(), |
| 4812 | ElementsAre(PeerConnectionInterface::PeerConnectionState::kConnecting, |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 4813 | PeerConnectionInterface::PeerConnectionState::kConnected)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4814 | EXPECT_THAT(caller()->ice_gathering_state_history(), |
| 4815 | ElementsAre(PeerConnectionInterface::kIceGatheringGathering, |
| 4816 | PeerConnectionInterface::kIceGatheringComplete)); |
| 4817 | |
| 4818 | // Block connections to/from the caller and wait for ICE to become |
| 4819 | // disconnected. |
| 4820 | for (const auto& caller_address : CallerAddresses()) { |
| 4821 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4822 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4823 | RTC_LOG(LS_INFO) << "Firewall rules applied"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4824 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 4825 | caller()->ice_connection_state(), kDefaultTimeout, |
| 4826 | fake_clock); |
| 4827 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 4828 | caller()->standardized_ice_connection_state(), |
| 4829 | kDefaultTimeout, fake_clock); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4830 | |
| 4831 | // Let ICE re-establish by removing the firewall rules. |
| 4832 | firewall()->ClearRules(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4833 | RTC_LOG(LS_INFO) << "Firewall rules cleared"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4834 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4835 | caller()->ice_connection_state(), kDefaultTimeout, |
| 4836 | fake_clock); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4837 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4838 | caller()->standardized_ice_connection_state(), |
| 4839 | kDefaultTimeout, fake_clock); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4840 | |
| 4841 | // According to RFC7675, if there is no response within 30 seconds then the |
| 4842 | // peer should consider the other side to have rejected the connection. This |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4843 | // is signaled by the state transitioning to "failed". |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4844 | constexpr int kConsentTimeout = 30000; |
| 4845 | for (const auto& caller_address : CallerAddresses()) { |
| 4846 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4847 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4848 | RTC_LOG(LS_INFO) << "Firewall rules applied again"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4849 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4850 | caller()->ice_connection_state(), kConsentTimeout, |
| 4851 | fake_clock); |
| 4852 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4853 | caller()->standardized_ice_connection_state(), |
| 4854 | kConsentTimeout, fake_clock); |
| 4855 | |
| 4856 | // We need to manually close the peerconnections before the fake clock goes |
| 4857 | // out of scope, or we trigger a DCHECK in rtp_sender.cc when we briefly |
| 4858 | // return to using non-faked time. |
| 4859 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 4860 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
| 4861 | } |
| 4862 | |
| 4863 | // Tests that if the connection doesn't get set up properly we eventually reach |
| 4864 | // the "failed" iceConnectionState. |
| 4865 | TEST_P(PeerConnectionIntegrationIceStatesTest, IceStateSetupFailure) { |
| 4866 | rtc::ScopedFakeClock fake_clock; |
| 4867 | // Some things use a time of "0" as a special value, so we need to start out |
| 4868 | // the fake clock at a nonzero time. |
| 4869 | fake_clock.AdvanceTime(TimeDelta::seconds(1)); |
| 4870 | |
| 4871 | // Block connections to/from the caller and wait for ICE to become |
| 4872 | // disconnected. |
| 4873 | for (const auto& caller_address : CallerAddresses()) { |
| 4874 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4875 | } |
| 4876 | |
| 4877 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4878 | ConnectFakeSignaling(); |
| 4879 | SetPortAllocatorFlags(); |
| 4880 | SetUpNetworkInterfaces(); |
| 4881 | caller()->AddAudioVideoTracks(); |
| 4882 | caller()->CreateAndSetAndSignalOffer(); |
| 4883 | |
| 4884 | // According to RFC7675, if there is no response within 30 seconds then the |
| 4885 | // peer should consider the other side to have rejected the connection. This |
| 4886 | // is signaled by the state transitioning to "failed". |
| 4887 | constexpr int kConsentTimeout = 30000; |
| 4888 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4889 | caller()->standardized_ice_connection_state(), |
| 4890 | kConsentTimeout, fake_clock); |
| 4891 | |
| 4892 | // We need to manually close the peerconnections before the fake clock goes |
| 4893 | // out of scope, or we trigger a DCHECK in rtp_sender.cc when we briefly |
| 4894 | // return to using non-faked time. |
| 4895 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 4896 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | // Tests that the best connection is set to the appropriate IPv4/IPv6 connection |
| 4900 | // and that the statistics in the metric observers are updated correctly. |
| 4901 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyBestConnection) { |
| 4902 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4903 | ConnectFakeSignaling(); |
| 4904 | SetPortAllocatorFlags(); |
| 4905 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4906 | caller()->AddAudioVideoTracks(); |
| 4907 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4908 | caller()->CreateAndSetAndSignalOffer(); |
| 4909 | |
| 4910 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4911 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 4912 | // TODO(bugs.webrtc.org/9456): Fix it. |
| 4913 | const int num_best_ipv4 = webrtc::metrics::NumEvents( |
| 4914 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv4); |
| 4915 | const int num_best_ipv6 = webrtc::metrics::NumEvents( |
| 4916 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4917 | if (TestIPv6()) { |
| 4918 | // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4 |
| 4919 | // connection. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 4920 | EXPECT_EQ(0, num_best_ipv4); |
| 4921 | EXPECT_EQ(1, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4922 | } else { |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 4923 | EXPECT_EQ(1, num_best_ipv4); |
| 4924 | EXPECT_EQ(0, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 4927 | EXPECT_EQ(0, webrtc::metrics::NumEvents( |
| 4928 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4929 | webrtc::kIceCandidatePairHostHost)); |
| 4930 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
| 4931 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4932 | webrtc::kIceCandidatePairHostPublicHostPublic)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP | |
| 4936 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4937 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4938 | constexpr uint32_t kFlagsIPv6NoStun = |
| 4939 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4940 | cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4941 | constexpr uint32_t kFlagsIPv4Stun = |
| 4942 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4943 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4944 | INSTANTIATE_TEST_SUITE_P( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4945 | PeerConnectionIntegrationTest, |
| 4946 | PeerConnectionIntegrationIceStatesTest, |
| 4947 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 4948 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 4949 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 4950 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4951 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4952 | // This test sets up a call between two parties with audio and video. |
| 4953 | // During the call, the caller restarts ICE and the test verifies that |
| 4954 | // new ICE candidates are generated and audio and video still can flow, and the |
| 4955 | // ICE state reaches completed again. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4956 | TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4957 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4958 | ConnectFakeSignaling(); |
| 4959 | // Do normal offer/answer and wait for ICE to complete. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4960 | caller()->AddAudioVideoTracks(); |
| 4961 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4962 | caller()->CreateAndSetAndSignalOffer(); |
| 4963 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4964 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4965 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4966 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4967 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4968 | |
| 4969 | // To verify that the ICE restart actually occurs, get |
| 4970 | // ufrag/password/candidates before and after restart. |
| 4971 | // Create an SDP string of the first audio candidate for both clients. |
| 4972 | const webrtc::IceCandidateCollection* audio_candidates_caller = |
| 4973 | caller()->pc()->local_description()->candidates(0); |
| 4974 | const webrtc::IceCandidateCollection* audio_candidates_callee = |
| 4975 | callee()->pc()->local_description()->candidates(0); |
| 4976 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 4977 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 4978 | std::string caller_candidate_pre_restart; |
| 4979 | ASSERT_TRUE( |
| 4980 | audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart)); |
| 4981 | std::string callee_candidate_pre_restart; |
| 4982 | ASSERT_TRUE( |
| 4983 | audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart)); |
| 4984 | const cricket::SessionDescription* desc = |
| 4985 | caller()->pc()->local_description()->description(); |
| 4986 | std::string caller_ufrag_pre_restart = |
| 4987 | desc->transport_infos()[0].description.ice_ufrag; |
| 4988 | desc = callee()->pc()->local_description()->description(); |
| 4989 | std::string callee_ufrag_pre_restart = |
| 4990 | desc->transport_infos()[0].description.ice_ufrag; |
| 4991 | |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 4992 | EXPECT_EQ(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4993 | // Have the caller initiate an ICE restart. |
| 4994 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 4995 | caller()->CreateAndSetAndSignalOffer(); |
| 4996 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4997 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4998 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4999 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5000 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5001 | |
| 5002 | // Grab the ufrags/candidates again. |
| 5003 | audio_candidates_caller = caller()->pc()->local_description()->candidates(0); |
| 5004 | audio_candidates_callee = callee()->pc()->local_description()->candidates(0); |
| 5005 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 5006 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 5007 | std::string caller_candidate_post_restart; |
| 5008 | ASSERT_TRUE( |
| 5009 | audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart)); |
| 5010 | std::string callee_candidate_post_restart; |
| 5011 | ASSERT_TRUE( |
| 5012 | audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart)); |
| 5013 | desc = caller()->pc()->local_description()->description(); |
| 5014 | std::string caller_ufrag_post_restart = |
| 5015 | desc->transport_infos()[0].description.ice_ufrag; |
| 5016 | desc = callee()->pc()->local_description()->description(); |
| 5017 | std::string callee_ufrag_post_restart = |
| 5018 | desc->transport_infos()[0].description.ice_ufrag; |
| 5019 | // Sanity check that an ICE restart was actually negotiated in SDP. |
| 5020 | ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart); |
| 5021 | ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart); |
| 5022 | ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart); |
| 5023 | ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 5024 | EXPECT_GT(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5025 | |
| 5026 | // Ensure that additional frames are received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5027 | MediaExpectations media_expectations; |
| 5028 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5029 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | // Verify that audio/video can be received end-to-end when ICE renomination is |
| 5033 | // enabled. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5034 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5035 | PeerConnectionInterface::RTCConfiguration config; |
| 5036 | config.enable_ice_renomination = true; |
| 5037 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 5038 | ConnectFakeSignaling(); |
| 5039 | // Do normal offer/answer and wait for some frames to be received in each |
| 5040 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5041 | caller()->AddAudioVideoTracks(); |
| 5042 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5043 | caller()->CreateAndSetAndSignalOffer(); |
| 5044 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5045 | // Sanity check that ICE renomination was actually negotiated. |
| 5046 | const cricket::SessionDescription* desc = |
| 5047 | caller()->pc()->local_description()->description(); |
| 5048 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 5049 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5050 | } |
| 5051 | desc = callee()->pc()->local_description()->description(); |
| 5052 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 5053 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5054 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5055 | MediaExpectations media_expectations; |
| 5056 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5057 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5058 | } |
| 5059 | |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5060 | // With a max bundle policy and RTCP muxing, adding a new media description to |
| 5061 | // the connection should not affect ICE at all because the new media will use |
| 5062 | // the existing connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5063 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 5064 | AddMediaToConnectedBundleDoesNotRestartIce) { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5065 | PeerConnectionInterface::RTCConfiguration config; |
| 5066 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 5067 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 5068 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig( |
| 5069 | config, PeerConnectionInterface::RTCConfiguration())); |
| 5070 | ConnectFakeSignaling(); |
| 5071 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5072 | caller()->AddAudioTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5073 | caller()->CreateAndSetAndSignalOffer(); |
| 5074 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | ff52f1b | 2017-10-26 12:24:50 -0700 | [diff] [blame] | 5075 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 5076 | caller()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5077 | |
| 5078 | caller()->clear_ice_connection_state_history(); |
| 5079 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5080 | caller()->AddVideoTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 5081 | caller()->CreateAndSetAndSignalOffer(); |
| 5082 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5083 | |
| 5084 | EXPECT_EQ(0u, caller()->ice_connection_state_history().size()); |
| 5085 | } |
| 5086 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5087 | // This test sets up a call between two parties with audio and video. It then |
| 5088 | // renegotiates setting the video m-line to "port 0", then later renegotiates |
| 5089 | // again, enabling video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5090 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5091 | VideoFlowsAfterMediaSectionIsRejectedAndRecycled) { |
| 5092 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5093 | ConnectFakeSignaling(); |
| 5094 | |
| 5095 | // Do initial negotiation, only sending media from the caller. Will result in |
| 5096 | // video and audio recvonly "m=" sections. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5097 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5098 | caller()->CreateAndSetAndSignalOffer(); |
| 5099 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5100 | |
| 5101 | // Negotiate again, disabling the video "m=" section (the callee will set the |
| 5102 | // port to 0 due to offer_to_receive_video = 0). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5103 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 5104 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5105 | options.offer_to_receive_video = 0; |
| 5106 | callee()->SetOfferAnswerOptions(options); |
| 5107 | } else { |
| 5108 | callee()->SetRemoteOfferHandler([this] { |
| 5109 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 5110 | }); |
| 5111 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5112 | caller()->CreateAndSetAndSignalOffer(); |
| 5113 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5114 | // Sanity check that video "m=" section was actually rejected. |
| 5115 | const ContentInfo* answer_video_content = cricket::GetFirstVideoContent( |
| 5116 | callee()->pc()->local_description()->description()); |
| 5117 | ASSERT_NE(nullptr, answer_video_content); |
| 5118 | ASSERT_TRUE(answer_video_content->rejected); |
| 5119 | |
| 5120 | // Enable video and do negotiation again, making sure video is received |
| 5121 | // end-to-end, also adding media stream to callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5122 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 5123 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5124 | options.offer_to_receive_video = 1; |
| 5125 | callee()->SetOfferAnswerOptions(options); |
| 5126 | } else { |
| 5127 | // The caller's transceiver is stopped, so we need to add another track. |
| 5128 | auto caller_transceiver = |
| 5129 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 5130 | EXPECT_TRUE(caller_transceiver->stopped()); |
| 5131 | caller()->AddVideoTrack(); |
| 5132 | } |
| 5133 | callee()->AddVideoTrack(); |
| 5134 | callee()->SetRemoteOfferHandler(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5135 | caller()->CreateAndSetAndSignalOffer(); |
| 5136 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5137 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5138 | // Verify the caller receives frames from the newly added stream, and the |
| 5139 | // callee receives additional frames from the re-enabled video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5140 | MediaExpectations media_expectations; |
| 5141 | media_expectations.CalleeExpectsSomeAudio(); |
| 5142 | media_expectations.ExpectBidirectionalVideo(); |
| 5143 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5146 | // This tests that if we negotiate after calling CreateSender but before we |
| 5147 | // have a track, then set a track later, frames from the newly-set track are |
| 5148 | // received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5149 | TEST_F(PeerConnectionIntegrationTestPlanB, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5150 | MediaFlowsAfterEarlyWarmupWithCreateSender) { |
| 5151 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5152 | ConnectFakeSignaling(); |
| 5153 | auto caller_audio_sender = |
| 5154 | caller()->pc()->CreateSender("audio", "caller_stream"); |
| 5155 | auto caller_video_sender = |
| 5156 | caller()->pc()->CreateSender("video", "caller_stream"); |
| 5157 | auto callee_audio_sender = |
| 5158 | callee()->pc()->CreateSender("audio", "callee_stream"); |
| 5159 | auto callee_video_sender = |
| 5160 | callee()->pc()->CreateSender("video", "callee_stream"); |
| 5161 | caller()->CreateAndSetAndSignalOffer(); |
| 5162 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 5163 | // Wait for ICE to complete, without any tracks being set. |
| 5164 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5165 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5166 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5167 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5168 | // Now set the tracks, and expect frames to immediately start flowing. |
| 5169 | EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 5170 | EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 5171 | EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 5172 | EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5173 | MediaExpectations media_expectations; |
| 5174 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5175 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5176 | } |
| 5177 | |
| 5178 | // This tests that if we negotiate after calling AddTransceiver but before we |
| 5179 | // have a track, then set a track later, frames from the newly-set tracks are |
| 5180 | // received end-to-end. |
| 5181 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5182 | MediaFlowsAfterEarlyWarmupWithAddTransceiver) { |
| 5183 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5184 | ConnectFakeSignaling(); |
| 5185 | auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 5186 | ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type()); |
| 5187 | auto caller_audio_sender = audio_result.MoveValue()->sender(); |
| 5188 | auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 5189 | ASSERT_EQ(RTCErrorType::NONE, video_result.error().type()); |
| 5190 | auto caller_video_sender = video_result.MoveValue()->sender(); |
| 5191 | callee()->SetRemoteOfferHandler([this] { |
| 5192 | ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size()); |
| 5193 | callee()->pc()->GetTransceivers()[0]->SetDirection( |
| 5194 | RtpTransceiverDirection::kSendRecv); |
| 5195 | callee()->pc()->GetTransceivers()[1]->SetDirection( |
| 5196 | RtpTransceiverDirection::kSendRecv); |
| 5197 | }); |
| 5198 | caller()->CreateAndSetAndSignalOffer(); |
| 5199 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 5200 | // Wait for ICE to complete, without any tracks being set. |
| 5201 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 5202 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5203 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5204 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5205 | // Now set the tracks, and expect frames to immediately start flowing. |
| 5206 | auto callee_audio_sender = callee()->pc()->GetSenders()[0]; |
| 5207 | auto callee_video_sender = callee()->pc()->GetSenders()[1]; |
| 5208 | ASSERT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 5209 | ASSERT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 5210 | ASSERT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 5211 | ASSERT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
| 5212 | MediaExpectations media_expectations; |
| 5213 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5214 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | // This test verifies that a remote video track can be added via AddStream, |
| 5218 | // and sent end-to-end. For this particular test, it's simply echoed back |
| 5219 | // from the caller to the callee, rather than being forwarded to a third |
| 5220 | // PeerConnection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5221 | TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5222 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5223 | ConnectFakeSignaling(); |
| 5224 | // Just send a video track from the caller. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5225 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5226 | caller()->CreateAndSetAndSignalOffer(); |
| 5227 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 5228 | ASSERT_EQ(1U, callee()->remote_streams()->count()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5229 | |
| 5230 | // Echo the stream back, and do a new offer/anwer (initiated by callee this |
| 5231 | // time). |
| 5232 | callee()->pc()->AddStream(callee()->remote_streams()->at(0)); |
| 5233 | callee()->CreateAndSetAndSignalOffer(); |
| 5234 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 5235 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5236 | MediaExpectations media_expectations; |
| 5237 | media_expectations.ExpectBidirectionalVideo(); |
| 5238 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | // Test that we achieve the expected end-to-end connection time, using a |
| 5242 | // fake clock and simulated latency on the media and signaling paths. |
| 5243 | // We use a TURN<->TURN connection because this is usually the quickest to |
| 5244 | // set up initially, especially when we're confident the connection will work |
| 5245 | // and can start sending media before we get a STUN response. |
| 5246 | // |
| 5247 | // With various optimizations enabled, here are the network delays we expect to |
| 5248 | // be on the critical path: |
| 5249 | // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then |
| 5250 | // signaling answer (with DTLS fingerprint). |
| 5251 | // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when |
| 5252 | // using TURN<->TURN pair, and DTLS exchange is 4 packets, |
| 5253 | // the first of which should have arrived before the answer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5254 | TEST_P(PeerConnectionIntegrationTest, EndToEndConnectionTimeWithTurnTurnPair) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5255 | rtc::ScopedFakeClock fake_clock; |
| 5256 | // Some things use a time of "0" as a special value, so we need to start out |
| 5257 | // the fake clock at a nonzero time. |
| 5258 | // TODO(deadbeef): Fix this. |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 5259 | fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5260 | |
| 5261 | static constexpr int media_hop_delay_ms = 50; |
| 5262 | static constexpr int signaling_trip_delay_ms = 500; |
| 5263 | // For explanation of these values, see comment above. |
| 5264 | static constexpr int required_media_hops = 9; |
| 5265 | static constexpr int required_signaling_trips = 2; |
| 5266 | // For internal delays (such as posting an event asychronously). |
| 5267 | static constexpr int allowed_internal_delay_ms = 20; |
| 5268 | static constexpr int total_connection_time_ms = |
| 5269 | media_hop_delay_ms * required_media_hops + |
| 5270 | signaling_trip_delay_ms * required_signaling_trips + |
| 5271 | allowed_internal_delay_ms; |
| 5272 | |
| 5273 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 5274 | 3478}; |
| 5275 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 5276 | 0}; |
| 5277 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 5278 | 3478}; |
| 5279 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 5280 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5281 | cricket::TestTurnServer* turn_server_1 = CreateTurnServer( |
| 5282 | turn_server_1_internal_address, turn_server_1_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5283 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5284 | cricket::TestTurnServer* turn_server_2 = CreateTurnServer( |
| 5285 | turn_server_2_internal_address, turn_server_2_external_address); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5286 | // Bypass permission check on received packets so media can be sent before |
| 5287 | // the candidate is signaled. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5288 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_1] { |
| 5289 | turn_server_1->set_enable_permission_checks(false); |
| 5290 | }); |
| 5291 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_2] { |
| 5292 | turn_server_2->set_enable_permission_checks(false); |
| 5293 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5294 | |
| 5295 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5296 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 5297 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 5298 | ice_server_1.username = "test"; |
| 5299 | ice_server_1.password = "test"; |
| 5300 | client_1_config.servers.push_back(ice_server_1); |
| 5301 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5302 | client_1_config.presume_writable_when_fully_relayed = true; |
| 5303 | |
| 5304 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5305 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 5306 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 5307 | ice_server_2.username = "test"; |
| 5308 | ice_server_2.password = "test"; |
| 5309 | client_2_config.servers.push_back(ice_server_2); |
| 5310 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5311 | client_2_config.presume_writable_when_fully_relayed = true; |
| 5312 | |
| 5313 | ASSERT_TRUE( |
| 5314 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5315 | // Set up the simulated delays. |
| 5316 | SetSignalingDelayMs(signaling_trip_delay_ms); |
| 5317 | ConnectFakeSignaling(); |
| 5318 | virtual_socket_server()->set_delay_mean(media_hop_delay_ms); |
| 5319 | virtual_socket_server()->UpdateDelayDistribution(); |
| 5320 | |
| 5321 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5322 | // set up ICE/DTLS with no media. |
| 5323 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5324 | options.offer_to_receive_audio = 1; |
| 5325 | options.offer_to_receive_video = 1; |
| 5326 | caller()->SetOfferAnswerOptions(options); |
| 5327 | caller()->CreateAndSetAndSignalOffer(); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 5328 | EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms, |
| 5329 | fake_clock); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 5330 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 5331 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 5332 | // 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] | 5333 | ClosePeerConnections(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5334 | } |
| 5335 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5336 | // Verify that a TurnCustomizer passed in through RTCConfiguration |
| 5337 | // is actually used by the underlying TURN candidate pair. |
| 5338 | // Note that turnport_unittest.cc contains more detailed, lower-level tests. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5339 | TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) { |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5340 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 5341 | 3478}; |
| 5342 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 5343 | 0}; |
| 5344 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 5345 | 3478}; |
| 5346 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 5347 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5348 | CreateTurnServer(turn_server_1_internal_address, |
| 5349 | turn_server_1_external_address); |
| 5350 | CreateTurnServer(turn_server_2_internal_address, |
| 5351 | turn_server_2_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5352 | |
| 5353 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5354 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 5355 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 5356 | ice_server_1.username = "test"; |
| 5357 | ice_server_1.password = "test"; |
| 5358 | client_1_config.servers.push_back(ice_server_1); |
| 5359 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5360 | auto* customizer1 = CreateTurnCustomizer(); |
| 5361 | client_1_config.turn_customizer = customizer1; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5362 | |
| 5363 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5364 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 5365 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 5366 | ice_server_2.username = "test"; |
| 5367 | ice_server_2.password = "test"; |
| 5368 | client_2_config.servers.push_back(ice_server_2); |
| 5369 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5370 | auto* customizer2 = CreateTurnCustomizer(); |
| 5371 | client_2_config.turn_customizer = customizer2; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5372 | |
| 5373 | ASSERT_TRUE( |
| 5374 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5375 | ConnectFakeSignaling(); |
| 5376 | |
| 5377 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5378 | // set up ICE/DTLS with no media. |
| 5379 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5380 | options.offer_to_receive_audio = 1; |
| 5381 | options.offer_to_receive_video = 1; |
| 5382 | caller()->SetOfferAnswerOptions(options); |
| 5383 | caller()->CreateAndSetAndSignalOffer(); |
| 5384 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5385 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5386 | ExpectTurnCustomizerCountersIncremented(customizer1); |
| 5387 | ExpectTurnCustomizerCountersIncremented(customizer2); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5388 | } |
| 5389 | |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 5390 | // Verifies that you can use TCP instead of UDP to connect to a TURN server and |
| 5391 | // send media between the caller and the callee. |
| 5392 | TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) { |
| 5393 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5394 | 3478}; |
| 5395 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5396 | |
| 5397 | // Enable TCP for the fake turn server. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5398 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5399 | cricket::PROTO_TCP); |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 5400 | |
| 5401 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5402 | ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp"); |
| 5403 | ice_server.username = "test"; |
| 5404 | ice_server.password = "test"; |
| 5405 | |
| 5406 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5407 | client_1_config.servers.push_back(ice_server); |
| 5408 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5409 | |
| 5410 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5411 | client_2_config.servers.push_back(ice_server); |
| 5412 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5413 | |
| 5414 | ASSERT_TRUE( |
| 5415 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5416 | |
| 5417 | // Do normal offer/answer and wait for ICE to complete. |
| 5418 | ConnectFakeSignaling(); |
| 5419 | caller()->AddAudioVideoTracks(); |
| 5420 | callee()->AddAudioVideoTracks(); |
| 5421 | caller()->CreateAndSetAndSignalOffer(); |
| 5422 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5423 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5424 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5425 | |
| 5426 | MediaExpectations media_expectations; |
| 5427 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5428 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 5429 | } |
| 5430 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5431 | // Verify that a SSLCertificateVerifier passed in through |
| 5432 | // PeerConnectionDependencies is actually used by the underlying SSL |
| 5433 | // implementation to determine whether a certificate presented by the TURN |
| 5434 | // server is accepted by the client. Note that openssladapter_unittest.cc |
| 5435 | // contains more detailed, lower-level tests. |
| 5436 | TEST_P(PeerConnectionIntegrationTest, |
| 5437 | SSLCertificateVerifierUsedForTurnConnections) { |
| 5438 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5439 | 3478}; |
| 5440 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5441 | |
| 5442 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 5443 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5444 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5445 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5446 | |
| 5447 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5448 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 5449 | ice_server.username = "test"; |
| 5450 | ice_server.password = "test"; |
| 5451 | |
| 5452 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5453 | client_1_config.servers.push_back(ice_server); |
| 5454 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5455 | |
| 5456 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5457 | client_2_config.servers.push_back(ice_server); |
| 5458 | // Setting the type to kRelay forces the connection to go through a TURN |
| 5459 | // server. |
| 5460 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5461 | |
| 5462 | // Get a copy to the pointer so we can verify calls later. |
| 5463 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 5464 | new rtc::TestCertificateVerifier(); |
| 5465 | client_1_cert_verifier->verify_certificate_ = true; |
| 5466 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 5467 | new rtc::TestCertificateVerifier(); |
| 5468 | client_2_cert_verifier->verify_certificate_ = true; |
| 5469 | |
| 5470 | // Create the dependencies with the test certificate verifier. |
| 5471 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 5472 | client_1_deps.tls_cert_verifier = |
| 5473 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 5474 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 5475 | client_2_deps.tls_cert_verifier = |
| 5476 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 5477 | |
| 5478 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 5479 | client_1_config, std::move(client_1_deps), client_2_config, |
| 5480 | std::move(client_2_deps))); |
| 5481 | ConnectFakeSignaling(); |
| 5482 | |
| 5483 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5484 | // set up ICE/DTLS with no media. |
| 5485 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5486 | options.offer_to_receive_audio = 1; |
| 5487 | options.offer_to_receive_video = 1; |
| 5488 | caller()->SetOfferAnswerOptions(options); |
| 5489 | caller()->CreateAndSetAndSignalOffer(); |
| 5490 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5491 | |
| 5492 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 5493 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | TEST_P(PeerConnectionIntegrationTest, |
| 5497 | SSLCertificateVerifierFailureUsedForTurnConnectionsFailsConnection) { |
| 5498 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5499 | 3478}; |
| 5500 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5501 | |
| 5502 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 5503 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5504 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5505 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5506 | |
| 5507 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5508 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 5509 | ice_server.username = "test"; |
| 5510 | ice_server.password = "test"; |
| 5511 | |
| 5512 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5513 | client_1_config.servers.push_back(ice_server); |
| 5514 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5515 | |
| 5516 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5517 | client_2_config.servers.push_back(ice_server); |
| 5518 | // Setting the type to kRelay forces the connection to go through a TURN |
| 5519 | // server. |
| 5520 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5521 | |
| 5522 | // Get a copy to the pointer so we can verify calls later. |
| 5523 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 5524 | new rtc::TestCertificateVerifier(); |
| 5525 | client_1_cert_verifier->verify_certificate_ = false; |
| 5526 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 5527 | new rtc::TestCertificateVerifier(); |
| 5528 | client_2_cert_verifier->verify_certificate_ = false; |
| 5529 | |
| 5530 | // Create the dependencies with the test certificate verifier. |
| 5531 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 5532 | client_1_deps.tls_cert_verifier = |
| 5533 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 5534 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 5535 | client_2_deps.tls_cert_verifier = |
| 5536 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 5537 | |
| 5538 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 5539 | client_1_config, std::move(client_1_deps), client_2_config, |
| 5540 | std::move(client_2_deps))); |
| 5541 | ConnectFakeSignaling(); |
| 5542 | |
| 5543 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5544 | // set up ICE/DTLS with no media. |
| 5545 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5546 | options.offer_to_receive_audio = 1; |
| 5547 | options.offer_to_receive_video = 1; |
| 5548 | caller()->SetOfferAnswerOptions(options); |
| 5549 | caller()->CreateAndSetAndSignalOffer(); |
| 5550 | bool wait_res = true; |
| 5551 | // TODO(bugs.webrtc.org/9219): When IceConnectionState is implemented |
| 5552 | // properly, should be able to just wait for a state of "failed" instead of |
| 5553 | // waiting a fixed 10 seconds. |
| 5554 | WAIT_(DtlsConnected(), kDefaultTimeout, wait_res); |
| 5555 | ASSERT_FALSE(wait_res); |
| 5556 | |
| 5557 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 5558 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 5561 | // Test that the injected ICE transport factory is used to create ICE transports |
| 5562 | // for WebRTC connections. |
| 5563 | TEST_P(PeerConnectionIntegrationTest, IceTransportFactoryUsedForConnections) { |
| 5564 | PeerConnectionInterface::RTCConfiguration default_config; |
| 5565 | PeerConnectionDependencies dependencies(nullptr); |
| 5566 | auto ice_transport_factory = std::make_unique<MockIceTransportFactory>(); |
| 5567 | EXPECT_CALL(*ice_transport_factory, RecordIceTransportCreated()).Times(1); |
| 5568 | dependencies.ice_transport_factory = std::move(ice_transport_factory); |
| 5569 | auto wrapper = |
| 5570 | CreatePeerConnectionWrapper("Caller", nullptr, &default_config, |
| 5571 | std::move(dependencies), nullptr, nullptr); |
| 5572 | ASSERT_TRUE(wrapper); |
| 5573 | wrapper->CreateDataChannel(); |
| 5574 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 5575 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 5576 | wrapper->pc()->SetLocalDescription(observer, |
| 5577 | wrapper->CreateOfferAndWait().release()); |
| 5578 | } |
| 5579 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5580 | // Test that audio and video flow end-to-end when codec names don't use the |
| 5581 | // expected casing, given that they're supposed to be case insensitive. To test |
| 5582 | // this, all but one codec is removed from each media description, and its |
| 5583 | // casing is changed. |
| 5584 | // |
| 5585 | // In the past, this has regressed and caused crashes/black video, due to the |
| 5586 | // fact that code at some layers was doing case-insensitive comparisons and |
| 5587 | // code at other layers was not. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5588 | TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) { |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5589 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5590 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5591 | caller()->AddAudioVideoTracks(); |
| 5592 | callee()->AddAudioVideoTracks(); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5593 | |
| 5594 | // Remove all but one audio/video codec (opus and VP8), and change the |
| 5595 | // casing of the caller's generated offer. |
| 5596 | caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) { |
| 5597 | cricket::AudioContentDescription* audio = |
| 5598 | GetFirstAudioContentDescription(description); |
| 5599 | ASSERT_NE(nullptr, audio); |
| 5600 | auto audio_codecs = audio->codecs(); |
| 5601 | audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(), |
| 5602 | [](const cricket::AudioCodec& codec) { |
| 5603 | return codec.name != "opus"; |
| 5604 | }), |
| 5605 | audio_codecs.end()); |
| 5606 | ASSERT_EQ(1u, audio_codecs.size()); |
| 5607 | audio_codecs[0].name = "OpUs"; |
| 5608 | audio->set_codecs(audio_codecs); |
| 5609 | |
| 5610 | cricket::VideoContentDescription* video = |
| 5611 | GetFirstVideoContentDescription(description); |
| 5612 | ASSERT_NE(nullptr, video); |
| 5613 | auto video_codecs = video->codecs(); |
| 5614 | video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(), |
| 5615 | [](const cricket::VideoCodec& codec) { |
| 5616 | return codec.name != "VP8"; |
| 5617 | }), |
| 5618 | video_codecs.end()); |
| 5619 | ASSERT_EQ(1u, video_codecs.size()); |
| 5620 | video_codecs[0].name = "vP8"; |
| 5621 | video->set_codecs(video_codecs); |
| 5622 | }); |
| 5623 | |
| 5624 | caller()->CreateAndSetAndSignalOffer(); |
| 5625 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5626 | |
| 5627 | // Verify frames are still received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5628 | MediaExpectations media_expectations; |
| 5629 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5630 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5631 | } |
| 5632 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5633 | TEST_P(PeerConnectionIntegrationTest, GetSourcesAudio) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5634 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5635 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5636 | caller()->AddAudioTrack(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5637 | caller()->CreateAndSetAndSignalOffer(); |
| 5638 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 5639 | // Wait for one audio frame to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5640 | MediaExpectations media_expectations; |
| 5641 | media_expectations.CalleeExpectsSomeAudio(1); |
| 5642 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5643 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5644 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 5645 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5646 | auto sources = receiver->GetSources(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5647 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
| 5648 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5649 | sources[0].source_id()); |
| 5650 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
| 5651 | } |
| 5652 | |
| 5653 | TEST_P(PeerConnectionIntegrationTest, GetSourcesVideo) { |
| 5654 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5655 | ConnectFakeSignaling(); |
| 5656 | caller()->AddVideoTrack(); |
| 5657 | caller()->CreateAndSetAndSignalOffer(); |
| 5658 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5659 | // Wait for one video frame to be received by the callee. |
| 5660 | MediaExpectations media_expectations; |
| 5661 | media_expectations.CalleeExpectsSomeVideo(1); |
| 5662 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5663 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 5664 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 5665 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_VIDEO); |
| 5666 | auto sources = receiver->GetSources(); |
| 5667 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
Yves Gerey | f781bb5 | 2019-07-23 19:15:39 +0200 | [diff] [blame] | 5668 | ASSERT_GT(sources.size(), 0u); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5669 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
| 5670 | sources[0].source_id()); |
| 5671 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5672 | } |
| 5673 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5674 | // Test that if a track is removed and added again with a different stream ID, |
| 5675 | // the new stream ID is successfully communicated in SDP and media continues to |
| 5676 | // flow end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5677 | // TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because |
| 5678 | // it will not reuse a transceiver that has already been sending. After creating |
| 5679 | // a new transceiver it tries to create an offer with two senders of the same |
| 5680 | // track ids and it fails. |
| 5681 | TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5682 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5683 | ConnectFakeSignaling(); |
| 5684 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5685 | // Add track using stream 1, do offer/answer. |
| 5686 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 5687 | caller()->CreateLocalAudioTrack(); |
| 5688 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 5689 | caller()->AddTrack(track, {"stream_1"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5690 | caller()->CreateAndSetAndSignalOffer(); |
| 5691 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5692 | { |
| 5693 | MediaExpectations media_expectations; |
| 5694 | media_expectations.CalleeExpectsSomeAudio(1); |
| 5695 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5696 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5697 | // Remove the sender, and create a new one with the new stream. |
| 5698 | caller()->pc()->RemoveTrack(sender); |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 5699 | sender = caller()->AddTrack(track, {"stream_2"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5700 | caller()->CreateAndSetAndSignalOffer(); |
| 5701 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5702 | // Wait for additional audio frames to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5703 | { |
| 5704 | MediaExpectations media_expectations; |
| 5705 | media_expectations.CalleeExpectsSomeAudio(); |
| 5706 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5707 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5708 | } |
| 5709 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5710 | TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) { |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5711 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5712 | ConnectFakeSignaling(); |
| 5713 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 5714 | auto output = std::make_unique<testing::NiceMock<MockRtcEventLogOutput>>(); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 5715 | ON_CALL(*output, IsActive()).WillByDefault(::testing::Return(true)); |
| 5716 | ON_CALL(*output, Write(::testing::_)).WillByDefault(::testing::Return(true)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5717 | EXPECT_CALL(*output, Write(::testing::_)).Times(::testing::AtLeast(1)); |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 5718 | EXPECT_TRUE(caller()->pc()->StartRtcEventLog( |
| 5719 | std::move(output), webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5720 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5721 | caller()->AddAudioVideoTracks(); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5722 | caller()->CreateAndSetAndSignalOffer(); |
| 5723 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5724 | } |
| 5725 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5726 | // Test that if candidates are only signaled by applying full session |
| 5727 | // descriptions (instead of using AddIceCandidate), the peers can connect to |
| 5728 | // each other and exchange media. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5729 | TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5730 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5731 | // Each side will signal the session descriptions but not candidates. |
| 5732 | ConnectFakeSignalingForSdpOnly(); |
| 5733 | |
| 5734 | // Add audio video track and exchange the initial offer/answer with media |
| 5735 | // information only. This will start ICE gathering on each side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5736 | caller()->AddAudioVideoTracks(); |
| 5737 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5738 | caller()->CreateAndSetAndSignalOffer(); |
| 5739 | |
| 5740 | // Wait for all candidates to be gathered on both the caller and callee. |
| 5741 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 5742 | caller()->ice_gathering_state(), kDefaultTimeout); |
| 5743 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 5744 | callee()->ice_gathering_state(), kDefaultTimeout); |
| 5745 | |
| 5746 | // The candidates will now be included in the session description, so |
| 5747 | // signaling them will start the ICE connection. |
| 5748 | caller()->CreateAndSetAndSignalOffer(); |
| 5749 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5750 | |
| 5751 | // Ensure that media flows in both directions. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5752 | MediaExpectations media_expectations; |
| 5753 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5754 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5755 | } |
| 5756 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5757 | // Test that SetAudioPlayout can be used to disable audio playout from the |
| 5758 | // start, then later enable it. This may be useful, for example, if the caller |
| 5759 | // needs to play a local ringtone until some event occurs, after which it |
| 5760 | // switches to playing the received audio. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5761 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5762 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5763 | ConnectFakeSignaling(); |
| 5764 | |
| 5765 | // Set up audio-only call where audio playout is disabled on caller's side. |
| 5766 | caller()->pc()->SetAudioPlayout(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5767 | caller()->AddAudioTrack(); |
| 5768 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5769 | caller()->CreateAndSetAndSignalOffer(); |
| 5770 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5771 | |
| 5772 | // Pump messages for a second. |
| 5773 | WAIT(false, 1000); |
| 5774 | // Since audio playout is disabled, the caller shouldn't have received |
| 5775 | // anything (at the playout level, at least). |
| 5776 | EXPECT_EQ(0, caller()->audio_frames_received()); |
| 5777 | // As a sanity check, make sure the callee (for which playout isn't disabled) |
| 5778 | // did still see frames on its audio level. |
| 5779 | ASSERT_GT(callee()->audio_frames_received(), 0); |
| 5780 | |
| 5781 | // Enable playout again, and ensure audio starts flowing. |
| 5782 | caller()->pc()->SetAudioPlayout(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5783 | MediaExpectations media_expectations; |
| 5784 | media_expectations.ExpectBidirectionalAudio(); |
| 5785 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | double GetAudioEnergyStat(PeerConnectionWrapper* pc) { |
| 5789 | auto report = pc->NewGetStats(); |
| 5790 | auto track_stats_list = |
| 5791 | report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 5792 | const webrtc::RTCMediaStreamTrackStats* remote_track_stats = nullptr; |
| 5793 | for (const auto* track_stats : track_stats_list) { |
| 5794 | if (track_stats->remote_source.is_defined() && |
| 5795 | *track_stats->remote_source) { |
| 5796 | remote_track_stats = track_stats; |
| 5797 | break; |
| 5798 | } |
| 5799 | } |
| 5800 | |
| 5801 | if (!remote_track_stats->total_audio_energy.is_defined()) { |
| 5802 | return 0.0; |
| 5803 | } |
| 5804 | return *remote_track_stats->total_audio_energy; |
| 5805 | } |
| 5806 | |
| 5807 | // Test that if audio playout is disabled via the SetAudioPlayout() method, then |
| 5808 | // incoming audio is still processed and statistics are generated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5809 | TEST_P(PeerConnectionIntegrationTest, |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5810 | DisableAudioPlayoutStillGeneratesAudioStats) { |
| 5811 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5812 | ConnectFakeSignaling(); |
| 5813 | |
| 5814 | // Set up audio-only call where playout is disabled but audio-processing is |
| 5815 | // still active. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5816 | caller()->AddAudioTrack(); |
| 5817 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5818 | caller()->pc()->SetAudioPlayout(false); |
| 5819 | |
| 5820 | caller()->CreateAndSetAndSignalOffer(); |
| 5821 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5822 | |
| 5823 | // Wait for the callee to receive audio stats. |
| 5824 | EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs); |
| 5825 | } |
| 5826 | |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5827 | // Test that SetAudioRecording can be used to disable audio recording from the |
| 5828 | // start, then later enable it. This may be useful, for example, if the caller |
| 5829 | // wants to ensure that no audio resources are active before a certain state |
| 5830 | // is reached. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5831 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) { |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5832 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5833 | ConnectFakeSignaling(); |
| 5834 | |
| 5835 | // Set up audio-only call where audio recording is disabled on caller's side. |
| 5836 | caller()->pc()->SetAudioRecording(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5837 | caller()->AddAudioTrack(); |
| 5838 | callee()->AddAudioTrack(); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5839 | caller()->CreateAndSetAndSignalOffer(); |
| 5840 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5841 | |
| 5842 | // Pump messages for a second. |
| 5843 | WAIT(false, 1000); |
| 5844 | // Since caller has disabled audio recording, the callee shouldn't have |
| 5845 | // received anything. |
| 5846 | EXPECT_EQ(0, callee()->audio_frames_received()); |
| 5847 | // As a sanity check, make sure the caller did still see frames on its |
| 5848 | // audio level since audio recording is enabled on the calle side. |
| 5849 | ASSERT_GT(caller()->audio_frames_received(), 0); |
| 5850 | |
| 5851 | // Enable audio recording again, and ensure audio starts flowing. |
| 5852 | caller()->pc()->SetAudioRecording(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5853 | MediaExpectations media_expectations; |
| 5854 | media_expectations.ExpectBidirectionalAudio(); |
| 5855 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5856 | } |
| 5857 | |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5858 | // Test that after closing PeerConnections, they stop sending any packets (ICE, |
| 5859 | // DTLS, RTP...). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5860 | TEST_P(PeerConnectionIntegrationTest, ClosingConnectionStopsPacketFlow) { |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5861 | // Set up audio/video/data, wait for some frames to be received. |
| 5862 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5863 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5864 | caller()->AddAudioVideoTracks(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5865 | #ifdef HAVE_SCTP |
| 5866 | caller()->CreateDataChannel(); |
| 5867 | #endif |
| 5868 | caller()->CreateAndSetAndSignalOffer(); |
| 5869 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5870 | MediaExpectations media_expectations; |
| 5871 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 5872 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5873 | // Close PeerConnections. |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 5874 | ClosePeerConnections(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5875 | // Pump messages for a second, and ensure no new packets end up sent. |
| 5876 | uint32_t sent_packets_a = virtual_socket_server()->sent_packets(); |
| 5877 | WAIT(false, 1000); |
| 5878 | uint32_t sent_packets_b = virtual_socket_server()->sent_packets(); |
| 5879 | EXPECT_EQ(sent_packets_a, sent_packets_b); |
| 5880 | } |
| 5881 | |
Steve Anton | 7eca093 | 2018-03-30 15:18:41 -0700 | [diff] [blame] | 5882 | // Test that transport stats are generated by the RTCStatsCollector for a |
| 5883 | // connection that only involves data channels. This is a regression test for |
| 5884 | // crbug.com/826972. |
| 5885 | #ifdef HAVE_SCTP |
| 5886 | TEST_P(PeerConnectionIntegrationTest, |
| 5887 | TransportStatsReportedForDataChannelOnlyConnection) { |
| 5888 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5889 | ConnectFakeSignaling(); |
| 5890 | caller()->CreateDataChannel(); |
| 5891 | |
| 5892 | caller()->CreateAndSetAndSignalOffer(); |
| 5893 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5894 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 5895 | |
| 5896 | auto caller_report = caller()->NewGetStats(); |
| 5897 | EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size()); |
| 5898 | auto callee_report = callee()->NewGetStats(); |
| 5899 | EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size()); |
| 5900 | } |
| 5901 | #endif // HAVE_SCTP |
| 5902 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 5903 | TEST_P(PeerConnectionIntegrationTest, |
| 5904 | IceEventsGeneratedAndLoggedInRtcEventLog) { |
| 5905 | ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog()); |
| 5906 | ConnectFakeSignaling(); |
| 5907 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5908 | options.offer_to_receive_audio = 1; |
| 5909 | caller()->SetOfferAnswerOptions(options); |
| 5910 | caller()->CreateAndSetAndSignalOffer(); |
| 5911 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5912 | ASSERT_NE(nullptr, caller()->event_log_factory()); |
| 5913 | ASSERT_NE(nullptr, callee()->event_log_factory()); |
| 5914 | webrtc::FakeRtcEventLog* caller_event_log = |
| 5915 | static_cast<webrtc::FakeRtcEventLog*>( |
| 5916 | caller()->event_log_factory()->last_log_created()); |
| 5917 | webrtc::FakeRtcEventLog* callee_event_log = |
| 5918 | static_cast<webrtc::FakeRtcEventLog*>( |
| 5919 | callee()->event_log_factory()->last_log_created()); |
| 5920 | ASSERT_NE(nullptr, caller_event_log); |
| 5921 | ASSERT_NE(nullptr, callee_event_log); |
| 5922 | int caller_ice_config_count = caller_event_log->GetEventCount( |
| 5923 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 5924 | int caller_ice_event_count = caller_event_log->GetEventCount( |
| 5925 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 5926 | int callee_ice_config_count = callee_event_log->GetEventCount( |
| 5927 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 5928 | int callee_ice_event_count = callee_event_log->GetEventCount( |
| 5929 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 5930 | EXPECT_LT(0, caller_ice_config_count); |
| 5931 | EXPECT_LT(0, caller_ice_event_count); |
| 5932 | EXPECT_LT(0, callee_ice_config_count); |
| 5933 | EXPECT_LT(0, callee_ice_event_count); |
| 5934 | } |
| 5935 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5936 | TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) { |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5937 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5938 | 3478}; |
| 5939 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5940 | |
| 5941 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 5942 | |
| 5943 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5944 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 5945 | ice_server.username = "test"; |
| 5946 | ice_server.password = "test"; |
| 5947 | |
| 5948 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 5949 | caller_config.servers.push_back(ice_server); |
| 5950 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5951 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 5952 | caller_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5953 | |
| 5954 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 5955 | callee_config.servers.push_back(ice_server); |
| 5956 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5957 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 5958 | callee_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5959 | |
| 5960 | ASSERT_TRUE( |
| 5961 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 5962 | |
| 5963 | // Do normal offer/answer and wait for ICE to complete. |
| 5964 | ConnectFakeSignaling(); |
| 5965 | caller()->AddAudioVideoTracks(); |
| 5966 | callee()->AddAudioVideoTracks(); |
| 5967 | caller()->CreateAndSetAndSignalOffer(); |
| 5968 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5969 | // Since we are doing continual gathering, the ICE transport does not reach |
| 5970 | // kIceGatheringComplete (see |
| 5971 | // P2PTransportChannel::OnCandidatesAllocationDone), and consequently not |
| 5972 | // kIceConnectionComplete. |
| 5973 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5974 | caller()->ice_connection_state(), kDefaultTimeout); |
| 5975 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5976 | callee()->ice_connection_state(), kDefaultTimeout); |
| 5977 | // Note that we cannot use the metric |
| 5978 | // |WebRTC.PeerConnection.CandidatePairType_UDP| in this test since this |
| 5979 | // metric is only populated when we reach kIceConnectionComplete in the |
| 5980 | // current implementation. |
| 5981 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 5982 | caller()->last_candidate_gathered().type()); |
| 5983 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 5984 | callee()->last_candidate_gathered().type()); |
| 5985 | |
| 5986 | // Loosen the caller's candidate filter. |
| 5987 | caller_config = caller()->pc()->GetConfiguration(); |
| 5988 | caller_config.type = webrtc::PeerConnectionInterface::kAll; |
| 5989 | caller()->pc()->SetConfiguration(caller_config); |
| 5990 | // We should have gathered a new host candidate. |
| 5991 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 5992 | caller()->last_candidate_gathered().type(), kDefaultTimeout); |
| 5993 | |
| 5994 | // Loosen the callee's candidate filter. |
| 5995 | callee_config = callee()->pc()->GetConfiguration(); |
| 5996 | callee_config.type = webrtc::PeerConnectionInterface::kAll; |
| 5997 | callee()->pc()->SetConfiguration(callee_config); |
| 5998 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 5999 | callee()->last_candidate_gathered().type(), kDefaultTimeout); |
| 6000 | } |
| 6001 | |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 6002 | TEST_P(PeerConnectionIntegrationTest, OnIceCandidateError) { |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 6003 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 6004 | 3478}; |
| 6005 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 6006 | |
| 6007 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 6008 | |
| 6009 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 6010 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 6011 | ice_server.username = "test"; |
| 6012 | ice_server.password = "123"; |
| 6013 | |
| 6014 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 6015 | caller_config.servers.push_back(ice_server); |
| 6016 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6017 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 6018 | |
| 6019 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 6020 | callee_config.servers.push_back(ice_server); |
| 6021 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 6022 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 6023 | |
| 6024 | ASSERT_TRUE( |
| 6025 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 6026 | |
| 6027 | // Do normal offer/answer and wait for ICE to complete. |
| 6028 | ConnectFakeSignaling(); |
| 6029 | caller()->AddAudioVideoTracks(); |
| 6030 | callee()->AddAudioVideoTracks(); |
| 6031 | caller()->CreateAndSetAndSignalOffer(); |
| 6032 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6033 | EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout); |
| 6034 | EXPECT_EQ("Unauthorized", caller()->error_event().error_text); |
| 6035 | EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url); |
| 6036 | EXPECT_NE(std::string::npos, |
| 6037 | caller()->error_event().host_candidate.find(":")); |
| 6038 | } |
| 6039 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 6040 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6041 | AudioKeepsFlowingAfterImplicitRollback) { |
| 6042 | PeerConnectionInterface::RTCConfiguration config; |
| 6043 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 6044 | config.enable_implicit_rollback = true; |
| 6045 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 6046 | ConnectFakeSignaling(); |
| 6047 | caller()->AddAudioTrack(); |
| 6048 | callee()->AddAudioTrack(); |
| 6049 | caller()->CreateAndSetAndSignalOffer(); |
| 6050 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6051 | MediaExpectations media_expectations; |
| 6052 | media_expectations.ExpectBidirectionalAudio(); |
| 6053 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6054 | SetSignalIceCandidates(false); // Workaround candidate outrace sdp. |
| 6055 | caller()->AddVideoTrack(); |
| 6056 | callee()->AddVideoTrack(); |
| 6057 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 6058 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 6059 | callee()->pc()->SetLocalDescription(observer, |
| 6060 | callee()->CreateOfferAndWait().release()); |
| 6061 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 6062 | caller()->CreateAndSetAndSignalOffer(); // Implicit rollback. |
| 6063 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6064 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6065 | } |
| 6066 | |
| 6067 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6068 | ImplicitRollbackVisitsStableState) { |
| 6069 | RTCConfiguration config; |
| 6070 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 6071 | config.enable_implicit_rollback = true; |
| 6072 | |
| 6073 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 6074 | |
| 6075 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> sld_observer( |
| 6076 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 6077 | callee()->pc()->SetLocalDescription(sld_observer, |
| 6078 | callee()->CreateOfferAndWait().release()); |
| 6079 | EXPECT_TRUE_WAIT(sld_observer->called(), kDefaultTimeout); |
| 6080 | EXPECT_EQ(sld_observer->error(), ""); |
| 6081 | |
| 6082 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> srd_observer( |
| 6083 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 6084 | callee()->pc()->SetRemoteDescription( |
| 6085 | srd_observer, caller()->CreateOfferAndWait().release()); |
| 6086 | EXPECT_TRUE_WAIT(srd_observer->called(), kDefaultTimeout); |
| 6087 | EXPECT_EQ(srd_observer->error(), ""); |
| 6088 | |
| 6089 | EXPECT_THAT(callee()->peer_connection_signaling_state_history(), |
| 6090 | ElementsAre(PeerConnectionInterface::kHaveLocalOffer, |
| 6091 | PeerConnectionInterface::kStable, |
| 6092 | PeerConnectionInterface::kHaveRemoteOffer)); |
| 6093 | } |
| 6094 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 6095 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 6096 | PeerConnectionIntegrationTest, |
| 6097 | Values(SdpSemantics::kPlanB, |
| 6098 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 6099 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6100 | // Tests that verify interoperability between Plan B and Unified Plan |
| 6101 | // PeerConnections. |
| 6102 | class PeerConnectionIntegrationInteropTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6103 | : public PeerConnectionIntegrationBaseTest, |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6104 | public ::testing::WithParamInterface< |
| 6105 | std::tuple<SdpSemantics, SdpSemantics>> { |
| 6106 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6107 | // Setting the SdpSemantics for the base test to kDefault does not matter |
| 6108 | // because we specify not to use the test semantics when creating |
| 6109 | // PeerConnectionWrappers. |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6110 | PeerConnectionIntegrationInteropTest() |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 6111 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6112 | caller_semantics_(std::get<0>(GetParam())), |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6113 | callee_semantics_(std::get<1>(GetParam())) {} |
| 6114 | |
| 6115 | bool CreatePeerConnectionWrappersWithSemantics() { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 6116 | return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_, |
| 6117 | callee_semantics_); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | const SdpSemantics caller_semantics_; |
| 6121 | const SdpSemantics callee_semantics_; |
| 6122 | }; |
| 6123 | |
| 6124 | TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) { |
| 6125 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6126 | ConnectFakeSignaling(); |
| 6127 | |
| 6128 | caller()->CreateAndSetAndSignalOffer(); |
| 6129 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6130 | } |
| 6131 | |
| 6132 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) { |
| 6133 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6134 | ConnectFakeSignaling(); |
| 6135 | auto audio_sender = caller()->AddAudioTrack(); |
| 6136 | |
| 6137 | caller()->CreateAndSetAndSignalOffer(); |
| 6138 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6139 | |
| 6140 | // Verify that one audio receiver has been created on the remote and that it |
| 6141 | // has the same track ID as the sending track. |
| 6142 | auto receivers = callee()->pc()->GetReceivers(); |
| 6143 | ASSERT_EQ(1u, receivers.size()); |
| 6144 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type()); |
| 6145 | EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id()); |
| 6146 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6147 | MediaExpectations media_expectations; |
| 6148 | media_expectations.CalleeExpectsSomeAudio(); |
| 6149 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6150 | } |
| 6151 | |
| 6152 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) { |
| 6153 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6154 | ConnectFakeSignaling(); |
| 6155 | auto video_sender = caller()->AddVideoTrack(); |
| 6156 | auto audio_sender = caller()->AddAudioTrack(); |
| 6157 | |
| 6158 | caller()->CreateAndSetAndSignalOffer(); |
| 6159 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6160 | |
| 6161 | // Verify that one audio and one video receiver have been created on the |
| 6162 | // remote and that they have the same track IDs as the sending tracks. |
| 6163 | auto audio_receivers = |
| 6164 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO); |
| 6165 | ASSERT_EQ(1u, audio_receivers.size()); |
| 6166 | EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id()); |
| 6167 | auto video_receivers = |
| 6168 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO); |
| 6169 | ASSERT_EQ(1u, video_receivers.size()); |
| 6170 | EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id()); |
| 6171 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6172 | MediaExpectations media_expectations; |
| 6173 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 6174 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 6178 | OneAudioOneVideoLocalToOneAudioOneVideoRemote) { |
| 6179 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6180 | ConnectFakeSignaling(); |
| 6181 | caller()->AddAudioVideoTracks(); |
| 6182 | callee()->AddAudioVideoTracks(); |
| 6183 | |
| 6184 | caller()->CreateAndSetAndSignalOffer(); |
| 6185 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6186 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6187 | MediaExpectations media_expectations; |
| 6188 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 6189 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 6193 | ReverseRolesOneAudioLocalToOneVideoRemote) { |
| 6194 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 6195 | ConnectFakeSignaling(); |
| 6196 | caller()->AddAudioTrack(); |
| 6197 | callee()->AddVideoTrack(); |
| 6198 | |
| 6199 | caller()->CreateAndSetAndSignalOffer(); |
| 6200 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6201 | |
| 6202 | // Verify that only the audio track has been negotiated. |
| 6203 | EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size()); |
| 6204 | // Might also check that the callee's NegotiationNeeded flag is set. |
| 6205 | |
| 6206 | // Reverse roles. |
| 6207 | callee()->CreateAndSetAndSignalOffer(); |
| 6208 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6209 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6210 | MediaExpectations media_expectations; |
| 6211 | media_expectations.CallerExpectsSomeVideo(); |
| 6212 | media_expectations.CalleeExpectsSomeAudio(); |
| 6213 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6214 | } |
| 6215 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 6216 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | ba42e99 | 2018-04-09 14:10:01 -0700 | [diff] [blame] | 6217 | PeerConnectionIntegrationTest, |
| 6218 | PeerConnectionIntegrationInteropTest, |
| 6219 | Values(std::make_tuple(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 6220 | std::make_tuple(SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB))); |
| 6221 | |
| 6222 | // Test that if the Unified Plan side offers two video tracks then the Plan B |
| 6223 | // side will only see the first one and ignore the second. |
| 6224 | TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 6225 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics( |
| 6226 | SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6227 | ConnectFakeSignaling(); |
| 6228 | auto first_sender = caller()->AddVideoTrack(); |
| 6229 | caller()->AddVideoTrack(); |
| 6230 | |
| 6231 | caller()->CreateAndSetAndSignalOffer(); |
| 6232 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6233 | |
| 6234 | // Verify that there is only one receiver and it corresponds to the first |
| 6235 | // added track. |
| 6236 | auto receivers = callee()->pc()->GetReceivers(); |
| 6237 | ASSERT_EQ(1u, receivers.size()); |
| 6238 | EXPECT_TRUE(receivers[0]->track()->enabled()); |
| 6239 | EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id()); |
| 6240 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 6241 | MediaExpectations media_expectations; |
| 6242 | media_expectations.CalleeExpectsSomeVideo(); |
| 6243 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 6244 | } |
| 6245 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 6246 | // Test that if the initial offer tagged BUNDLE section is rejected due to its |
| 6247 | // associated RtpTransceiver being stopped and another transceiver is added, |
| 6248 | // then renegotiation causes the callee to receive the new video track without |
| 6249 | // error. |
| 6250 | // This is a regression test for bugs.webrtc.org/9954 |
| 6251 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6252 | ReOfferWithStoppedBundleTaggedTransceiver) { |
| 6253 | RTCConfiguration config; |
| 6254 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 6255 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 6256 | ConnectFakeSignaling(); |
| 6257 | auto audio_transceiver_or_error = |
| 6258 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 6259 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 6260 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 6261 | |
| 6262 | caller()->CreateAndSetAndSignalOffer(); |
| 6263 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6264 | { |
| 6265 | MediaExpectations media_expectations; |
| 6266 | media_expectations.CalleeExpectsSomeAudio(); |
| 6267 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6268 | } |
| 6269 | |
| 6270 | audio_transceiver->Stop(); |
| 6271 | caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack()); |
| 6272 | |
| 6273 | caller()->CreateAndSetAndSignalOffer(); |
| 6274 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6275 | { |
| 6276 | MediaExpectations media_expectations; |
| 6277 | media_expectations.CalleeExpectsSomeVideo(); |
| 6278 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 6279 | } |
| 6280 | } |
| 6281 | |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 6282 | #ifdef HAVE_SCTP |
| 6283 | |
| 6284 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6285 | EndToEndCallWithBundledSctpDataChannel) { |
| 6286 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6287 | ConnectFakeSignaling(); |
| 6288 | caller()->CreateDataChannel(); |
| 6289 | caller()->AddAudioVideoTracks(); |
| 6290 | callee()->AddAudioVideoTracks(); |
| 6291 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 6292 | caller()->CreateAndSetAndSignalOffer(); |
| 6293 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6294 | // Ensure that media and data are multiplexed on the same DTLS transport. |
| 6295 | // This only works on Unified Plan, because transports are not exposed in plan |
| 6296 | // B. |
| 6297 | auto sctp_info = caller()->pc()->GetSctpTransport()->Information(); |
| 6298 | EXPECT_EQ(sctp_info.dtls_transport(), |
| 6299 | caller()->pc()->GetSenders()[0]->dtls_transport()); |
| 6300 | } |
| 6301 | |
| 6302 | #endif // HAVE_SCTP |
| 6303 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 6304 | } // namespace |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 6305 | } // namespace webrtc |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 6306 | |
| 6307 | #endif // if !defined(THREAD_SANITIZER) |