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 | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 980 | void OnIceCandidateError(const std::string& address, |
| 981 | int port, |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 982 | const std::string& url, |
| 983 | int error_code, |
| 984 | const std::string& error_text) override { |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 985 | error_event_ = cricket::IceCandidateErrorEvent(address, port, url, |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 986 | error_code, error_text); |
| 987 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 988 | void OnDataChannel( |
| 989 | rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 990 | RTC_LOG(LS_INFO) << debug_name_ << ": OnDataChannel"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 991 | data_channel_ = data_channel; |
| 992 | data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 993 | } |
| 994 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 995 | std::string debug_name_; |
| 996 | |
| 997 | std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 998 | // Reference to the mDNS responder owned by |fake_network_manager_| after set. |
| 999 | webrtc::FakeMdnsResponder* mdns_responder_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1000 | |
| 1001 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 1002 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 1003 | peer_connection_factory_; |
| 1004 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1005 | cricket::PortAllocator* port_allocator_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1006 | // Needed to keep track of number of frames sent. |
| 1007 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
| 1008 | // Needed to keep track of number of frames received. |
| 1009 | std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1010 | fake_video_renderers_; |
| 1011 | // Needed to ensure frames aren't received for removed tracks. |
| 1012 | std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 1013 | removed_fake_video_renderers_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1014 | |
| 1015 | // For remote peer communication. |
| 1016 | SignalingMessageReceiver* signaling_message_receiver_ = nullptr; |
| 1017 | int signaling_delay_ms_ = 0; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1018 | bool signal_ice_candidates_ = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 1019 | cricket::Candidate last_candidate_gathered_; |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 1020 | cricket::IceCandidateErrorEvent error_event_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1021 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1022 | // 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] | 1023 | // them, if required. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1024 | std::vector<rtc::scoped_refptr<webrtc::VideoTrackSource>> |
| 1025 | video_track_sources_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1026 | // |local_video_renderer_| attached to the first created local video track. |
| 1027 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; |
| 1028 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1029 | SdpSemantics sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1030 | PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; |
| 1031 | std::function<void(cricket::SessionDescription*)> received_sdp_munger_; |
| 1032 | std::function<void(cricket::SessionDescription*)> generated_sdp_munger_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1033 | std::function<void()> remote_offer_handler_; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1034 | rtc::MockAsyncResolver* remote_async_resolver_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1035 | rtc::scoped_refptr<DataChannelInterface> data_channel_; |
| 1036 | std::unique_ptr<MockDataChannelObserver> data_observer_; |
| 1037 | |
| 1038 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
| 1039 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1040 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1041 | ice_connection_state_history_; |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 1042 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1043 | standardized_ice_connection_state_history_; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 1044 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 1045 | peer_connection_state_history_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1046 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 1047 | ice_gathering_state_history_; |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 1048 | std::vector<cricket::CandidatePairChangeEvent> |
| 1049 | ice_candidate_pair_change_history_; |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 1050 | std::vector<PeerConnectionInterface::SignalingState> |
| 1051 | peer_connection_signaling_state_history_; |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1052 | webrtc::FakeRtcEventLogFactory* event_log_factory_; |
| 1053 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1054 | rtc::AsyncInvoker invoker_; |
| 1055 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1056 | friend class PeerConnectionIntegrationBaseTest; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1057 | }; |
| 1058 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 1059 | class MockRtcEventLogOutput : public webrtc::RtcEventLogOutput { |
| 1060 | public: |
| 1061 | virtual ~MockRtcEventLogOutput() = default; |
| 1062 | MOCK_CONST_METHOD0(IsActive, bool()); |
| 1063 | MOCK_METHOD1(Write, bool(const std::string&)); |
| 1064 | }; |
| 1065 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1066 | // This helper object is used for both specifying how many audio/video frames |
| 1067 | // are expected to be received for a caller/callee. It provides helper functions |
| 1068 | // to specify these expectations. The object initially starts in a state of no |
| 1069 | // expectations. |
| 1070 | class MediaExpectations { |
| 1071 | public: |
| 1072 | enum ExpectFrames { |
| 1073 | kExpectSomeFrames, |
| 1074 | kExpectNoFrames, |
| 1075 | kNoExpectation, |
| 1076 | }; |
| 1077 | |
| 1078 | void ExpectBidirectionalAudioAndVideo() { |
| 1079 | ExpectBidirectionalAudio(); |
| 1080 | ExpectBidirectionalVideo(); |
| 1081 | } |
| 1082 | |
| 1083 | void ExpectBidirectionalAudio() { |
| 1084 | CallerExpectsSomeAudio(); |
| 1085 | CalleeExpectsSomeAudio(); |
| 1086 | } |
| 1087 | |
| 1088 | void ExpectNoAudio() { |
| 1089 | CallerExpectsNoAudio(); |
| 1090 | CalleeExpectsNoAudio(); |
| 1091 | } |
| 1092 | |
| 1093 | void ExpectBidirectionalVideo() { |
| 1094 | CallerExpectsSomeVideo(); |
| 1095 | CalleeExpectsSomeVideo(); |
| 1096 | } |
| 1097 | |
| 1098 | void ExpectNoVideo() { |
| 1099 | CallerExpectsNoVideo(); |
| 1100 | CalleeExpectsNoVideo(); |
| 1101 | } |
| 1102 | |
| 1103 | void CallerExpectsSomeAudioAndVideo() { |
| 1104 | CallerExpectsSomeAudio(); |
| 1105 | CallerExpectsSomeVideo(); |
| 1106 | } |
| 1107 | |
| 1108 | void CalleeExpectsSomeAudioAndVideo() { |
| 1109 | CalleeExpectsSomeAudio(); |
| 1110 | CalleeExpectsSomeVideo(); |
| 1111 | } |
| 1112 | |
| 1113 | // Caller's audio functions. |
| 1114 | void CallerExpectsSomeAudio( |
| 1115 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1116 | caller_audio_expectation_ = kExpectSomeFrames; |
| 1117 | caller_audio_frames_expected_ = expected_audio_frames; |
| 1118 | } |
| 1119 | |
| 1120 | void CallerExpectsNoAudio() { |
| 1121 | caller_audio_expectation_ = kExpectNoFrames; |
| 1122 | caller_audio_frames_expected_ = 0; |
| 1123 | } |
| 1124 | |
| 1125 | // Caller's video functions. |
| 1126 | void CallerExpectsSomeVideo( |
| 1127 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1128 | caller_video_expectation_ = kExpectSomeFrames; |
| 1129 | caller_video_frames_expected_ = expected_video_frames; |
| 1130 | } |
| 1131 | |
| 1132 | void CallerExpectsNoVideo() { |
| 1133 | caller_video_expectation_ = kExpectNoFrames; |
| 1134 | caller_video_frames_expected_ = 0; |
| 1135 | } |
| 1136 | |
| 1137 | // Callee's audio functions. |
| 1138 | void CalleeExpectsSomeAudio( |
| 1139 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1140 | callee_audio_expectation_ = kExpectSomeFrames; |
| 1141 | callee_audio_frames_expected_ = expected_audio_frames; |
| 1142 | } |
| 1143 | |
| 1144 | void CalleeExpectsNoAudio() { |
| 1145 | callee_audio_expectation_ = kExpectNoFrames; |
| 1146 | callee_audio_frames_expected_ = 0; |
| 1147 | } |
| 1148 | |
| 1149 | // Callee's video functions. |
| 1150 | void CalleeExpectsSomeVideo( |
| 1151 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1152 | callee_video_expectation_ = kExpectSomeFrames; |
| 1153 | callee_video_frames_expected_ = expected_video_frames; |
| 1154 | } |
| 1155 | |
| 1156 | void CalleeExpectsNoVideo() { |
| 1157 | callee_video_expectation_ = kExpectNoFrames; |
| 1158 | callee_video_frames_expected_ = 0; |
| 1159 | } |
| 1160 | |
| 1161 | ExpectFrames caller_audio_expectation_ = kNoExpectation; |
| 1162 | ExpectFrames caller_video_expectation_ = kNoExpectation; |
| 1163 | ExpectFrames callee_audio_expectation_ = kNoExpectation; |
| 1164 | ExpectFrames callee_video_expectation_ = kNoExpectation; |
| 1165 | int caller_audio_frames_expected_ = 0; |
| 1166 | int caller_video_frames_expected_ = 0; |
| 1167 | int callee_audio_frames_expected_ = 0; |
| 1168 | int callee_video_frames_expected_ = 0; |
| 1169 | }; |
| 1170 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 1171 | class MockIceTransport : public webrtc::IceTransportInterface { |
| 1172 | public: |
| 1173 | MockIceTransport(const std::string& name, int component) |
| 1174 | : internal_(std::make_unique<cricket::FakeIceTransport>( |
| 1175 | name, |
| 1176 | component, |
| 1177 | nullptr /* network_thread */)) {} |
| 1178 | ~MockIceTransport() = default; |
| 1179 | cricket::IceTransportInternal* internal() { return internal_.get(); } |
| 1180 | |
| 1181 | private: |
| 1182 | std::unique_ptr<cricket::FakeIceTransport> internal_; |
| 1183 | }; |
| 1184 | |
| 1185 | class MockIceTransportFactory : public IceTransportFactory { |
| 1186 | public: |
| 1187 | ~MockIceTransportFactory() override = default; |
| 1188 | rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 1189 | const std::string& transport_name, |
| 1190 | int component, |
| 1191 | IceTransportInit init) { |
| 1192 | RecordIceTransportCreated(); |
| 1193 | return new rtc::RefCountedObject<MockIceTransport>(transport_name, |
| 1194 | component); |
| 1195 | } |
| 1196 | MOCK_METHOD0(RecordIceTransportCreated, void()); |
| 1197 | }; |
| 1198 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1199 | // Tests two PeerConnections connecting to each other end-to-end, using a |
| 1200 | // virtual network, fake A/V capture and fake encoder/decoders. The |
| 1201 | // PeerConnections share the threads/socket servers, but use separate versions |
| 1202 | // of everything else (including "PeerConnectionFactory"s). |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 1203 | class PeerConnectionIntegrationBaseTest : public ::testing::Test { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1204 | public: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1205 | explicit PeerConnectionIntegrationBaseTest(SdpSemantics sdp_semantics) |
| 1206 | : sdp_semantics_(sdp_semantics), |
| 1207 | ss_(new rtc::VirtualSocketServer()), |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1208 | fss_(new rtc::FirewallSocketServer(ss_.get())), |
| 1209 | network_thread_(new rtc::Thread(fss_.get())), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1210 | worker_thread_(rtc::Thread::Create()), |
| 1211 | loopback_media_transports_(network_thread_.get()) { |
Sebastian Jansson | 8a793a0 | 2018-03-13 15:21:48 +0100 | [diff] [blame] | 1212 | network_thread_->SetName("PCNetworkThread", this); |
| 1213 | worker_thread_->SetName("PCWorkerThread", this); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1214 | RTC_CHECK(network_thread_->Start()); |
| 1215 | RTC_CHECK(worker_thread_->Start()); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1216 | webrtc::metrics::Reset(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1219 | ~PeerConnectionIntegrationBaseTest() { |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1220 | // The PeerConnections should deleted before the TurnCustomizers. |
| 1221 | // A TurnPort is created with a raw pointer to a TurnCustomizer. The |
| 1222 | // TurnPort has the same lifetime as the PeerConnection, so it's expected |
| 1223 | // that the TurnCustomizer outlives the life of the PeerConnection or else |
| 1224 | // when Send() is called it will hit a seg fault. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1225 | if (caller_) { |
| 1226 | caller_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1227 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1228 | } |
| 1229 | if (callee_) { |
| 1230 | callee_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1231 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1232 | } |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1233 | |
| 1234 | // If turn servers were created for the test they need to be destroyed on |
| 1235 | // the network thread. |
| 1236 | network_thread()->Invoke<void>(RTC_FROM_HERE, [this] { |
| 1237 | turn_servers_.clear(); |
| 1238 | turn_customizers_.clear(); |
| 1239 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | bool SignalingStateStable() { |
| 1243 | return caller_->SignalingStateStable() && callee_->SignalingStateStable(); |
| 1244 | } |
| 1245 | |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1246 | bool DtlsConnected() { |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1247 | // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS |
| 1248 | // are connected. This is an important distinction. Once we have separate |
| 1249 | // ICE and DTLS state, this check needs to use the DTLS state. |
| 1250 | return (callee()->ice_connection_state() == |
| 1251 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1252 | callee()->ice_connection_state() == |
| 1253 | webrtc::PeerConnectionInterface::kIceConnectionCompleted) && |
| 1254 | (caller()->ice_connection_state() == |
| 1255 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1256 | caller()->ice_connection_state() == |
| 1257 | webrtc::PeerConnectionInterface::kIceConnectionCompleted); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1260 | // When |event_log_factory| is null, the default implementation of the event |
| 1261 | // log factory will be used. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1262 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWrapper( |
| 1263 | const std::string& debug_name, |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1264 | const PeerConnectionFactory::Options* options, |
| 1265 | const RTCConfiguration* config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1266 | webrtc::PeerConnectionDependencies dependencies, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1267 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 1268 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1269 | RTCConfiguration modified_config; |
| 1270 | if (config) { |
| 1271 | modified_config = *config; |
| 1272 | } |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1273 | modified_config.sdp_semantics = sdp_semantics_; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1274 | if (!dependencies.cert_generator) { |
| 1275 | dependencies.cert_generator = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1276 | std::make_unique<FakeRTCCertificateGenerator>(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1277 | } |
| 1278 | std::unique_ptr<PeerConnectionWrapper> client( |
| 1279 | new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1280 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1281 | if (!client->Init(options, &modified_config, std::move(dependencies), |
| 1282 | network_thread_.get(), worker_thread_.get(), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1283 | std::move(event_log_factory), |
| 1284 | std::move(media_transport_factory))) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1285 | return nullptr; |
| 1286 | } |
| 1287 | return client; |
| 1288 | } |
| 1289 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1290 | std::unique_ptr<PeerConnectionWrapper> |
| 1291 | CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1292 | const std::string& debug_name, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1293 | const PeerConnectionFactory::Options* options, |
| 1294 | const RTCConfiguration* config, |
| 1295 | webrtc::PeerConnectionDependencies dependencies) { |
| 1296 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory( |
| 1297 | new webrtc::FakeRtcEventLogFactory(rtc::Thread::Current())); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1298 | return CreatePeerConnectionWrapper(debug_name, options, config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1299 | std::move(dependencies), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1300 | std::move(event_log_factory), |
| 1301 | /*media_transport_factory=*/nullptr); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1304 | bool CreatePeerConnectionWrappers() { |
| 1305 | return CreatePeerConnectionWrappersWithConfig( |
| 1306 | PeerConnectionInterface::RTCConfiguration(), |
| 1307 | PeerConnectionInterface::RTCConfiguration()); |
| 1308 | } |
| 1309 | |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1310 | bool CreatePeerConnectionWrappersWithSdpSemantics( |
| 1311 | SdpSemantics caller_semantics, |
| 1312 | SdpSemantics callee_semantics) { |
| 1313 | // Can't specify the sdp_semantics in the passed-in configuration since it |
| 1314 | // will be overwritten by CreatePeerConnectionWrapper with whatever is |
| 1315 | // stored in sdp_semantics_. So get around this by modifying the instance |
| 1316 | // variable before calling CreatePeerConnectionWrapper for the caller and |
| 1317 | // callee PeerConnections. |
| 1318 | SdpSemantics original_semantics = sdp_semantics_; |
| 1319 | sdp_semantics_ = caller_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1320 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1321 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1322 | nullptr, /*media_transport_factory=*/nullptr); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1323 | sdp_semantics_ = callee_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1324 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1325 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1326 | nullptr, /*media_transport_factory=*/nullptr); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1327 | sdp_semantics_ = original_semantics; |
| 1328 | return caller_ && callee_; |
| 1329 | } |
| 1330 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1331 | bool CreatePeerConnectionWrappersWithConfig( |
| 1332 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1333 | const PeerConnectionInterface::RTCConfiguration& callee_config) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1334 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1335 | "Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1336 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1337 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1338 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1339 | "Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1340 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1341 | /*media_transport_factory=*/nullptr); |
| 1342 | return caller_ && callee_; |
| 1343 | } |
| 1344 | |
| 1345 | bool CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 1346 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1347 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1348 | std::unique_ptr<webrtc::MediaTransportFactory> caller_factory, |
| 1349 | std::unique_ptr<webrtc::MediaTransportFactory> callee_factory) { |
| 1350 | caller_ = |
| 1351 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
| 1352 | webrtc::PeerConnectionDependencies(nullptr), |
| 1353 | nullptr, std::move(caller_factory)); |
| 1354 | callee_ = |
| 1355 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
| 1356 | webrtc::PeerConnectionDependencies(nullptr), |
| 1357 | nullptr, std::move(callee_factory)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1358 | return caller_ && callee_; |
| 1359 | } |
| 1360 | |
| 1361 | bool CreatePeerConnectionWrappersWithConfigAndDeps( |
| 1362 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1363 | webrtc::PeerConnectionDependencies caller_dependencies, |
| 1364 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1365 | webrtc::PeerConnectionDependencies callee_dependencies) { |
| 1366 | caller_ = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1367 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1368 | std::move(caller_dependencies), nullptr, |
| 1369 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1370 | callee_ = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1371 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1372 | std::move(callee_dependencies), nullptr, |
| 1373 | /*media_transport_factory=*/nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1374 | return caller_ && callee_; |
| 1375 | } |
| 1376 | |
| 1377 | bool CreatePeerConnectionWrappersWithOptions( |
| 1378 | const PeerConnectionFactory::Options& caller_options, |
| 1379 | const PeerConnectionFactory::Options& callee_options) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1380 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1381 | "Caller", &caller_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1382 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1383 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1384 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1385 | "Callee", &callee_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1386 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1387 | /*media_transport_factory=*/nullptr); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1388 | return caller_ && callee_; |
| 1389 | } |
| 1390 | |
| 1391 | bool CreatePeerConnectionWrappersWithFakeRtcEventLog() { |
| 1392 | PeerConnectionInterface::RTCConfiguration default_config; |
| 1393 | caller_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1394 | "Caller", nullptr, &default_config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1395 | webrtc::PeerConnectionDependencies(nullptr)); |
| 1396 | callee_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1397 | "Callee", nullptr, &default_config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1398 | webrtc::PeerConnectionDependencies(nullptr)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1399 | return caller_ && callee_; |
| 1400 | } |
| 1401 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1402 | std::unique_ptr<PeerConnectionWrapper> |
| 1403 | CreatePeerConnectionWrapperWithAlternateKey() { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1404 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 1405 | new FakeRTCCertificateGenerator()); |
| 1406 | cert_generator->use_alternate_key(); |
| 1407 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1408 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 1409 | dependencies.cert_generator = std::move(cert_generator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1410 | return CreatePeerConnectionWrapper("New Peer", nullptr, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1411 | std::move(dependencies), nullptr, |
| 1412 | /*media_transport_factory=*/nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1415 | cricket::TestTurnServer* CreateTurnServer( |
| 1416 | rtc::SocketAddress internal_address, |
| 1417 | rtc::SocketAddress external_address, |
| 1418 | cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP, |
| 1419 | const std::string& common_name = "test turn server") { |
| 1420 | rtc::Thread* thread = network_thread(); |
| 1421 | std::unique_ptr<cricket::TestTurnServer> turn_server = |
| 1422 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnServer>>( |
| 1423 | RTC_FROM_HERE, |
| 1424 | [thread, internal_address, external_address, type, common_name] { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1425 | return std::make_unique<cricket::TestTurnServer>( |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1426 | thread, internal_address, external_address, type, |
| 1427 | /*ignore_bad_certs=*/true, common_name); |
| 1428 | }); |
| 1429 | turn_servers_.push_back(std::move(turn_server)); |
| 1430 | // Interactions with the turn server should be done on the network thread. |
| 1431 | return turn_servers_.back().get(); |
| 1432 | } |
| 1433 | |
| 1434 | cricket::TestTurnCustomizer* CreateTurnCustomizer() { |
| 1435 | std::unique_ptr<cricket::TestTurnCustomizer> turn_customizer = |
| 1436 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnCustomizer>>( |
| 1437 | RTC_FROM_HERE, |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1438 | [] { return std::make_unique<cricket::TestTurnCustomizer>(); }); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1439 | turn_customizers_.push_back(std::move(turn_customizer)); |
| 1440 | // Interactions with the turn customizer should be done on the network |
| 1441 | // thread. |
| 1442 | return turn_customizers_.back().get(); |
| 1443 | } |
| 1444 | |
| 1445 | // Checks that the function counters for a TestTurnCustomizer are greater than |
| 1446 | // 0. |
| 1447 | void ExpectTurnCustomizerCountersIncremented( |
| 1448 | cricket::TestTurnCustomizer* turn_customizer) { |
| 1449 | unsigned int allow_channel_data_counter = |
| 1450 | network_thread()->Invoke<unsigned int>( |
| 1451 | RTC_FROM_HERE, [turn_customizer] { |
| 1452 | return turn_customizer->allow_channel_data_cnt_; |
| 1453 | }); |
| 1454 | EXPECT_GT(allow_channel_data_counter, 0u); |
| 1455 | unsigned int modify_counter = network_thread()->Invoke<unsigned int>( |
| 1456 | RTC_FROM_HERE, |
| 1457 | [turn_customizer] { return turn_customizer->modify_cnt_; }); |
| 1458 | EXPECT_GT(modify_counter, 0u); |
| 1459 | } |
| 1460 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1461 | // Once called, SDP blobs and ICE candidates will be automatically signaled |
| 1462 | // between PeerConnections. |
| 1463 | void ConnectFakeSignaling() { |
| 1464 | caller_->set_signaling_message_receiver(callee_.get()); |
| 1465 | callee_->set_signaling_message_receiver(caller_.get()); |
| 1466 | } |
| 1467 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1468 | // Once called, SDP blobs will be automatically signaled between |
| 1469 | // PeerConnections. Note that ICE candidates will not be signaled unless they |
| 1470 | // are in the exchanged SDP blobs. |
| 1471 | void ConnectFakeSignalingForSdpOnly() { |
| 1472 | ConnectFakeSignaling(); |
| 1473 | SetSignalIceCandidates(false); |
| 1474 | } |
| 1475 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1476 | void SetSignalingDelayMs(int delay_ms) { |
| 1477 | caller_->set_signaling_delay_ms(delay_ms); |
| 1478 | callee_->set_signaling_delay_ms(delay_ms); |
| 1479 | } |
| 1480 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1481 | void SetSignalIceCandidates(bool signal) { |
| 1482 | caller_->set_signal_ice_candidates(signal); |
| 1483 | callee_->set_signal_ice_candidates(signal); |
| 1484 | } |
| 1485 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1486 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1487 | // times to avoid test flakiness. |
| 1488 | void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc, |
| 1489 | const std::string& data, |
| 1490 | int retries) { |
| 1491 | for (int i = 0; i < retries; ++i) { |
| 1492 | dc->Send(DataBuffer(data)); |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | rtc::Thread* network_thread() { return network_thread_.get(); } |
| 1497 | |
| 1498 | rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1499 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1500 | webrtc::MediaTransportPair* loopback_media_transports() { |
| 1501 | return &loopback_media_transports_; |
| 1502 | } |
| 1503 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1504 | PeerConnectionWrapper* caller() { return caller_.get(); } |
| 1505 | |
| 1506 | // Set the |caller_| to the |wrapper| passed in and return the |
| 1507 | // original |caller_|. |
| 1508 | PeerConnectionWrapper* SetCallerPcWrapperAndReturnCurrent( |
| 1509 | PeerConnectionWrapper* wrapper) { |
| 1510 | PeerConnectionWrapper* old = caller_.release(); |
| 1511 | caller_.reset(wrapper); |
| 1512 | return old; |
| 1513 | } |
| 1514 | |
| 1515 | PeerConnectionWrapper* callee() { return callee_.get(); } |
| 1516 | |
| 1517 | // Set the |callee_| to the |wrapper| passed in and return the |
| 1518 | // original |callee_|. |
| 1519 | PeerConnectionWrapper* SetCalleePcWrapperAndReturnCurrent( |
| 1520 | PeerConnectionWrapper* wrapper) { |
| 1521 | PeerConnectionWrapper* old = callee_.release(); |
| 1522 | callee_.reset(wrapper); |
| 1523 | return old; |
| 1524 | } |
| 1525 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1526 | void SetPortAllocatorFlags(uint32_t caller_flags, uint32_t callee_flags) { |
| 1527 | network_thread()->Invoke<void>( |
| 1528 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1529 | caller()->port_allocator(), caller_flags)); |
| 1530 | network_thread()->Invoke<void>( |
| 1531 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1532 | callee()->port_allocator(), callee_flags)); |
| 1533 | } |
| 1534 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1535 | rtc::FirewallSocketServer* firewall() const { return fss_.get(); } |
| 1536 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1537 | // Expects the provided number of new frames to be received within |
| 1538 | // kMaxWaitForFramesMs. The new expected frames are specified in |
| 1539 | // |media_expectations|. Returns false if any of the expectations were |
| 1540 | // not met. |
| 1541 | bool ExpectNewFrames(const MediaExpectations& media_expectations) { |
| 1542 | // First initialize the expected frame counts based upon the current |
| 1543 | // frame count. |
| 1544 | int total_caller_audio_frames_expected = caller()->audio_frames_received(); |
| 1545 | if (media_expectations.caller_audio_expectation_ == |
| 1546 | MediaExpectations::kExpectSomeFrames) { |
| 1547 | total_caller_audio_frames_expected += |
| 1548 | media_expectations.caller_audio_frames_expected_; |
| 1549 | } |
| 1550 | int total_caller_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1551 | caller()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1552 | if (media_expectations.caller_video_expectation_ == |
| 1553 | MediaExpectations::kExpectSomeFrames) { |
| 1554 | total_caller_video_frames_expected += |
| 1555 | media_expectations.caller_video_frames_expected_; |
| 1556 | } |
| 1557 | int total_callee_audio_frames_expected = callee()->audio_frames_received(); |
| 1558 | if (media_expectations.callee_audio_expectation_ == |
| 1559 | MediaExpectations::kExpectSomeFrames) { |
| 1560 | total_callee_audio_frames_expected += |
| 1561 | media_expectations.callee_audio_frames_expected_; |
| 1562 | } |
| 1563 | int total_callee_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1564 | callee()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1565 | if (media_expectations.callee_video_expectation_ == |
| 1566 | MediaExpectations::kExpectSomeFrames) { |
| 1567 | total_callee_video_frames_expected += |
| 1568 | media_expectations.callee_video_frames_expected_; |
| 1569 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1570 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1571 | // Wait for the expected frames. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1572 | EXPECT_TRUE_WAIT(caller()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1573 | total_caller_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1574 | caller()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1575 | total_caller_video_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1576 | callee()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1577 | total_callee_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1578 | callee()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1579 | total_callee_video_frames_expected, |
| 1580 | kMaxWaitForFramesMs); |
| 1581 | bool expectations_correct = |
| 1582 | caller()->audio_frames_received() >= |
| 1583 | total_caller_audio_frames_expected && |
| 1584 | caller()->min_video_frames_received_per_track() >= |
| 1585 | total_caller_video_frames_expected && |
| 1586 | callee()->audio_frames_received() >= |
| 1587 | total_callee_audio_frames_expected && |
| 1588 | callee()->min_video_frames_received_per_track() >= |
| 1589 | total_callee_video_frames_expected; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1590 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1591 | // After the combined wait, print out a more detailed message upon |
| 1592 | // failure. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1593 | EXPECT_GE(caller()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1594 | total_caller_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1595 | EXPECT_GE(caller()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1596 | total_caller_video_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1597 | EXPECT_GE(callee()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1598 | total_callee_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1599 | EXPECT_GE(callee()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1600 | total_callee_video_frames_expected); |
| 1601 | |
| 1602 | // We want to make sure nothing unexpected was received. |
| 1603 | if (media_expectations.caller_audio_expectation_ == |
| 1604 | MediaExpectations::kExpectNoFrames) { |
| 1605 | EXPECT_EQ(caller()->audio_frames_received(), |
| 1606 | total_caller_audio_frames_expected); |
| 1607 | if (caller()->audio_frames_received() != |
| 1608 | total_caller_audio_frames_expected) { |
| 1609 | expectations_correct = false; |
| 1610 | } |
| 1611 | } |
| 1612 | if (media_expectations.caller_video_expectation_ == |
| 1613 | MediaExpectations::kExpectNoFrames) { |
| 1614 | EXPECT_EQ(caller()->min_video_frames_received_per_track(), |
| 1615 | total_caller_video_frames_expected); |
| 1616 | if (caller()->min_video_frames_received_per_track() != |
| 1617 | total_caller_video_frames_expected) { |
| 1618 | expectations_correct = false; |
| 1619 | } |
| 1620 | } |
| 1621 | if (media_expectations.callee_audio_expectation_ == |
| 1622 | MediaExpectations::kExpectNoFrames) { |
| 1623 | EXPECT_EQ(callee()->audio_frames_received(), |
| 1624 | total_callee_audio_frames_expected); |
| 1625 | if (callee()->audio_frames_received() != |
| 1626 | total_callee_audio_frames_expected) { |
| 1627 | expectations_correct = false; |
| 1628 | } |
| 1629 | } |
| 1630 | if (media_expectations.callee_video_expectation_ == |
| 1631 | MediaExpectations::kExpectNoFrames) { |
| 1632 | EXPECT_EQ(callee()->min_video_frames_received_per_track(), |
| 1633 | total_callee_video_frames_expected); |
| 1634 | if (callee()->min_video_frames_received_per_track() != |
| 1635 | total_callee_video_frames_expected) { |
| 1636 | expectations_correct = false; |
| 1637 | } |
| 1638 | } |
| 1639 | return expectations_correct; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 1642 | void ClosePeerConnections() { |
| 1643 | caller()->pc()->Close(); |
| 1644 | callee()->pc()->Close(); |
| 1645 | } |
| 1646 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1647 | void TestNegotiatedCipherSuite( |
| 1648 | const PeerConnectionFactory::Options& caller_options, |
| 1649 | const PeerConnectionFactory::Options& callee_options, |
| 1650 | int expected_cipher_suite) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1651 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options, |
| 1652 | callee_options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1653 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1654 | caller()->AddAudioVideoTracks(); |
| 1655 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1656 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1657 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1658 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1659 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1660 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1661 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 1662 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1663 | expected_cipher_suite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1666 | void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled, |
| 1667 | bool remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1668 | bool aes_ctr_enabled, |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1669 | int expected_cipher_suite) { |
| 1670 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1671 | caller_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1672 | local_gcm_enabled; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1673 | caller_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1674 | aes_ctr_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1675 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1676 | callee_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1677 | remote_gcm_enabled; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 1678 | callee_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = |
| 1679 | aes_ctr_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1680 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1681 | expected_cipher_suite); |
| 1682 | } |
| 1683 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1684 | protected: |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1685 | SdpSemantics sdp_semantics_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1686 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1687 | private: |
| 1688 | // |ss_| is used by |network_thread_| so it must be destroyed later. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1689 | std::unique_ptr<rtc::VirtualSocketServer> ss_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1690 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1691 | // |network_thread_| and |worker_thread_| are used by both |
| 1692 | // |caller_| and |callee_| so they must be destroyed |
| 1693 | // later. |
| 1694 | std::unique_ptr<rtc::Thread> network_thread_; |
| 1695 | std::unique_ptr<rtc::Thread> worker_thread_; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1696 | // The turn servers and turn customizers should be accessed & deleted on the |
| 1697 | // network thread to avoid a race with the socket read/write that occurs |
| 1698 | // on the network thread. |
| 1699 | std::vector<std::unique_ptr<cricket::TestTurnServer>> turn_servers_; |
| 1700 | std::vector<std::unique_ptr<cricket::TestTurnCustomizer>> turn_customizers_; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1701 | webrtc::MediaTransportPair loopback_media_transports_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1702 | std::unique_ptr<PeerConnectionWrapper> caller_; |
| 1703 | std::unique_ptr<PeerConnectionWrapper> callee_; |
| 1704 | }; |
| 1705 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1706 | class PeerConnectionIntegrationTest |
| 1707 | : public PeerConnectionIntegrationBaseTest, |
| 1708 | public ::testing::WithParamInterface<SdpSemantics> { |
| 1709 | protected: |
| 1710 | PeerConnectionIntegrationTest() |
| 1711 | : PeerConnectionIntegrationBaseTest(GetParam()) {} |
| 1712 | }; |
| 1713 | |
| 1714 | class PeerConnectionIntegrationTestPlanB |
| 1715 | : public PeerConnectionIntegrationBaseTest { |
| 1716 | protected: |
| 1717 | PeerConnectionIntegrationTestPlanB() |
| 1718 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {} |
| 1719 | }; |
| 1720 | |
| 1721 | class PeerConnectionIntegrationTestUnifiedPlan |
| 1722 | : public PeerConnectionIntegrationBaseTest { |
| 1723 | protected: |
| 1724 | PeerConnectionIntegrationTestUnifiedPlan() |
| 1725 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 1726 | }; |
| 1727 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1728 | // Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This |
| 1729 | // includes testing that the callback is invoked if an observer is connected |
| 1730 | // after the first packet has already been received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1731 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1732 | RtpReceiverObserverOnFirstPacketReceived) { |
| 1733 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1734 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1735 | caller()->AddAudioVideoTracks(); |
| 1736 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1737 | // Start offer/answer exchange and wait for it to complete. |
| 1738 | caller()->CreateAndSetAndSignalOffer(); |
| 1739 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1740 | // Should be one receiver each for audio/video. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1741 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1742 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1743 | // Wait for all "first packet received" callbacks to be fired. |
| 1744 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1745 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1746 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1747 | return o->first_packet_received(); |
| 1748 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1749 | kMaxWaitForFramesMs); |
| 1750 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1751 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1752 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1753 | return o->first_packet_received(); |
| 1754 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1755 | kMaxWaitForFramesMs); |
| 1756 | // If new observers are set after the first packet was already received, the |
| 1757 | // callback should still be invoked. |
| 1758 | caller()->ResetRtpReceiverObservers(); |
| 1759 | callee()->ResetRtpReceiverObservers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1760 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1761 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1762 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1763 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1764 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1765 | return o->first_packet_received(); |
| 1766 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1767 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1768 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1769 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1770 | return o->first_packet_received(); |
| 1771 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 1775 | public: |
| 1776 | DummyDtmfObserver() : completed_(false) {} |
| 1777 | |
| 1778 | // Implements DtmfSenderObserverInterface. |
| 1779 | void OnToneChange(const std::string& tone) override { |
| 1780 | tones_.push_back(tone); |
| 1781 | if (tone.empty()) { |
| 1782 | completed_ = true; |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | const std::vector<std::string>& tones() const { return tones_; } |
| 1787 | bool completed() const { return completed_; } |
| 1788 | |
| 1789 | private: |
| 1790 | bool completed_; |
| 1791 | std::vector<std::string> tones_; |
| 1792 | }; |
| 1793 | |
| 1794 | // Assumes |sender| already has an audio track added and the offer/answer |
| 1795 | // exchange is done. |
| 1796 | void TestDtmfFromSenderToReceiver(PeerConnectionWrapper* sender, |
| 1797 | PeerConnectionWrapper* receiver) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1798 | // We should be able to get a DTMF sender from the local sender. |
| 1799 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender = |
| 1800 | sender->pc()->GetSenders().at(0)->GetDtmfSender(); |
| 1801 | ASSERT_TRUE(dtmf_sender); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1802 | DummyDtmfObserver observer; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1803 | dtmf_sender->RegisterObserver(&observer); |
| 1804 | |
| 1805 | // Test the DtmfSender object just created. |
| 1806 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 1807 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 1808 | |
| 1809 | EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout); |
| 1810 | std::vector<std::string> tones = {"1", "a", ""}; |
| 1811 | EXPECT_EQ(tones, observer.tones()); |
| 1812 | dtmf_sender->UnregisterObserver(); |
| 1813 | // TODO(deadbeef): Verify the tones were actually received end-to-end. |
| 1814 | } |
| 1815 | |
| 1816 | // Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each |
| 1817 | // direction). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1818 | TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1819 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1820 | ConnectFakeSignaling(); |
| 1821 | // Only need audio for DTMF. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1822 | caller()->AddAudioTrack(); |
| 1823 | callee()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1824 | caller()->CreateAndSetAndSignalOffer(); |
| 1825 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1826 | // DTLS must finish before the DTMF sender can be used reliably. |
| 1827 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1828 | TestDtmfFromSenderToReceiver(caller(), callee()); |
| 1829 | TestDtmfFromSenderToReceiver(callee(), caller()); |
| 1830 | } |
| 1831 | |
| 1832 | // Basic end-to-end test, verifying media can be encoded/transmitted/decoded |
| 1833 | // between two connections, using DTLS-SRTP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1834 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1835 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1836 | ConnectFakeSignaling(); |
Harald Alvestrand | 194939b | 2018-01-24 16:04:13 +0100 | [diff] [blame] | 1837 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1838 | // Do normal offer/answer and wait for some frames to be received in each |
| 1839 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1840 | caller()->AddAudioVideoTracks(); |
| 1841 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1842 | caller()->CreateAndSetAndSignalOffer(); |
| 1843 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1844 | MediaExpectations media_expectations; |
| 1845 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1846 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1847 | EXPECT_METRIC_LE( |
| 1848 | 2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1849 | webrtc::kEnumCounterKeyProtocolDtls)); |
| 1850 | EXPECT_METRIC_EQ( |
| 1851 | 0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1852 | webrtc::kEnumCounterKeyProtocolSdes)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | // Uses SDES instead of DTLS for key agreement. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1856 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1857 | PeerConnectionInterface::RTCConfiguration sdes_config; |
| 1858 | sdes_config.enable_dtls_srtp.emplace(false); |
| 1859 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config)); |
| 1860 | ConnectFakeSignaling(); |
| 1861 | |
| 1862 | // Do normal offer/answer and wait for some frames to be received in each |
| 1863 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1864 | caller()->AddAudioVideoTracks(); |
| 1865 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1866 | caller()->CreateAndSetAndSignalOffer(); |
| 1867 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1868 | MediaExpectations media_expectations; |
| 1869 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1870 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 1871 | EXPECT_METRIC_LE( |
| 1872 | 2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1873 | webrtc::kEnumCounterKeyProtocolSdes)); |
| 1874 | EXPECT_METRIC_EQ( |
| 1875 | 0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1876 | webrtc::kEnumCounterKeyProtocolDtls)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
Steve Anton | 9a44b2d | 2019-07-12 12:58:30 -0700 | [diff] [blame] | 1879 | // Basic end-to-end test specifying the |enable_encrypted_rtp_header_extensions| |
| 1880 | // option to offer encrypted versions of all header extensions alongside the |
| 1881 | // unencrypted versions. |
| 1882 | TEST_P(PeerConnectionIntegrationTest, |
| 1883 | EndToEndCallWithEncryptedRtpHeaderExtensions) { |
| 1884 | CryptoOptions crypto_options; |
| 1885 | crypto_options.srtp.enable_encrypted_rtp_header_extensions = true; |
| 1886 | PeerConnectionInterface::RTCConfiguration config; |
| 1887 | config.crypto_options = crypto_options; |
| 1888 | // Note: This allows offering >14 RTP header extensions. |
| 1889 | config.offer_extmap_allow_mixed = true; |
| 1890 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 1891 | ConnectFakeSignaling(); |
| 1892 | |
| 1893 | // Do normal offer/answer and wait for some frames to be received in each |
| 1894 | // direction. |
| 1895 | caller()->AddAudioVideoTracks(); |
| 1896 | callee()->AddAudioVideoTracks(); |
| 1897 | caller()->CreateAndSetAndSignalOffer(); |
| 1898 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1899 | MediaExpectations media_expectations; |
| 1900 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1901 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1902 | } |
| 1903 | |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1904 | // Tests that the GetRemoteAudioSSLCertificate method returns the remote DTLS |
| 1905 | // certificate once the DTLS handshake has finished. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1906 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1907 | GetRemoteAudioSSLCertificateReturnsExchangedCertificate) { |
| 1908 | auto GetRemoteAudioSSLCertificate = [](PeerConnectionWrapper* wrapper) { |
| 1909 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1910 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1911 | return pc->GetRemoteAudioSSLCertificate(); |
| 1912 | }; |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1913 | auto GetRemoteAudioSSLCertChain = [](PeerConnectionWrapper* wrapper) { |
| 1914 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1915 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1916 | return pc->GetRemoteAudioSSLCertChain(); |
| 1917 | }; |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1918 | |
| 1919 | auto caller_cert = rtc::RTCCertificate::FromPEM(kRsaPems[0]); |
| 1920 | auto callee_cert = rtc::RTCCertificate::FromPEM(kRsaPems[1]); |
| 1921 | |
| 1922 | // Configure each side with a known certificate so they can be compared later. |
| 1923 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 1924 | caller_config.enable_dtls_srtp.emplace(true); |
| 1925 | caller_config.certificates.push_back(caller_cert); |
| 1926 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 1927 | callee_config.enable_dtls_srtp.emplace(true); |
| 1928 | callee_config.certificates.push_back(callee_cert); |
| 1929 | ASSERT_TRUE( |
| 1930 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 1931 | ConnectFakeSignaling(); |
| 1932 | |
| 1933 | // When first initialized, there should not be a remote SSL certificate (and |
| 1934 | // calling this method should not crash). |
| 1935 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(caller())); |
| 1936 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(callee())); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1937 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(caller())); |
| 1938 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(callee())); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1939 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1940 | caller()->AddAudioTrack(); |
| 1941 | callee()->AddAudioTrack(); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1942 | caller()->CreateAndSetAndSignalOffer(); |
| 1943 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1944 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 1945 | |
| 1946 | // Once DTLS has been connected, each side should return the other's SSL |
| 1947 | // certificate when calling GetRemoteAudioSSLCertificate. |
| 1948 | |
| 1949 | auto caller_remote_cert = GetRemoteAudioSSLCertificate(caller()); |
| 1950 | ASSERT_TRUE(caller_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1951 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1952 | caller_remote_cert->ToPEMString()); |
| 1953 | |
| 1954 | auto callee_remote_cert = GetRemoteAudioSSLCertificate(callee()); |
| 1955 | ASSERT_TRUE(callee_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1956 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1957 | callee_remote_cert->ToPEMString()); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1958 | |
| 1959 | auto caller_remote_cert_chain = GetRemoteAudioSSLCertChain(caller()); |
| 1960 | ASSERT_TRUE(caller_remote_cert_chain); |
| 1961 | ASSERT_EQ(1U, caller_remote_cert_chain->GetSize()); |
| 1962 | auto remote_cert = &caller_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1963 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1964 | remote_cert->ToPEMString()); |
| 1965 | |
| 1966 | auto callee_remote_cert_chain = GetRemoteAudioSSLCertChain(callee()); |
| 1967 | ASSERT_TRUE(callee_remote_cert_chain); |
| 1968 | ASSERT_EQ(1U, callee_remote_cert_chain->GetSize()); |
| 1969 | remote_cert = &callee_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1970 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1971 | remote_cert->ToPEMString()); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1974 | // This test sets up a call between two parties with a source resolution of |
| 1975 | // 1280x720 and verifies that a 16:9 aspect ratio is received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1976 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1977 | Send1280By720ResolutionAndReceive16To9AspectRatio) { |
| 1978 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1979 | ConnectFakeSignaling(); |
| 1980 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1981 | // Add video tracks with 16:9 aspect ratio, size 1280 x 720. |
| 1982 | webrtc::FakePeriodicVideoSource::Config config; |
| 1983 | config.width = 1280; |
| 1984 | config.height = 720; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 1985 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1986 | caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); |
| 1987 | callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1988 | |
| 1989 | // Do normal offer/answer and wait for at least one frame to be received in |
| 1990 | // each direction. |
| 1991 | caller()->CreateAndSetAndSignalOffer(); |
| 1992 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 1993 | callee()->min_video_frames_received_per_track() > 0, |
| 1994 | kMaxWaitForFramesMs); |
| 1995 | |
| 1996 | // Check rendered aspect ratio. |
| 1997 | EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio()); |
| 1998 | EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio()); |
| 1999 | EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio()); |
| 2000 | EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio()); |
| 2001 | } |
| 2002 | |
| 2003 | // This test sets up an one-way call, with media only from caller to |
| 2004 | // callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2005 | TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2006 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2007 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2008 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2009 | caller()->CreateAndSetAndSignalOffer(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2010 | MediaExpectations media_expectations; |
| 2011 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2012 | media_expectations.CallerExpectsNoAudio(); |
| 2013 | media_expectations.CallerExpectsNoVideo(); |
| 2014 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | // This test sets up a audio call initially, with the callee rejecting video |
| 2018 | // initially. Then later the callee decides to upgrade to audio/video, and |
| 2019 | // initiates a new offer/answer exchange. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2020 | TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2021 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2022 | ConnectFakeSignaling(); |
| 2023 | // Initially, offer an audio/video stream from the caller, but refuse to |
| 2024 | // send/receive video on the callee side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2025 | caller()->AddAudioVideoTracks(); |
| 2026 | callee()->AddAudioTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2027 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2028 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2029 | options.offer_to_receive_video = 0; |
| 2030 | callee()->SetOfferAnswerOptions(options); |
| 2031 | } else { |
| 2032 | callee()->SetRemoteOfferHandler([this] { |
| 2033 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2034 | }); |
| 2035 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2036 | // Do offer/answer and make sure audio is still received end-to-end. |
| 2037 | caller()->CreateAndSetAndSignalOffer(); |
| 2038 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2039 | { |
| 2040 | MediaExpectations media_expectations; |
| 2041 | media_expectations.ExpectBidirectionalAudio(); |
| 2042 | media_expectations.ExpectNoVideo(); |
| 2043 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2044 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2045 | // Sanity check that the callee's description has a rejected video section. |
| 2046 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2047 | const ContentInfo* callee_video_content = |
| 2048 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2049 | ASSERT_NE(nullptr, callee_video_content); |
| 2050 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2051 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2052 | // Now negotiate with video and ensure negotiation succeeds, with video |
| 2053 | // frames and additional audio frames being received. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2054 | callee()->AddVideoTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2055 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2056 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2057 | options.offer_to_receive_video = 1; |
| 2058 | callee()->SetOfferAnswerOptions(options); |
| 2059 | } else { |
| 2060 | callee()->SetRemoteOfferHandler(nullptr); |
| 2061 | caller()->SetRemoteOfferHandler([this] { |
| 2062 | // The caller creates a new transceiver to receive video on when receiving |
| 2063 | // the offer, but by default it is send only. |
| 2064 | auto transceivers = caller()->pc()->GetTransceivers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 2065 | ASSERT_EQ(3U, transceivers.size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2066 | ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO, |
| 2067 | transceivers[2]->receiver()->media_type()); |
| 2068 | transceivers[2]->sender()->SetTrack(caller()->CreateLocalVideoTrack()); |
| 2069 | transceivers[2]->SetDirection(RtpTransceiverDirection::kSendRecv); |
| 2070 | }); |
| 2071 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2072 | callee()->CreateAndSetAndSignalOffer(); |
| 2073 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2074 | { |
| 2075 | // Expect additional audio frames to be received after the upgrade. |
| 2076 | MediaExpectations media_expectations; |
| 2077 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2078 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2079 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2082 | // Simpler than the above test; just add an audio track to an established |
| 2083 | // video-only connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2084 | TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) { |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2085 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2086 | ConnectFakeSignaling(); |
| 2087 | // Do initial offer/answer with just a video track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2088 | caller()->AddVideoTrack(); |
| 2089 | callee()->AddVideoTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2090 | caller()->CreateAndSetAndSignalOffer(); |
| 2091 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2092 | // Now add an audio track and do another offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2093 | caller()->AddAudioTrack(); |
| 2094 | callee()->AddAudioTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2095 | caller()->CreateAndSetAndSignalOffer(); |
| 2096 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2097 | // Ensure both audio and video frames are received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2098 | MediaExpectations media_expectations; |
| 2099 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2100 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2103 | // This test sets up a call that's transferred to a new caller with a different |
| 2104 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2105 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2106 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2107 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2108 | caller()->AddAudioVideoTracks(); |
| 2109 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2110 | caller()->CreateAndSetAndSignalOffer(); |
| 2111 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2112 | |
| 2113 | // Keep the original peer around which will still send packets to the |
| 2114 | // receiving client. These SRTP packets will be dropped. |
| 2115 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2116 | SetCallerPcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2117 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2118 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2119 | // directly above. |
| 2120 | original_peer->pc()->Close(); |
| 2121 | |
| 2122 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2123 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2124 | caller()->CreateAndSetAndSignalOffer(); |
| 2125 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2126 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2127 | MediaExpectations media_expectations; |
| 2128 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2129 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | // This test sets up a call that's transferred to a new callee with a different |
| 2133 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2134 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2135 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2136 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2137 | caller()->AddAudioVideoTracks(); |
| 2138 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2139 | caller()->CreateAndSetAndSignalOffer(); |
| 2140 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2141 | |
| 2142 | // Keep the original peer around which will still send packets to the |
| 2143 | // receiving client. These SRTP packets will be dropped. |
| 2144 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2145 | SetCalleePcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2146 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2147 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2148 | // directly above. |
| 2149 | original_peer->pc()->Close(); |
| 2150 | |
| 2151 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2152 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2153 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2154 | caller()->CreateAndSetAndSignalOffer(); |
| 2155 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2156 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2157 | MediaExpectations media_expectations; |
| 2158 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2159 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | // This test sets up a non-bundled call and negotiates bundling at the same |
| 2163 | // time as starting an ICE restart. When bundling is in effect in the restart, |
| 2164 | // the DTLS-SRTP context should be successfully reset. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2165 | TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2166 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2167 | ConnectFakeSignaling(); |
| 2168 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2169 | caller()->AddAudioVideoTracks(); |
| 2170 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2171 | // Remove the bundle group from the SDP received by the callee. |
| 2172 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2173 | desc->RemoveGroupByName("BUNDLE"); |
| 2174 | }); |
| 2175 | caller()->CreateAndSetAndSignalOffer(); |
| 2176 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2177 | { |
| 2178 | MediaExpectations media_expectations; |
| 2179 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2180 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2181 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2182 | // Now stop removing the BUNDLE group, and trigger an ICE restart. |
| 2183 | callee()->SetReceivedSdpMunger(nullptr); |
| 2184 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2185 | caller()->CreateAndSetAndSignalOffer(); |
| 2186 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2187 | |
| 2188 | // Expect additional frames to be received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2189 | { |
| 2190 | MediaExpectations media_expectations; |
| 2191 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2192 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2193 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | // Test CVO (Coordination of Video Orientation). If a video source is rotated |
| 2197 | // and both peers support the CVO RTP header extension, the actual video frames |
| 2198 | // don't need to be encoded in different resolutions, since the rotation is |
| 2199 | // communicated through the RTP header extension. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2200 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2201 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2202 | ConnectFakeSignaling(); |
| 2203 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2204 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2205 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2206 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2207 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2208 | |
| 2209 | // Wait for video frames to be received by both sides. |
| 2210 | caller()->CreateAndSetAndSignalOffer(); |
| 2211 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2212 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2213 | callee()->min_video_frames_received_per_track() > 0, |
| 2214 | kMaxWaitForFramesMs); |
| 2215 | |
| 2216 | // Ensure that the aspect ratio is unmodified. |
| 2217 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2218 | // not just assumed. |
| 2219 | EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio()); |
| 2220 | EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio()); |
| 2221 | EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio()); |
| 2222 | EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio()); |
| 2223 | // Ensure that the CVO bits were surfaced to the renderer. |
| 2224 | EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation()); |
| 2225 | EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation()); |
| 2226 | } |
| 2227 | |
| 2228 | // Test that when the CVO extension isn't supported, video is rotated the |
| 2229 | // old-fashioned way, by encoding rotated frames. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2230 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2231 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2232 | ConnectFakeSignaling(); |
| 2233 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2234 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2235 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2236 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2237 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2238 | |
| 2239 | // Remove the CVO extension from the offered SDP. |
| 2240 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2241 | cricket::VideoContentDescription* video = |
| 2242 | GetFirstVideoContentDescription(desc); |
| 2243 | video->ClearRtpHeaderExtensions(); |
| 2244 | }); |
| 2245 | // Wait for video frames to be received by both sides. |
| 2246 | caller()->CreateAndSetAndSignalOffer(); |
| 2247 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2248 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2249 | callee()->min_video_frames_received_per_track() > 0, |
| 2250 | kMaxWaitForFramesMs); |
| 2251 | |
| 2252 | // Expect that the aspect ratio is inversed to account for the 90/270 degree |
| 2253 | // rotation. |
| 2254 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2255 | // not just assumed. |
| 2256 | EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio()); |
| 2257 | EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio()); |
| 2258 | EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio()); |
| 2259 | EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio()); |
| 2260 | // Expect that each endpoint is unaware of the rotation of the other endpoint. |
| 2261 | EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation()); |
| 2262 | EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation()); |
| 2263 | } |
| 2264 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2265 | // Test that if the answerer rejects the audio m= section, no audio is sent or |
| 2266 | // received, but video still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2267 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2268 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2269 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2270 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2271 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2272 | // Only add video track for callee, and set offer_to_receive_audio to 0, so |
| 2273 | // it will reject the audio m= section completely. |
| 2274 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2275 | options.offer_to_receive_audio = 0; |
| 2276 | callee()->SetOfferAnswerOptions(options); |
| 2277 | } else { |
| 2278 | // Stopping the audio RtpTransceiver will cause the media section to be |
| 2279 | // rejected in the answer. |
| 2280 | callee()->SetRemoteOfferHandler([this] { |
| 2281 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)->Stop(); |
| 2282 | }); |
| 2283 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2284 | callee()->AddTrack(callee()->CreateLocalVideoTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2285 | // Do offer/answer and wait for successful end-to-end video frames. |
| 2286 | caller()->CreateAndSetAndSignalOffer(); |
| 2287 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2288 | MediaExpectations media_expectations; |
| 2289 | media_expectations.ExpectBidirectionalVideo(); |
| 2290 | media_expectations.ExpectNoAudio(); |
| 2291 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2292 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2293 | // Sanity check that the callee's description has a rejected audio section. |
| 2294 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2295 | const ContentInfo* callee_audio_content = |
| 2296 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2297 | ASSERT_NE(nullptr, callee_audio_content); |
| 2298 | EXPECT_TRUE(callee_audio_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2299 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2300 | // The caller's transceiver should have stopped after receiving the answer. |
| 2301 | EXPECT_TRUE(caller() |
| 2302 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO) |
| 2303 | ->stopped()); |
| 2304 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | // Test that if the answerer rejects the video m= section, no video is sent or |
| 2308 | // received, but audio still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2309 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2310 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2311 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2312 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2313 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2314 | // Only add audio track for callee, and set offer_to_receive_video to 0, so |
| 2315 | // it will reject the video m= section completely. |
| 2316 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2317 | options.offer_to_receive_video = 0; |
| 2318 | callee()->SetOfferAnswerOptions(options); |
| 2319 | } else { |
| 2320 | // Stopping the video RtpTransceiver will cause the media section to be |
| 2321 | // rejected in the answer. |
| 2322 | callee()->SetRemoteOfferHandler([this] { |
| 2323 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2324 | }); |
| 2325 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2326 | callee()->AddTrack(callee()->CreateLocalAudioTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2327 | // Do offer/answer and wait for successful end-to-end audio frames. |
| 2328 | caller()->CreateAndSetAndSignalOffer(); |
| 2329 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2330 | MediaExpectations media_expectations; |
| 2331 | media_expectations.ExpectBidirectionalAudio(); |
| 2332 | media_expectations.ExpectNoVideo(); |
| 2333 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2334 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2335 | // Sanity check that the callee's description has a rejected video section. |
| 2336 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2337 | const ContentInfo* callee_video_content = |
| 2338 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2339 | ASSERT_NE(nullptr, callee_video_content); |
| 2340 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2341 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2342 | // The caller's transceiver should have stopped after receiving the answer. |
| 2343 | EXPECT_TRUE(caller() |
| 2344 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 2345 | ->stopped()); |
| 2346 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | // Test that if the answerer rejects both audio and video m= sections, nothing |
| 2350 | // bad happens. |
| 2351 | // TODO(deadbeef): Test that a data channel still works. Currently this doesn't |
| 2352 | // test anything but the fact that negotiation succeeds, which doesn't mean |
| 2353 | // much. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2354 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2355 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2356 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2357 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2358 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2359 | // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it |
| 2360 | // will reject both audio and video m= sections. |
| 2361 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2362 | options.offer_to_receive_audio = 0; |
| 2363 | options.offer_to_receive_video = 0; |
| 2364 | callee()->SetOfferAnswerOptions(options); |
| 2365 | } else { |
| 2366 | callee()->SetRemoteOfferHandler([this] { |
| 2367 | // Stopping all transceivers will cause all media sections to be rejected. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2368 | for (const auto& transceiver : callee()->pc()->GetTransceivers()) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2369 | transceiver->Stop(); |
| 2370 | } |
| 2371 | }); |
| 2372 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2373 | // Do offer/answer and wait for stable signaling state. |
| 2374 | caller()->CreateAndSetAndSignalOffer(); |
| 2375 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2376 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2377 | // Sanity check that the callee's description has rejected m= sections. |
| 2378 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2379 | const ContentInfo* callee_audio_content = |
| 2380 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2381 | ASSERT_NE(nullptr, callee_audio_content); |
| 2382 | EXPECT_TRUE(callee_audio_content->rejected); |
| 2383 | const ContentInfo* callee_video_content = |
| 2384 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2385 | ASSERT_NE(nullptr, callee_video_content); |
| 2386 | EXPECT_TRUE(callee_video_content->rejected); |
| 2387 | } |
| 2388 | |
| 2389 | // This test sets up an audio and video call between two parties. After the |
| 2390 | // call runs for a while, the caller sends an updated offer with video being |
| 2391 | // rejected. Once the re-negotiation is done, the video flow should stop and |
| 2392 | // the audio flow should continue. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2393 | TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2394 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2395 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2396 | caller()->AddAudioVideoTracks(); |
| 2397 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2398 | caller()->CreateAndSetAndSignalOffer(); |
| 2399 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2400 | { |
| 2401 | MediaExpectations media_expectations; |
| 2402 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2403 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2404 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2405 | // Renegotiate, rejecting the video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2406 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2407 | caller()->SetGeneratedSdpMunger( |
| 2408 | [](cricket::SessionDescription* description) { |
| 2409 | for (cricket::ContentInfo& content : description->contents()) { |
| 2410 | if (cricket::IsVideoContent(&content)) { |
| 2411 | content.rejected = true; |
| 2412 | } |
| 2413 | } |
| 2414 | }); |
| 2415 | } else { |
| 2416 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2417 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2418 | caller()->CreateAndSetAndSignalOffer(); |
| 2419 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2420 | |
| 2421 | // Sanity check that the caller's description has a rejected video section. |
| 2422 | ASSERT_NE(nullptr, caller()->pc()->local_description()); |
| 2423 | const ContentInfo* caller_video_content = |
| 2424 | GetFirstVideoContent(caller()->pc()->local_description()->description()); |
| 2425 | ASSERT_NE(nullptr, caller_video_content); |
| 2426 | EXPECT_TRUE(caller_video_content->rejected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2427 | // Wait for some additional audio frames to be received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2428 | { |
| 2429 | MediaExpectations media_expectations; |
| 2430 | media_expectations.ExpectBidirectionalAudio(); |
| 2431 | media_expectations.ExpectNoVideo(); |
| 2432 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2433 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
Taylor Brandstetter | 60c8dc8 | 2018-04-11 15:20:27 -0700 | [diff] [blame] | 2436 | // Do one offer/answer with audio, another that disables it (rejecting the m= |
| 2437 | // section), and another that re-enables it. Regression test for: |
| 2438 | // bugs.webrtc.org/6023 |
| 2439 | TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) { |
| 2440 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2441 | ConnectFakeSignaling(); |
| 2442 | |
| 2443 | // Add audio track, do normal offer/answer. |
| 2444 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 2445 | caller()->CreateLocalAudioTrack(); |
| 2446 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
| 2447 | caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2448 | caller()->CreateAndSetAndSignalOffer(); |
| 2449 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2450 | |
| 2451 | // Remove audio track, and set offer_to_receive_audio to false to cause the |
| 2452 | // m= section to be completely disabled, not just "recvonly". |
| 2453 | caller()->pc()->RemoveTrack(sender); |
| 2454 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2455 | options.offer_to_receive_audio = 0; |
| 2456 | caller()->SetOfferAnswerOptions(options); |
| 2457 | caller()->CreateAndSetAndSignalOffer(); |
| 2458 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2459 | |
| 2460 | // Add the audio track again, expecting negotiation to succeed and frames to |
| 2461 | // flow. |
| 2462 | sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2463 | options.offer_to_receive_audio = 1; |
| 2464 | caller()->SetOfferAnswerOptions(options); |
| 2465 | caller()->CreateAndSetAndSignalOffer(); |
| 2466 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2467 | |
| 2468 | MediaExpectations media_expectations; |
| 2469 | media_expectations.CalleeExpectsSomeAudio(); |
| 2470 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2471 | } |
| 2472 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2473 | // Basic end-to-end test, but without SSRC/MSID signaling. This functionality |
| 2474 | // is needed to support legacy endpoints. |
| 2475 | // TODO(deadbeef): When we support the MID extension and demuxing on MID, also |
| 2476 | // add a test for an end-to-end test without MID signaling either (basically, |
| 2477 | // the minimum acceptable SDP). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2478 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2479 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2480 | ConnectFakeSignaling(); |
| 2481 | // 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] | 2482 | caller()->AddAudioVideoTracks(); |
| 2483 | callee()->AddAudioVideoTracks(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2484 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2485 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2486 | caller()->CreateAndSetAndSignalOffer(); |
| 2487 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2488 | MediaExpectations media_expectations; |
| 2489 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2490 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 2493 | // Basic end-to-end test, without SSRC signaling. This means that the track |
| 2494 | // was created properly and frames are delivered when the MSIDs are communicated |
| 2495 | // with a=msid lines and no a=ssrc lines. |
| 2496 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2497 | EndToEndCallWithoutSsrcSignaling) { |
| 2498 | const char kStreamId[] = "streamId"; |
| 2499 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2500 | ConnectFakeSignaling(); |
| 2501 | // Add just audio tracks. |
| 2502 | caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId}); |
| 2503 | callee()->AddAudioTrack(); |
| 2504 | |
| 2505 | // Remove SSRCs from the received offer SDP. |
| 2506 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids); |
| 2507 | caller()->CreateAndSetAndSignalOffer(); |
| 2508 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2509 | MediaExpectations media_expectations; |
| 2510 | media_expectations.ExpectBidirectionalAudio(); |
| 2511 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2512 | } |
| 2513 | |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2514 | // Tests that video flows between multiple video tracks when SSRCs are not |
| 2515 | // signaled. This exercises the MID RTP header extension which is needed to |
| 2516 | // demux the incoming video tracks. |
| 2517 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2518 | EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) { |
| 2519 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2520 | ConnectFakeSignaling(); |
| 2521 | caller()->AddVideoTrack(); |
| 2522 | caller()->AddVideoTrack(); |
| 2523 | callee()->AddVideoTrack(); |
| 2524 | callee()->AddVideoTrack(); |
| 2525 | |
| 2526 | caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2527 | callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2528 | caller()->CreateAndSetAndSignalOffer(); |
| 2529 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2530 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 2531 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 2532 | |
| 2533 | // Expect video to be received in both directions on both tracks. |
| 2534 | MediaExpectations media_expectations; |
| 2535 | media_expectations.ExpectBidirectionalVideo(); |
| 2536 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2537 | } |
| 2538 | |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 2539 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLinePresent) { |
| 2540 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2541 | ConnectFakeSignaling(); |
| 2542 | caller()->AddAudioTrack(); |
| 2543 | caller()->AddVideoTrack(); |
| 2544 | caller()->CreateAndSetAndSignalOffer(); |
| 2545 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2546 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2547 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2548 | EXPECT_TRUE(callee_receivers[0]->stream_ids().empty()); |
| 2549 | EXPECT_TRUE(callee_receivers[1]->stream_ids().empty()); |
| 2550 | } |
| 2551 | |
| 2552 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLineMissing) { |
| 2553 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2554 | ConnectFakeSignaling(); |
| 2555 | caller()->AddAudioTrack(); |
| 2556 | caller()->AddVideoTrack(); |
| 2557 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2558 | caller()->CreateAndSetAndSignalOffer(); |
| 2559 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2560 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2561 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2562 | ASSERT_EQ(1u, callee_receivers[0]->stream_ids().size()); |
| 2563 | ASSERT_EQ(1u, callee_receivers[1]->stream_ids().size()); |
| 2564 | EXPECT_EQ(callee_receivers[0]->stream_ids()[0], |
| 2565 | callee_receivers[1]->stream_ids()[0]); |
| 2566 | EXPECT_EQ(callee_receivers[0]->streams()[0], |
| 2567 | callee_receivers[1]->streams()[0]); |
| 2568 | } |
| 2569 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2570 | // Test that if two video tracks are sent (from caller to callee, in this test), |
| 2571 | // they're transmitted correctly end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2572 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2573 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2574 | ConnectFakeSignaling(); |
| 2575 | // Add one audio/video stream, and one video-only stream. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2576 | caller()->AddAudioVideoTracks(); |
| 2577 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2578 | caller()->CreateAndSetAndSignalOffer(); |
| 2579 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2580 | ASSERT_EQ(3u, callee()->pc()->GetReceivers().size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2581 | |
| 2582 | MediaExpectations media_expectations; |
| 2583 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2584 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) { |
| 2588 | bool first = true; |
| 2589 | for (cricket::ContentInfo& content : desc->contents()) { |
| 2590 | if (first) { |
| 2591 | first = false; |
| 2592 | continue; |
| 2593 | } |
| 2594 | content.bundle_only = true; |
| 2595 | } |
| 2596 | first = true; |
| 2597 | for (cricket::TransportInfo& transport : desc->transport_infos()) { |
| 2598 | if (first) { |
| 2599 | first = false; |
| 2600 | continue; |
| 2601 | } |
| 2602 | transport.description.ice_ufrag.clear(); |
| 2603 | transport.description.ice_pwd.clear(); |
| 2604 | transport.description.connection_role = cricket::CONNECTIONROLE_NONE; |
| 2605 | transport.description.identity_fingerprint.reset(nullptr); |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | // Test that if applying a true "max bundle" offer, which uses ports of 0, |
| 2610 | // "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and |
| 2611 | // "a=ice-pwd" for all but the audio "m=" section, negotiation still completes |
| 2612 | // successfully and media flows. |
| 2613 | // TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works. |
| 2614 | // TODO(deadbeef): Won't need this test once we start generating actual |
| 2615 | // standards-compliant SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2616 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2617 | EndToEndCallWithSpecCompliantMaxBundleOffer) { |
| 2618 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2619 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2620 | caller()->AddAudioVideoTracks(); |
| 2621 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2622 | // Do the equivalent of setting the port to 0, adding a=bundle-only, and |
| 2623 | // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all |
| 2624 | // but the first m= section. |
| 2625 | callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer); |
| 2626 | caller()->CreateAndSetAndSignalOffer(); |
| 2627 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2628 | MediaExpectations media_expectations; |
| 2629 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2630 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | // Test that we can receive the audio output level from a remote audio track. |
| 2634 | // TODO(deadbeef): Use a fake audio source and verify that the output level is |
| 2635 | // exactly what the source on the other side was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2636 | TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2637 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2638 | ConnectFakeSignaling(); |
| 2639 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2640 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2641 | caller()->CreateAndSetAndSignalOffer(); |
| 2642 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2643 | |
| 2644 | // Get the audio output level stats. Note that the level is not available |
| 2645 | // until an RTCP packet has been received. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2646 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2647 | kMaxWaitForFramesMs); |
| 2648 | } |
| 2649 | |
| 2650 | // Test that an audio input level is reported. |
| 2651 | // TODO(deadbeef): Use a fake audio source and verify that the input level is |
| 2652 | // exactly what the source was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2653 | TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2654 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2655 | ConnectFakeSignaling(); |
| 2656 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2657 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2658 | caller()->CreateAndSetAndSignalOffer(); |
| 2659 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2660 | |
| 2661 | // Get the audio input level stats. The level should be available very |
| 2662 | // soon after the test starts. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2663 | EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2664 | kMaxWaitForStatsMs); |
| 2665 | } |
| 2666 | |
| 2667 | // 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] | 2668 | TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2669 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2670 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2671 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2672 | // Do offer/answer, wait for the callee to receive some frames. |
| 2673 | caller()->CreateAndSetAndSignalOffer(); |
| 2674 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2675 | |
| 2676 | MediaExpectations media_expectations; |
| 2677 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2678 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2679 | |
| 2680 | // Get a handle to the remote tracks created, so they can be used as GetStats |
| 2681 | // filters. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2682 | for (const auto& receiver : callee()->pc()->GetReceivers()) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2683 | // We received frames, so we definitely should have nonzero "received bytes" |
| 2684 | // stats at this point. |
| 2685 | EXPECT_GT(callee()->OldGetStatsForTrack(receiver->track())->BytesReceived(), |
| 2686 | 0); |
| 2687 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | // 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] | 2691 | TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2692 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2693 | ConnectFakeSignaling(); |
| 2694 | auto audio_track = caller()->CreateLocalAudioTrack(); |
| 2695 | auto video_track = caller()->CreateLocalVideoTrack(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2696 | caller()->AddTrack(audio_track); |
| 2697 | caller()->AddTrack(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2698 | // Do offer/answer, wait for the callee to receive some frames. |
| 2699 | caller()->CreateAndSetAndSignalOffer(); |
| 2700 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2701 | MediaExpectations media_expectations; |
| 2702 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2703 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2704 | |
| 2705 | // The callee received frames, so we definitely should have nonzero "sent |
| 2706 | // bytes" stats at this point. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2707 | EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0); |
| 2708 | EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0); |
| 2709 | } |
| 2710 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2711 | // Test that we can get capture start ntp time. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2712 | TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) { |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2713 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2714 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2715 | caller()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2716 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2717 | callee()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2718 | |
| 2719 | // Do offer/answer, wait for the callee to receive some frames. |
| 2720 | caller()->CreateAndSetAndSignalOffer(); |
| 2721 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2722 | |
| 2723 | // Get the remote audio track created on the receiver, so they can be used as |
| 2724 | // GetStats filters. |
Steve Anton | fc85371 | 2018-03-01 13:48:58 -0800 | [diff] [blame] | 2725 | auto receivers = callee()->pc()->GetReceivers(); |
| 2726 | ASSERT_EQ(1u, receivers.size()); |
| 2727 | auto remote_audio_track = receivers[0]->track(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2728 | |
| 2729 | // Get the audio output level stats. Note that the level is not available |
| 2730 | // until an RTCP packet has been received. |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 2731 | EXPECT_TRUE_WAIT( |
| 2732 | callee()->OldGetStatsForTrack(remote_audio_track)->CaptureStartNtpTime() > |
| 2733 | 0, |
| 2734 | 2 * kMaxWaitForFramesMs); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2735 | } |
| 2736 | |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 2737 | // Test that the track ID is associated with all local and remote SSRC stats |
| 2738 | // using the old GetStats() and more than 1 audio and more than 1 video track. |
| 2739 | // This is a regression test for crbug.com/906988 |
| 2740 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2741 | OldGetStatsAssociatesTrackIdForManyMediaSections) { |
| 2742 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2743 | ConnectFakeSignaling(); |
| 2744 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 2745 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 2746 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 2747 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 2748 | caller()->CreateAndSetAndSignalOffer(); |
| 2749 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2750 | |
| 2751 | MediaExpectations media_expectations; |
| 2752 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2753 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 2754 | |
| 2755 | std::vector<std::string> track_ids = { |
| 2756 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 2757 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 2758 | |
| 2759 | auto caller_stats = caller()->OldGetStats(); |
| 2760 | EXPECT_THAT(caller_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 2761 | auto callee_stats = callee()->OldGetStats(); |
| 2762 | EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 2763 | } |
| 2764 | |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2765 | // Test that the new GetStats() returns stats for all outgoing/incoming streams |
| 2766 | // with the correct track IDs if there are more than one audio and more than one |
| 2767 | // video senders/receivers. |
| 2768 | TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) { |
| 2769 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2770 | ConnectFakeSignaling(); |
| 2771 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 2772 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 2773 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 2774 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 2775 | caller()->CreateAndSetAndSignalOffer(); |
| 2776 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2777 | |
| 2778 | MediaExpectations media_expectations; |
| 2779 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2780 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 2781 | |
| 2782 | std::vector<std::string> track_ids = { |
| 2783 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 2784 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 2785 | |
| 2786 | rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report = |
| 2787 | caller()->NewGetStats(); |
| 2788 | ASSERT_TRUE(caller_report); |
| 2789 | auto outbound_stream_stats = |
| 2790 | caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>(); |
| 2791 | ASSERT_EQ(4u, outbound_stream_stats.size()); |
| 2792 | std::vector<std::string> outbound_track_ids; |
| 2793 | for (const auto& stat : outbound_stream_stats) { |
| 2794 | ASSERT_TRUE(stat->bytes_sent.is_defined()); |
| 2795 | EXPECT_LT(0u, *stat->bytes_sent); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 2796 | if (*stat->kind == "video") { |
| 2797 | ASSERT_TRUE(stat->key_frames_encoded.is_defined()); |
| 2798 | EXPECT_GT(*stat->key_frames_encoded, 0u); |
| 2799 | ASSERT_TRUE(stat->frames_encoded.is_defined()); |
| 2800 | EXPECT_GE(*stat->frames_encoded, *stat->key_frames_encoded); |
| 2801 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2802 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 2803 | const auto* track_stat = |
| 2804 | caller_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 2805 | ASSERT_TRUE(track_stat); |
| 2806 | outbound_track_ids.push_back(*track_stat->track_identifier); |
| 2807 | } |
| 2808 | EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 2809 | |
| 2810 | rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report = |
| 2811 | callee()->NewGetStats(); |
| 2812 | ASSERT_TRUE(callee_report); |
| 2813 | auto inbound_stream_stats = |
| 2814 | callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2815 | ASSERT_EQ(4u, inbound_stream_stats.size()); |
| 2816 | std::vector<std::string> inbound_track_ids; |
| 2817 | for (const auto& stat : inbound_stream_stats) { |
| 2818 | ASSERT_TRUE(stat->bytes_received.is_defined()); |
| 2819 | EXPECT_LT(0u, *stat->bytes_received); |
Rasmus Brandt | 2efae77 | 2019-06-27 14:29:34 +0200 | [diff] [blame] | 2820 | if (*stat->kind == "video") { |
| 2821 | ASSERT_TRUE(stat->key_frames_decoded.is_defined()); |
| 2822 | EXPECT_GT(*stat->key_frames_decoded, 0u); |
| 2823 | ASSERT_TRUE(stat->frames_decoded.is_defined()); |
| 2824 | EXPECT_GE(*stat->frames_decoded, *stat->key_frames_decoded); |
| 2825 | } |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2826 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 2827 | const auto* track_stat = |
| 2828 | callee_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 2829 | ASSERT_TRUE(track_stat); |
| 2830 | inbound_track_ids.push_back(*track_stat->track_identifier); |
| 2831 | } |
| 2832 | EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 2833 | } |
| 2834 | |
| 2835 | // Test that we can get stats (using the new stats implementation) for |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2836 | // unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in |
| 2837 | // SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2838 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2839 | GetStatsForUnsignaledStreamWithNewStatsApi) { |
| 2840 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2841 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2842 | caller()->AddAudioTrack(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2843 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2844 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2845 | caller()->CreateAndSetAndSignalOffer(); |
| 2846 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2847 | MediaExpectations media_expectations; |
| 2848 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2849 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2850 | |
| 2851 | // We received a frame, so we should have nonzero "bytes received" stats for |
| 2852 | // the unsignaled stream, if stats are working for it. |
| 2853 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2854 | callee()->NewGetStats(); |
| 2855 | ASSERT_NE(nullptr, report); |
| 2856 | auto inbound_stream_stats = |
| 2857 | report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2858 | ASSERT_EQ(1U, inbound_stream_stats.size()); |
| 2859 | ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined()); |
| 2860 | ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2861 | ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined()); |
| 2862 | } |
| 2863 | |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 2864 | // Same as above but for the legacy stats implementation. |
| 2865 | TEST_P(PeerConnectionIntegrationTest, |
| 2866 | GetStatsForUnsignaledStreamWithOldStatsApi) { |
| 2867 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2868 | ConnectFakeSignaling(); |
| 2869 | caller()->AddAudioTrack(); |
| 2870 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2871 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2872 | caller()->CreateAndSetAndSignalOffer(); |
| 2873 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2874 | |
| 2875 | // Note that, since the old stats implementation associates SSRCs with tracks |
| 2876 | // using SDP, when SSRCs aren't signaled in SDP these stats won't have an |
| 2877 | // associated track ID. So we can't use the track "selector" argument. |
| 2878 | // |
| 2879 | // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to |
| 2880 | // 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] | 2881 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0, |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 2882 | kDefaultTimeout); |
| 2883 | } |
| 2884 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2885 | // Test that we can successfully get the media related stats (audio level |
| 2886 | // etc.) for the unsignaled stream. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2887 | TEST_P(PeerConnectionIntegrationTest, |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2888 | GetMediaStatsForUnsignaledStreamWithNewStatsApi) { |
| 2889 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2890 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2891 | caller()->AddAudioVideoTracks(); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2892 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2893 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2894 | caller()->CreateAndSetAndSignalOffer(); |
| 2895 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2896 | MediaExpectations media_expectations; |
| 2897 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2898 | media_expectations.CalleeExpectsSomeVideo(1); |
| 2899 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2900 | |
| 2901 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2902 | callee()->NewGetStats(); |
| 2903 | ASSERT_NE(nullptr, report); |
| 2904 | |
| 2905 | auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2906 | auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats); |
| 2907 | ASSERT_GE(audio_index, 0); |
| 2908 | EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2911 | // Helper for test below. |
| 2912 | void ModifySsrcs(cricket::SessionDescription* desc) { |
| 2913 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2914 | for (StreamParams& stream : |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2915 | content.media_description()->mutable_streams()) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2916 | for (uint32_t& ssrc : stream.ssrcs) { |
| 2917 | ssrc = rtc::CreateRandomId(); |
| 2918 | } |
| 2919 | } |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | // Test that the "RTCMediaSteamTrackStats" object is updated correctly when |
| 2924 | // SSRCs are unsignaled, and the SSRC of the received (audio) stream changes. |
| 2925 | // This should result in two "RTCInboundRTPStreamStats", but only one |
| 2926 | // "RTCMediaStreamTrackStats", whose counters go up continuously rather than |
| 2927 | // being reset to 0 once the SSRC change occurs. |
| 2928 | // |
| 2929 | // Regression test for this bug: |
| 2930 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8158 |
| 2931 | // |
| 2932 | // The bug causes the track stats to only represent one of the two streams: |
| 2933 | // whichever one has the higher SSRC. So with this bug, there was a 50% chance |
| 2934 | // that the track stat counters would reset to 0 when the new stream is |
| 2935 | // received, and a 50% chance that they'll stop updating (while |
| 2936 | // "concealed_samples" continues increasing, due to silence being generated for |
| 2937 | // the inactive stream). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2938 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2939 | TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2940 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2941 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2942 | caller()->AddAudioTrack(); |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2943 | // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint |
| 2944 | // that doesn't signal SSRCs (from the callee's perspective). |
| 2945 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2946 | caller()->CreateAndSetAndSignalOffer(); |
| 2947 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2948 | // 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] | 2949 | { |
| 2950 | MediaExpectations media_expectations; |
| 2951 | media_expectations.CalleeExpectsSomeAudio(50); |
| 2952 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2953 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2954 | // Some audio frames were received, so we should have nonzero "samples |
| 2955 | // received" for the track. |
| 2956 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2957 | callee()->NewGetStats(); |
| 2958 | ASSERT_NE(nullptr, report); |
| 2959 | auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2960 | ASSERT_EQ(1U, track_stats.size()); |
| 2961 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 2962 | ASSERT_GT(*track_stats[0]->total_samples_received, 0U); |
| 2963 | // uint64_t prev_samples_received = *track_stats[0]->total_samples_received; |
| 2964 | |
| 2965 | // Create a new offer and munge it to cause the caller to use a new SSRC. |
| 2966 | caller()->SetGeneratedSdpMunger(ModifySsrcs); |
| 2967 | caller()->CreateAndSetAndSignalOffer(); |
| 2968 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2969 | // Wait for 25 more audio frames (250ms of audio) to be received, from the new |
| 2970 | // SSRC. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2971 | { |
| 2972 | MediaExpectations media_expectations; |
| 2973 | media_expectations.CalleeExpectsSomeAudio(25); |
| 2974 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2975 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2976 | |
| 2977 | report = callee()->NewGetStats(); |
| 2978 | ASSERT_NE(nullptr, report); |
| 2979 | track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2980 | ASSERT_EQ(1U, track_stats.size()); |
| 2981 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 2982 | // The "total samples received" stat should only be greater than it was |
| 2983 | // before. |
| 2984 | // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed. |
| 2985 | // Right now, the new SSRC will cause the counters to reset to 0. |
| 2986 | // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received); |
| 2987 | |
| 2988 | // Additionally, the percentage of concealed samples (samples generated to |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2989 | // 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] | 2990 | // good sign that we're seeing stats from the old stream that's no longer |
| 2991 | // receiving packets, and is generating concealed samples of silence. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2992 | constexpr double kAcceptableConcealedSamplesPercentage = 0.50; |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2993 | ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined()); |
| 2994 | EXPECT_LT(*track_stats[0]->concealed_samples, |
| 2995 | *track_stats[0]->total_samples_received * |
| 2996 | kAcceptableConcealedSamplesPercentage); |
| 2997 | |
| 2998 | // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a |
| 2999 | // sanity check that the SSRC really changed. |
| 3000 | // TODO(deadbeef): This isn't working right now, because we're not returning |
| 3001 | // *any* stats for the inactive stream. Uncomment when the bug is completely |
| 3002 | // fixed. |
| 3003 | // auto inbound_stream_stats = |
| 3004 | // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 3005 | // ASSERT_EQ(2U, inbound_stream_stats.size()); |
| 3006 | } |
| 3007 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3008 | // 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] | 3009 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3010 | PeerConnectionFactory::Options dtls_10_options; |
| 3011 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3012 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 3013 | dtls_10_options)); |
| 3014 | ConnectFakeSignaling(); |
| 3015 | // Do normal offer/answer and wait for some frames to be received in each |
| 3016 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3017 | caller()->AddAudioVideoTracks(); |
| 3018 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3019 | caller()->CreateAndSetAndSignalOffer(); |
| 3020 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3021 | MediaExpectations media_expectations; |
| 3022 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3023 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | // 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] | 3027 | TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3028 | PeerConnectionFactory::Options dtls_10_options; |
| 3029 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3030 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 3031 | dtls_10_options)); |
| 3032 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3033 | caller()->AddAudioVideoTracks(); |
| 3034 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3035 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3036 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3037 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3038 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3039 | kDefaultTimeout); |
| 3040 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3041 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3042 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 3043 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 3044 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 3045 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | // 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] | 3049 | TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3050 | PeerConnectionFactory::Options dtls_12_options; |
| 3051 | dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3052 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options, |
| 3053 | dtls_12_options)); |
| 3054 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3055 | caller()->AddAudioVideoTracks(); |
| 3056 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3057 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3058 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3059 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3060 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3061 | kDefaultTimeout); |
| 3062 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 3063 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 3064 | // TODO(bugs.webrtc.org/9456): Fix it. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 3065 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 3066 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 3067 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | // Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the |
| 3071 | // callee only supports 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3072 | TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3073 | PeerConnectionFactory::Options caller_options; |
| 3074 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3075 | PeerConnectionFactory::Options callee_options; |
| 3076 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3077 | ASSERT_TRUE( |
| 3078 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 3079 | ConnectFakeSignaling(); |
| 3080 | // Do normal offer/answer and wait for some frames to be received in each |
| 3081 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3082 | caller()->AddAudioVideoTracks(); |
| 3083 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3084 | caller()->CreateAndSetAndSignalOffer(); |
| 3085 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3086 | MediaExpectations media_expectations; |
| 3087 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3088 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | // Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the |
| 3092 | // callee supports 1.2. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3093 | TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3094 | PeerConnectionFactory::Options caller_options; |
| 3095 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 3096 | PeerConnectionFactory::Options callee_options; |
| 3097 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 3098 | ASSERT_TRUE( |
| 3099 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 3100 | ConnectFakeSignaling(); |
| 3101 | // Do normal offer/answer and wait for some frames to be received in each |
| 3102 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3103 | caller()->AddAudioVideoTracks(); |
| 3104 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3105 | caller()->CreateAndSetAndSignalOffer(); |
| 3106 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3107 | MediaExpectations media_expectations; |
| 3108 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3109 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3112 | // The three tests below verify that "enable_aes128_sha1_32_crypto_cipher" |
| 3113 | // works as expected; the cipher should only be used if enabled by both sides. |
| 3114 | TEST_P(PeerConnectionIntegrationTest, |
| 3115 | Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) { |
| 3116 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3117 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3118 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3119 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3120 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3121 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3122 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3123 | expected_cipher_suite); |
| 3124 | } |
| 3125 | |
| 3126 | TEST_P(PeerConnectionIntegrationTest, |
| 3127 | Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) { |
| 3128 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3129 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3130 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3131 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3132 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3133 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3134 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3135 | expected_cipher_suite); |
| 3136 | } |
| 3137 | |
| 3138 | TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) { |
| 3139 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3140 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3141 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3142 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3143 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_32; |
| 3144 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3145 | expected_cipher_suite); |
| 3146 | } |
| 3147 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3148 | // 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] | 3149 | TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3150 | bool local_gcm_enabled = false; |
| 3151 | bool remote_gcm_enabled = false; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3152 | bool aes_ctr_enabled = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3153 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 3154 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3155 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3158 | // Test that a GCM cipher is used if both ends support it and non-GCM is |
| 3159 | // disabled. |
| 3160 | TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenOnlyGcmSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3161 | bool local_gcm_enabled = true; |
| 3162 | bool remote_gcm_enabled = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3163 | bool aes_ctr_enabled = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3164 | int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm; |
| 3165 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3166 | aes_ctr_enabled, expected_cipher_suite); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3169 | // Verify that media can be transmitted end-to-end when GCM crypto suites are |
| 3170 | // enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported, |
| 3171 | // only verify that a GCM cipher is negotiated, and not necessarily that SRTP |
| 3172 | // works with it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3173 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3174 | PeerConnectionFactory::Options gcm_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3175 | gcm_options.crypto_options.srtp.enable_gcm_crypto_suites = true; |
Philipp Hancke | 2ebbff8 | 2019-10-26 06:12:55 +0200 | [diff] [blame] | 3176 | gcm_options.crypto_options.srtp.enable_aes128_sha1_80_crypto_cipher = false; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3177 | ASSERT_TRUE( |
| 3178 | CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options)); |
| 3179 | ConnectFakeSignaling(); |
| 3180 | // Do normal offer/answer and wait for some frames to be received in each |
| 3181 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3182 | caller()->AddAudioVideoTracks(); |
| 3183 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3184 | caller()->CreateAndSetAndSignalOffer(); |
| 3185 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3186 | MediaExpectations media_expectations; |
| 3187 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3188 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3191 | // This test sets up a call between two parties with audio, video and an RTP |
| 3192 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3193 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithRtpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3194 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3195 | rtc_config.enable_rtp_data_channel = true; |
| 3196 | rtc_config.enable_dtls_srtp = false; |
| 3197 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3198 | ConnectFakeSignaling(); |
| 3199 | // Expect that data channel created on caller side will show up for callee as |
| 3200 | // well. |
| 3201 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3202 | caller()->AddAudioVideoTracks(); |
| 3203 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3204 | caller()->CreateAndSetAndSignalOffer(); |
| 3205 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3206 | // 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] | 3207 | MediaExpectations media_expectations; |
| 3208 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3209 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3210 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3211 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3212 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3213 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3214 | |
| 3215 | // Ensure data can be sent in both directions. |
| 3216 | std::string data = "hello world"; |
| 3217 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3218 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3219 | kDefaultTimeout); |
| 3220 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3221 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3222 | kDefaultTimeout); |
| 3223 | } |
| 3224 | |
| 3225 | // Ensure that an RTP data channel is signaled as closed for the caller when |
| 3226 | // the callee rejects it in a subsequent offer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3227 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3228 | RtpDataChannelSignaledClosedInCalleeOffer) { |
| 3229 | // Same procedure as above test. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3230 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3231 | rtc_config.enable_rtp_data_channel = true; |
| 3232 | rtc_config.enable_dtls_srtp = false; |
| 3233 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3234 | ConnectFakeSignaling(); |
| 3235 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3236 | caller()->AddAudioVideoTracks(); |
| 3237 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3238 | caller()->CreateAndSetAndSignalOffer(); |
| 3239 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3240 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3241 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3242 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3243 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3244 | |
| 3245 | // Close the data channel on the callee, and do an updated offer/answer. |
| 3246 | callee()->data_channel()->Close(); |
| 3247 | callee()->CreateAndSetAndSignalOffer(); |
| 3248 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3249 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3250 | EXPECT_FALSE(callee()->data_observer()->IsOpen()); |
| 3251 | } |
| 3252 | |
| 3253 | // Tests that data is buffered in an RTP data channel until an observer is |
| 3254 | // registered for it. |
| 3255 | // |
| 3256 | // NOTE: RTP data channels can receive data before the underlying |
| 3257 | // transport has detected that a channel is writable and thus data can be |
| 3258 | // received before the data channel state changes to open. That is hard to test |
| 3259 | // but the same buffering is expected to be used in that case. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3260 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3261 | DataBufferedUntilRtpDataChannelObserverRegistered) { |
| 3262 | // Use fake clock and simulated network delay so that we predictably can wait |
| 3263 | // until an SCTP message has been delivered without "sleep()"ing. |
| 3264 | rtc::ScopedFakeClock fake_clock; |
| 3265 | // Some things use a time of "0" as a special value, so we need to start out |
| 3266 | // the fake clock at a nonzero time. |
| 3267 | // TODO(deadbeef): Fix this. |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 3268 | fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3269 | virtual_socket_server()->set_delay_mean(5); // 5 ms per hop. |
| 3270 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3271 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3272 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3273 | rtc_config.enable_rtp_data_channel = true; |
| 3274 | rtc_config.enable_dtls_srtp = false; |
| 3275 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3276 | ConnectFakeSignaling(); |
| 3277 | caller()->CreateDataChannel(); |
| 3278 | caller()->CreateAndSetAndSignalOffer(); |
| 3279 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
| 3280 | ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr, |
| 3281 | kDefaultTimeout, fake_clock); |
| 3282 | ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(), |
| 3283 | kDefaultTimeout, fake_clock); |
| 3284 | ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen, |
| 3285 | callee()->data_channel()->state(), kDefaultTimeout, |
| 3286 | fake_clock); |
| 3287 | |
| 3288 | // Unregister the observer which is normally automatically registered. |
| 3289 | callee()->data_channel()->UnregisterObserver(); |
| 3290 | // Send data and advance fake clock until it should have been received. |
| 3291 | std::string data = "hello world"; |
| 3292 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3293 | SIMULATED_WAIT(false, 50, fake_clock); |
| 3294 | |
| 3295 | // Attach data channel and expect data to be received immediately. Note that |
| 3296 | // EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any |
| 3297 | // further, but data can be received even if the callback is asynchronous. |
| 3298 | MockDataChannelObserver new_observer(callee()->data_channel()); |
| 3299 | EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout, |
| 3300 | fake_clock); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 3301 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 3302 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 3303 | // 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] | 3304 | ClosePeerConnections(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | // This test sets up a call between two parties with audio, video and but only |
| 3308 | // the caller client supports RTP data channels. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3309 | TEST_P(PeerConnectionIntegrationTest, RtpDataChannelsRejectedByCallee) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3310 | PeerConnectionInterface::RTCConfiguration rtc_config_1; |
| 3311 | rtc_config_1.enable_rtp_data_channel = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3312 | // Must disable DTLS to make negotiation succeed. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3313 | rtc_config_1.enable_dtls_srtp = false; |
| 3314 | PeerConnectionInterface::RTCConfiguration rtc_config_2; |
| 3315 | rtc_config_2.enable_dtls_srtp = false; |
| 3316 | rtc_config_2.enable_dtls_srtp = false; |
| 3317 | ASSERT_TRUE( |
| 3318 | CreatePeerConnectionWrappersWithConfig(rtc_config_1, rtc_config_2)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3319 | ConnectFakeSignaling(); |
| 3320 | caller()->CreateDataChannel(); |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 3321 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3322 | caller()->AddAudioVideoTracks(); |
| 3323 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3324 | caller()->CreateAndSetAndSignalOffer(); |
| 3325 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3326 | // The caller should still have a data channel, but it should be closed, and |
| 3327 | // one should ever have been created for the callee. |
| 3328 | EXPECT_TRUE(caller()->data_channel() != nullptr); |
| 3329 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3330 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 3331 | } |
| 3332 | |
| 3333 | // This test sets up a call between two parties with audio, and video. When |
| 3334 | // 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] | 3335 | TEST_P(PeerConnectionIntegrationTest, AddRtpDataChannelInSubsequentOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3336 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3337 | rtc_config.enable_rtp_data_channel = true; |
| 3338 | rtc_config.enable_dtls_srtp = false; |
| 3339 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3340 | ConnectFakeSignaling(); |
| 3341 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3342 | caller()->AddAudioVideoTracks(); |
| 3343 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3344 | caller()->CreateAndSetAndSignalOffer(); |
| 3345 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3346 | // Create data channel and do new offer and answer. |
| 3347 | caller()->CreateDataChannel(); |
| 3348 | caller()->CreateAndSetAndSignalOffer(); |
| 3349 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3350 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3351 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3352 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3353 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3354 | // Ensure data can be sent in both directions. |
| 3355 | std::string data = "hello world"; |
| 3356 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3357 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3358 | kDefaultTimeout); |
| 3359 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3360 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3361 | kDefaultTimeout); |
| 3362 | } |
| 3363 | |
| 3364 | #ifdef HAVE_SCTP |
| 3365 | |
| 3366 | // This test sets up a call between two parties with audio, video and an SCTP |
| 3367 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3368 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3369 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3370 | ConnectFakeSignaling(); |
| 3371 | // Expect that data channel created on caller side will show up for callee as |
| 3372 | // well. |
| 3373 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3374 | caller()->AddAudioVideoTracks(); |
| 3375 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3376 | caller()->CreateAndSetAndSignalOffer(); |
| 3377 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3378 | // 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] | 3379 | MediaExpectations media_expectations; |
| 3380 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3381 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3382 | // Caller data channel should already exist (it created one). Callee data |
| 3383 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3384 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3385 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3386 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3387 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3388 | |
| 3389 | // Ensure data can be sent in both directions. |
| 3390 | std::string data = "hello world"; |
| 3391 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3392 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3393 | kDefaultTimeout); |
| 3394 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3395 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3396 | kDefaultTimeout); |
| 3397 | } |
| 3398 | |
| 3399 | // Ensure that when the callee closes an SCTP data channel, the closing |
| 3400 | // 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] | 3401 | TEST_P(PeerConnectionIntegrationTest, CalleeClosesSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3402 | // Same procedure as above test. |
| 3403 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3404 | ConnectFakeSignaling(); |
| 3405 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3406 | caller()->AddAudioVideoTracks(); |
| 3407 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3408 | caller()->CreateAndSetAndSignalOffer(); |
| 3409 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3410 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3411 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3412 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3413 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3414 | |
| 3415 | // Close the data channel on the callee side, and wait for it to reach the |
| 3416 | // "closed" state on both sides. |
| 3417 | callee()->data_channel()->Close(); |
| 3418 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3419 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3420 | } |
| 3421 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3422 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelConfigSentToOtherSide) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3423 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3424 | ConnectFakeSignaling(); |
| 3425 | webrtc::DataChannelInit init; |
| 3426 | init.id = 53; |
| 3427 | init.maxRetransmits = 52; |
| 3428 | caller()->CreateDataChannel("data-channel", &init); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3429 | caller()->AddAudioVideoTracks(); |
| 3430 | callee()->AddAudioVideoTracks(); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3431 | caller()->CreateAndSetAndSignalOffer(); |
| 3432 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 074dece | 2017-10-24 13:04:12 -0700 | [diff] [blame] | 3433 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3434 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 3435 | // Since "negotiated" is false, the "id" parameter should be ignored. |
| 3436 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3437 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 3438 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 3439 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 3440 | } |
| 3441 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3442 | // Test usrsctp's ability to process unordered data stream, where data actually |
| 3443 | // arrives out of order using simulated delays. Previously there have been some |
| 3444 | // bugs in this area. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3445 | TEST_P(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3446 | // Introduce random network delays. |
| 3447 | // Otherwise it's not a true "unordered" test. |
| 3448 | virtual_socket_server()->set_delay_mean(20); |
| 3449 | virtual_socket_server()->set_delay_stddev(5); |
| 3450 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3451 | // Normal procedure, but with unordered data channel config. |
| 3452 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3453 | ConnectFakeSignaling(); |
| 3454 | webrtc::DataChannelInit init; |
| 3455 | init.ordered = false; |
| 3456 | caller()->CreateDataChannel(&init); |
| 3457 | caller()->CreateAndSetAndSignalOffer(); |
| 3458 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3459 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3460 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3461 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3462 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3463 | |
| 3464 | static constexpr int kNumMessages = 100; |
| 3465 | // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 3466 | static constexpr size_t kMaxMessageSize = 4096; |
| 3467 | // Create and send random messages. |
| 3468 | std::vector<std::string> sent_messages; |
| 3469 | for (int i = 0; i < kNumMessages; ++i) { |
| 3470 | size_t length = |
| 3471 | (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand) |
| 3472 | std::string message; |
| 3473 | ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 3474 | caller()->data_channel()->Send(DataBuffer(message)); |
| 3475 | callee()->data_channel()->Send(DataBuffer(message)); |
| 3476 | sent_messages.push_back(message); |
| 3477 | } |
| 3478 | |
| 3479 | // Wait for all messages to be received. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3480 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3481 | caller()->data_observer()->received_message_count(), |
| 3482 | kDefaultTimeout); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3483 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3484 | callee()->data_observer()->received_message_count(), |
| 3485 | kDefaultTimeout); |
| 3486 | |
| 3487 | // Sort and compare to make sure none of the messages were corrupted. |
| 3488 | std::vector<std::string> caller_received_messages = |
| 3489 | caller()->data_observer()->messages(); |
| 3490 | std::vector<std::string> callee_received_messages = |
| 3491 | callee()->data_observer()->messages(); |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3492 | absl::c_sort(sent_messages); |
| 3493 | absl::c_sort(caller_received_messages); |
| 3494 | absl::c_sort(callee_received_messages); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3495 | EXPECT_EQ(sent_messages, caller_received_messages); |
| 3496 | EXPECT_EQ(sent_messages, callee_received_messages); |
| 3497 | } |
| 3498 | |
| 3499 | // This test sets up a call between two parties with audio, and video. When |
| 3500 | // 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] | 3501 | TEST_P(PeerConnectionIntegrationTest, AddSctpDataChannelInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3502 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3503 | ConnectFakeSignaling(); |
| 3504 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3505 | caller()->AddAudioVideoTracks(); |
| 3506 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3507 | caller()->CreateAndSetAndSignalOffer(); |
| 3508 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3509 | // Create data channel and do new offer and answer. |
| 3510 | caller()->CreateDataChannel(); |
| 3511 | caller()->CreateAndSetAndSignalOffer(); |
| 3512 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3513 | // Caller data channel should already exist (it created one). Callee data |
| 3514 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3515 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3516 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3517 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3518 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3519 | // Ensure data can be sent in both directions. |
| 3520 | std::string data = "hello world"; |
| 3521 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3522 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3523 | kDefaultTimeout); |
| 3524 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3525 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3526 | kDefaultTimeout); |
| 3527 | } |
| 3528 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3529 | // Set up a connection initially just using SCTP data channels, later upgrading |
| 3530 | // to audio/video, ensuring frames are received end-to-end. Effectively the |
| 3531 | // inverse of the test above. |
| 3532 | // This was broken in M57; see https://crbug.com/711243 |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3533 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelToAudioVideoUpgrade) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3534 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3535 | ConnectFakeSignaling(); |
| 3536 | // Do initial offer/answer with just data channel. |
| 3537 | caller()->CreateDataChannel(); |
| 3538 | caller()->CreateAndSetAndSignalOffer(); |
| 3539 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3540 | // Wait until data can be sent over the data channel. |
| 3541 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3542 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3543 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3544 | |
| 3545 | // Do subsequent offer/answer with two-way audio and video. Audio and video |
| 3546 | // 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] | 3547 | caller()->AddAudioVideoTracks(); |
| 3548 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3549 | caller()->CreateAndSetAndSignalOffer(); |
| 3550 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3551 | MediaExpectations media_expectations; |
| 3552 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3553 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3556 | static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) { |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 3557 | cricket::SctpDataContentDescription* dcd_offer = |
| 3558 | GetFirstSctpDataContentDescription(desc); |
Harald Alvestrand | 17ea068 | 2019-12-13 11:51:04 +0100 | [diff] [blame] | 3559 | // See https://crbug.com/webrtc/11211 - this function is a no-op |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3560 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3561 | dcd_offer->set_use_sctpmap(false); |
| 3562 | dcd_offer->set_protocol("UDP/DTLS/SCTP"); |
| 3563 | } |
| 3564 | |
| 3565 | // Test that the data channel works when a spec-compliant SCTP m= section is |
| 3566 | // offered (using "a=sctp-port" instead of "a=sctpmap", and using |
| 3567 | // "UDP/DTLS/SCTP" as the protocol). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3568 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3569 | DataChannelWorksWhenSpecCompliantSctpOfferReceived) { |
| 3570 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3571 | ConnectFakeSignaling(); |
| 3572 | caller()->CreateDataChannel(); |
| 3573 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 3574 | caller()->CreateAndSetAndSignalOffer(); |
| 3575 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3576 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3577 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3578 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3579 | |
| 3580 | // Ensure data can be sent in both directions. |
| 3581 | std::string data = "hello world"; |
| 3582 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3583 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3584 | kDefaultTimeout); |
| 3585 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3586 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3587 | kDefaultTimeout); |
| 3588 | } |
| 3589 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 3590 | // Tests that the datagram transport to SCTP fallback works correctly when |
| 3591 | // datagram transport negotiation fails. |
| 3592 | TEST_P(PeerConnectionIntegrationTest, |
| 3593 | DatagramTransportDataChannelFallbackToSctp) { |
| 3594 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3595 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3596 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3597 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3598 | |
| 3599 | // Configure one endpoint to use datagram transport for data channels while |
| 3600 | // the other does not. |
| 3601 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3602 | rtc_config, RTCConfiguration(), |
| 3603 | loopback_media_transports()->first_factory(), nullptr)); |
| 3604 | ConnectFakeSignaling(); |
| 3605 | |
| 3606 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3607 | caller()->CreateDataChannel(); |
| 3608 | caller()->AddAudioVideoTracks(); |
| 3609 | callee()->AddAudioVideoTracks(); |
| 3610 | caller()->CreateAndSetAndSignalOffer(); |
| 3611 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3612 | |
| 3613 | // Negotiation should fallback to SCTP, allowing the data channel to be |
| 3614 | // established. |
| 3615 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3616 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3617 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3618 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3619 | |
| 3620 | // Ensure data can be sent in both directions. |
| 3621 | std::string data = "hello world"; |
| 3622 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3623 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3624 | kDefaultTimeout); |
| 3625 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3626 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3627 | kDefaultTimeout); |
| 3628 | |
| 3629 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 3630 | MediaExpectations media_expectations; |
| 3631 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3632 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3633 | } |
| 3634 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 3635 | // Tests that the data channel transport works correctly when datagram transport |
| 3636 | // negotiation succeeds and does not fall back to SCTP. |
| 3637 | TEST_P(PeerConnectionIntegrationTest, |
| 3638 | DatagramTransportDataChannelDoesNotFallbackToSctp) { |
| 3639 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3640 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3641 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3642 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3643 | |
| 3644 | // Configure one endpoint to use datagram transport for data channels while |
| 3645 | // the other does not. |
| 3646 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3647 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3648 | loopback_media_transports()->second_factory())); |
| 3649 | ConnectFakeSignaling(); |
| 3650 | |
| 3651 | // The caller offers a data channel using either datagram transport or SCTP. |
| 3652 | caller()->CreateDataChannel(); |
| 3653 | caller()->AddAudioVideoTracks(); |
| 3654 | callee()->AddAudioVideoTracks(); |
| 3655 | caller()->CreateAndSetAndSignalOffer(); |
| 3656 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3657 | |
| 3658 | // Ensure that the data channel transport is ready. |
| 3659 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3660 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3661 | |
| 3662 | // Negotiation should succeed, allowing the data channel to be established. |
| 3663 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3664 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3665 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3666 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3667 | |
| 3668 | // Ensure data can be sent in both directions. |
| 3669 | std::string data = "hello world"; |
| 3670 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3671 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3672 | kDefaultTimeout); |
| 3673 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3674 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3675 | kDefaultTimeout); |
| 3676 | |
| 3677 | // Ensure that failure of the datagram negotiation doesn't impede media flow. |
| 3678 | MediaExpectations media_expectations; |
| 3679 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3680 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3681 | } |
| 3682 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 3683 | TEST_P(PeerConnectionIntegrationTest, |
| 3684 | DatagramTransportDataChannelWithMediaOnCaller) { |
| 3685 | // Configure the caller to attempt use of datagram transport for media and |
| 3686 | // data channels. |
| 3687 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3688 | offerer_config.rtcp_mux_policy = |
| 3689 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3690 | offerer_config.bundle_policy = |
| 3691 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3692 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3693 | offerer_config.use_datagram_transport = true; |
| 3694 | |
| 3695 | // Configure the callee to only use datagram transport for data channels. |
| 3696 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3697 | answerer_config.rtcp_mux_policy = |
| 3698 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3699 | answerer_config.bundle_policy = |
| 3700 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3701 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3702 | |
| 3703 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3704 | offerer_config, answerer_config, |
| 3705 | loopback_media_transports()->first_factory(), |
| 3706 | loopback_media_transports()->second_factory())); |
| 3707 | ConnectFakeSignaling(); |
| 3708 | |
| 3709 | // Offer both media and data. |
| 3710 | caller()->AddAudioVideoTracks(); |
| 3711 | callee()->AddAudioVideoTracks(); |
| 3712 | caller()->CreateDataChannel(); |
| 3713 | caller()->CreateAndSetAndSignalOffer(); |
| 3714 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3715 | |
| 3716 | // Ensure that the data channel transport is ready. |
| 3717 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3718 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3719 | |
| 3720 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3721 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3722 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3723 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3724 | |
| 3725 | // Both endpoints should agree to use datagram transport for data channels. |
| 3726 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 3727 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 3728 | |
| 3729 | // Ensure data can be sent in both directions. |
| 3730 | std::string data = "hello world"; |
| 3731 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3732 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3733 | kDefaultTimeout); |
| 3734 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3735 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3736 | kDefaultTimeout); |
| 3737 | |
| 3738 | // Media flow should not be impacted. |
| 3739 | MediaExpectations media_expectations; |
| 3740 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3741 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3742 | } |
| 3743 | |
| 3744 | TEST_P(PeerConnectionIntegrationTest, |
| 3745 | DatagramTransportMediaWithDataChannelOnCaller) { |
| 3746 | // Configure the caller to attempt use of datagram transport for media and |
| 3747 | // data channels. |
| 3748 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3749 | offerer_config.rtcp_mux_policy = |
| 3750 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3751 | offerer_config.bundle_policy = |
| 3752 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3753 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3754 | offerer_config.use_datagram_transport = true; |
| 3755 | |
| 3756 | // Configure the callee to only use datagram transport for media. |
| 3757 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3758 | answerer_config.rtcp_mux_policy = |
| 3759 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3760 | answerer_config.bundle_policy = |
| 3761 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3762 | answerer_config.use_datagram_transport = true; |
| 3763 | |
| 3764 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3765 | offerer_config, answerer_config, |
| 3766 | loopback_media_transports()->first_factory(), |
| 3767 | loopback_media_transports()->second_factory())); |
| 3768 | ConnectFakeSignaling(); |
| 3769 | |
| 3770 | // Offer both media and data. |
| 3771 | caller()->AddAudioVideoTracks(); |
| 3772 | callee()->AddAudioVideoTracks(); |
| 3773 | caller()->CreateDataChannel(); |
| 3774 | caller()->CreateAndSetAndSignalOffer(); |
| 3775 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3776 | |
| 3777 | // Ensure that the data channel transport is ready. |
| 3778 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3779 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3780 | |
| 3781 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3782 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3783 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3784 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3785 | |
| 3786 | // Both endpoints should agree to use SCTP for data channels. |
| 3787 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 3788 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 3789 | |
| 3790 | // Ensure data can be sent in both directions. |
| 3791 | std::string data = "hello world"; |
| 3792 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3793 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3794 | kDefaultTimeout); |
| 3795 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3796 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3797 | kDefaultTimeout); |
| 3798 | |
| 3799 | // Media flow should not be impacted. |
| 3800 | MediaExpectations media_expectations; |
| 3801 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3802 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3803 | } |
| 3804 | |
| 3805 | TEST_P(PeerConnectionIntegrationTest, |
| 3806 | DatagramTransportDataChannelWithMediaOnCallee) { |
| 3807 | // Configure the caller to attempt use of datagram transport for data |
| 3808 | // channels. |
| 3809 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3810 | offerer_config.rtcp_mux_policy = |
| 3811 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3812 | offerer_config.bundle_policy = |
| 3813 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3814 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3815 | |
| 3816 | // Configure the callee to use datagram transport for data channels and media. |
| 3817 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3818 | answerer_config.rtcp_mux_policy = |
| 3819 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3820 | answerer_config.bundle_policy = |
| 3821 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3822 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3823 | answerer_config.use_datagram_transport = true; |
| 3824 | |
| 3825 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3826 | offerer_config, answerer_config, |
| 3827 | loopback_media_transports()->first_factory(), |
| 3828 | loopback_media_transports()->second_factory())); |
| 3829 | ConnectFakeSignaling(); |
| 3830 | |
| 3831 | // Offer both media and data. |
| 3832 | caller()->AddAudioVideoTracks(); |
| 3833 | callee()->AddAudioVideoTracks(); |
| 3834 | caller()->CreateDataChannel(); |
| 3835 | caller()->CreateAndSetAndSignalOffer(); |
| 3836 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3837 | |
| 3838 | // Ensure that the data channel transport is ready. |
| 3839 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3840 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3841 | |
| 3842 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3843 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3844 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3845 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3846 | |
| 3847 | // Both endpoints should agree to use datagram transport for data channels. |
| 3848 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 3849 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 3850 | |
| 3851 | // Ensure data can be sent in both directions. |
| 3852 | std::string data = "hello world"; |
| 3853 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3854 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3855 | kDefaultTimeout); |
| 3856 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3857 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3858 | kDefaultTimeout); |
| 3859 | |
| 3860 | // Media flow should not be impacted. |
| 3861 | MediaExpectations media_expectations; |
| 3862 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3863 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3864 | } |
| 3865 | |
| 3866 | TEST_P(PeerConnectionIntegrationTest, |
| 3867 | DatagramTransportMediaWithDataChannelOnCallee) { |
| 3868 | // Configure the caller to attempt use of datagram transport for media. |
| 3869 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3870 | offerer_config.rtcp_mux_policy = |
| 3871 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3872 | offerer_config.bundle_policy = |
| 3873 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3874 | offerer_config.use_datagram_transport = true; |
| 3875 | |
| 3876 | // Configure the callee to only use datagram transport for media and data |
| 3877 | // channels. |
| 3878 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3879 | answerer_config.rtcp_mux_policy = |
| 3880 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3881 | answerer_config.bundle_policy = |
| 3882 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3883 | answerer_config.use_datagram_transport = true; |
| 3884 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3885 | |
| 3886 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3887 | offerer_config, answerer_config, |
| 3888 | loopback_media_transports()->first_factory(), |
| 3889 | loopback_media_transports()->second_factory())); |
| 3890 | ConnectFakeSignaling(); |
| 3891 | |
| 3892 | // Offer both media and data. |
| 3893 | caller()->AddAudioVideoTracks(); |
| 3894 | callee()->AddAudioVideoTracks(); |
| 3895 | caller()->CreateDataChannel(); |
| 3896 | caller()->CreateAndSetAndSignalOffer(); |
| 3897 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3898 | |
| 3899 | // Ensure that the data channel transport is ready. |
| 3900 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3901 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3902 | |
| 3903 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3904 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3905 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3906 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3907 | |
| 3908 | // Both endpoints should agree to use SCTP for data channels. |
| 3909 | EXPECT_NE(nullptr, caller()->pc()->GetSctpTransport()); |
| 3910 | EXPECT_NE(nullptr, callee()->pc()->GetSctpTransport()); |
| 3911 | |
| 3912 | // Ensure data can be sent in both directions. |
| 3913 | std::string data = "hello world"; |
| 3914 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3915 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3916 | kDefaultTimeout); |
| 3917 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3918 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3919 | kDefaultTimeout); |
| 3920 | |
| 3921 | // Media flow should not be impacted. |
| 3922 | MediaExpectations media_expectations; |
| 3923 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3924 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3925 | } |
| 3926 | |
| 3927 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelAndMedia) { |
| 3928 | // Configure the caller to use datagram transport for data channels and media. |
| 3929 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 3930 | offerer_config.rtcp_mux_policy = |
| 3931 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3932 | offerer_config.bundle_policy = |
| 3933 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3934 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 3935 | offerer_config.use_datagram_transport = true; |
| 3936 | |
| 3937 | // Configure the callee to use datagram transport for data channels and media. |
| 3938 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 3939 | answerer_config.rtcp_mux_policy = |
| 3940 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3941 | answerer_config.bundle_policy = |
| 3942 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3943 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 3944 | answerer_config.use_datagram_transport = true; |
| 3945 | |
| 3946 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3947 | offerer_config, answerer_config, |
| 3948 | loopback_media_transports()->first_factory(), |
| 3949 | loopback_media_transports()->second_factory())); |
| 3950 | ConnectFakeSignaling(); |
| 3951 | |
| 3952 | // Offer both media and data. |
| 3953 | caller()->AddAudioVideoTracks(); |
| 3954 | callee()->AddAudioVideoTracks(); |
| 3955 | caller()->CreateDataChannel(); |
| 3956 | caller()->CreateAndSetAndSignalOffer(); |
| 3957 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3958 | |
| 3959 | // Ensure that the data channel transport is ready. |
| 3960 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3961 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3962 | |
| 3963 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3964 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3965 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3966 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3967 | |
| 3968 | // Both endpoints should agree to use datagram transport for data channels. |
| 3969 | EXPECT_EQ(nullptr, caller()->pc()->GetSctpTransport()); |
| 3970 | EXPECT_EQ(nullptr, callee()->pc()->GetSctpTransport()); |
| 3971 | |
| 3972 | // Ensure data can be sent in both directions. |
| 3973 | std::string data = "hello world"; |
| 3974 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3975 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3976 | kDefaultTimeout); |
| 3977 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3978 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3979 | kDefaultTimeout); |
| 3980 | |
| 3981 | // Media flow should not be impacted. |
| 3982 | MediaExpectations media_expectations; |
| 3983 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3984 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3985 | } |
| 3986 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 3987 | // Tests that data channels use SCTP instead of datagram transport if datagram |
| 3988 | // transport is configured in receive-only mode on the caller. |
| 3989 | TEST_P(PeerConnectionIntegrationTest, |
| 3990 | DatagramTransportDataChannelReceiveOnlyOnCallerUsesSctp) { |
| 3991 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3992 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3993 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3994 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 3995 | rtc_config.use_datagram_transport_for_data_channels_receive_only = true; |
| 3996 | |
| 3997 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3998 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3999 | loopback_media_transports()->second_factory())); |
| 4000 | ConnectFakeSignaling(); |
| 4001 | |
| 4002 | // The caller should offer a data channel using SCTP. |
| 4003 | caller()->CreateDataChannel(); |
| 4004 | caller()->AddAudioVideoTracks(); |
| 4005 | callee()->AddAudioVideoTracks(); |
| 4006 | caller()->CreateAndSetAndSignalOffer(); |
| 4007 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4008 | |
| 4009 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4010 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4011 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4012 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4013 | |
| 4014 | // SCTP transports should be present, since they are in use. |
| 4015 | EXPECT_NE(caller()->pc()->GetSctpTransport(), nullptr); |
| 4016 | EXPECT_NE(callee()->pc()->GetSctpTransport(), nullptr); |
| 4017 | |
| 4018 | // Ensure data can be sent in both directions. |
| 4019 | std::string data = "hello world"; |
| 4020 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4021 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4022 | kDefaultTimeout); |
| 4023 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4024 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4025 | kDefaultTimeout); |
| 4026 | } |
| 4027 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4028 | #endif // HAVE_SCTP |
| 4029 | |
Bjorn A Mellem | 7da4e56 | 2019-09-26 11:02:11 -0700 | [diff] [blame] | 4030 | // Tests that a callee configured for receive-only use of datagram transport |
| 4031 | // data channels accepts them on incoming calls. |
| 4032 | TEST_P(PeerConnectionIntegrationTest, |
| 4033 | DatagramTransportDataChannelReceiveOnlyOnCallee) { |
| 4034 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4035 | offerer_config.rtcp_mux_policy = |
| 4036 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4037 | offerer_config.bundle_policy = |
| 4038 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4039 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4040 | |
| 4041 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4042 | answerer_config.rtcp_mux_policy = |
| 4043 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4044 | answerer_config.bundle_policy = |
| 4045 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4046 | answerer_config.use_datagram_transport_for_data_channels = true; |
| 4047 | answerer_config.use_datagram_transport_for_data_channels_receive_only = true; |
| 4048 | |
| 4049 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4050 | offerer_config, answerer_config, |
| 4051 | loopback_media_transports()->first_factory(), |
| 4052 | loopback_media_transports()->second_factory())); |
| 4053 | ConnectFakeSignaling(); |
| 4054 | |
| 4055 | caller()->CreateDataChannel(); |
| 4056 | caller()->CreateAndSetAndSignalOffer(); |
| 4057 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4058 | |
| 4059 | // Ensure that the data channel transport is ready. |
| 4060 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4061 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4062 | |
| 4063 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4064 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4065 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4066 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4067 | |
| 4068 | // SCTP transports should not be present, since datagram transport is used. |
| 4069 | EXPECT_EQ(caller()->pc()->GetSctpTransport(), nullptr); |
| 4070 | EXPECT_EQ(callee()->pc()->GetSctpTransport(), nullptr); |
| 4071 | |
| 4072 | // Ensure data can be sent in both directions. |
| 4073 | std::string data = "hello world"; |
| 4074 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4075 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4076 | kDefaultTimeout); |
| 4077 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4078 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4079 | kDefaultTimeout); |
| 4080 | } |
| 4081 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4082 | // This test sets up a call between two parties with a datagram transport data |
| 4083 | // channel. |
| 4084 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelEndToEnd) { |
| 4085 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4086 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4087 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4088 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4089 | rtc_config.enable_dtls_srtp = false; |
| 4090 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4091 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4092 | loopback_media_transports()->second_factory())); |
| 4093 | ConnectFakeSignaling(); |
| 4094 | |
| 4095 | // Expect that data channel created on caller side will show up for callee as |
| 4096 | // well. |
| 4097 | caller()->CreateDataChannel(); |
| 4098 | caller()->CreateAndSetAndSignalOffer(); |
| 4099 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4100 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4101 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4102 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4103 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4104 | |
| 4105 | // Caller data channel should already exist (it created one). Callee data |
| 4106 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4107 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4108 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4109 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4110 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4111 | |
| 4112 | // Ensure data can be sent in both directions. |
| 4113 | std::string data = "hello world"; |
| 4114 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4115 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4116 | kDefaultTimeout); |
| 4117 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4118 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4119 | kDefaultTimeout); |
| 4120 | } |
| 4121 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 4122 | // Tests that 'zero-rtt' data channel transports (which are ready-to-send as |
| 4123 | // soon as they're created) work correctly. |
| 4124 | TEST_P(PeerConnectionIntegrationTest, DatagramTransportDataChannelZeroRtt) { |
| 4125 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4126 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4127 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4128 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4129 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 4130 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4131 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4132 | loopback_media_transports()->second_factory())); |
| 4133 | ConnectFakeSignaling(); |
| 4134 | |
| 4135 | // Ensure that the callee's media transport is ready-to-send immediately. |
| 4136 | // Note that only the callee can become writable in zero RTTs. The caller |
| 4137 | // must wait for the callee's answer. |
| 4138 | loopback_media_transports()->SetSecondStateAfterConnect( |
| 4139 | webrtc::MediaTransportState::kWritable); |
| 4140 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4141 | |
| 4142 | // Expect that data channel created on caller side will show up for callee as |
| 4143 | // well. |
| 4144 | caller()->CreateDataChannel(); |
| 4145 | caller()->CreateAndSetAndSignalOffer(); |
| 4146 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4147 | |
| 4148 | loopback_media_transports()->SetFirstState( |
| 4149 | webrtc::MediaTransportState::kWritable); |
| 4150 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4151 | |
| 4152 | // Caller data channel should already exist (it created one). Callee data |
| 4153 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 4154 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4155 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4156 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4157 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4158 | |
| 4159 | // Ensure data can be sent in both directions. |
| 4160 | std::string data = "hello world"; |
| 4161 | caller()->data_channel()->Send(DataBuffer(data)); |
| 4162 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 4163 | kDefaultTimeout); |
| 4164 | callee()->data_channel()->Send(DataBuffer(data)); |
| 4165 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 4166 | kDefaultTimeout); |
| 4167 | } |
| 4168 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4169 | // Ensures that when the callee closes a datagram transport data channel, the |
| 4170 | // closing procedure results in the data channel being closed for the caller |
| 4171 | // as well. |
| 4172 | TEST_P(PeerConnectionIntegrationTest, |
| 4173 | DatagramTransportDataChannelCalleeCloses) { |
| 4174 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4175 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4176 | rtc_config.enable_dtls_srtp = false; |
| 4177 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4178 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4179 | loopback_media_transports()->second_factory())); |
| 4180 | ConnectFakeSignaling(); |
| 4181 | |
| 4182 | // Create a data channel on the caller and signal it to the callee. |
| 4183 | caller()->CreateDataChannel(); |
| 4184 | caller()->CreateAndSetAndSignalOffer(); |
| 4185 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4186 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4187 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4188 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4189 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4190 | |
| 4191 | // Data channels exist and open on both ends of the connection. |
| 4192 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 4193 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4194 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4195 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4196 | |
| 4197 | // Close the data channel on the callee side, and wait for it to reach the |
| 4198 | // "closed" state on both sides. |
| 4199 | callee()->data_channel()->Close(); |
| 4200 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4201 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4202 | } |
| 4203 | |
| 4204 | // Tests that datagram transport data channels can do in-band negotiation. |
| 4205 | TEST_P(PeerConnectionIntegrationTest, |
| 4206 | DatagramTransportDataChannelConfigSentToOtherSide) { |
| 4207 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 4208 | rtc_config.use_datagram_transport_for_data_channels = true; |
| 4209 | rtc_config.enable_dtls_srtp = false; |
| 4210 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4211 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 4212 | loopback_media_transports()->second_factory())); |
| 4213 | ConnectFakeSignaling(); |
| 4214 | |
| 4215 | // Create a data channel with a non-default configuration and signal it to the |
| 4216 | // callee. |
| 4217 | webrtc::DataChannelInit init; |
| 4218 | init.id = 53; |
| 4219 | init.maxRetransmits = 52; |
| 4220 | caller()->CreateDataChannel("data-channel", &init); |
| 4221 | caller()->CreateAndSetAndSignalOffer(); |
| 4222 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4223 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 4224 | // Ensure that the data channel transport is ready. |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 4225 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 4226 | loopback_media_transports()->FlushAsyncInvokes(); |
| 4227 | |
| 4228 | // Ensure that the data channel exists on the callee with the correct |
| 4229 | // configuration. |
| 4230 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 4231 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 4232 | // Since "negotiate" is false, the "id" parameter is ignored. |
| 4233 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
| 4234 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 4235 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 4236 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 4237 | } |
| 4238 | |
| 4239 | TEST_P(PeerConnectionIntegrationTest, |
| 4240 | DatagramTransportDataChannelRejectedWithNoFallback) { |
| 4241 | PeerConnectionInterface::RTCConfiguration offerer_config; |
| 4242 | offerer_config.rtcp_mux_policy = |
| 4243 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4244 | offerer_config.bundle_policy = |
| 4245 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4246 | offerer_config.use_datagram_transport_for_data_channels = true; |
| 4247 | // Disabling DTLS precludes a fallback to SCTP. |
| 4248 | offerer_config.enable_dtls_srtp = false; |
| 4249 | |
| 4250 | PeerConnectionInterface::RTCConfiguration answerer_config; |
| 4251 | answerer_config.rtcp_mux_policy = |
| 4252 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4253 | answerer_config.bundle_policy = |
| 4254 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4255 | // Both endpoints must disable DTLS or SetRemoteDescription will fail. |
| 4256 | answerer_config.enable_dtls_srtp = false; |
| 4257 | |
| 4258 | // Configure one endpoint to use datagram transport for data channels while |
| 4259 | // the other does not. |
| 4260 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 4261 | offerer_config, answerer_config, |
| 4262 | loopback_media_transports()->first_factory(), nullptr)); |
| 4263 | ConnectFakeSignaling(); |
| 4264 | |
| 4265 | // The caller offers a data channel using either datagram transport or SCTP. |
| 4266 | caller()->CreateDataChannel(); |
| 4267 | caller()->AddAudioVideoTracks(); |
| 4268 | callee()->AddAudioVideoTracks(); |
| 4269 | caller()->CreateAndSetAndSignalOffer(); |
| 4270 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4271 | |
| 4272 | // Caller data channel should already exist (it created one). Callee data |
| 4273 | // channel should not exist, since negotiation happens in-band, not in SDP. |
| 4274 | EXPECT_NE(nullptr, caller()->data_channel()); |
| 4275 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 4276 | |
| 4277 | // The caller's data channel should close when the datagram transport is |
| 4278 | // rejected. |
| 4279 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 4280 | |
| 4281 | // Media flow should not be impacted by the failed data channel. |
| 4282 | MediaExpectations media_expectations; |
| 4283 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4284 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4285 | } |
| 4286 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4287 | // Test that the ICE connection and gathering states eventually reach |
| 4288 | // "complete". |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4289 | TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4290 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4291 | ConnectFakeSignaling(); |
| 4292 | // Do normal offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4293 | caller()->AddAudioVideoTracks(); |
| 4294 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4295 | caller()->CreateAndSetAndSignalOffer(); |
| 4296 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4297 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 4298 | caller()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 4299 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 4300 | callee()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 4301 | // After the best candidate pair is selected and all candidates are signaled, |
| 4302 | // the ICE connection state should reach "complete". |
| 4303 | // TODO(deadbeef): Currently, the ICE "controlled" agent (the |
| 4304 | // answerer/"callee" by default) only reaches "connected". When this is |
| 4305 | // fixed, this test should be updated. |
| 4306 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4307 | caller()->ice_connection_state(), kDefaultTimeout); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4308 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4309 | callee()->ice_connection_state(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4312 | constexpr int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4313 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 4314 | cricket::PORTALLOCATOR_DISABLE_TCP; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4315 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4316 | // Use a mock resolver to resolve the hostname back to the original IP on both |
| 4317 | // sides and check that the ICE connection connects. |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4318 | TEST_P(PeerConnectionIntegrationTest, |
| 4319 | IceStatesReachCompletionWithRemoteHostname) { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4320 | auto caller_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4321 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4322 | auto callee_resolver_factory = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4323 | std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4324 | NiceMock<rtc::MockAsyncResolver> callee_async_resolver; |
| 4325 | NiceMock<rtc::MockAsyncResolver> caller_async_resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4326 | |
| 4327 | // This also verifies that the injected AsyncResolverFactory is used by |
| 4328 | // P2PTransportChannel. |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4329 | EXPECT_CALL(*caller_resolver_factory, Create()) |
| 4330 | .WillOnce(Return(&caller_async_resolver)); |
| 4331 | webrtc::PeerConnectionDependencies caller_deps(nullptr); |
| 4332 | caller_deps.async_resolver_factory = std::move(caller_resolver_factory); |
| 4333 | |
| 4334 | EXPECT_CALL(*callee_resolver_factory, Create()) |
| 4335 | .WillOnce(Return(&callee_async_resolver)); |
| 4336 | webrtc::PeerConnectionDependencies callee_deps(nullptr); |
| 4337 | callee_deps.async_resolver_factory = std::move(callee_resolver_factory); |
| 4338 | |
| 4339 | PeerConnectionInterface::RTCConfiguration config; |
| 4340 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4341 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4342 | |
| 4343 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 4344 | config, std::move(caller_deps), config, std::move(callee_deps))); |
| 4345 | |
| 4346 | caller()->SetRemoteAsyncResolver(&callee_async_resolver); |
| 4347 | callee()->SetRemoteAsyncResolver(&caller_async_resolver); |
| 4348 | |
| 4349 | // Enable hostname candidates with mDNS names. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4350 | caller()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4351 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4352 | callee()->SetMdnsResponder( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 4353 | std::make_unique<webrtc::FakeMdnsResponder>(network_thread())); |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4354 | |
| 4355 | SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4356 | |
| 4357 | ConnectFakeSignaling(); |
| 4358 | caller()->AddAudioVideoTracks(); |
| 4359 | callee()->AddAudioVideoTracks(); |
| 4360 | caller()->CreateAndSetAndSignalOffer(); |
| 4361 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4362 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4363 | caller()->ice_connection_state(), kDefaultTimeout); |
| 4364 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4365 | callee()->ice_connection_state(), kDefaultTimeout); |
Jeroen de Borst | 833979f | 2018-12-13 08:25:54 -0800 | [diff] [blame] | 4366 | |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 4367 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 4368 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4369 | webrtc::kIceCandidatePairHostNameHostName)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4372 | // Test that firewalling the ICE connection causes the clients to identify the |
| 4373 | // disconnected state and then removing the firewall causes them to reconnect. |
| 4374 | class PeerConnectionIntegrationIceStatesTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4375 | : public PeerConnectionIntegrationBaseTest, |
| 4376 | public ::testing::WithParamInterface< |
| 4377 | std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4378 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4379 | PeerConnectionIntegrationIceStatesTest() |
| 4380 | : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) { |
| 4381 | port_allocator_flags_ = std::get<1>(std::get<1>(GetParam())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | void StartStunServer(const SocketAddress& server_address) { |
| 4385 | stun_server_.reset( |
| 4386 | cricket::TestStunServer::Create(network_thread(), server_address)); |
| 4387 | } |
| 4388 | |
| 4389 | bool TestIPv6() { |
| 4390 | return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 4391 | } |
| 4392 | |
| 4393 | void SetPortAllocatorFlags() { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 4394 | PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( |
| 4395 | port_allocator_flags_, port_allocator_flags_); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | std::vector<SocketAddress> CallerAddresses() { |
| 4399 | std::vector<SocketAddress> addresses; |
| 4400 | addresses.push_back(SocketAddress("1.1.1.1", 0)); |
| 4401 | if (TestIPv6()) { |
| 4402 | addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0)); |
| 4403 | } |
| 4404 | return addresses; |
| 4405 | } |
| 4406 | |
| 4407 | std::vector<SocketAddress> CalleeAddresses() { |
| 4408 | std::vector<SocketAddress> addresses; |
| 4409 | addresses.push_back(SocketAddress("2.2.2.2", 0)); |
| 4410 | if (TestIPv6()) { |
| 4411 | addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0)); |
| 4412 | } |
| 4413 | return addresses; |
| 4414 | } |
| 4415 | |
| 4416 | void SetUpNetworkInterfaces() { |
| 4417 | // Remove the default interfaces added by the test infrastructure. |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4418 | caller()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
| 4419 | callee()->network_manager()->RemoveInterface(kDefaultLocalAddress); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4420 | |
| 4421 | // Add network addresses for test. |
| 4422 | for (const auto& caller_address : CallerAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4423 | caller()->network_manager()->AddInterface(caller_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4424 | } |
| 4425 | for (const auto& callee_address : CalleeAddresses()) { |
Qingsi Wang | ecd3054 | 2019-05-22 14:34:56 -0700 | [diff] [blame] | 4426 | callee()->network_manager()->AddInterface(callee_address); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | private: |
| 4431 | uint32_t port_allocator_flags_; |
| 4432 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
| 4433 | }; |
| 4434 | |
| 4435 | // Tests that the PeerConnection goes through all the ICE gathering/connection |
| 4436 | // states over the duration of the call. This includes Disconnected and Failed |
| 4437 | // states, induced by putting a firewall between the peers and waiting for them |
| 4438 | // to time out. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4439 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) { |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4440 | rtc::ScopedFakeClock fake_clock; |
| 4441 | // Some things use a time of "0" as a special value, so we need to start out |
| 4442 | // the fake clock at a nonzero time. |
| 4443 | fake_clock.AdvanceTime(TimeDelta::seconds(1)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4444 | |
| 4445 | const SocketAddress kStunServerAddress = |
| 4446 | SocketAddress("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 4447 | StartStunServer(kStunServerAddress); |
| 4448 | |
| 4449 | PeerConnectionInterface::RTCConfiguration config; |
| 4450 | PeerConnectionInterface::IceServer ice_stun_server; |
| 4451 | ice_stun_server.urls.push_back( |
| 4452 | "stun:" + kStunServerAddress.HostAsURIString() + ":" + |
| 4453 | kStunServerAddress.PortAsString()); |
| 4454 | config.servers.push_back(ice_stun_server); |
| 4455 | |
| 4456 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 4457 | ConnectFakeSignaling(); |
| 4458 | SetPortAllocatorFlags(); |
| 4459 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4460 | caller()->AddAudioVideoTracks(); |
| 4461 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4462 | |
| 4463 | // Initial state before anything happens. |
| 4464 | ASSERT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 4465 | caller()->ice_gathering_state()); |
| 4466 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 4467 | caller()->ice_connection_state()); |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4468 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 4469 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4470 | |
| 4471 | // Start the call by creating the offer, setting it as the local description, |
| 4472 | // then sending it to the peer who will respond with an answer. This happens |
| 4473 | // asynchronously so that we can watch the states as it runs in the |
| 4474 | // background. |
| 4475 | caller()->CreateAndSetAndSignalOffer(); |
| 4476 | |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4477 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, |
| 4478 | caller()->ice_connection_state()); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4479 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 4480 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4481 | |
| 4482 | // Verify that the observer was notified of the intermediate transitions. |
| 4483 | EXPECT_THAT(caller()->ice_connection_state_history(), |
| 4484 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 4485 | PeerConnectionInterface::kIceConnectionConnected, |
| 4486 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4487 | EXPECT_THAT(caller()->standardized_ice_connection_state_history(), |
| 4488 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 4489 | PeerConnectionInterface::kIceConnectionConnected, |
| 4490 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 4491 | EXPECT_THAT( |
| 4492 | caller()->peer_connection_state_history(), |
| 4493 | ElementsAre(PeerConnectionInterface::PeerConnectionState::kConnecting, |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 4494 | PeerConnectionInterface::PeerConnectionState::kConnected)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4495 | EXPECT_THAT(caller()->ice_gathering_state_history(), |
| 4496 | ElementsAre(PeerConnectionInterface::kIceGatheringGathering, |
| 4497 | PeerConnectionInterface::kIceGatheringComplete)); |
| 4498 | |
| 4499 | // Block connections to/from the caller and wait for ICE to become |
| 4500 | // disconnected. |
| 4501 | for (const auto& caller_address : CallerAddresses()) { |
| 4502 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4503 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4504 | RTC_LOG(LS_INFO) << "Firewall rules applied"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4505 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 4506 | caller()->ice_connection_state(), kDefaultTimeout, |
| 4507 | fake_clock); |
| 4508 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 4509 | caller()->standardized_ice_connection_state(), |
| 4510 | kDefaultTimeout, fake_clock); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4511 | |
| 4512 | // Let ICE re-establish by removing the firewall rules. |
| 4513 | firewall()->ClearRules(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4514 | RTC_LOG(LS_INFO) << "Firewall rules cleared"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4515 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4516 | caller()->ice_connection_state(), kDefaultTimeout, |
| 4517 | fake_clock); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 4518 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4519 | caller()->standardized_ice_connection_state(), |
| 4520 | kDefaultTimeout, fake_clock); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4521 | |
| 4522 | // According to RFC7675, if there is no response within 30 seconds then the |
| 4523 | // peer should consider the other side to have rejected the connection. This |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4524 | // is signaled by the state transitioning to "failed". |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4525 | constexpr int kConsentTimeout = 30000; |
| 4526 | for (const auto& caller_address : CallerAddresses()) { |
| 4527 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4528 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4529 | RTC_LOG(LS_INFO) << "Firewall rules applied again"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4530 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4531 | caller()->ice_connection_state(), kConsentTimeout, |
| 4532 | fake_clock); |
| 4533 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4534 | caller()->standardized_ice_connection_state(), |
| 4535 | kConsentTimeout, fake_clock); |
| 4536 | |
| 4537 | // We need to manually close the peerconnections before the fake clock goes |
| 4538 | // out of scope, or we trigger a DCHECK in rtp_sender.cc when we briefly |
| 4539 | // return to using non-faked time. |
| 4540 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 4541 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
| 4542 | } |
| 4543 | |
| 4544 | // Tests that if the connection doesn't get set up properly we eventually reach |
| 4545 | // the "failed" iceConnectionState. |
| 4546 | TEST_P(PeerConnectionIntegrationIceStatesTest, IceStateSetupFailure) { |
| 4547 | rtc::ScopedFakeClock fake_clock; |
| 4548 | // Some things use a time of "0" as a special value, so we need to start out |
| 4549 | // the fake clock at a nonzero time. |
| 4550 | fake_clock.AdvanceTime(TimeDelta::seconds(1)); |
| 4551 | |
| 4552 | // Block connections to/from the caller and wait for ICE to become |
| 4553 | // disconnected. |
| 4554 | for (const auto& caller_address : CallerAddresses()) { |
| 4555 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4556 | } |
| 4557 | |
| 4558 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4559 | ConnectFakeSignaling(); |
| 4560 | SetPortAllocatorFlags(); |
| 4561 | SetUpNetworkInterfaces(); |
| 4562 | caller()->AddAudioVideoTracks(); |
| 4563 | caller()->CreateAndSetAndSignalOffer(); |
| 4564 | |
| 4565 | // According to RFC7675, if there is no response within 30 seconds then the |
| 4566 | // peer should consider the other side to have rejected the connection. This |
| 4567 | // is signaled by the state transitioning to "failed". |
| 4568 | constexpr int kConsentTimeout = 30000; |
| 4569 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4570 | caller()->standardized_ice_connection_state(), |
| 4571 | kConsentTimeout, fake_clock); |
| 4572 | |
| 4573 | // We need to manually close the peerconnections before the fake clock goes |
| 4574 | // out of scope, or we trigger a DCHECK in rtp_sender.cc when we briefly |
| 4575 | // return to using non-faked time. |
| 4576 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 4577 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | // Tests that the best connection is set to the appropriate IPv4/IPv6 connection |
| 4581 | // and that the statistics in the metric observers are updated correctly. |
| 4582 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyBestConnection) { |
| 4583 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4584 | ConnectFakeSignaling(); |
| 4585 | SetPortAllocatorFlags(); |
| 4586 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4587 | caller()->AddAudioVideoTracks(); |
| 4588 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4589 | caller()->CreateAndSetAndSignalOffer(); |
| 4590 | |
| 4591 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4592 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 4593 | // TODO(bugs.webrtc.org/9456): Fix it. |
| 4594 | const int num_best_ipv4 = webrtc::metrics::NumEvents( |
| 4595 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv4); |
| 4596 | const int num_best_ipv6 = webrtc::metrics::NumEvents( |
| 4597 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4598 | if (TestIPv6()) { |
| 4599 | // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4 |
| 4600 | // connection. |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 4601 | EXPECT_METRIC_EQ(0, num_best_ipv4); |
| 4602 | EXPECT_METRIC_EQ(1, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4603 | } else { |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 4604 | EXPECT_METRIC_EQ(1, num_best_ipv4); |
| 4605 | EXPECT_METRIC_EQ(0, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4606 | } |
| 4607 | |
Ying Wang | ef3998f | 2019-12-09 13:06:53 +0100 | [diff] [blame] | 4608 | EXPECT_METRIC_EQ(0, webrtc::metrics::NumEvents( |
| 4609 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4610 | webrtc::kIceCandidatePairHostHost)); |
| 4611 | EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents( |
| 4612 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4613 | webrtc::kIceCandidatePairHostPublicHostPublic)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP | |
| 4617 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4618 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4619 | constexpr uint32_t kFlagsIPv6NoStun = |
| 4620 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4621 | cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4622 | constexpr uint32_t kFlagsIPv4Stun = |
| 4623 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4624 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4625 | INSTANTIATE_TEST_SUITE_P( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4626 | PeerConnectionIntegrationTest, |
| 4627 | PeerConnectionIntegrationIceStatesTest, |
| 4628 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 4629 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 4630 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 4631 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4632 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4633 | // This test sets up a call between two parties with audio and video. |
| 4634 | // During the call, the caller restarts ICE and the test verifies that |
| 4635 | // new ICE candidates are generated and audio and video still can flow, and the |
| 4636 | // ICE state reaches completed again. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4637 | TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4638 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4639 | ConnectFakeSignaling(); |
| 4640 | // Do normal offer/answer and wait for ICE to complete. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4641 | caller()->AddAudioVideoTracks(); |
| 4642 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4643 | caller()->CreateAndSetAndSignalOffer(); |
| 4644 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4645 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4646 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4647 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4648 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4649 | |
| 4650 | // To verify that the ICE restart actually occurs, get |
| 4651 | // ufrag/password/candidates before and after restart. |
| 4652 | // Create an SDP string of the first audio candidate for both clients. |
| 4653 | const webrtc::IceCandidateCollection* audio_candidates_caller = |
| 4654 | caller()->pc()->local_description()->candidates(0); |
| 4655 | const webrtc::IceCandidateCollection* audio_candidates_callee = |
| 4656 | callee()->pc()->local_description()->candidates(0); |
| 4657 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 4658 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 4659 | std::string caller_candidate_pre_restart; |
| 4660 | ASSERT_TRUE( |
| 4661 | audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart)); |
| 4662 | std::string callee_candidate_pre_restart; |
| 4663 | ASSERT_TRUE( |
| 4664 | audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart)); |
| 4665 | const cricket::SessionDescription* desc = |
| 4666 | caller()->pc()->local_description()->description(); |
| 4667 | std::string caller_ufrag_pre_restart = |
| 4668 | desc->transport_infos()[0].description.ice_ufrag; |
| 4669 | desc = callee()->pc()->local_description()->description(); |
| 4670 | std::string callee_ufrag_pre_restart = |
| 4671 | desc->transport_infos()[0].description.ice_ufrag; |
| 4672 | |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 4673 | EXPECT_EQ(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4674 | // Have the caller initiate an ICE restart. |
| 4675 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 4676 | caller()->CreateAndSetAndSignalOffer(); |
| 4677 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4678 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4679 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4680 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4681 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4682 | |
| 4683 | // Grab the ufrags/candidates again. |
| 4684 | audio_candidates_caller = caller()->pc()->local_description()->candidates(0); |
| 4685 | audio_candidates_callee = callee()->pc()->local_description()->candidates(0); |
| 4686 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 4687 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 4688 | std::string caller_candidate_post_restart; |
| 4689 | ASSERT_TRUE( |
| 4690 | audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart)); |
| 4691 | std::string callee_candidate_post_restart; |
| 4692 | ASSERT_TRUE( |
| 4693 | audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart)); |
| 4694 | desc = caller()->pc()->local_description()->description(); |
| 4695 | std::string caller_ufrag_post_restart = |
| 4696 | desc->transport_infos()[0].description.ice_ufrag; |
| 4697 | desc = callee()->pc()->local_description()->description(); |
| 4698 | std::string callee_ufrag_post_restart = |
| 4699 | desc->transport_infos()[0].description.ice_ufrag; |
| 4700 | // Sanity check that an ICE restart was actually negotiated in SDP. |
| 4701 | ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart); |
| 4702 | ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart); |
| 4703 | ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart); |
| 4704 | ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart); |
Alex Drake | 00c7ecf | 2019-08-06 10:54:47 -0700 | [diff] [blame] | 4705 | EXPECT_GT(caller()->ice_candidate_pair_change_history().size(), 1u); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4706 | |
| 4707 | // Ensure that additional frames are received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4708 | MediaExpectations media_expectations; |
| 4709 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4710 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | // Verify that audio/video can be received end-to-end when ICE renomination is |
| 4714 | // enabled. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4715 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4716 | PeerConnectionInterface::RTCConfiguration config; |
| 4717 | config.enable_ice_renomination = true; |
| 4718 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 4719 | ConnectFakeSignaling(); |
| 4720 | // Do normal offer/answer and wait for some frames to be received in each |
| 4721 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4722 | caller()->AddAudioVideoTracks(); |
| 4723 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4724 | caller()->CreateAndSetAndSignalOffer(); |
| 4725 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4726 | // Sanity check that ICE renomination was actually negotiated. |
| 4727 | const cricket::SessionDescription* desc = |
| 4728 | caller()->pc()->local_description()->description(); |
| 4729 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4730 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4731 | } |
| 4732 | desc = callee()->pc()->local_description()->description(); |
| 4733 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4734 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4735 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4736 | MediaExpectations media_expectations; |
| 4737 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4738 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4741 | // With a max bundle policy and RTCP muxing, adding a new media description to |
| 4742 | // the connection should not affect ICE at all because the new media will use |
| 4743 | // the existing connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4744 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4745 | AddMediaToConnectedBundleDoesNotRestartIce) { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4746 | PeerConnectionInterface::RTCConfiguration config; |
| 4747 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4748 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4749 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig( |
| 4750 | config, PeerConnectionInterface::RTCConfiguration())); |
| 4751 | ConnectFakeSignaling(); |
| 4752 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4753 | caller()->AddAudioTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4754 | caller()->CreateAndSetAndSignalOffer(); |
| 4755 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | ff52f1b | 2017-10-26 12:24:50 -0700 | [diff] [blame] | 4756 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4757 | caller()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4758 | |
| 4759 | caller()->clear_ice_connection_state_history(); |
| 4760 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4761 | caller()->AddVideoTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4762 | caller()->CreateAndSetAndSignalOffer(); |
| 4763 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4764 | |
| 4765 | EXPECT_EQ(0u, caller()->ice_connection_state_history().size()); |
| 4766 | } |
| 4767 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4768 | // This test sets up a call between two parties with audio and video. It then |
| 4769 | // renegotiates setting the video m-line to "port 0", then later renegotiates |
| 4770 | // again, enabling video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4771 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4772 | VideoFlowsAfterMediaSectionIsRejectedAndRecycled) { |
| 4773 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4774 | ConnectFakeSignaling(); |
| 4775 | |
| 4776 | // Do initial negotiation, only sending media from the caller. Will result in |
| 4777 | // video and audio recvonly "m=" sections. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4778 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4779 | caller()->CreateAndSetAndSignalOffer(); |
| 4780 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4781 | |
| 4782 | // Negotiate again, disabling the video "m=" section (the callee will set the |
| 4783 | // port to 0 due to offer_to_receive_video = 0). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4784 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 4785 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4786 | options.offer_to_receive_video = 0; |
| 4787 | callee()->SetOfferAnswerOptions(options); |
| 4788 | } else { |
| 4789 | callee()->SetRemoteOfferHandler([this] { |
| 4790 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 4791 | }); |
| 4792 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4793 | caller()->CreateAndSetAndSignalOffer(); |
| 4794 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4795 | // Sanity check that video "m=" section was actually rejected. |
| 4796 | const ContentInfo* answer_video_content = cricket::GetFirstVideoContent( |
| 4797 | callee()->pc()->local_description()->description()); |
| 4798 | ASSERT_NE(nullptr, answer_video_content); |
| 4799 | ASSERT_TRUE(answer_video_content->rejected); |
| 4800 | |
| 4801 | // Enable video and do negotiation again, making sure video is received |
| 4802 | // end-to-end, also adding media stream to callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4803 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 4804 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4805 | options.offer_to_receive_video = 1; |
| 4806 | callee()->SetOfferAnswerOptions(options); |
| 4807 | } else { |
| 4808 | // The caller's transceiver is stopped, so we need to add another track. |
| 4809 | auto caller_transceiver = |
| 4810 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 4811 | EXPECT_TRUE(caller_transceiver->stopped()); |
| 4812 | caller()->AddVideoTrack(); |
| 4813 | } |
| 4814 | callee()->AddVideoTrack(); |
| 4815 | callee()->SetRemoteOfferHandler(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4816 | caller()->CreateAndSetAndSignalOffer(); |
| 4817 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4818 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4819 | // Verify the caller receives frames from the newly added stream, and the |
| 4820 | // callee receives additional frames from the re-enabled video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4821 | MediaExpectations media_expectations; |
| 4822 | media_expectations.CalleeExpectsSomeAudio(); |
| 4823 | media_expectations.ExpectBidirectionalVideo(); |
| 4824 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4827 | // This tests that if we negotiate after calling CreateSender but before we |
| 4828 | // have a track, then set a track later, frames from the newly-set track are |
| 4829 | // received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4830 | TEST_F(PeerConnectionIntegrationTestPlanB, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4831 | MediaFlowsAfterEarlyWarmupWithCreateSender) { |
| 4832 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4833 | ConnectFakeSignaling(); |
| 4834 | auto caller_audio_sender = |
| 4835 | caller()->pc()->CreateSender("audio", "caller_stream"); |
| 4836 | auto caller_video_sender = |
| 4837 | caller()->pc()->CreateSender("video", "caller_stream"); |
| 4838 | auto callee_audio_sender = |
| 4839 | callee()->pc()->CreateSender("audio", "callee_stream"); |
| 4840 | auto callee_video_sender = |
| 4841 | callee()->pc()->CreateSender("video", "callee_stream"); |
| 4842 | caller()->CreateAndSetAndSignalOffer(); |
| 4843 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 4844 | // Wait for ICE to complete, without any tracks being set. |
| 4845 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4846 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4847 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4848 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4849 | // Now set the tracks, and expect frames to immediately start flowing. |
| 4850 | EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 4851 | EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 4852 | EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 4853 | EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4854 | MediaExpectations media_expectations; |
| 4855 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4856 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4857 | } |
| 4858 | |
| 4859 | // This tests that if we negotiate after calling AddTransceiver but before we |
| 4860 | // have a track, then set a track later, frames from the newly-set tracks are |
| 4861 | // received end-to-end. |
| 4862 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 4863 | MediaFlowsAfterEarlyWarmupWithAddTransceiver) { |
| 4864 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4865 | ConnectFakeSignaling(); |
| 4866 | auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 4867 | ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type()); |
| 4868 | auto caller_audio_sender = audio_result.MoveValue()->sender(); |
| 4869 | auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 4870 | ASSERT_EQ(RTCErrorType::NONE, video_result.error().type()); |
| 4871 | auto caller_video_sender = video_result.MoveValue()->sender(); |
| 4872 | callee()->SetRemoteOfferHandler([this] { |
| 4873 | ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size()); |
| 4874 | callee()->pc()->GetTransceivers()[0]->SetDirection( |
| 4875 | RtpTransceiverDirection::kSendRecv); |
| 4876 | callee()->pc()->GetTransceivers()[1]->SetDirection( |
| 4877 | RtpTransceiverDirection::kSendRecv); |
| 4878 | }); |
| 4879 | caller()->CreateAndSetAndSignalOffer(); |
| 4880 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 4881 | // Wait for ICE to complete, without any tracks being set. |
| 4882 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4883 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4884 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4885 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4886 | // Now set the tracks, and expect frames to immediately start flowing. |
| 4887 | auto callee_audio_sender = callee()->pc()->GetSenders()[0]; |
| 4888 | auto callee_video_sender = callee()->pc()->GetSenders()[1]; |
| 4889 | ASSERT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 4890 | ASSERT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 4891 | ASSERT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 4892 | ASSERT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
| 4893 | MediaExpectations media_expectations; |
| 4894 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4895 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | // This test verifies that a remote video track can be added via AddStream, |
| 4899 | // and sent end-to-end. For this particular test, it's simply echoed back |
| 4900 | // from the caller to the callee, rather than being forwarded to a third |
| 4901 | // PeerConnection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4902 | TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4903 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4904 | ConnectFakeSignaling(); |
| 4905 | // Just send a video track from the caller. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4906 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4907 | caller()->CreateAndSetAndSignalOffer(); |
| 4908 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 4909 | ASSERT_EQ(1U, callee()->remote_streams()->count()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4910 | |
| 4911 | // Echo the stream back, and do a new offer/anwer (initiated by callee this |
| 4912 | // time). |
| 4913 | callee()->pc()->AddStream(callee()->remote_streams()->at(0)); |
| 4914 | callee()->CreateAndSetAndSignalOffer(); |
| 4915 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 4916 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4917 | MediaExpectations media_expectations; |
| 4918 | media_expectations.ExpectBidirectionalVideo(); |
| 4919 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | // Test that we achieve the expected end-to-end connection time, using a |
| 4923 | // fake clock and simulated latency on the media and signaling paths. |
| 4924 | // We use a TURN<->TURN connection because this is usually the quickest to |
| 4925 | // set up initially, especially when we're confident the connection will work |
| 4926 | // and can start sending media before we get a STUN response. |
| 4927 | // |
| 4928 | // With various optimizations enabled, here are the network delays we expect to |
| 4929 | // be on the critical path: |
| 4930 | // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then |
| 4931 | // signaling answer (with DTLS fingerprint). |
| 4932 | // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when |
| 4933 | // using TURN<->TURN pair, and DTLS exchange is 4 packets, |
| 4934 | // the first of which should have arrived before the answer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4935 | TEST_P(PeerConnectionIntegrationTest, EndToEndConnectionTimeWithTurnTurnPair) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4936 | rtc::ScopedFakeClock fake_clock; |
| 4937 | // Some things use a time of "0" as a special value, so we need to start out |
| 4938 | // the fake clock at a nonzero time. |
| 4939 | // TODO(deadbeef): Fix this. |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 4940 | fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4941 | |
| 4942 | static constexpr int media_hop_delay_ms = 50; |
| 4943 | static constexpr int signaling_trip_delay_ms = 500; |
| 4944 | // For explanation of these values, see comment above. |
| 4945 | static constexpr int required_media_hops = 9; |
| 4946 | static constexpr int required_signaling_trips = 2; |
| 4947 | // For internal delays (such as posting an event asychronously). |
| 4948 | static constexpr int allowed_internal_delay_ms = 20; |
| 4949 | static constexpr int total_connection_time_ms = |
| 4950 | media_hop_delay_ms * required_media_hops + |
| 4951 | signaling_trip_delay_ms * required_signaling_trips + |
| 4952 | allowed_internal_delay_ms; |
| 4953 | |
| 4954 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 4955 | 3478}; |
| 4956 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 4957 | 0}; |
| 4958 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 4959 | 3478}; |
| 4960 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 4961 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4962 | cricket::TestTurnServer* turn_server_1 = CreateTurnServer( |
| 4963 | turn_server_1_internal_address, turn_server_1_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4964 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4965 | cricket::TestTurnServer* turn_server_2 = CreateTurnServer( |
| 4966 | turn_server_2_internal_address, turn_server_2_external_address); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4967 | // Bypass permission check on received packets so media can be sent before |
| 4968 | // the candidate is signaled. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4969 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_1] { |
| 4970 | turn_server_1->set_enable_permission_checks(false); |
| 4971 | }); |
| 4972 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_2] { |
| 4973 | turn_server_2->set_enable_permission_checks(false); |
| 4974 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4975 | |
| 4976 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 4977 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 4978 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 4979 | ice_server_1.username = "test"; |
| 4980 | ice_server_1.password = "test"; |
| 4981 | client_1_config.servers.push_back(ice_server_1); |
| 4982 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4983 | client_1_config.presume_writable_when_fully_relayed = true; |
| 4984 | |
| 4985 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 4986 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 4987 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 4988 | ice_server_2.username = "test"; |
| 4989 | ice_server_2.password = "test"; |
| 4990 | client_2_config.servers.push_back(ice_server_2); |
| 4991 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4992 | client_2_config.presume_writable_when_fully_relayed = true; |
| 4993 | |
| 4994 | ASSERT_TRUE( |
| 4995 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 4996 | // Set up the simulated delays. |
| 4997 | SetSignalingDelayMs(signaling_trip_delay_ms); |
| 4998 | ConnectFakeSignaling(); |
| 4999 | virtual_socket_server()->set_delay_mean(media_hop_delay_ms); |
| 5000 | virtual_socket_server()->UpdateDelayDistribution(); |
| 5001 | |
| 5002 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5003 | // set up ICE/DTLS with no media. |
| 5004 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5005 | options.offer_to_receive_audio = 1; |
| 5006 | options.offer_to_receive_video = 1; |
| 5007 | caller()->SetOfferAnswerOptions(options); |
| 5008 | caller()->CreateAndSetAndSignalOffer(); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 5009 | EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms, |
| 5010 | fake_clock); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 5011 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 5012 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 5013 | // 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] | 5014 | ClosePeerConnections(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5017 | // Verify that a TurnCustomizer passed in through RTCConfiguration |
| 5018 | // is actually used by the underlying TURN candidate pair. |
| 5019 | // Note that turnport_unittest.cc contains more detailed, lower-level tests. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5020 | TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) { |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5021 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 5022 | 3478}; |
| 5023 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 5024 | 0}; |
| 5025 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 5026 | 3478}; |
| 5027 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 5028 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5029 | CreateTurnServer(turn_server_1_internal_address, |
| 5030 | turn_server_1_external_address); |
| 5031 | CreateTurnServer(turn_server_2_internal_address, |
| 5032 | turn_server_2_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5033 | |
| 5034 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5035 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 5036 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 5037 | ice_server_1.username = "test"; |
| 5038 | ice_server_1.password = "test"; |
| 5039 | client_1_config.servers.push_back(ice_server_1); |
| 5040 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5041 | auto* customizer1 = CreateTurnCustomizer(); |
| 5042 | client_1_config.turn_customizer = customizer1; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5043 | |
| 5044 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5045 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 5046 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 5047 | ice_server_2.username = "test"; |
| 5048 | ice_server_2.password = "test"; |
| 5049 | client_2_config.servers.push_back(ice_server_2); |
| 5050 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5051 | auto* customizer2 = CreateTurnCustomizer(); |
| 5052 | client_2_config.turn_customizer = customizer2; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5053 | |
| 5054 | ASSERT_TRUE( |
| 5055 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5056 | ConnectFakeSignaling(); |
| 5057 | |
| 5058 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5059 | // set up ICE/DTLS with no media. |
| 5060 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5061 | options.offer_to_receive_audio = 1; |
| 5062 | options.offer_to_receive_video = 1; |
| 5063 | caller()->SetOfferAnswerOptions(options); |
| 5064 | caller()->CreateAndSetAndSignalOffer(); |
| 5065 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5066 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5067 | ExpectTurnCustomizerCountersIncremented(customizer1); |
| 5068 | ExpectTurnCustomizerCountersIncremented(customizer2); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 5069 | } |
| 5070 | |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 5071 | // Verifies that you can use TCP instead of UDP to connect to a TURN server and |
| 5072 | // send media between the caller and the callee. |
| 5073 | TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) { |
| 5074 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5075 | 3478}; |
| 5076 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5077 | |
| 5078 | // Enable TCP for the fake turn server. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5079 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5080 | cricket::PROTO_TCP); |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 5081 | |
| 5082 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5083 | ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp"); |
| 5084 | ice_server.username = "test"; |
| 5085 | ice_server.password = "test"; |
| 5086 | |
| 5087 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5088 | client_1_config.servers.push_back(ice_server); |
| 5089 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5090 | |
| 5091 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5092 | client_2_config.servers.push_back(ice_server); |
| 5093 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5094 | |
| 5095 | ASSERT_TRUE( |
| 5096 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 5097 | |
| 5098 | // Do normal offer/answer and wait for ICE to complete. |
| 5099 | ConnectFakeSignaling(); |
| 5100 | caller()->AddAudioVideoTracks(); |
| 5101 | callee()->AddAudioVideoTracks(); |
| 5102 | caller()->CreateAndSetAndSignalOffer(); |
| 5103 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5104 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5105 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 5106 | |
| 5107 | MediaExpectations media_expectations; |
| 5108 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5109 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 5110 | } |
| 5111 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5112 | // Verify that a SSLCertificateVerifier passed in through |
| 5113 | // PeerConnectionDependencies is actually used by the underlying SSL |
| 5114 | // implementation to determine whether a certificate presented by the TURN |
| 5115 | // server is accepted by the client. Note that openssladapter_unittest.cc |
| 5116 | // contains more detailed, lower-level tests. |
| 5117 | TEST_P(PeerConnectionIntegrationTest, |
| 5118 | SSLCertificateVerifierUsedForTurnConnections) { |
| 5119 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5120 | 3478}; |
| 5121 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5122 | |
| 5123 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 5124 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5125 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5126 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5127 | |
| 5128 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5129 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 5130 | ice_server.username = "test"; |
| 5131 | ice_server.password = "test"; |
| 5132 | |
| 5133 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5134 | client_1_config.servers.push_back(ice_server); |
| 5135 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5136 | |
| 5137 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5138 | client_2_config.servers.push_back(ice_server); |
| 5139 | // Setting the type to kRelay forces the connection to go through a TURN |
| 5140 | // server. |
| 5141 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5142 | |
| 5143 | // Get a copy to the pointer so we can verify calls later. |
| 5144 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 5145 | new rtc::TestCertificateVerifier(); |
| 5146 | client_1_cert_verifier->verify_certificate_ = true; |
| 5147 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 5148 | new rtc::TestCertificateVerifier(); |
| 5149 | client_2_cert_verifier->verify_certificate_ = true; |
| 5150 | |
| 5151 | // Create the dependencies with the test certificate verifier. |
| 5152 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 5153 | client_1_deps.tls_cert_verifier = |
| 5154 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 5155 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 5156 | client_2_deps.tls_cert_verifier = |
| 5157 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 5158 | |
| 5159 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 5160 | client_1_config, std::move(client_1_deps), client_2_config, |
| 5161 | std::move(client_2_deps))); |
| 5162 | ConnectFakeSignaling(); |
| 5163 | |
| 5164 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5165 | // set up ICE/DTLS with no media. |
| 5166 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5167 | options.offer_to_receive_audio = 1; |
| 5168 | options.offer_to_receive_video = 1; |
| 5169 | caller()->SetOfferAnswerOptions(options); |
| 5170 | caller()->CreateAndSetAndSignalOffer(); |
| 5171 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5172 | |
| 5173 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 5174 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | TEST_P(PeerConnectionIntegrationTest, |
| 5178 | SSLCertificateVerifierFailureUsedForTurnConnectionsFailsConnection) { |
| 5179 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5180 | 3478}; |
| 5181 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5182 | |
| 5183 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 5184 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 5185 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 5186 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5187 | |
| 5188 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5189 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 5190 | ice_server.username = "test"; |
| 5191 | ice_server.password = "test"; |
| 5192 | |
| 5193 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 5194 | client_1_config.servers.push_back(ice_server); |
| 5195 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5196 | |
| 5197 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 5198 | client_2_config.servers.push_back(ice_server); |
| 5199 | // Setting the type to kRelay forces the connection to go through a TURN |
| 5200 | // server. |
| 5201 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5202 | |
| 5203 | // Get a copy to the pointer so we can verify calls later. |
| 5204 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 5205 | new rtc::TestCertificateVerifier(); |
| 5206 | client_1_cert_verifier->verify_certificate_ = false; |
| 5207 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 5208 | new rtc::TestCertificateVerifier(); |
| 5209 | client_2_cert_verifier->verify_certificate_ = false; |
| 5210 | |
| 5211 | // Create the dependencies with the test certificate verifier. |
| 5212 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 5213 | client_1_deps.tls_cert_verifier = |
| 5214 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 5215 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 5216 | client_2_deps.tls_cert_verifier = |
| 5217 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 5218 | |
| 5219 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 5220 | client_1_config, std::move(client_1_deps), client_2_config, |
| 5221 | std::move(client_2_deps))); |
| 5222 | ConnectFakeSignaling(); |
| 5223 | |
| 5224 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 5225 | // set up ICE/DTLS with no media. |
| 5226 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5227 | options.offer_to_receive_audio = 1; |
| 5228 | options.offer_to_receive_video = 1; |
| 5229 | caller()->SetOfferAnswerOptions(options); |
| 5230 | caller()->CreateAndSetAndSignalOffer(); |
| 5231 | bool wait_res = true; |
| 5232 | // TODO(bugs.webrtc.org/9219): When IceConnectionState is implemented |
| 5233 | // properly, should be able to just wait for a state of "failed" instead of |
| 5234 | // waiting a fixed 10 seconds. |
| 5235 | WAIT_(DtlsConnected(), kDefaultTimeout, wait_res); |
| 5236 | ASSERT_FALSE(wait_res); |
| 5237 | |
| 5238 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 5239 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 5242 | // Test that the injected ICE transport factory is used to create ICE transports |
| 5243 | // for WebRTC connections. |
| 5244 | TEST_P(PeerConnectionIntegrationTest, IceTransportFactoryUsedForConnections) { |
| 5245 | PeerConnectionInterface::RTCConfiguration default_config; |
| 5246 | PeerConnectionDependencies dependencies(nullptr); |
| 5247 | auto ice_transport_factory = std::make_unique<MockIceTransportFactory>(); |
| 5248 | EXPECT_CALL(*ice_transport_factory, RecordIceTransportCreated()).Times(1); |
| 5249 | dependencies.ice_transport_factory = std::move(ice_transport_factory); |
| 5250 | auto wrapper = |
| 5251 | CreatePeerConnectionWrapper("Caller", nullptr, &default_config, |
| 5252 | std::move(dependencies), nullptr, nullptr); |
| 5253 | ASSERT_TRUE(wrapper); |
| 5254 | wrapper->CreateDataChannel(); |
| 5255 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 5256 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 5257 | wrapper->pc()->SetLocalDescription(observer, |
| 5258 | wrapper->CreateOfferAndWait().release()); |
| 5259 | } |
| 5260 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5261 | // Test that audio and video flow end-to-end when codec names don't use the |
| 5262 | // expected casing, given that they're supposed to be case insensitive. To test |
| 5263 | // this, all but one codec is removed from each media description, and its |
| 5264 | // casing is changed. |
| 5265 | // |
| 5266 | // In the past, this has regressed and caused crashes/black video, due to the |
| 5267 | // fact that code at some layers was doing case-insensitive comparisons and |
| 5268 | // code at other layers was not. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5269 | TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) { |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5270 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5271 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5272 | caller()->AddAudioVideoTracks(); |
| 5273 | callee()->AddAudioVideoTracks(); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5274 | |
| 5275 | // Remove all but one audio/video codec (opus and VP8), and change the |
| 5276 | // casing of the caller's generated offer. |
| 5277 | caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) { |
| 5278 | cricket::AudioContentDescription* audio = |
| 5279 | GetFirstAudioContentDescription(description); |
| 5280 | ASSERT_NE(nullptr, audio); |
| 5281 | auto audio_codecs = audio->codecs(); |
| 5282 | audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(), |
| 5283 | [](const cricket::AudioCodec& codec) { |
| 5284 | return codec.name != "opus"; |
| 5285 | }), |
| 5286 | audio_codecs.end()); |
| 5287 | ASSERT_EQ(1u, audio_codecs.size()); |
| 5288 | audio_codecs[0].name = "OpUs"; |
| 5289 | audio->set_codecs(audio_codecs); |
| 5290 | |
| 5291 | cricket::VideoContentDescription* video = |
| 5292 | GetFirstVideoContentDescription(description); |
| 5293 | ASSERT_NE(nullptr, video); |
| 5294 | auto video_codecs = video->codecs(); |
| 5295 | video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(), |
| 5296 | [](const cricket::VideoCodec& codec) { |
| 5297 | return codec.name != "VP8"; |
| 5298 | }), |
| 5299 | video_codecs.end()); |
| 5300 | ASSERT_EQ(1u, video_codecs.size()); |
| 5301 | video_codecs[0].name = "vP8"; |
| 5302 | video->set_codecs(video_codecs); |
| 5303 | }); |
| 5304 | |
| 5305 | caller()->CreateAndSetAndSignalOffer(); |
| 5306 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5307 | |
| 5308 | // Verify frames are still received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5309 | MediaExpectations media_expectations; |
| 5310 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5311 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5314 | TEST_P(PeerConnectionIntegrationTest, GetSourcesAudio) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5315 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5316 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5317 | caller()->AddAudioTrack(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5318 | caller()->CreateAndSetAndSignalOffer(); |
| 5319 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 5320 | // Wait for one audio frame to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5321 | MediaExpectations media_expectations; |
| 5322 | media_expectations.CalleeExpectsSomeAudio(1); |
| 5323 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5324 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5325 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 5326 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5327 | auto sources = receiver->GetSources(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5328 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
| 5329 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5330 | sources[0].source_id()); |
| 5331 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
| 5332 | } |
| 5333 | |
| 5334 | TEST_P(PeerConnectionIntegrationTest, GetSourcesVideo) { |
| 5335 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5336 | ConnectFakeSignaling(); |
| 5337 | caller()->AddVideoTrack(); |
| 5338 | caller()->CreateAndSetAndSignalOffer(); |
| 5339 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5340 | // Wait for one video frame to be received by the callee. |
| 5341 | MediaExpectations media_expectations; |
| 5342 | media_expectations.CalleeExpectsSomeVideo(1); |
| 5343 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5344 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 5345 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 5346 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_VIDEO); |
| 5347 | auto sources = receiver->GetSources(); |
| 5348 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
Yves Gerey | f781bb5 | 2019-07-23 19:15:39 +0200 | [diff] [blame] | 5349 | ASSERT_GT(sources.size(), 0u); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 5350 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
| 5351 | sources[0].source_id()); |
| 5352 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 5353 | } |
| 5354 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5355 | // Test that if a track is removed and added again with a different stream ID, |
| 5356 | // the new stream ID is successfully communicated in SDP and media continues to |
| 5357 | // flow end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5358 | // TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because |
| 5359 | // it will not reuse a transceiver that has already been sending. After creating |
| 5360 | // a new transceiver it tries to create an offer with two senders of the same |
| 5361 | // track ids and it fails. |
| 5362 | TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5363 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5364 | ConnectFakeSignaling(); |
| 5365 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5366 | // Add track using stream 1, do offer/answer. |
| 5367 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 5368 | caller()->CreateLocalAudioTrack(); |
| 5369 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 5370 | caller()->AddTrack(track, {"stream_1"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5371 | caller()->CreateAndSetAndSignalOffer(); |
| 5372 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5373 | { |
| 5374 | MediaExpectations media_expectations; |
| 5375 | media_expectations.CalleeExpectsSomeAudio(1); |
| 5376 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5377 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5378 | // Remove the sender, and create a new one with the new stream. |
| 5379 | caller()->pc()->RemoveTrack(sender); |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 5380 | sender = caller()->AddTrack(track, {"stream_2"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5381 | caller()->CreateAndSetAndSignalOffer(); |
| 5382 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5383 | // Wait for additional audio frames to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5384 | { |
| 5385 | MediaExpectations media_expectations; |
| 5386 | media_expectations.CalleeExpectsSomeAudio(); |
| 5387 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5388 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 5389 | } |
| 5390 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5391 | TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) { |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5392 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5393 | ConnectFakeSignaling(); |
| 5394 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 5395 | auto output = std::make_unique<testing::NiceMock<MockRtcEventLogOutput>>(); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 5396 | ON_CALL(*output, IsActive()).WillByDefault(::testing::Return(true)); |
| 5397 | ON_CALL(*output, Write(::testing::_)).WillByDefault(::testing::Return(true)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5398 | EXPECT_CALL(*output, Write(::testing::_)).Times(::testing::AtLeast(1)); |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 5399 | EXPECT_TRUE(caller()->pc()->StartRtcEventLog( |
| 5400 | std::move(output), webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5401 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5402 | caller()->AddAudioVideoTracks(); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 5403 | caller()->CreateAndSetAndSignalOffer(); |
| 5404 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5405 | } |
| 5406 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5407 | // Test that if candidates are only signaled by applying full session |
| 5408 | // descriptions (instead of using AddIceCandidate), the peers can connect to |
| 5409 | // each other and exchange media. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5410 | TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5411 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5412 | // Each side will signal the session descriptions but not candidates. |
| 5413 | ConnectFakeSignalingForSdpOnly(); |
| 5414 | |
| 5415 | // Add audio video track and exchange the initial offer/answer with media |
| 5416 | // information only. This will start ICE gathering on each side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5417 | caller()->AddAudioVideoTracks(); |
| 5418 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5419 | caller()->CreateAndSetAndSignalOffer(); |
| 5420 | |
| 5421 | // Wait for all candidates to be gathered on both the caller and callee. |
| 5422 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 5423 | caller()->ice_gathering_state(), kDefaultTimeout); |
| 5424 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 5425 | callee()->ice_gathering_state(), kDefaultTimeout); |
| 5426 | |
| 5427 | // The candidates will now be included in the session description, so |
| 5428 | // signaling them will start the ICE connection. |
| 5429 | caller()->CreateAndSetAndSignalOffer(); |
| 5430 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5431 | |
| 5432 | // Ensure that media flows in both directions. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5433 | MediaExpectations media_expectations; |
| 5434 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5435 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 5436 | } |
| 5437 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5438 | // Test that SetAudioPlayout can be used to disable audio playout from the |
| 5439 | // start, then later enable it. This may be useful, for example, if the caller |
| 5440 | // needs to play a local ringtone until some event occurs, after which it |
| 5441 | // switches to playing the received audio. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5442 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5443 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5444 | ConnectFakeSignaling(); |
| 5445 | |
| 5446 | // Set up audio-only call where audio playout is disabled on caller's side. |
| 5447 | caller()->pc()->SetAudioPlayout(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5448 | caller()->AddAudioTrack(); |
| 5449 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5450 | caller()->CreateAndSetAndSignalOffer(); |
| 5451 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5452 | |
| 5453 | // Pump messages for a second. |
| 5454 | WAIT(false, 1000); |
| 5455 | // Since audio playout is disabled, the caller shouldn't have received |
| 5456 | // anything (at the playout level, at least). |
| 5457 | EXPECT_EQ(0, caller()->audio_frames_received()); |
| 5458 | // As a sanity check, make sure the callee (for which playout isn't disabled) |
| 5459 | // did still see frames on its audio level. |
| 5460 | ASSERT_GT(callee()->audio_frames_received(), 0); |
| 5461 | |
| 5462 | // Enable playout again, and ensure audio starts flowing. |
| 5463 | caller()->pc()->SetAudioPlayout(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5464 | MediaExpectations media_expectations; |
| 5465 | media_expectations.ExpectBidirectionalAudio(); |
| 5466 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | double GetAudioEnergyStat(PeerConnectionWrapper* pc) { |
| 5470 | auto report = pc->NewGetStats(); |
| 5471 | auto track_stats_list = |
| 5472 | report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 5473 | const webrtc::RTCMediaStreamTrackStats* remote_track_stats = nullptr; |
| 5474 | for (const auto* track_stats : track_stats_list) { |
| 5475 | if (track_stats->remote_source.is_defined() && |
| 5476 | *track_stats->remote_source) { |
| 5477 | remote_track_stats = track_stats; |
| 5478 | break; |
| 5479 | } |
| 5480 | } |
| 5481 | |
| 5482 | if (!remote_track_stats->total_audio_energy.is_defined()) { |
| 5483 | return 0.0; |
| 5484 | } |
| 5485 | return *remote_track_stats->total_audio_energy; |
| 5486 | } |
| 5487 | |
| 5488 | // Test that if audio playout is disabled via the SetAudioPlayout() method, then |
| 5489 | // incoming audio is still processed and statistics are generated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5490 | TEST_P(PeerConnectionIntegrationTest, |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5491 | DisableAudioPlayoutStillGeneratesAudioStats) { |
| 5492 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5493 | ConnectFakeSignaling(); |
| 5494 | |
| 5495 | // Set up audio-only call where playout is disabled but audio-processing is |
| 5496 | // still active. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5497 | caller()->AddAudioTrack(); |
| 5498 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 5499 | caller()->pc()->SetAudioPlayout(false); |
| 5500 | |
| 5501 | caller()->CreateAndSetAndSignalOffer(); |
| 5502 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5503 | |
| 5504 | // Wait for the callee to receive audio stats. |
| 5505 | EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs); |
| 5506 | } |
| 5507 | |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5508 | // Test that SetAudioRecording can be used to disable audio recording from the |
| 5509 | // start, then later enable it. This may be useful, for example, if the caller |
| 5510 | // wants to ensure that no audio resources are active before a certain state |
| 5511 | // is reached. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5512 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) { |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5513 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5514 | ConnectFakeSignaling(); |
| 5515 | |
| 5516 | // Set up audio-only call where audio recording is disabled on caller's side. |
| 5517 | caller()->pc()->SetAudioRecording(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5518 | caller()->AddAudioTrack(); |
| 5519 | callee()->AddAudioTrack(); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5520 | caller()->CreateAndSetAndSignalOffer(); |
| 5521 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5522 | |
| 5523 | // Pump messages for a second. |
| 5524 | WAIT(false, 1000); |
| 5525 | // Since caller has disabled audio recording, the callee shouldn't have |
| 5526 | // received anything. |
| 5527 | EXPECT_EQ(0, callee()->audio_frames_received()); |
| 5528 | // As a sanity check, make sure the caller did still see frames on its |
| 5529 | // audio level since audio recording is enabled on the calle side. |
| 5530 | ASSERT_GT(caller()->audio_frames_received(), 0); |
| 5531 | |
| 5532 | // Enable audio recording again, and ensure audio starts flowing. |
| 5533 | caller()->pc()->SetAudioRecording(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5534 | MediaExpectations media_expectations; |
| 5535 | media_expectations.ExpectBidirectionalAudio(); |
| 5536 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 5537 | } |
| 5538 | |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5539 | // Test that after closing PeerConnections, they stop sending any packets (ICE, |
| 5540 | // DTLS, RTP...). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5541 | TEST_P(PeerConnectionIntegrationTest, ClosingConnectionStopsPacketFlow) { |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5542 | // Set up audio/video/data, wait for some frames to be received. |
| 5543 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5544 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5545 | caller()->AddAudioVideoTracks(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5546 | #ifdef HAVE_SCTP |
| 5547 | caller()->CreateDataChannel(); |
| 5548 | #endif |
| 5549 | caller()->CreateAndSetAndSignalOffer(); |
| 5550 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5551 | MediaExpectations media_expectations; |
| 5552 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 5553 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5554 | // Close PeerConnections. |
Steve Anton | d91969e | 2019-05-30 12:27:03 -0700 | [diff] [blame] | 5555 | ClosePeerConnections(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5556 | // Pump messages for a second, and ensure no new packets end up sent. |
| 5557 | uint32_t sent_packets_a = virtual_socket_server()->sent_packets(); |
| 5558 | WAIT(false, 1000); |
| 5559 | uint32_t sent_packets_b = virtual_socket_server()->sent_packets(); |
| 5560 | EXPECT_EQ(sent_packets_a, sent_packets_b); |
| 5561 | } |
| 5562 | |
Steve Anton | 7eca093 | 2018-03-30 15:18:41 -0700 | [diff] [blame] | 5563 | // Test that transport stats are generated by the RTCStatsCollector for a |
| 5564 | // connection that only involves data channels. This is a regression test for |
| 5565 | // crbug.com/826972. |
| 5566 | #ifdef HAVE_SCTP |
| 5567 | TEST_P(PeerConnectionIntegrationTest, |
| 5568 | TransportStatsReportedForDataChannelOnlyConnection) { |
| 5569 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5570 | ConnectFakeSignaling(); |
| 5571 | caller()->CreateDataChannel(); |
| 5572 | |
| 5573 | caller()->CreateAndSetAndSignalOffer(); |
| 5574 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5575 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 5576 | |
| 5577 | auto caller_report = caller()->NewGetStats(); |
| 5578 | EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size()); |
| 5579 | auto callee_report = callee()->NewGetStats(); |
| 5580 | EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size()); |
| 5581 | } |
| 5582 | #endif // HAVE_SCTP |
| 5583 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 5584 | TEST_P(PeerConnectionIntegrationTest, |
| 5585 | IceEventsGeneratedAndLoggedInRtcEventLog) { |
| 5586 | ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog()); |
| 5587 | ConnectFakeSignaling(); |
| 5588 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5589 | options.offer_to_receive_audio = 1; |
| 5590 | caller()->SetOfferAnswerOptions(options); |
| 5591 | caller()->CreateAndSetAndSignalOffer(); |
| 5592 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5593 | ASSERT_NE(nullptr, caller()->event_log_factory()); |
| 5594 | ASSERT_NE(nullptr, callee()->event_log_factory()); |
| 5595 | webrtc::FakeRtcEventLog* caller_event_log = |
| 5596 | static_cast<webrtc::FakeRtcEventLog*>( |
| 5597 | caller()->event_log_factory()->last_log_created()); |
| 5598 | webrtc::FakeRtcEventLog* callee_event_log = |
| 5599 | static_cast<webrtc::FakeRtcEventLog*>( |
| 5600 | callee()->event_log_factory()->last_log_created()); |
| 5601 | ASSERT_NE(nullptr, caller_event_log); |
| 5602 | ASSERT_NE(nullptr, callee_event_log); |
| 5603 | int caller_ice_config_count = caller_event_log->GetEventCount( |
| 5604 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 5605 | int caller_ice_event_count = caller_event_log->GetEventCount( |
| 5606 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 5607 | int callee_ice_config_count = callee_event_log->GetEventCount( |
| 5608 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 5609 | int callee_ice_event_count = callee_event_log->GetEventCount( |
| 5610 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 5611 | EXPECT_LT(0, caller_ice_config_count); |
| 5612 | EXPECT_LT(0, caller_ice_event_count); |
| 5613 | EXPECT_LT(0, callee_ice_config_count); |
| 5614 | EXPECT_LT(0, callee_ice_event_count); |
| 5615 | } |
| 5616 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5617 | TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) { |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5618 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5619 | 3478}; |
| 5620 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5621 | |
| 5622 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 5623 | |
| 5624 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5625 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 5626 | ice_server.username = "test"; |
| 5627 | ice_server.password = "test"; |
| 5628 | |
| 5629 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 5630 | caller_config.servers.push_back(ice_server); |
| 5631 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5632 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 5633 | caller_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5634 | |
| 5635 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 5636 | callee_config.servers.push_back(ice_server); |
| 5637 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5638 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 5639 | callee_config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5640 | |
| 5641 | ASSERT_TRUE( |
| 5642 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 5643 | |
| 5644 | // Do normal offer/answer and wait for ICE to complete. |
| 5645 | ConnectFakeSignaling(); |
| 5646 | caller()->AddAudioVideoTracks(); |
| 5647 | callee()->AddAudioVideoTracks(); |
| 5648 | caller()->CreateAndSetAndSignalOffer(); |
| 5649 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5650 | // Since we are doing continual gathering, the ICE transport does not reach |
| 5651 | // kIceGatheringComplete (see |
| 5652 | // P2PTransportChannel::OnCandidatesAllocationDone), and consequently not |
| 5653 | // kIceConnectionComplete. |
| 5654 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5655 | caller()->ice_connection_state(), kDefaultTimeout); |
| 5656 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5657 | callee()->ice_connection_state(), kDefaultTimeout); |
| 5658 | // Note that we cannot use the metric |
| 5659 | // |WebRTC.PeerConnection.CandidatePairType_UDP| in this test since this |
| 5660 | // metric is only populated when we reach kIceConnectionComplete in the |
| 5661 | // current implementation. |
| 5662 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 5663 | caller()->last_candidate_gathered().type()); |
| 5664 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 5665 | callee()->last_candidate_gathered().type()); |
| 5666 | |
| 5667 | // Loosen the caller's candidate filter. |
| 5668 | caller_config = caller()->pc()->GetConfiguration(); |
| 5669 | caller_config.type = webrtc::PeerConnectionInterface::kAll; |
| 5670 | caller()->pc()->SetConfiguration(caller_config); |
| 5671 | // We should have gathered a new host candidate. |
| 5672 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 5673 | caller()->last_candidate_gathered().type(), kDefaultTimeout); |
| 5674 | |
| 5675 | // Loosen the callee's candidate filter. |
| 5676 | callee_config = callee()->pc()->GetConfiguration(); |
| 5677 | callee_config.type = webrtc::PeerConnectionInterface::kAll; |
| 5678 | callee()->pc()->SetConfiguration(callee_config); |
| 5679 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 5680 | callee()->last_candidate_gathered().type(), kDefaultTimeout); |
| 5681 | } |
| 5682 | |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 5683 | TEST_P(PeerConnectionIntegrationTest, OnIceCandidateError) { |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 5684 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5685 | 3478}; |
| 5686 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5687 | |
| 5688 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 5689 | |
| 5690 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5691 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 5692 | ice_server.username = "test"; |
| 5693 | ice_server.password = "123"; |
| 5694 | |
| 5695 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 5696 | caller_config.servers.push_back(ice_server); |
| 5697 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5698 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 5699 | |
| 5700 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 5701 | callee_config.servers.push_back(ice_server); |
| 5702 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5703 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 5704 | |
| 5705 | ASSERT_TRUE( |
| 5706 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 5707 | |
| 5708 | // Do normal offer/answer and wait for ICE to complete. |
| 5709 | ConnectFakeSignaling(); |
| 5710 | caller()->AddAudioVideoTracks(); |
| 5711 | callee()->AddAudioVideoTracks(); |
| 5712 | caller()->CreateAndSetAndSignalOffer(); |
| 5713 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5714 | EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout); |
| 5715 | EXPECT_EQ("Unauthorized", caller()->error_event().error_text); |
| 5716 | EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url); |
Eldar Rello | 0095d37 | 2019-12-02 22:22:07 +0200 | [diff] [blame] | 5717 | EXPECT_NE(caller()->error_event().address, ""); |
Eldar Rello | da13ea2 | 2019-06-01 12:23:43 +0300 | [diff] [blame] | 5718 | } |
| 5719 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 5720 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5721 | AudioKeepsFlowingAfterImplicitRollback) { |
| 5722 | PeerConnectionInterface::RTCConfiguration config; |
| 5723 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 5724 | config.enable_implicit_rollback = true; |
| 5725 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 5726 | ConnectFakeSignaling(); |
| 5727 | caller()->AddAudioTrack(); |
| 5728 | callee()->AddAudioTrack(); |
| 5729 | caller()->CreateAndSetAndSignalOffer(); |
| 5730 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5731 | MediaExpectations media_expectations; |
| 5732 | media_expectations.ExpectBidirectionalAudio(); |
| 5733 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5734 | SetSignalIceCandidates(false); // Workaround candidate outrace sdp. |
| 5735 | caller()->AddVideoTrack(); |
| 5736 | callee()->AddVideoTrack(); |
| 5737 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 5738 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 5739 | callee()->pc()->SetLocalDescription(observer, |
| 5740 | callee()->CreateOfferAndWait().release()); |
| 5741 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 5742 | caller()->CreateAndSetAndSignalOffer(); // Implicit rollback. |
| 5743 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5744 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5745 | } |
| 5746 | |
| 5747 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5748 | ImplicitRollbackVisitsStableState) { |
| 5749 | RTCConfiguration config; |
| 5750 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
| 5751 | config.enable_implicit_rollback = true; |
| 5752 | |
| 5753 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 5754 | |
| 5755 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> sld_observer( |
| 5756 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 5757 | callee()->pc()->SetLocalDescription(sld_observer, |
| 5758 | callee()->CreateOfferAndWait().release()); |
| 5759 | EXPECT_TRUE_WAIT(sld_observer->called(), kDefaultTimeout); |
| 5760 | EXPECT_EQ(sld_observer->error(), ""); |
| 5761 | |
| 5762 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> srd_observer( |
| 5763 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
| 5764 | callee()->pc()->SetRemoteDescription( |
| 5765 | srd_observer, caller()->CreateOfferAndWait().release()); |
| 5766 | EXPECT_TRUE_WAIT(srd_observer->called(), kDefaultTimeout); |
| 5767 | EXPECT_EQ(srd_observer->error(), ""); |
| 5768 | |
| 5769 | EXPECT_THAT(callee()->peer_connection_signaling_state_history(), |
| 5770 | ElementsAre(PeerConnectionInterface::kHaveLocalOffer, |
| 5771 | PeerConnectionInterface::kStable, |
| 5772 | PeerConnectionInterface::kHaveRemoteOffer)); |
| 5773 | } |
| 5774 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 5775 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 5776 | PeerConnectionIntegrationTest, |
| 5777 | Values(SdpSemantics::kPlanB, |
| 5778 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 5779 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5780 | // Tests that verify interoperability between Plan B and Unified Plan |
| 5781 | // PeerConnections. |
| 5782 | class PeerConnectionIntegrationInteropTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5783 | : public PeerConnectionIntegrationBaseTest, |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5784 | public ::testing::WithParamInterface< |
| 5785 | std::tuple<SdpSemantics, SdpSemantics>> { |
| 5786 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5787 | // Setting the SdpSemantics for the base test to kDefault does not matter |
| 5788 | // because we specify not to use the test semantics when creating |
| 5789 | // PeerConnectionWrappers. |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5790 | PeerConnectionIntegrationInteropTest() |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 5791 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5792 | caller_semantics_(std::get<0>(GetParam())), |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5793 | callee_semantics_(std::get<1>(GetParam())) {} |
| 5794 | |
| 5795 | bool CreatePeerConnectionWrappersWithSemantics() { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 5796 | return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_, |
| 5797 | callee_semantics_); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | const SdpSemantics caller_semantics_; |
| 5801 | const SdpSemantics callee_semantics_; |
| 5802 | }; |
| 5803 | |
| 5804 | TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) { |
| 5805 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5806 | ConnectFakeSignaling(); |
| 5807 | |
| 5808 | caller()->CreateAndSetAndSignalOffer(); |
| 5809 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5810 | } |
| 5811 | |
| 5812 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) { |
| 5813 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5814 | ConnectFakeSignaling(); |
| 5815 | auto audio_sender = caller()->AddAudioTrack(); |
| 5816 | |
| 5817 | caller()->CreateAndSetAndSignalOffer(); |
| 5818 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5819 | |
| 5820 | // Verify that one audio receiver has been created on the remote and that it |
| 5821 | // has the same track ID as the sending track. |
| 5822 | auto receivers = callee()->pc()->GetReceivers(); |
| 5823 | ASSERT_EQ(1u, receivers.size()); |
| 5824 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type()); |
| 5825 | EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id()); |
| 5826 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5827 | MediaExpectations media_expectations; |
| 5828 | media_expectations.CalleeExpectsSomeAudio(); |
| 5829 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) { |
| 5833 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5834 | ConnectFakeSignaling(); |
| 5835 | auto video_sender = caller()->AddVideoTrack(); |
| 5836 | auto audio_sender = caller()->AddAudioTrack(); |
| 5837 | |
| 5838 | caller()->CreateAndSetAndSignalOffer(); |
| 5839 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5840 | |
| 5841 | // Verify that one audio and one video receiver have been created on the |
| 5842 | // remote and that they have the same track IDs as the sending tracks. |
| 5843 | auto audio_receivers = |
| 5844 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO); |
| 5845 | ASSERT_EQ(1u, audio_receivers.size()); |
| 5846 | EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id()); |
| 5847 | auto video_receivers = |
| 5848 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO); |
| 5849 | ASSERT_EQ(1u, video_receivers.size()); |
| 5850 | EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id()); |
| 5851 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5852 | MediaExpectations media_expectations; |
| 5853 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 5854 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 5858 | OneAudioOneVideoLocalToOneAudioOneVideoRemote) { |
| 5859 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5860 | ConnectFakeSignaling(); |
| 5861 | caller()->AddAudioVideoTracks(); |
| 5862 | callee()->AddAudioVideoTracks(); |
| 5863 | |
| 5864 | caller()->CreateAndSetAndSignalOffer(); |
| 5865 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5866 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5867 | MediaExpectations media_expectations; |
| 5868 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5869 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 5873 | ReverseRolesOneAudioLocalToOneVideoRemote) { |
| 5874 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5875 | ConnectFakeSignaling(); |
| 5876 | caller()->AddAudioTrack(); |
| 5877 | callee()->AddVideoTrack(); |
| 5878 | |
| 5879 | caller()->CreateAndSetAndSignalOffer(); |
| 5880 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5881 | |
| 5882 | // Verify that only the audio track has been negotiated. |
| 5883 | EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size()); |
| 5884 | // Might also check that the callee's NegotiationNeeded flag is set. |
| 5885 | |
| 5886 | // Reverse roles. |
| 5887 | callee()->CreateAndSetAndSignalOffer(); |
| 5888 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5889 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5890 | MediaExpectations media_expectations; |
| 5891 | media_expectations.CallerExpectsSomeVideo(); |
| 5892 | media_expectations.CalleeExpectsSomeAudio(); |
| 5893 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5894 | } |
| 5895 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 5896 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | ba42e99 | 2018-04-09 14:10:01 -0700 | [diff] [blame] | 5897 | PeerConnectionIntegrationTest, |
| 5898 | PeerConnectionIntegrationInteropTest, |
| 5899 | Values(std::make_tuple(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 5900 | std::make_tuple(SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB))); |
| 5901 | |
| 5902 | // Test that if the Unified Plan side offers two video tracks then the Plan B |
| 5903 | // side will only see the first one and ignore the second. |
| 5904 | TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 5905 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics( |
| 5906 | SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5907 | ConnectFakeSignaling(); |
| 5908 | auto first_sender = caller()->AddVideoTrack(); |
| 5909 | caller()->AddVideoTrack(); |
| 5910 | |
| 5911 | caller()->CreateAndSetAndSignalOffer(); |
| 5912 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5913 | |
| 5914 | // Verify that there is only one receiver and it corresponds to the first |
| 5915 | // added track. |
| 5916 | auto receivers = callee()->pc()->GetReceivers(); |
| 5917 | ASSERT_EQ(1u, receivers.size()); |
| 5918 | EXPECT_TRUE(receivers[0]->track()->enabled()); |
| 5919 | EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id()); |
| 5920 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5921 | MediaExpectations media_expectations; |
| 5922 | media_expectations.CalleeExpectsSomeVideo(); |
| 5923 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5924 | } |
| 5925 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 5926 | // Test that if the initial offer tagged BUNDLE section is rejected due to its |
| 5927 | // associated RtpTransceiver being stopped and another transceiver is added, |
| 5928 | // then renegotiation causes the callee to receive the new video track without |
| 5929 | // error. |
| 5930 | // This is a regression test for bugs.webrtc.org/9954 |
| 5931 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5932 | ReOfferWithStoppedBundleTaggedTransceiver) { |
| 5933 | RTCConfiguration config; |
| 5934 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 5935 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 5936 | ConnectFakeSignaling(); |
| 5937 | auto audio_transceiver_or_error = |
| 5938 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 5939 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 5940 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 5941 | |
| 5942 | caller()->CreateAndSetAndSignalOffer(); |
| 5943 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5944 | { |
| 5945 | MediaExpectations media_expectations; |
| 5946 | media_expectations.CalleeExpectsSomeAudio(); |
| 5947 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5948 | } |
| 5949 | |
| 5950 | audio_transceiver->Stop(); |
| 5951 | caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack()); |
| 5952 | |
| 5953 | caller()->CreateAndSetAndSignalOffer(); |
| 5954 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5955 | { |
| 5956 | MediaExpectations media_expectations; |
| 5957 | media_expectations.CalleeExpectsSomeVideo(); |
| 5958 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5959 | } |
| 5960 | } |
| 5961 | |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 5962 | #ifdef HAVE_SCTP |
| 5963 | |
| 5964 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5965 | EndToEndCallWithBundledSctpDataChannel) { |
| 5966 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5967 | ConnectFakeSignaling(); |
| 5968 | caller()->CreateDataChannel(); |
| 5969 | caller()->AddAudioVideoTracks(); |
| 5970 | callee()->AddAudioVideoTracks(); |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 5971 | caller()->CreateAndSetAndSignalOffer(); |
| 5972 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Harald Alvestrand | 17ea068 | 2019-12-13 11:51:04 +0100 | [diff] [blame] | 5973 | ASSERT_EQ_WAIT(SctpTransportState::kConnected, |
| 5974 | caller()->pc()->GetSctpTransport()->Information().state(), |
| 5975 | kDefaultTimeout); |
| 5976 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 5977 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 5978 | } |
| 5979 | |
| 5980 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5981 | EndToEndCallWithDataChannelOnlyConnects) { |
| 5982 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5983 | ConnectFakeSignaling(); |
| 5984 | caller()->CreateDataChannel(); |
| 5985 | caller()->CreateAndSetAndSignalOffer(); |
| 5986 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5987 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 5988 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 5989 | ASSERT_TRUE(caller()->data_observer()->IsOpen()); |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 5990 | } |
| 5991 | |
Harald Alvestrand | 2697ac1 | 2019-12-16 10:37:04 +0100 | [diff] [blame] | 5992 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, DataChannelClosesWhenClosed) { |
| 5993 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5994 | ConnectFakeSignaling(); |
| 5995 | caller()->CreateDataChannel(); |
| 5996 | caller()->CreateAndSetAndSignalOffer(); |
| 5997 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5998 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 5999 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6000 | caller()->data_channel()->Close(); |
| 6001 | ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6002 | } |
| 6003 | |
| 6004 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6005 | DataChannelClosesWhenClosedReverse) { |
| 6006 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6007 | ConnectFakeSignaling(); |
| 6008 | caller()->CreateDataChannel(); |
| 6009 | caller()->CreateAndSetAndSignalOffer(); |
| 6010 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6011 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 6012 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6013 | callee()->data_channel()->Close(); |
| 6014 | ASSERT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6015 | } |
| 6016 | |
| 6017 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 6018 | DataChannelClosesWhenPeerConnectionClosed) { |
| 6019 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 6020 | ConnectFakeSignaling(); |
| 6021 | caller()->CreateDataChannel(); |
| 6022 | caller()->CreateAndSetAndSignalOffer(); |
| 6023 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 6024 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 6025 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6026 | caller()->pc()->Close(); |
| 6027 | ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 6028 | } |
| 6029 | |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame] | 6030 | #endif // HAVE_SCTP |
| 6031 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 6032 | } // namespace |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 6033 | } // namespace webrtc |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 6034 | |
| 6035 | #endif // if !defined(THREAD_SANITIZER) |