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" |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 25 | #include "absl/memory/memory.h" |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 26 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 27 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "api/media_stream_interface.h" |
| 29 | #include "api/peer_connection_interface.h" |
| 30 | #include "api/peer_connection_proxy.h" |
| 31 | #include "api/rtp_receiver_interface.h" |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 32 | #include "api/test/loopback_media_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 33 | #include "api/uma_metrics.h" |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 34 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 35 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
| 36 | #include "api/video_codecs/sdp_video_format.h" |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 37 | #include "call/call.h" |
| 38 | #include "logging/rtc_event_log/fake_rtc_event_log_factory.h" |
Bjorn Terelius | b8b3c99 | 2019-01-09 11:15:34 +0100 | [diff] [blame] | 39 | #include "logging/rtc_event_log/rtc_event_log_factory.h" |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 40 | #include "logging/rtc_event_log/rtc_event_log_factory_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "media/engine/fake_webrtc_video_engine.h" |
| 42 | #include "media/engine/webrtc_media_engine.h" |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 43 | #include "modules/audio_processing/include/audio_processing.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 44 | #include "p2p/base/mock_async_resolver.h" |
| 45 | #include "p2p/base/p2p_constants.h" |
| 46 | #include "p2p/base/port_interface.h" |
| 47 | #include "p2p/base/test_stun_server.h" |
| 48 | #include "p2p/base/test_turn_customizer.h" |
| 49 | #include "p2p/base/test_turn_server.h" |
| 50 | #include "p2p/client/basic_port_allocator.h" |
| 51 | #include "pc/dtmf_sender.h" |
| 52 | #include "pc/local_audio_source.h" |
| 53 | #include "pc/media_session.h" |
| 54 | #include "pc/peer_connection.h" |
| 55 | #include "pc/peer_connection_factory.h" |
| 56 | #include "pc/rtp_media_utils.h" |
| 57 | #include "pc/session_description.h" |
| 58 | #include "pc/test/fake_audio_capture_module.h" |
| 59 | #include "pc/test/fake_periodic_video_track_source.h" |
| 60 | #include "pc/test/fake_rtc_certificate_generator.h" |
| 61 | #include "pc/test/fake_video_track_renderer.h" |
| 62 | #include "pc/test/mock_peer_connection_observers.h" |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 63 | #include "rtc_base/fake_clock.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 64 | #include "rtc_base/fake_network.h" |
| 65 | #include "rtc_base/firewall_socket_server.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 66 | #include "rtc_base/gunit.h" |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 67 | #include "rtc_base/numerics/safe_conversions.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 68 | #include "rtc_base/test_certificate_verifier.h" |
| 69 | #include "rtc_base/time_utils.h" |
| 70 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 71 | #include "system_wrappers/include/metrics.h" |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 72 | #include "test/field_trial.h" |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 73 | #include "test/gmock.h" |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 74 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 75 | namespace webrtc { |
| 76 | namespace { |
| 77 | |
| 78 | using ::cricket::ContentInfo; |
| 79 | using ::cricket::StreamParams; |
| 80 | using ::rtc::SocketAddress; |
| 81 | using ::testing::_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 82 | using ::testing::Combine; |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 83 | using ::testing::Contains; |
Mirko Bonadei | e46f5db | 2019-03-26 20:14:46 +0100 | [diff] [blame] | 84 | using ::testing::DoAll; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 85 | using ::testing::ElementsAre; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 86 | using ::testing::NiceMock; |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 87 | using ::testing::Return; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 88 | using ::testing::SetArgPointee; |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 89 | using ::testing::UnorderedElementsAreArray; |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 90 | using ::testing::Values; |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 91 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 92 | |
| 93 | static const int kDefaultTimeout = 10000; |
| 94 | static const int kMaxWaitForStatsMs = 3000; |
| 95 | static const int kMaxWaitForActivationMs = 5000; |
| 96 | static const int kMaxWaitForFramesMs = 10000; |
| 97 | // Default number of audio/video frames to wait for before considering a test |
| 98 | // successful. |
| 99 | static const int kDefaultExpectedAudioFrameCount = 3; |
| 100 | static const int kDefaultExpectedVideoFrameCount = 3; |
| 101 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 102 | static const char kDataChannelLabel[] = "data_channel"; |
| 103 | |
| 104 | // SRTP cipher name negotiated by the tests. This must be updated if the |
| 105 | // default changes. |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 106 | static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_80; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 107 | static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; |
| 108 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 109 | static const SocketAddress kDefaultLocalAddress("192.168.1.1", 0); |
| 110 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 111 | // Helper function for constructing offer/answer options to initiate an ICE |
| 112 | // restart. |
| 113 | PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() { |
| 114 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 115 | options.ice_restart = true; |
| 116 | return options; |
| 117 | } |
| 118 | |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 119 | // Remove all stream information (SSRCs, track IDs, etc.) and "msid-semantic" |
| 120 | // attribute from received SDP, simulating a legacy endpoint. |
| 121 | void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) { |
| 122 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 123 | content.media_description()->mutable_streams().clear(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 124 | } |
| 125 | desc->set_msid_supported(false); |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 126 | desc->set_msid_signaling(0); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 129 | // Removes all stream information besides the stream ids, simulating an |
| 130 | // endpoint that only signals a=msid lines to convey stream_ids. |
| 131 | void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc) { |
| 132 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 133 | std::string track_id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 134 | std::vector<std::string> stream_ids; |
| 135 | if (!content.media_description()->streams().empty()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 136 | const StreamParams& first_stream = |
| 137 | content.media_description()->streams()[0]; |
| 138 | track_id = first_stream.id; |
| 139 | stream_ids = first_stream.stream_ids(); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 140 | } |
| 141 | content.media_description()->mutable_streams().clear(); |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 142 | StreamParams new_stream; |
| 143 | new_stream.id = track_id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 144 | new_stream.set_stream_ids(stream_ids); |
| 145 | content.media_description()->AddStream(new_stream); |
| 146 | } |
| 147 | } |
| 148 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 149 | int FindFirstMediaStatsIndexByKind( |
| 150 | const std::string& kind, |
| 151 | const std::vector<const webrtc::RTCMediaStreamTrackStats*>& |
| 152 | media_stats_vec) { |
| 153 | for (size_t i = 0; i < media_stats_vec.size(); i++) { |
| 154 | if (media_stats_vec[i]->kind.ValueToString() == kind) { |
| 155 | return i; |
| 156 | } |
| 157 | } |
| 158 | return -1; |
| 159 | } |
| 160 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 161 | class SignalingMessageReceiver { |
| 162 | public: |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 163 | virtual void ReceiveSdpMessage(SdpType type, const std::string& msg) = 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 164 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 165 | int sdp_mline_index, |
| 166 | const std::string& msg) = 0; |
| 167 | |
| 168 | protected: |
| 169 | SignalingMessageReceiver() {} |
| 170 | virtual ~SignalingMessageReceiver() {} |
| 171 | }; |
| 172 | |
| 173 | class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { |
| 174 | public: |
| 175 | explicit MockRtpReceiverObserver(cricket::MediaType media_type) |
| 176 | : expected_media_type_(media_type) {} |
| 177 | |
| 178 | void OnFirstPacketReceived(cricket::MediaType media_type) override { |
| 179 | ASSERT_EQ(expected_media_type_, media_type); |
| 180 | first_packet_received_ = true; |
| 181 | } |
| 182 | |
| 183 | bool first_packet_received() const { return first_packet_received_; } |
| 184 | |
| 185 | virtual ~MockRtpReceiverObserver() {} |
| 186 | |
| 187 | private: |
| 188 | bool first_packet_received_ = false; |
| 189 | cricket::MediaType expected_media_type_; |
| 190 | }; |
| 191 | |
| 192 | // Helper class that wraps a peer connection, observes it, and can accept |
| 193 | // signaling messages from another wrapper. |
| 194 | // |
| 195 | // Uses a fake network, fake A/V capture, and optionally fake |
| 196 | // encoders/decoders, though they aren't used by default since they don't |
| 197 | // advertise support of any codecs. |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 198 | // TODO(steveanton): See how this could become a subclass of |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 199 | // PeerConnectionWrapper defined in peerconnectionwrapper.h. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 200 | class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 201 | public SignalingMessageReceiver { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 202 | public: |
| 203 | // Different factory methods for convenience. |
| 204 | // TODO(deadbeef): Could use the pattern of: |
| 205 | // |
| 206 | // PeerConnectionWrapper = |
| 207 | // WrapperBuilder.WithConfig(...).WithOptions(...).build(); |
| 208 | // |
| 209 | // To reduce some code duplication. |
| 210 | static PeerConnectionWrapper* CreateWithDtlsIdentityStore( |
| 211 | const std::string& debug_name, |
| 212 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 213 | rtc::Thread* network_thread, |
| 214 | rtc::Thread* worker_thread) { |
| 215 | PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 216 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 217 | dependencies.cert_generator = std::move(cert_generator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 218 | if (!client->Init(nullptr, nullptr, std::move(dependencies), network_thread, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 219 | worker_thread, nullptr, |
| 220 | /*media_transport_factory=*/nullptr)) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 221 | delete client; |
| 222 | return nullptr; |
| 223 | } |
| 224 | return client; |
| 225 | } |
| 226 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 227 | webrtc::PeerConnectionFactoryInterface* pc_factory() const { |
| 228 | return peer_connection_factory_.get(); |
| 229 | } |
| 230 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 231 | webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); } |
| 232 | |
| 233 | // If a signaling message receiver is set (via ConnectFakeSignaling), this |
| 234 | // will set the whole offer/answer exchange in motion. Just need to wait for |
| 235 | // the signaling state to reach "stable". |
| 236 | void CreateAndSetAndSignalOffer() { |
| 237 | auto offer = CreateOffer(); |
| 238 | ASSERT_NE(nullptr, offer); |
| 239 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(offer))); |
| 240 | } |
| 241 | |
| 242 | // Sets the options to be used when CreateAndSetAndSignalOffer is called, or |
| 243 | // when a remote offer is received (via fake signaling) and an answer is |
| 244 | // generated. By default, uses default options. |
| 245 | void SetOfferAnswerOptions( |
| 246 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 247 | offer_answer_options_ = options; |
| 248 | } |
| 249 | |
| 250 | // Set a callback to be invoked when SDP is received via the fake signaling |
| 251 | // channel, which provides an opportunity to munge (modify) the SDP. This is |
| 252 | // used to test SDP being applied that a PeerConnection would normally not |
| 253 | // generate, but a non-JSEP endpoint might. |
| 254 | void SetReceivedSdpMunger( |
| 255 | std::function<void(cricket::SessionDescription*)> munger) { |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 256 | received_sdp_munger_ = std::move(munger); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 257 | } |
| 258 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 259 | // Similar to the above, but this is run on SDP immediately after it's |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 260 | // generated. |
| 261 | void SetGeneratedSdpMunger( |
| 262 | std::function<void(cricket::SessionDescription*)> munger) { |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 263 | generated_sdp_munger_ = std::move(munger); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 266 | // Set a callback to be invoked when a remote offer is received via the fake |
| 267 | // signaling channel. This provides an opportunity to change the |
| 268 | // PeerConnection state before an answer is created and sent to the caller. |
| 269 | void SetRemoteOfferHandler(std::function<void()> handler) { |
| 270 | remote_offer_handler_ = std::move(handler); |
| 271 | } |
| 272 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 273 | void SetRemoteAsyncResolver(rtc::MockAsyncResolver* resolver) { |
| 274 | remote_async_resolver_ = resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 277 | // Every ICE connection state in order that has been seen by the observer. |
| 278 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 279 | ice_connection_state_history() const { |
| 280 | return ice_connection_state_history_; |
| 281 | } |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 282 | void clear_ice_connection_state_history() { |
| 283 | ice_connection_state_history_.clear(); |
| 284 | } |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 285 | |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 286 | // Every standardized ICE connection state in order that has been seen by the |
| 287 | // observer. |
| 288 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 289 | standardized_ice_connection_state_history() const { |
| 290 | return standardized_ice_connection_state_history_; |
| 291 | } |
| 292 | |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 293 | // Every PeerConnection state in order that has been seen by the observer. |
| 294 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 295 | peer_connection_state_history() const { |
| 296 | return peer_connection_state_history_; |
| 297 | } |
| 298 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 299 | // Every ICE gathering state in order that has been seen by the observer. |
| 300 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 301 | ice_gathering_state_history() const { |
| 302 | return ice_gathering_state_history_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 305 | void AddAudioVideoTracks() { |
| 306 | AddAudioTrack(); |
| 307 | AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 310 | rtc::scoped_refptr<RtpSenderInterface> AddAudioTrack() { |
| 311 | return AddTrack(CreateLocalAudioTrack()); |
| 312 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 313 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 314 | rtc::scoped_refptr<RtpSenderInterface> AddVideoTrack() { |
| 315 | return AddTrack(CreateLocalVideoTrack()); |
| 316 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 317 | |
| 318 | rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack() { |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 319 | cricket::AudioOptions options; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 320 | // 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] | 321 | options.highpass_filter = false; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 322 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 323 | peer_connection_factory_->CreateAudioSource(options); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 324 | // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 325 | // always use the default input. |
deadbeef | b1a15d7 | 2017-09-07 14:12:05 -0700 | [diff] [blame] | 326 | return peer_connection_factory_->CreateAudioTrack(rtc::CreateRandomUuid(), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 327 | source); |
| 328 | } |
| 329 | |
| 330 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack() { |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 331 | webrtc::FakePeriodicVideoSource::Config config; |
| 332 | config.timestamp_offset_ms = rtc::TimeMillis(); |
| 333 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 337 | CreateLocalVideoTrackWithConfig( |
| 338 | webrtc::FakePeriodicVideoSource::Config config) { |
| 339 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
| 343 | CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) { |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 344 | webrtc::FakePeriodicVideoSource::Config config; |
| 345 | config.rotation = rotation; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 346 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 347 | return CreateLocalVideoTrackInternal(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 350 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 351 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 352 | const std::vector<std::string>& stream_ids = {}) { |
| 353 | auto result = pc()->AddTrack(track, stream_ids); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 354 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 355 | return result.MoveValue(); |
| 356 | } |
| 357 | |
| 358 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceiversOfType( |
| 359 | cricket::MediaType media_type) { |
| 360 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 361 | for (const auto& receiver : pc()->GetReceivers()) { |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 362 | if (receiver->media_type() == media_type) { |
| 363 | receivers.push_back(receiver); |
| 364 | } |
| 365 | } |
| 366 | return receivers; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 369 | rtc::scoped_refptr<RtpTransceiverInterface> GetFirstTransceiverOfType( |
| 370 | cricket::MediaType media_type) { |
| 371 | for (auto transceiver : pc()->GetTransceivers()) { |
| 372 | if (transceiver->receiver()->media_type() == media_type) { |
| 373 | return transceiver; |
| 374 | } |
| 375 | } |
| 376 | return nullptr; |
| 377 | } |
| 378 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 379 | bool SignalingStateStable() { |
| 380 | return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable; |
| 381 | } |
| 382 | |
| 383 | void CreateDataChannel() { CreateDataChannel(nullptr); } |
| 384 | |
| 385 | void CreateDataChannel(const webrtc::DataChannelInit* init) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 386 | CreateDataChannel(kDataChannelLabel, init); |
| 387 | } |
| 388 | |
| 389 | void CreateDataChannel(const std::string& label, |
| 390 | const webrtc::DataChannelInit* init) { |
| 391 | data_channel_ = pc()->CreateDataChannel(label, init); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 392 | ASSERT_TRUE(data_channel_.get() != nullptr); |
| 393 | data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
| 394 | } |
| 395 | |
| 396 | DataChannelInterface* data_channel() { return data_channel_; } |
| 397 | const MockDataChannelObserver* data_observer() const { |
| 398 | return data_observer_.get(); |
| 399 | } |
| 400 | |
| 401 | int audio_frames_received() const { |
| 402 | return fake_audio_capture_module_->frames_received(); |
| 403 | } |
| 404 | |
| 405 | // Takes minimum of video frames received for each track. |
| 406 | // |
| 407 | // Can be used like: |
| 408 | // EXPECT_GE(expected_frames, min_video_frames_received_per_track()); |
| 409 | // |
| 410 | // To ensure that all video tracks received at least a certain number of |
| 411 | // frames. |
| 412 | int min_video_frames_received_per_track() const { |
| 413 | int min_frames = INT_MAX; |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 414 | if (fake_video_renderers_.empty()) { |
| 415 | return 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 416 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 417 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 418 | for (const auto& pair : fake_video_renderers_) { |
| 419 | min_frames = std::min(min_frames, pair.second->num_rendered_frames()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 420 | } |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 421 | return min_frames; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | // Returns a MockStatsObserver in a state after stats gathering finished, |
| 425 | // which can be used to access the gathered stats. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 426 | rtc::scoped_refptr<MockStatsObserver> OldGetStatsForTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 427 | webrtc::MediaStreamTrackInterface* track) { |
| 428 | rtc::scoped_refptr<MockStatsObserver> observer( |
| 429 | new rtc::RefCountedObject<MockStatsObserver>()); |
| 430 | EXPECT_TRUE(peer_connection_->GetStats( |
| 431 | observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard)); |
| 432 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 433 | return observer; |
| 434 | } |
| 435 | |
| 436 | // Version that doesn't take a track "filter", and gathers all stats. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 437 | rtc::scoped_refptr<MockStatsObserver> OldGetStats() { |
| 438 | return OldGetStatsForTrack(nullptr); |
| 439 | } |
| 440 | |
| 441 | // Synchronously gets stats and returns them. If it times out, fails the test |
| 442 | // and returns null. |
| 443 | rtc::scoped_refptr<const webrtc::RTCStatsReport> NewGetStats() { |
| 444 | rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback( |
| 445 | new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>()); |
| 446 | peer_connection_->GetStats(callback); |
| 447 | EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout); |
| 448 | return callback->report(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | int rendered_width() { |
| 452 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 453 | return fake_video_renderers_.empty() |
| 454 | ? 0 |
| 455 | : fake_video_renderers_.begin()->second->width(); |
| 456 | } |
| 457 | |
| 458 | int rendered_height() { |
| 459 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 460 | return fake_video_renderers_.empty() |
| 461 | ? 0 |
| 462 | : fake_video_renderers_.begin()->second->height(); |
| 463 | } |
| 464 | |
| 465 | double rendered_aspect_ratio() { |
| 466 | if (rendered_height() == 0) { |
| 467 | return 0.0; |
| 468 | } |
| 469 | return static_cast<double>(rendered_width()) / rendered_height(); |
| 470 | } |
| 471 | |
| 472 | webrtc::VideoRotation rendered_rotation() { |
| 473 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 474 | return fake_video_renderers_.empty() |
| 475 | ? webrtc::kVideoRotation_0 |
| 476 | : fake_video_renderers_.begin()->second->rotation(); |
| 477 | } |
| 478 | |
| 479 | int local_rendered_width() { |
| 480 | return local_video_renderer_ ? local_video_renderer_->width() : 0; |
| 481 | } |
| 482 | |
| 483 | int local_rendered_height() { |
| 484 | return local_video_renderer_ ? local_video_renderer_->height() : 0; |
| 485 | } |
| 486 | |
| 487 | double local_rendered_aspect_ratio() { |
| 488 | if (local_rendered_height() == 0) { |
| 489 | return 0.0; |
| 490 | } |
| 491 | return static_cast<double>(local_rendered_width()) / |
| 492 | local_rendered_height(); |
| 493 | } |
| 494 | |
| 495 | size_t number_of_remote_streams() { |
| 496 | if (!pc()) { |
| 497 | return 0; |
| 498 | } |
| 499 | return pc()->remote_streams()->count(); |
| 500 | } |
| 501 | |
| 502 | StreamCollectionInterface* remote_streams() const { |
| 503 | if (!pc()) { |
| 504 | ADD_FAILURE(); |
| 505 | return nullptr; |
| 506 | } |
| 507 | return pc()->remote_streams(); |
| 508 | } |
| 509 | |
| 510 | StreamCollectionInterface* local_streams() { |
| 511 | if (!pc()) { |
| 512 | ADD_FAILURE(); |
| 513 | return nullptr; |
| 514 | } |
| 515 | return pc()->local_streams(); |
| 516 | } |
| 517 | |
| 518 | webrtc::PeerConnectionInterface::SignalingState signaling_state() { |
| 519 | return pc()->signaling_state(); |
| 520 | } |
| 521 | |
| 522 | webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
| 523 | return pc()->ice_connection_state(); |
| 524 | } |
| 525 | |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 526 | webrtc::PeerConnectionInterface::IceConnectionState |
| 527 | standardized_ice_connection_state() { |
| 528 | return pc()->standardized_ice_connection_state(); |
| 529 | } |
| 530 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 531 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 532 | return pc()->ice_gathering_state(); |
| 533 | } |
| 534 | |
| 535 | // Returns a MockRtpReceiverObserver for each RtpReceiver returned by |
| 536 | // GetReceivers. They're updated automatically when a remote offer/answer |
| 537 | // from the fake signaling channel is applied, or when |
| 538 | // ResetRtpReceiverObservers below is called. |
| 539 | const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& |
| 540 | rtp_receiver_observers() { |
| 541 | return rtp_receiver_observers_; |
| 542 | } |
| 543 | |
| 544 | void ResetRtpReceiverObservers() { |
| 545 | rtp_receiver_observers_.clear(); |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 546 | for (const rtc::scoped_refptr<RtpReceiverInterface>& receiver : |
| 547 | pc()->GetReceivers()) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 548 | std::unique_ptr<MockRtpReceiverObserver> observer( |
| 549 | new MockRtpReceiverObserver(receiver->media_type())); |
| 550 | receiver->SetObserver(observer.get()); |
| 551 | rtp_receiver_observers_.push_back(std::move(observer)); |
| 552 | } |
| 553 | } |
| 554 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 555 | rtc::FakeNetworkManager* network() const { |
| 556 | return fake_network_manager_.get(); |
| 557 | } |
| 558 | cricket::PortAllocator* port_allocator() const { return port_allocator_; } |
| 559 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 560 | webrtc::FakeRtcEventLogFactory* event_log_factory() const { |
| 561 | return event_log_factory_; |
| 562 | } |
| 563 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 564 | const cricket::Candidate& last_candidate_gathered() const { |
| 565 | return last_candidate_gathered_; |
| 566 | } |
| 567 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 568 | private: |
| 569 | explicit PeerConnectionWrapper(const std::string& debug_name) |
| 570 | : debug_name_(debug_name) {} |
| 571 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 572 | bool Init( |
| 573 | const PeerConnectionFactory::Options* options, |
| 574 | const PeerConnectionInterface::RTCConfiguration* config, |
| 575 | webrtc::PeerConnectionDependencies dependencies, |
| 576 | rtc::Thread* network_thread, |
| 577 | rtc::Thread* worker_thread, |
| 578 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 579 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 580 | // There's an error in this test code if Init ends up being called twice. |
| 581 | RTC_DCHECK(!peer_connection_); |
| 582 | RTC_DCHECK(!peer_connection_factory_); |
| 583 | |
| 584 | fake_network_manager_.reset(new rtc::FakeNetworkManager()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 585 | fake_network_manager_->AddInterface(kDefaultLocalAddress); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 586 | |
| 587 | std::unique_ptr<cricket::PortAllocator> port_allocator( |
| 588 | new cricket::BasicPortAllocator(fake_network_manager_.get())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 589 | port_allocator_ = port_allocator.get(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 590 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 591 | if (!fake_audio_capture_module_) { |
| 592 | return false; |
| 593 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 594 | rtc::Thread* const signaling_thread = rtc::Thread::Current(); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 595 | |
| 596 | webrtc::PeerConnectionFactoryDependencies pc_factory_dependencies; |
| 597 | pc_factory_dependencies.network_thread = network_thread; |
| 598 | pc_factory_dependencies.worker_thread = worker_thread; |
| 599 | pc_factory_dependencies.signaling_thread = signaling_thread; |
| 600 | pc_factory_dependencies.media_engine = |
| 601 | cricket::WebRtcMediaEngineFactory::Create( |
| 602 | rtc::scoped_refptr<webrtc::AudioDeviceModule>( |
| 603 | fake_audio_capture_module_), |
| 604 | webrtc::CreateBuiltinAudioEncoderFactory(), |
| 605 | webrtc::CreateBuiltinAudioDecoderFactory(), |
| 606 | webrtc::CreateBuiltinVideoEncoderFactory(), |
Qingsi Wang | 59844ce | 2018-11-01 04:45:53 +0000 | [diff] [blame] | 607 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 608 | webrtc::AudioProcessingBuilder().Create()); |
| 609 | pc_factory_dependencies.call_factory = webrtc::CreateCallFactory(); |
| 610 | if (event_log_factory) { |
| 611 | event_log_factory_ = event_log_factory.get(); |
| 612 | pc_factory_dependencies.event_log_factory = std::move(event_log_factory); |
| 613 | } else { |
| 614 | pc_factory_dependencies.event_log_factory = |
| 615 | webrtc::CreateRtcEventLogFactory(); |
| 616 | } |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 617 | if (media_transport_factory) { |
| 618 | pc_factory_dependencies.media_transport_factory = |
| 619 | std::move(media_transport_factory); |
| 620 | } |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 621 | peer_connection_factory_ = webrtc::CreateModularPeerConnectionFactory( |
| 622 | std::move(pc_factory_dependencies)); |
| 623 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 624 | if (!peer_connection_factory_) { |
| 625 | return false; |
| 626 | } |
| 627 | if (options) { |
| 628 | peer_connection_factory_->SetOptions(*options); |
| 629 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 630 | if (config) { |
| 631 | sdp_semantics_ = config->sdp_semantics; |
| 632 | } |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 633 | |
| 634 | dependencies.allocator = std::move(port_allocator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 635 | peer_connection_ = CreatePeerConnection(config, std::move(dependencies)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 636 | return peer_connection_.get() != nullptr; |
| 637 | } |
| 638 | |
| 639 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 640 | const PeerConnectionInterface::RTCConfiguration* config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 641 | webrtc::PeerConnectionDependencies dependencies) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 642 | PeerConnectionInterface::RTCConfiguration modified_config; |
| 643 | // If |config| is null, this will result in a default configuration being |
| 644 | // used. |
| 645 | if (config) { |
| 646 | modified_config = *config; |
| 647 | } |
| 648 | // Disable resolution adaptation; we don't want it interfering with the |
| 649 | // test results. |
| 650 | // TODO(deadbeef): Do something more robust. Since we're testing for aspect |
| 651 | // ratios and not specific resolutions, is this even necessary? |
| 652 | modified_config.set_cpu_adaptation(false); |
| 653 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 654 | dependencies.observer = this; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 655 | return peer_connection_factory_->CreatePeerConnection( |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 656 | modified_config, std::move(dependencies)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | void set_signaling_message_receiver( |
| 660 | SignalingMessageReceiver* signaling_message_receiver) { |
| 661 | signaling_message_receiver_ = signaling_message_receiver; |
| 662 | } |
| 663 | |
| 664 | void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; } |
| 665 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 666 | void set_signal_ice_candidates(bool signal) { |
| 667 | signal_ice_candidates_ = signal; |
| 668 | } |
| 669 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 670 | rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrackInternal( |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 671 | webrtc::FakePeriodicVideoSource::Config config) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 672 | // Set max frame rate to 10fps to reduce the risk of test flakiness. |
| 673 | // TODO(deadbeef): Do something more robust. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 674 | config.frame_interval_ms = 100; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 675 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 676 | video_track_sources_.emplace_back( |
Niels Möller | 0f40582 | 2018-05-17 09:16:41 +0200 | [diff] [blame] | 677 | new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>( |
| 678 | config, false /* remote */)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 679 | rtc::scoped_refptr<webrtc::VideoTrackInterface> track( |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 680 | peer_connection_factory_->CreateVideoTrack( |
| 681 | rtc::CreateRandomUuid(), video_track_sources_.back())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 682 | if (!local_video_renderer_) { |
| 683 | local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track)); |
| 684 | } |
| 685 | return track; |
| 686 | } |
| 687 | |
| 688 | void HandleIncomingOffer(const std::string& msg) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 689 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingOffer"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 690 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 691 | webrtc::CreateSessionDescription(SdpType::kOffer, msg); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 692 | if (received_sdp_munger_) { |
| 693 | received_sdp_munger_(desc->description()); |
| 694 | } |
| 695 | |
| 696 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 697 | // Setting a remote description may have changed the number of receivers, |
| 698 | // so reset the receiver observers. |
| 699 | ResetRtpReceiverObservers(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 700 | if (remote_offer_handler_) { |
| 701 | remote_offer_handler_(); |
| 702 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 703 | auto answer = CreateAnswer(); |
| 704 | ASSERT_NE(nullptr, answer); |
| 705 | EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer))); |
| 706 | } |
| 707 | |
| 708 | void HandleIncomingAnswer(const std::string& msg) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 709 | RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 710 | std::unique_ptr<SessionDescriptionInterface> desc = |
| 711 | webrtc::CreateSessionDescription(SdpType::kAnswer, msg); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 712 | if (received_sdp_munger_) { |
| 713 | received_sdp_munger_(desc->description()); |
| 714 | } |
| 715 | |
| 716 | EXPECT_TRUE(SetRemoteDescription(std::move(desc))); |
| 717 | // Set the RtpReceiverObserver after receivers are created. |
| 718 | ResetRtpReceiverObservers(); |
| 719 | } |
| 720 | |
| 721 | // Returns null on failure. |
| 722 | std::unique_ptr<SessionDescriptionInterface> CreateOffer() { |
| 723 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 724 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 725 | pc()->CreateOffer(observer, offer_answer_options_); |
| 726 | return WaitForDescriptionFromObserver(observer); |
| 727 | } |
| 728 | |
| 729 | // Returns null on failure. |
| 730 | std::unique_ptr<SessionDescriptionInterface> CreateAnswer() { |
| 731 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 732 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 733 | pc()->CreateAnswer(observer, offer_answer_options_); |
| 734 | return WaitForDescriptionFromObserver(observer); |
| 735 | } |
| 736 | |
| 737 | std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver( |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 738 | MockCreateSessionDescriptionObserver* observer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 739 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
| 740 | if (!observer->result()) { |
| 741 | return nullptr; |
| 742 | } |
| 743 | auto description = observer->MoveDescription(); |
| 744 | if (generated_sdp_munger_) { |
| 745 | generated_sdp_munger_(description->description()); |
| 746 | } |
| 747 | return description; |
| 748 | } |
| 749 | |
| 750 | // Setting the local description and sending the SDP message over the fake |
| 751 | // signaling channel are combined into the same method because the SDP |
| 752 | // message needs to be sent as soon as SetLocalDescription finishes, without |
| 753 | // waiting for the observer to be called. This ensures that ICE candidates |
| 754 | // don't outrace the description. |
| 755 | bool SetLocalDescriptionAndSendSdpMessage( |
| 756 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 757 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 758 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 759 | RTC_LOG(LS_INFO) << debug_name_ << ": SetLocalDescriptionAndSendSdpMessage"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 760 | SdpType type = desc->GetType(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 761 | std::string sdp; |
| 762 | EXPECT_TRUE(desc->ToString(&sdp)); |
| 763 | pc()->SetLocalDescription(observer, desc.release()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 764 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 765 | RemoveUnusedVideoRenderers(); |
| 766 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 767 | // As mentioned above, we need to send the message immediately after |
| 768 | // SetLocalDescription. |
| 769 | SendSdpMessage(type, sdp); |
| 770 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 771 | return true; |
| 772 | } |
| 773 | |
| 774 | bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) { |
| 775 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 776 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 777 | RTC_LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 778 | pc()->SetRemoteDescription(observer, desc.release()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 779 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 780 | RemoveUnusedVideoRenderers(); |
| 781 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 782 | EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout); |
| 783 | return observer->result(); |
| 784 | } |
| 785 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 786 | // This is a work around to remove unused fake_video_renderers from |
| 787 | // transceivers that have either stopped or are no longer receiving. |
| 788 | void RemoveUnusedVideoRenderers() { |
| 789 | auto transceivers = pc()->GetTransceivers(); |
| 790 | for (auto& transceiver : transceivers) { |
| 791 | if (transceiver->receiver()->media_type() != cricket::MEDIA_TYPE_VIDEO) { |
| 792 | continue; |
| 793 | } |
| 794 | // Remove fake video renderers from any stopped transceivers. |
| 795 | if (transceiver->stopped()) { |
| 796 | auto it = |
| 797 | fake_video_renderers_.find(transceiver->receiver()->track()->id()); |
| 798 | if (it != fake_video_renderers_.end()) { |
| 799 | fake_video_renderers_.erase(it); |
| 800 | } |
| 801 | } |
| 802 | // Remove fake video renderers from any transceivers that are no longer |
| 803 | // receiving. |
| 804 | if ((transceiver->current_direction() && |
| 805 | !webrtc::RtpTransceiverDirectionHasRecv( |
| 806 | *transceiver->current_direction()))) { |
| 807 | auto it = |
| 808 | fake_video_renderers_.find(transceiver->receiver()->track()->id()); |
| 809 | if (it != fake_video_renderers_.end()) { |
| 810 | fake_video_renderers_.erase(it); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 816 | // Simulate sending a blob of SDP with delay |signaling_delay_ms_| (0 by |
| 817 | // default). |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 818 | void SendSdpMessage(SdpType type, const std::string& msg) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 819 | if (signaling_delay_ms_ == 0) { |
| 820 | RelaySdpMessageIfReceiverExists(type, msg); |
| 821 | } else { |
| 822 | invoker_.AsyncInvokeDelayed<void>( |
| 823 | RTC_FROM_HERE, rtc::Thread::Current(), |
| 824 | rtc::Bind(&PeerConnectionWrapper::RelaySdpMessageIfReceiverExists, |
| 825 | this, type, msg), |
| 826 | signaling_delay_ms_); |
| 827 | } |
| 828 | } |
| 829 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 830 | void RelaySdpMessageIfReceiverExists(SdpType type, const std::string& msg) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 831 | if (signaling_message_receiver_) { |
| 832 | signaling_message_receiver_->ReceiveSdpMessage(type, msg); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | // Simulate trickling an ICE candidate with delay |signaling_delay_ms_| (0 by |
| 837 | // default). |
| 838 | void SendIceMessage(const std::string& sdp_mid, |
| 839 | int sdp_mline_index, |
| 840 | const std::string& msg) { |
| 841 | if (signaling_delay_ms_ == 0) { |
| 842 | RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, msg); |
| 843 | } else { |
| 844 | invoker_.AsyncInvokeDelayed<void>( |
| 845 | RTC_FROM_HERE, rtc::Thread::Current(), |
| 846 | rtc::Bind(&PeerConnectionWrapper::RelayIceMessageIfReceiverExists, |
| 847 | this, sdp_mid, sdp_mline_index, msg), |
| 848 | signaling_delay_ms_); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | void RelayIceMessageIfReceiverExists(const std::string& sdp_mid, |
| 853 | int sdp_mline_index, |
| 854 | const std::string& msg) { |
| 855 | if (signaling_message_receiver_) { |
| 856 | signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index, |
| 857 | msg); |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | // SignalingMessageReceiver callbacks. |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 862 | void ReceiveSdpMessage(SdpType type, const std::string& msg) override { |
| 863 | if (type == SdpType::kOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 864 | HandleIncomingOffer(msg); |
| 865 | } else { |
| 866 | HandleIncomingAnswer(msg); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | void ReceiveIceMessage(const std::string& sdp_mid, |
| 871 | int sdp_mline_index, |
| 872 | const std::string& msg) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 873 | RTC_LOG(LS_INFO) << debug_name_ << ": ReceiveIceMessage"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 874 | std::unique_ptr<webrtc::IceCandidateInterface> candidate( |
| 875 | webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr)); |
| 876 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 877 | } |
| 878 | |
| 879 | // PeerConnectionObserver callbacks. |
| 880 | void OnSignalingChange( |
| 881 | webrtc::PeerConnectionInterface::SignalingState new_state) override { |
| 882 | EXPECT_EQ(pc()->signaling_state(), new_state); |
| 883 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 884 | void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver, |
| 885 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 886 | streams) override { |
| 887 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 888 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
| 889 | static_cast<VideoTrackInterface*>(receiver->track().get())); |
| 890 | ASSERT_TRUE(fake_video_renderers_.find(video_track->id()) == |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 891 | fake_video_renderers_.end()); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 892 | fake_video_renderers_[video_track->id()] = |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 893 | absl::make_unique<FakeVideoTrackRenderer>(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 894 | } |
| 895 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 896 | void OnRemoveTrack( |
| 897 | rtc::scoped_refptr<RtpReceiverInterface> receiver) override { |
| 898 | if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) { |
| 899 | auto it = fake_video_renderers_.find(receiver->track()->id()); |
| 900 | RTC_DCHECK(it != fake_video_renderers_.end()); |
| 901 | fake_video_renderers_.erase(it); |
| 902 | } |
| 903 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 904 | void OnRenegotiationNeeded() override {} |
| 905 | void OnIceConnectionChange( |
| 906 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 907 | EXPECT_EQ(pc()->ice_connection_state(), new_state); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 908 | ice_connection_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 909 | } |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 910 | void OnStandardizedIceConnectionChange( |
| 911 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 912 | standardized_ice_connection_state_history_.push_back(new_state); |
| 913 | } |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 914 | void OnConnectionChange( |
| 915 | webrtc::PeerConnectionInterface::PeerConnectionState new_state) override { |
| 916 | peer_connection_state_history_.push_back(new_state); |
| 917 | } |
| 918 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 919 | void OnIceGatheringChange( |
| 920 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 921 | EXPECT_EQ(pc()->ice_gathering_state(), new_state); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 922 | ice_gathering_state_history_.push_back(new_state); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 923 | } |
| 924 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 925 | RTC_LOG(LS_INFO) << debug_name_ << ": OnIceCandidate"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 926 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 927 | if (remote_async_resolver_) { |
| 928 | const auto& local_candidate = candidate->candidate(); |
| 929 | const auto& mdns_responder = network()->GetMdnsResponderForTesting(); |
| 930 | if (local_candidate.address().IsUnresolvedIP()) { |
| 931 | RTC_DCHECK(local_candidate.type() == cricket::LOCAL_PORT_TYPE); |
| 932 | rtc::SocketAddress resolved_addr(local_candidate.address()); |
| 933 | const auto resolved_ip = mdns_responder->GetMappedAddressForName( |
| 934 | local_candidate.address().hostname()); |
| 935 | RTC_DCHECK(!resolved_ip.IsNil()); |
| 936 | resolved_addr.SetResolvedIP(resolved_ip); |
| 937 | EXPECT_CALL(*remote_async_resolver_, GetResolvedAddress(_, _)) |
| 938 | .WillOnce(DoAll(SetArgPointee<1>(resolved_addr), Return(true))); |
| 939 | EXPECT_CALL(*remote_async_resolver_, Destroy(_)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 940 | } |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 941 | } |
| 942 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 943 | std::string ice_sdp; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 944 | EXPECT_TRUE(candidate->ToString(&ice_sdp)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 945 | if (signaling_message_receiver_ == nullptr || !signal_ice_candidates_) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 946 | // Remote party may be deleted. |
| 947 | return; |
| 948 | } |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 949 | SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 950 | last_candidate_gathered_ = candidate->candidate(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 951 | } |
| 952 | void OnDataChannel( |
| 953 | rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 954 | RTC_LOG(LS_INFO) << debug_name_ << ": OnDataChannel"; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 955 | data_channel_ = data_channel; |
| 956 | data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 957 | } |
| 958 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 959 | std::string debug_name_; |
| 960 | |
| 961 | std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; |
| 962 | |
| 963 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 964 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 965 | peer_connection_factory_; |
| 966 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 967 | cricket::PortAllocator* port_allocator_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 968 | // Needed to keep track of number of frames sent. |
| 969 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
| 970 | // Needed to keep track of number of frames received. |
| 971 | std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 972 | fake_video_renderers_; |
| 973 | // Needed to ensure frames aren't received for removed tracks. |
| 974 | std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>> |
| 975 | removed_fake_video_renderers_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 976 | |
| 977 | // For remote peer communication. |
| 978 | SignalingMessageReceiver* signaling_message_receiver_ = nullptr; |
| 979 | int signaling_delay_ms_ = 0; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 980 | bool signal_ice_candidates_ = true; |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 981 | cricket::Candidate last_candidate_gathered_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 982 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 983 | // 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] | 984 | // them, if required. |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 985 | std::vector<rtc::scoped_refptr<webrtc::VideoTrackSource>> |
| 986 | video_track_sources_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 987 | // |local_video_renderer_| attached to the first created local video track. |
| 988 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_; |
| 989 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 990 | SdpSemantics sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 991 | PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; |
| 992 | std::function<void(cricket::SessionDescription*)> received_sdp_munger_; |
| 993 | std::function<void(cricket::SessionDescription*)> generated_sdp_munger_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 994 | std::function<void()> remote_offer_handler_; |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 995 | rtc::MockAsyncResolver* remote_async_resolver_ = nullptr; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 996 | rtc::scoped_refptr<DataChannelInterface> data_channel_; |
| 997 | std::unique_ptr<MockDataChannelObserver> data_observer_; |
| 998 | |
| 999 | std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; |
| 1000 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1001 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1002 | ice_connection_state_history_; |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 1003 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 1004 | standardized_ice_connection_state_history_; |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 1005 | std::vector<PeerConnectionInterface::PeerConnectionState> |
| 1006 | peer_connection_state_history_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1007 | std::vector<PeerConnectionInterface::IceGatheringState> |
| 1008 | ice_gathering_state_history_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1009 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1010 | webrtc::FakeRtcEventLogFactory* event_log_factory_; |
| 1011 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1012 | rtc::AsyncInvoker invoker_; |
| 1013 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1014 | friend class PeerConnectionIntegrationBaseTest; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1015 | }; |
| 1016 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 1017 | class MockRtcEventLogOutput : public webrtc::RtcEventLogOutput { |
| 1018 | public: |
| 1019 | virtual ~MockRtcEventLogOutput() = default; |
| 1020 | MOCK_CONST_METHOD0(IsActive, bool()); |
| 1021 | MOCK_METHOD1(Write, bool(const std::string&)); |
| 1022 | }; |
| 1023 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1024 | // This helper object is used for both specifying how many audio/video frames |
| 1025 | // are expected to be received for a caller/callee. It provides helper functions |
| 1026 | // to specify these expectations. The object initially starts in a state of no |
| 1027 | // expectations. |
| 1028 | class MediaExpectations { |
| 1029 | public: |
| 1030 | enum ExpectFrames { |
| 1031 | kExpectSomeFrames, |
| 1032 | kExpectNoFrames, |
| 1033 | kNoExpectation, |
| 1034 | }; |
| 1035 | |
| 1036 | void ExpectBidirectionalAudioAndVideo() { |
| 1037 | ExpectBidirectionalAudio(); |
| 1038 | ExpectBidirectionalVideo(); |
| 1039 | } |
| 1040 | |
| 1041 | void ExpectBidirectionalAudio() { |
| 1042 | CallerExpectsSomeAudio(); |
| 1043 | CalleeExpectsSomeAudio(); |
| 1044 | } |
| 1045 | |
| 1046 | void ExpectNoAudio() { |
| 1047 | CallerExpectsNoAudio(); |
| 1048 | CalleeExpectsNoAudio(); |
| 1049 | } |
| 1050 | |
| 1051 | void ExpectBidirectionalVideo() { |
| 1052 | CallerExpectsSomeVideo(); |
| 1053 | CalleeExpectsSomeVideo(); |
| 1054 | } |
| 1055 | |
| 1056 | void ExpectNoVideo() { |
| 1057 | CallerExpectsNoVideo(); |
| 1058 | CalleeExpectsNoVideo(); |
| 1059 | } |
| 1060 | |
| 1061 | void CallerExpectsSomeAudioAndVideo() { |
| 1062 | CallerExpectsSomeAudio(); |
| 1063 | CallerExpectsSomeVideo(); |
| 1064 | } |
| 1065 | |
| 1066 | void CalleeExpectsSomeAudioAndVideo() { |
| 1067 | CalleeExpectsSomeAudio(); |
| 1068 | CalleeExpectsSomeVideo(); |
| 1069 | } |
| 1070 | |
| 1071 | // Caller's audio functions. |
| 1072 | void CallerExpectsSomeAudio( |
| 1073 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1074 | caller_audio_expectation_ = kExpectSomeFrames; |
| 1075 | caller_audio_frames_expected_ = expected_audio_frames; |
| 1076 | } |
| 1077 | |
| 1078 | void CallerExpectsNoAudio() { |
| 1079 | caller_audio_expectation_ = kExpectNoFrames; |
| 1080 | caller_audio_frames_expected_ = 0; |
| 1081 | } |
| 1082 | |
| 1083 | // Caller's video functions. |
| 1084 | void CallerExpectsSomeVideo( |
| 1085 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1086 | caller_video_expectation_ = kExpectSomeFrames; |
| 1087 | caller_video_frames_expected_ = expected_video_frames; |
| 1088 | } |
| 1089 | |
| 1090 | void CallerExpectsNoVideo() { |
| 1091 | caller_video_expectation_ = kExpectNoFrames; |
| 1092 | caller_video_frames_expected_ = 0; |
| 1093 | } |
| 1094 | |
| 1095 | // Callee's audio functions. |
| 1096 | void CalleeExpectsSomeAudio( |
| 1097 | int expected_audio_frames = kDefaultExpectedAudioFrameCount) { |
| 1098 | callee_audio_expectation_ = kExpectSomeFrames; |
| 1099 | callee_audio_frames_expected_ = expected_audio_frames; |
| 1100 | } |
| 1101 | |
| 1102 | void CalleeExpectsNoAudio() { |
| 1103 | callee_audio_expectation_ = kExpectNoFrames; |
| 1104 | callee_audio_frames_expected_ = 0; |
| 1105 | } |
| 1106 | |
| 1107 | // Callee's video functions. |
| 1108 | void CalleeExpectsSomeVideo( |
| 1109 | int expected_video_frames = kDefaultExpectedVideoFrameCount) { |
| 1110 | callee_video_expectation_ = kExpectSomeFrames; |
| 1111 | callee_video_frames_expected_ = expected_video_frames; |
| 1112 | } |
| 1113 | |
| 1114 | void CalleeExpectsNoVideo() { |
| 1115 | callee_video_expectation_ = kExpectNoFrames; |
| 1116 | callee_video_frames_expected_ = 0; |
| 1117 | } |
| 1118 | |
| 1119 | ExpectFrames caller_audio_expectation_ = kNoExpectation; |
| 1120 | ExpectFrames caller_video_expectation_ = kNoExpectation; |
| 1121 | ExpectFrames callee_audio_expectation_ = kNoExpectation; |
| 1122 | ExpectFrames callee_video_expectation_ = kNoExpectation; |
| 1123 | int caller_audio_frames_expected_ = 0; |
| 1124 | int caller_video_frames_expected_ = 0; |
| 1125 | int callee_audio_frames_expected_ = 0; |
| 1126 | int callee_video_frames_expected_ = 0; |
| 1127 | }; |
| 1128 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1129 | // Tests two PeerConnections connecting to each other end-to-end, using a |
| 1130 | // virtual network, fake A/V capture and fake encoder/decoders. The |
| 1131 | // PeerConnections share the threads/socket servers, but use separate versions |
| 1132 | // of everything else (including "PeerConnectionFactory"s). |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 1133 | class PeerConnectionIntegrationBaseTest : public ::testing::Test { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1134 | public: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1135 | explicit PeerConnectionIntegrationBaseTest(SdpSemantics sdp_semantics) |
| 1136 | : sdp_semantics_(sdp_semantics), |
| 1137 | ss_(new rtc::VirtualSocketServer()), |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1138 | fss_(new rtc::FirewallSocketServer(ss_.get())), |
| 1139 | network_thread_(new rtc::Thread(fss_.get())), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1140 | worker_thread_(rtc::Thread::Create()), |
| 1141 | loopback_media_transports_(network_thread_.get()) { |
Sebastian Jansson | 8a793a0 | 2018-03-13 15:21:48 +0100 | [diff] [blame] | 1142 | network_thread_->SetName("PCNetworkThread", this); |
| 1143 | worker_thread_->SetName("PCWorkerThread", this); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1144 | RTC_CHECK(network_thread_->Start()); |
| 1145 | RTC_CHECK(worker_thread_->Start()); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1146 | webrtc::metrics::Reset(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1149 | ~PeerConnectionIntegrationBaseTest() { |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1150 | // The PeerConnections should deleted before the TurnCustomizers. |
| 1151 | // A TurnPort is created with a raw pointer to a TurnCustomizer. The |
| 1152 | // TurnPort has the same lifetime as the PeerConnection, so it's expected |
| 1153 | // that the TurnCustomizer outlives the life of the PeerConnection or else |
| 1154 | // when Send() is called it will hit a seg fault. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1155 | if (caller_) { |
| 1156 | caller_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1157 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1158 | } |
| 1159 | if (callee_) { |
| 1160 | callee_->set_signaling_message_receiver(nullptr); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1161 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1162 | } |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1163 | |
| 1164 | // If turn servers were created for the test they need to be destroyed on |
| 1165 | // the network thread. |
| 1166 | network_thread()->Invoke<void>(RTC_FROM_HERE, [this] { |
| 1167 | turn_servers_.clear(); |
| 1168 | turn_customizers_.clear(); |
| 1169 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | bool SignalingStateStable() { |
| 1173 | return caller_->SignalingStateStable() && callee_->SignalingStateStable(); |
| 1174 | } |
| 1175 | |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1176 | bool DtlsConnected() { |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1177 | // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS |
| 1178 | // are connected. This is an important distinction. Once we have separate |
| 1179 | // ICE and DTLS state, this check needs to use the DTLS state. |
| 1180 | return (callee()->ice_connection_state() == |
| 1181 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1182 | callee()->ice_connection_state() == |
| 1183 | webrtc::PeerConnectionInterface::kIceConnectionCompleted) && |
| 1184 | (caller()->ice_connection_state() == |
| 1185 | webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 1186 | caller()->ice_connection_state() == |
| 1187 | webrtc::PeerConnectionInterface::kIceConnectionCompleted); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1190 | // When |event_log_factory| is null, the default implementation of the event |
| 1191 | // log factory will be used. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1192 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWrapper( |
| 1193 | const std::string& debug_name, |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1194 | const PeerConnectionFactory::Options* options, |
| 1195 | const RTCConfiguration* config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1196 | webrtc::PeerConnectionDependencies dependencies, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1197 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory, |
| 1198 | std::unique_ptr<webrtc::MediaTransportFactory> media_transport_factory) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1199 | RTCConfiguration modified_config; |
| 1200 | if (config) { |
| 1201 | modified_config = *config; |
| 1202 | } |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1203 | modified_config.sdp_semantics = sdp_semantics_; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1204 | if (!dependencies.cert_generator) { |
| 1205 | dependencies.cert_generator = |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1206 | absl::make_unique<FakeRTCCertificateGenerator>(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1207 | } |
| 1208 | std::unique_ptr<PeerConnectionWrapper> client( |
| 1209 | new PeerConnectionWrapper(debug_name)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1210 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1211 | if (!client->Init(options, &modified_config, std::move(dependencies), |
| 1212 | network_thread_.get(), worker_thread_.get(), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1213 | std::move(event_log_factory), |
| 1214 | std::move(media_transport_factory))) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1215 | return nullptr; |
| 1216 | } |
| 1217 | return client; |
| 1218 | } |
| 1219 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1220 | std::unique_ptr<PeerConnectionWrapper> |
| 1221 | CreatePeerConnectionWrapperWithFakeRtcEventLog( |
| 1222 | const std::string& debug_name, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1223 | const PeerConnectionFactory::Options* options, |
| 1224 | const RTCConfiguration* config, |
| 1225 | webrtc::PeerConnectionDependencies dependencies) { |
| 1226 | std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory( |
| 1227 | new webrtc::FakeRtcEventLogFactory(rtc::Thread::Current())); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1228 | return CreatePeerConnectionWrapper(debug_name, options, config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1229 | std::move(dependencies), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1230 | std::move(event_log_factory), |
| 1231 | /*media_transport_factory=*/nullptr); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1234 | bool CreatePeerConnectionWrappers() { |
| 1235 | return CreatePeerConnectionWrappersWithConfig( |
| 1236 | PeerConnectionInterface::RTCConfiguration(), |
| 1237 | PeerConnectionInterface::RTCConfiguration()); |
| 1238 | } |
| 1239 | |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1240 | bool CreatePeerConnectionWrappersWithSdpSemantics( |
| 1241 | SdpSemantics caller_semantics, |
| 1242 | SdpSemantics callee_semantics) { |
| 1243 | // Can't specify the sdp_semantics in the passed-in configuration since it |
| 1244 | // will be overwritten by CreatePeerConnectionWrapper with whatever is |
| 1245 | // stored in sdp_semantics_. So get around this by modifying the instance |
| 1246 | // variable before calling CreatePeerConnectionWrapper for the caller and |
| 1247 | // callee PeerConnections. |
| 1248 | SdpSemantics original_semantics = sdp_semantics_; |
| 1249 | sdp_semantics_ = caller_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1250 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1251 | "Caller", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1252 | nullptr, /*media_transport_factory=*/nullptr); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1253 | sdp_semantics_ = callee_semantics; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1254 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1255 | "Callee", nullptr, nullptr, webrtc::PeerConnectionDependencies(nullptr), |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1256 | nullptr, /*media_transport_factory=*/nullptr); |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1257 | sdp_semantics_ = original_semantics; |
| 1258 | return caller_ && callee_; |
| 1259 | } |
| 1260 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1261 | bool CreatePeerConnectionWrappersWithConfig( |
| 1262 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1263 | const PeerConnectionInterface::RTCConfiguration& callee_config) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1264 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1265 | "Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1266 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1267 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1268 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1269 | "Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1270 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1271 | /*media_transport_factory=*/nullptr); |
| 1272 | return caller_ && callee_; |
| 1273 | } |
| 1274 | |
| 1275 | bool CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 1276 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1277 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1278 | std::unique_ptr<webrtc::MediaTransportFactory> caller_factory, |
| 1279 | std::unique_ptr<webrtc::MediaTransportFactory> callee_factory) { |
| 1280 | caller_ = |
| 1281 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
| 1282 | webrtc::PeerConnectionDependencies(nullptr), |
| 1283 | nullptr, std::move(caller_factory)); |
| 1284 | callee_ = |
| 1285 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
| 1286 | webrtc::PeerConnectionDependencies(nullptr), |
| 1287 | nullptr, std::move(callee_factory)); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1288 | return caller_ && callee_; |
| 1289 | } |
| 1290 | |
| 1291 | bool CreatePeerConnectionWrappersWithConfigAndDeps( |
| 1292 | const PeerConnectionInterface::RTCConfiguration& caller_config, |
| 1293 | webrtc::PeerConnectionDependencies caller_dependencies, |
| 1294 | const PeerConnectionInterface::RTCConfiguration& callee_config, |
| 1295 | webrtc::PeerConnectionDependencies callee_dependencies) { |
| 1296 | caller_ = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1297 | CreatePeerConnectionWrapper("Caller", nullptr, &caller_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1298 | std::move(caller_dependencies), nullptr, |
| 1299 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1300 | callee_ = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1301 | CreatePeerConnectionWrapper("Callee", nullptr, &callee_config, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1302 | std::move(callee_dependencies), nullptr, |
| 1303 | /*media_transport_factory=*/nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1304 | return caller_ && callee_; |
| 1305 | } |
| 1306 | |
| 1307 | bool CreatePeerConnectionWrappersWithOptions( |
| 1308 | const PeerConnectionFactory::Options& caller_options, |
| 1309 | const PeerConnectionFactory::Options& callee_options) { |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1310 | caller_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1311 | "Caller", &caller_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1312 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1313 | /*media_transport_factory=*/nullptr); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1314 | callee_ = CreatePeerConnectionWrapper( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1315 | "Callee", &callee_options, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1316 | webrtc::PeerConnectionDependencies(nullptr), nullptr, |
| 1317 | /*media_transport_factory=*/nullptr); |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1318 | return caller_ && callee_; |
| 1319 | } |
| 1320 | |
| 1321 | bool CreatePeerConnectionWrappersWithFakeRtcEventLog() { |
| 1322 | PeerConnectionInterface::RTCConfiguration default_config; |
| 1323 | caller_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1324 | "Caller", nullptr, &default_config, |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 1325 | webrtc::PeerConnectionDependencies(nullptr)); |
| 1326 | callee_ = CreatePeerConnectionWrapperWithFakeRtcEventLog( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1327 | "Callee", nullptr, &default_config, |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1328 | webrtc::PeerConnectionDependencies(nullptr)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1329 | return caller_ && callee_; |
| 1330 | } |
| 1331 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1332 | std::unique_ptr<PeerConnectionWrapper> |
| 1333 | CreatePeerConnectionWrapperWithAlternateKey() { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1334 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 1335 | new FakeRTCCertificateGenerator()); |
| 1336 | cert_generator->use_alternate_key(); |
| 1337 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 1338 | webrtc::PeerConnectionDependencies dependencies(nullptr); |
| 1339 | dependencies.cert_generator = std::move(cert_generator); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1340 | return CreatePeerConnectionWrapper("New Peer", nullptr, nullptr, |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1341 | std::move(dependencies), nullptr, |
| 1342 | /*media_transport_factory=*/nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1345 | cricket::TestTurnServer* CreateTurnServer( |
| 1346 | rtc::SocketAddress internal_address, |
| 1347 | rtc::SocketAddress external_address, |
| 1348 | cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP, |
| 1349 | const std::string& common_name = "test turn server") { |
| 1350 | rtc::Thread* thread = network_thread(); |
| 1351 | std::unique_ptr<cricket::TestTurnServer> turn_server = |
| 1352 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnServer>>( |
| 1353 | RTC_FROM_HERE, |
| 1354 | [thread, internal_address, external_address, type, common_name] { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1355 | return absl::make_unique<cricket::TestTurnServer>( |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1356 | thread, internal_address, external_address, type, |
| 1357 | /*ignore_bad_certs=*/true, common_name); |
| 1358 | }); |
| 1359 | turn_servers_.push_back(std::move(turn_server)); |
| 1360 | // Interactions with the turn server should be done on the network thread. |
| 1361 | return turn_servers_.back().get(); |
| 1362 | } |
| 1363 | |
| 1364 | cricket::TestTurnCustomizer* CreateTurnCustomizer() { |
| 1365 | std::unique_ptr<cricket::TestTurnCustomizer> turn_customizer = |
| 1366 | network_thread()->Invoke<std::unique_ptr<cricket::TestTurnCustomizer>>( |
| 1367 | RTC_FROM_HERE, |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1368 | [] { return absl::make_unique<cricket::TestTurnCustomizer>(); }); |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1369 | turn_customizers_.push_back(std::move(turn_customizer)); |
| 1370 | // Interactions with the turn customizer should be done on the network |
| 1371 | // thread. |
| 1372 | return turn_customizers_.back().get(); |
| 1373 | } |
| 1374 | |
| 1375 | // Checks that the function counters for a TestTurnCustomizer are greater than |
| 1376 | // 0. |
| 1377 | void ExpectTurnCustomizerCountersIncremented( |
| 1378 | cricket::TestTurnCustomizer* turn_customizer) { |
| 1379 | unsigned int allow_channel_data_counter = |
| 1380 | network_thread()->Invoke<unsigned int>( |
| 1381 | RTC_FROM_HERE, [turn_customizer] { |
| 1382 | return turn_customizer->allow_channel_data_cnt_; |
| 1383 | }); |
| 1384 | EXPECT_GT(allow_channel_data_counter, 0u); |
| 1385 | unsigned int modify_counter = network_thread()->Invoke<unsigned int>( |
| 1386 | RTC_FROM_HERE, |
| 1387 | [turn_customizer] { return turn_customizer->modify_cnt_; }); |
| 1388 | EXPECT_GT(modify_counter, 0u); |
| 1389 | } |
| 1390 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1391 | // Once called, SDP blobs and ICE candidates will be automatically signaled |
| 1392 | // between PeerConnections. |
| 1393 | void ConnectFakeSignaling() { |
| 1394 | caller_->set_signaling_message_receiver(callee_.get()); |
| 1395 | callee_->set_signaling_message_receiver(caller_.get()); |
| 1396 | } |
| 1397 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1398 | // Once called, SDP blobs will be automatically signaled between |
| 1399 | // PeerConnections. Note that ICE candidates will not be signaled unless they |
| 1400 | // are in the exchanged SDP blobs. |
| 1401 | void ConnectFakeSignalingForSdpOnly() { |
| 1402 | ConnectFakeSignaling(); |
| 1403 | SetSignalIceCandidates(false); |
| 1404 | } |
| 1405 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1406 | void SetSignalingDelayMs(int delay_ms) { |
| 1407 | caller_->set_signaling_delay_ms(delay_ms); |
| 1408 | callee_->set_signaling_delay_ms(delay_ms); |
| 1409 | } |
| 1410 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1411 | void SetSignalIceCandidates(bool signal) { |
| 1412 | caller_->set_signal_ice_candidates(signal); |
| 1413 | callee_->set_signal_ice_candidates(signal); |
| 1414 | } |
| 1415 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1416 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1417 | // times to avoid test flakiness. |
| 1418 | void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc, |
| 1419 | const std::string& data, |
| 1420 | int retries) { |
| 1421 | for (int i = 0; i < retries; ++i) { |
| 1422 | dc->Send(DataBuffer(data)); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | rtc::Thread* network_thread() { return network_thread_.get(); } |
| 1427 | |
| 1428 | rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1429 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1430 | webrtc::MediaTransportPair* loopback_media_transports() { |
| 1431 | return &loopback_media_transports_; |
| 1432 | } |
| 1433 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1434 | PeerConnectionWrapper* caller() { return caller_.get(); } |
| 1435 | |
| 1436 | // Set the |caller_| to the |wrapper| passed in and return the |
| 1437 | // original |caller_|. |
| 1438 | PeerConnectionWrapper* SetCallerPcWrapperAndReturnCurrent( |
| 1439 | PeerConnectionWrapper* wrapper) { |
| 1440 | PeerConnectionWrapper* old = caller_.release(); |
| 1441 | caller_.reset(wrapper); |
| 1442 | return old; |
| 1443 | } |
| 1444 | |
| 1445 | PeerConnectionWrapper* callee() { return callee_.get(); } |
| 1446 | |
| 1447 | // Set the |callee_| to the |wrapper| passed in and return the |
| 1448 | // original |callee_|. |
| 1449 | PeerConnectionWrapper* SetCalleePcWrapperAndReturnCurrent( |
| 1450 | PeerConnectionWrapper* wrapper) { |
| 1451 | PeerConnectionWrapper* old = callee_.release(); |
| 1452 | callee_.reset(wrapper); |
| 1453 | return old; |
| 1454 | } |
| 1455 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 1456 | void SetPortAllocatorFlags(uint32_t caller_flags, uint32_t callee_flags) { |
| 1457 | network_thread()->Invoke<void>( |
| 1458 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1459 | caller()->port_allocator(), caller_flags)); |
| 1460 | network_thread()->Invoke<void>( |
| 1461 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::set_flags, |
| 1462 | callee()->port_allocator(), callee_flags)); |
| 1463 | } |
| 1464 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1465 | rtc::FirewallSocketServer* firewall() const { return fss_.get(); } |
| 1466 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1467 | // Expects the provided number of new frames to be received within |
| 1468 | // kMaxWaitForFramesMs. The new expected frames are specified in |
| 1469 | // |media_expectations|. Returns false if any of the expectations were |
| 1470 | // not met. |
| 1471 | bool ExpectNewFrames(const MediaExpectations& media_expectations) { |
| 1472 | // First initialize the expected frame counts based upon the current |
| 1473 | // frame count. |
| 1474 | int total_caller_audio_frames_expected = caller()->audio_frames_received(); |
| 1475 | if (media_expectations.caller_audio_expectation_ == |
| 1476 | MediaExpectations::kExpectSomeFrames) { |
| 1477 | total_caller_audio_frames_expected += |
| 1478 | media_expectations.caller_audio_frames_expected_; |
| 1479 | } |
| 1480 | int total_caller_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1481 | caller()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1482 | if (media_expectations.caller_video_expectation_ == |
| 1483 | MediaExpectations::kExpectSomeFrames) { |
| 1484 | total_caller_video_frames_expected += |
| 1485 | media_expectations.caller_video_frames_expected_; |
| 1486 | } |
| 1487 | int total_callee_audio_frames_expected = callee()->audio_frames_received(); |
| 1488 | if (media_expectations.callee_audio_expectation_ == |
| 1489 | MediaExpectations::kExpectSomeFrames) { |
| 1490 | total_callee_audio_frames_expected += |
| 1491 | media_expectations.callee_audio_frames_expected_; |
| 1492 | } |
| 1493 | int total_callee_video_frames_expected = |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1494 | callee()->min_video_frames_received_per_track(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1495 | if (media_expectations.callee_video_expectation_ == |
| 1496 | MediaExpectations::kExpectSomeFrames) { |
| 1497 | total_callee_video_frames_expected += |
| 1498 | media_expectations.callee_video_frames_expected_; |
| 1499 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1500 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1501 | // Wait for the expected frames. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1502 | EXPECT_TRUE_WAIT(caller()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1503 | total_caller_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1504 | caller()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1505 | total_caller_video_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1506 | callee()->audio_frames_received() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1507 | total_callee_audio_frames_expected && |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1508 | callee()->min_video_frames_received_per_track() >= |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1509 | total_callee_video_frames_expected, |
| 1510 | kMaxWaitForFramesMs); |
| 1511 | bool expectations_correct = |
| 1512 | caller()->audio_frames_received() >= |
| 1513 | total_caller_audio_frames_expected && |
| 1514 | caller()->min_video_frames_received_per_track() >= |
| 1515 | total_caller_video_frames_expected && |
| 1516 | callee()->audio_frames_received() >= |
| 1517 | total_callee_audio_frames_expected && |
| 1518 | callee()->min_video_frames_received_per_track() >= |
| 1519 | total_callee_video_frames_expected; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1520 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1521 | // After the combined wait, print out a more detailed message upon |
| 1522 | // failure. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1523 | EXPECT_GE(caller()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1524 | total_caller_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1525 | EXPECT_GE(caller()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1526 | total_caller_video_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1527 | EXPECT_GE(callee()->audio_frames_received(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1528 | total_callee_audio_frames_expected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1529 | EXPECT_GE(callee()->min_video_frames_received_per_track(), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1530 | total_callee_video_frames_expected); |
| 1531 | |
| 1532 | // We want to make sure nothing unexpected was received. |
| 1533 | if (media_expectations.caller_audio_expectation_ == |
| 1534 | MediaExpectations::kExpectNoFrames) { |
| 1535 | EXPECT_EQ(caller()->audio_frames_received(), |
| 1536 | total_caller_audio_frames_expected); |
| 1537 | if (caller()->audio_frames_received() != |
| 1538 | total_caller_audio_frames_expected) { |
| 1539 | expectations_correct = false; |
| 1540 | } |
| 1541 | } |
| 1542 | if (media_expectations.caller_video_expectation_ == |
| 1543 | MediaExpectations::kExpectNoFrames) { |
| 1544 | EXPECT_EQ(caller()->min_video_frames_received_per_track(), |
| 1545 | total_caller_video_frames_expected); |
| 1546 | if (caller()->min_video_frames_received_per_track() != |
| 1547 | total_caller_video_frames_expected) { |
| 1548 | expectations_correct = false; |
| 1549 | } |
| 1550 | } |
| 1551 | if (media_expectations.callee_audio_expectation_ == |
| 1552 | MediaExpectations::kExpectNoFrames) { |
| 1553 | EXPECT_EQ(callee()->audio_frames_received(), |
| 1554 | total_callee_audio_frames_expected); |
| 1555 | if (callee()->audio_frames_received() != |
| 1556 | total_callee_audio_frames_expected) { |
| 1557 | expectations_correct = false; |
| 1558 | } |
| 1559 | } |
| 1560 | if (media_expectations.callee_video_expectation_ == |
| 1561 | MediaExpectations::kExpectNoFrames) { |
| 1562 | EXPECT_EQ(callee()->min_video_frames_received_per_track(), |
| 1563 | total_callee_video_frames_expected); |
| 1564 | if (callee()->min_video_frames_received_per_track() != |
| 1565 | total_callee_video_frames_expected) { |
| 1566 | expectations_correct = false; |
| 1567 | } |
| 1568 | } |
| 1569 | return expectations_correct; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1572 | void TestNegotiatedCipherSuite( |
| 1573 | const PeerConnectionFactory::Options& caller_options, |
| 1574 | const PeerConnectionFactory::Options& callee_options, |
| 1575 | int expected_cipher_suite) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1576 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options, |
| 1577 | callee_options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1578 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1579 | caller()->AddAudioVideoTracks(); |
| 1580 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1581 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1582 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1583 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 1584 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1585 | // TODO(bugs.webrtc.org/9456): Fix it. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 1586 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1587 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 1588 | expected_cipher_suite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1591 | void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled, |
| 1592 | bool remote_gcm_enabled, |
| 1593 | int expected_cipher_suite) { |
| 1594 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1595 | caller_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1596 | local_gcm_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1597 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 1598 | callee_options.crypto_options.srtp.enable_gcm_crypto_suites = |
| 1599 | remote_gcm_enabled; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 1600 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 1601 | expected_cipher_suite); |
| 1602 | } |
| 1603 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1604 | protected: |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 1605 | SdpSemantics sdp_semantics_; |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1606 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1607 | private: |
| 1608 | // |ss_| is used by |network_thread_| so it must be destroyed later. |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1609 | std::unique_ptr<rtc::VirtualSocketServer> ss_; |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1610 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1611 | // |network_thread_| and |worker_thread_| are used by both |
| 1612 | // |caller_| and |callee_| so they must be destroyed |
| 1613 | // later. |
| 1614 | std::unique_ptr<rtc::Thread> network_thread_; |
| 1615 | std::unique_ptr<rtc::Thread> worker_thread_; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 1616 | // The turn servers and turn customizers should be accessed & deleted on the |
| 1617 | // network thread to avoid a race with the socket read/write that occurs |
| 1618 | // on the network thread. |
| 1619 | std::vector<std::unique_ptr<cricket::TestTurnServer>> turn_servers_; |
| 1620 | std::vector<std::unique_ptr<cricket::TestTurnCustomizer>> turn_customizers_; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 1621 | webrtc::MediaTransportPair loopback_media_transports_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1622 | std::unique_ptr<PeerConnectionWrapper> caller_; |
| 1623 | std::unique_ptr<PeerConnectionWrapper> callee_; |
| 1624 | }; |
| 1625 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1626 | class PeerConnectionIntegrationTest |
| 1627 | : public PeerConnectionIntegrationBaseTest, |
| 1628 | public ::testing::WithParamInterface<SdpSemantics> { |
| 1629 | protected: |
| 1630 | PeerConnectionIntegrationTest() |
| 1631 | : PeerConnectionIntegrationBaseTest(GetParam()) {} |
| 1632 | }; |
| 1633 | |
| 1634 | class PeerConnectionIntegrationTestPlanB |
| 1635 | : public PeerConnectionIntegrationBaseTest { |
| 1636 | protected: |
| 1637 | PeerConnectionIntegrationTestPlanB() |
| 1638 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {} |
| 1639 | }; |
| 1640 | |
| 1641 | class PeerConnectionIntegrationTestUnifiedPlan |
| 1642 | : public PeerConnectionIntegrationBaseTest { |
| 1643 | protected: |
| 1644 | PeerConnectionIntegrationTestUnifiedPlan() |
| 1645 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 1646 | }; |
| 1647 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1648 | // Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This |
| 1649 | // includes testing that the callback is invoked if an observer is connected |
| 1650 | // after the first packet has already been received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1651 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1652 | RtpReceiverObserverOnFirstPacketReceived) { |
| 1653 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1654 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1655 | caller()->AddAudioVideoTracks(); |
| 1656 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1657 | // Start offer/answer exchange and wait for it to complete. |
| 1658 | caller()->CreateAndSetAndSignalOffer(); |
| 1659 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1660 | // Should be one receiver each for audio/video. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1661 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1662 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1663 | // Wait for all "first packet received" callbacks to be fired. |
| 1664 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1665 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1666 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1667 | return o->first_packet_received(); |
| 1668 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1669 | kMaxWaitForFramesMs); |
| 1670 | EXPECT_TRUE_WAIT( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1671 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1672 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1673 | return o->first_packet_received(); |
| 1674 | }), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1675 | kMaxWaitForFramesMs); |
| 1676 | // If new observers are set after the first packet was already received, the |
| 1677 | // callback should still be invoked. |
| 1678 | caller()->ResetRtpReceiverObservers(); |
| 1679 | callee()->ResetRtpReceiverObservers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1680 | EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); |
| 1681 | EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1682 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1683 | absl::c_all_of(caller()->rtp_receiver_observers(), |
| 1684 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1685 | return o->first_packet_received(); |
| 1686 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1687 | EXPECT_TRUE( |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 1688 | absl::c_all_of(callee()->rtp_receiver_observers(), |
| 1689 | [](const std::unique_ptr<MockRtpReceiverObserver>& o) { |
| 1690 | return o->first_packet_received(); |
| 1691 | })); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 1695 | public: |
| 1696 | DummyDtmfObserver() : completed_(false) {} |
| 1697 | |
| 1698 | // Implements DtmfSenderObserverInterface. |
| 1699 | void OnToneChange(const std::string& tone) override { |
| 1700 | tones_.push_back(tone); |
| 1701 | if (tone.empty()) { |
| 1702 | completed_ = true; |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | const std::vector<std::string>& tones() const { return tones_; } |
| 1707 | bool completed() const { return completed_; } |
| 1708 | |
| 1709 | private: |
| 1710 | bool completed_; |
| 1711 | std::vector<std::string> tones_; |
| 1712 | }; |
| 1713 | |
| 1714 | // Assumes |sender| already has an audio track added and the offer/answer |
| 1715 | // exchange is done. |
| 1716 | void TestDtmfFromSenderToReceiver(PeerConnectionWrapper* sender, |
| 1717 | PeerConnectionWrapper* receiver) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1718 | // We should be able to get a DTMF sender from the local sender. |
| 1719 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender = |
| 1720 | sender->pc()->GetSenders().at(0)->GetDtmfSender(); |
| 1721 | ASSERT_TRUE(dtmf_sender); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1722 | DummyDtmfObserver observer; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1723 | dtmf_sender->RegisterObserver(&observer); |
| 1724 | |
| 1725 | // Test the DtmfSender object just created. |
| 1726 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 1727 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 1728 | |
| 1729 | EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout); |
| 1730 | std::vector<std::string> tones = {"1", "a", ""}; |
| 1731 | EXPECT_EQ(tones, observer.tones()); |
| 1732 | dtmf_sender->UnregisterObserver(); |
| 1733 | // TODO(deadbeef): Verify the tones were actually received end-to-end. |
| 1734 | } |
| 1735 | |
| 1736 | // Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each |
| 1737 | // direction). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1738 | TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1739 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1740 | ConnectFakeSignaling(); |
| 1741 | // Only need audio for DTMF. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1742 | caller()->AddAudioTrack(); |
| 1743 | callee()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1744 | caller()->CreateAndSetAndSignalOffer(); |
| 1745 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 1746 | // DTLS must finish before the DTMF sender can be used reliably. |
| 1747 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1748 | TestDtmfFromSenderToReceiver(caller(), callee()); |
| 1749 | TestDtmfFromSenderToReceiver(callee(), caller()); |
| 1750 | } |
| 1751 | |
| 1752 | // Basic end-to-end test, verifying media can be encoded/transmitted/decoded |
| 1753 | // between two connections, using DTLS-SRTP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1754 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1755 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1756 | ConnectFakeSignaling(); |
Harald Alvestrand | 194939b | 2018-01-24 16:04:13 +0100 | [diff] [blame] | 1757 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1758 | // Do normal offer/answer and wait for some frames to be received in each |
| 1759 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1760 | caller()->AddAudioVideoTracks(); |
| 1761 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1762 | caller()->CreateAndSetAndSignalOffer(); |
| 1763 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1764 | MediaExpectations media_expectations; |
| 1765 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1766 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1767 | EXPECT_LE(2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1768 | webrtc::kEnumCounterKeyProtocolDtls)); |
| 1769 | EXPECT_EQ(0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1770 | webrtc::kEnumCounterKeyProtocolSdes)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | // Uses SDES instead of DTLS for key agreement. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1774 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1775 | PeerConnectionInterface::RTCConfiguration sdes_config; |
| 1776 | sdes_config.enable_dtls_srtp.emplace(false); |
| 1777 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config)); |
| 1778 | ConnectFakeSignaling(); |
| 1779 | |
| 1780 | // Do normal offer/answer and wait for some frames to be received in each |
| 1781 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1782 | caller()->AddAudioVideoTracks(); |
| 1783 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1784 | caller()->CreateAndSetAndSignalOffer(); |
| 1785 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1786 | MediaExpectations media_expectations; |
| 1787 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1788 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 1789 | EXPECT_LE(2, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1790 | webrtc::kEnumCounterKeyProtocolSdes)); |
| 1791 | EXPECT_EQ(0, webrtc::metrics::NumEvents("WebRTC.PeerConnection.KeyProtocol", |
| 1792 | webrtc::kEnumCounterKeyProtocolDtls)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1795 | // Tests that the GetRemoteAudioSSLCertificate method returns the remote DTLS |
| 1796 | // certificate once the DTLS handshake has finished. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1797 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1798 | GetRemoteAudioSSLCertificateReturnsExchangedCertificate) { |
| 1799 | auto GetRemoteAudioSSLCertificate = [](PeerConnectionWrapper* wrapper) { |
| 1800 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1801 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1802 | return pc->GetRemoteAudioSSLCertificate(); |
| 1803 | }; |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1804 | auto GetRemoteAudioSSLCertChain = [](PeerConnectionWrapper* wrapper) { |
| 1805 | auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc()); |
| 1806 | auto pc = reinterpret_cast<PeerConnection*>(pci->internal()); |
| 1807 | return pc->GetRemoteAudioSSLCertChain(); |
| 1808 | }; |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1809 | |
| 1810 | auto caller_cert = rtc::RTCCertificate::FromPEM(kRsaPems[0]); |
| 1811 | auto callee_cert = rtc::RTCCertificate::FromPEM(kRsaPems[1]); |
| 1812 | |
| 1813 | // Configure each side with a known certificate so they can be compared later. |
| 1814 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 1815 | caller_config.enable_dtls_srtp.emplace(true); |
| 1816 | caller_config.certificates.push_back(caller_cert); |
| 1817 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 1818 | callee_config.enable_dtls_srtp.emplace(true); |
| 1819 | callee_config.certificates.push_back(callee_cert); |
| 1820 | ASSERT_TRUE( |
| 1821 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 1822 | ConnectFakeSignaling(); |
| 1823 | |
| 1824 | // When first initialized, there should not be a remote SSL certificate (and |
| 1825 | // calling this method should not crash). |
| 1826 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(caller())); |
| 1827 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(callee())); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1828 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(caller())); |
| 1829 | EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(callee())); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1830 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1831 | caller()->AddAudioTrack(); |
| 1832 | callee()->AddAudioTrack(); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1833 | caller()->CreateAndSetAndSignalOffer(); |
| 1834 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1835 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 1836 | |
| 1837 | // Once DTLS has been connected, each side should return the other's SSL |
| 1838 | // certificate when calling GetRemoteAudioSSLCertificate. |
| 1839 | |
| 1840 | auto caller_remote_cert = GetRemoteAudioSSLCertificate(caller()); |
| 1841 | ASSERT_TRUE(caller_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1842 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1843 | caller_remote_cert->ToPEMString()); |
| 1844 | |
| 1845 | auto callee_remote_cert = GetRemoteAudioSSLCertificate(callee()); |
| 1846 | ASSERT_TRUE(callee_remote_cert); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1847 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1848 | callee_remote_cert->ToPEMString()); |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1849 | |
| 1850 | auto caller_remote_cert_chain = GetRemoteAudioSSLCertChain(caller()); |
| 1851 | ASSERT_TRUE(caller_remote_cert_chain); |
| 1852 | ASSERT_EQ(1U, caller_remote_cert_chain->GetSize()); |
| 1853 | auto remote_cert = &caller_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1854 | EXPECT_EQ(callee_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1855 | remote_cert->ToPEMString()); |
| 1856 | |
| 1857 | auto callee_remote_cert_chain = GetRemoteAudioSSLCertChain(callee()); |
| 1858 | ASSERT_TRUE(callee_remote_cert_chain); |
| 1859 | ASSERT_EQ(1U, callee_remote_cert_chain->GetSize()); |
| 1860 | remote_cert = &callee_remote_cert_chain->Get(0); |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 1861 | EXPECT_EQ(caller_cert->GetSSLCertificate().ToPEMString(), |
Zhi Huang | 70b820f | 2018-01-27 14:16:15 -0800 | [diff] [blame] | 1862 | remote_cert->ToPEMString()); |
Steve Anton | 8c0f7a7 | 2017-10-03 10:03:10 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1865 | // This test sets up a call between two parties with a source resolution of |
| 1866 | // 1280x720 and verifies that a 16:9 aspect ratio is received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1867 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1868 | Send1280By720ResolutionAndReceive16To9AspectRatio) { |
| 1869 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1870 | ConnectFakeSignaling(); |
| 1871 | |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1872 | // Add video tracks with 16:9 aspect ratio, size 1280 x 720. |
| 1873 | webrtc::FakePeriodicVideoSource::Config config; |
| 1874 | config.width = 1280; |
| 1875 | config.height = 720; |
Johannes Kron | 965e794 | 2018-09-13 15:36:20 +0200 | [diff] [blame] | 1876 | config.timestamp_offset_ms = rtc::TimeMillis(); |
Niels Möller | 5c7efe7 | 2018-05-11 10:34:46 +0200 | [diff] [blame] | 1877 | caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); |
| 1878 | callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1879 | |
| 1880 | // Do normal offer/answer and wait for at least one frame to be received in |
| 1881 | // each direction. |
| 1882 | caller()->CreateAndSetAndSignalOffer(); |
| 1883 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 1884 | callee()->min_video_frames_received_per_track() > 0, |
| 1885 | kMaxWaitForFramesMs); |
| 1886 | |
| 1887 | // Check rendered aspect ratio. |
| 1888 | EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio()); |
| 1889 | EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio()); |
| 1890 | EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio()); |
| 1891 | EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio()); |
| 1892 | } |
| 1893 | |
| 1894 | // This test sets up an one-way call, with media only from caller to |
| 1895 | // callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1896 | TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1897 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1898 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1899 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1900 | caller()->CreateAndSetAndSignalOffer(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1901 | MediaExpectations media_expectations; |
| 1902 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 1903 | media_expectations.CallerExpectsNoAudio(); |
| 1904 | media_expectations.CallerExpectsNoVideo(); |
| 1905 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | // This test sets up a audio call initially, with the callee rejecting video |
| 1909 | // initially. Then later the callee decides to upgrade to audio/video, and |
| 1910 | // initiates a new offer/answer exchange. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1911 | TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1912 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1913 | ConnectFakeSignaling(); |
| 1914 | // Initially, offer an audio/video stream from the caller, but refuse to |
| 1915 | // send/receive video on the callee side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1916 | caller()->AddAudioVideoTracks(); |
| 1917 | callee()->AddAudioTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1918 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 1919 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1920 | options.offer_to_receive_video = 0; |
| 1921 | callee()->SetOfferAnswerOptions(options); |
| 1922 | } else { |
| 1923 | callee()->SetRemoteOfferHandler([this] { |
| 1924 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 1925 | }); |
| 1926 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1927 | // Do offer/answer and make sure audio is still received end-to-end. |
| 1928 | caller()->CreateAndSetAndSignalOffer(); |
| 1929 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1930 | { |
| 1931 | MediaExpectations media_expectations; |
| 1932 | media_expectations.ExpectBidirectionalAudio(); |
| 1933 | media_expectations.ExpectNoVideo(); |
| 1934 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1935 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1936 | // Sanity check that the callee's description has a rejected video section. |
| 1937 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 1938 | const ContentInfo* callee_video_content = |
| 1939 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 1940 | ASSERT_NE(nullptr, callee_video_content); |
| 1941 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1942 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1943 | // Now negotiate with video and ensure negotiation succeeds, with video |
| 1944 | // frames and additional audio frames being received. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1945 | callee()->AddVideoTrack(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1946 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 1947 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1948 | options.offer_to_receive_video = 1; |
| 1949 | callee()->SetOfferAnswerOptions(options); |
| 1950 | } else { |
| 1951 | callee()->SetRemoteOfferHandler(nullptr); |
| 1952 | caller()->SetRemoteOfferHandler([this] { |
| 1953 | // The caller creates a new transceiver to receive video on when receiving |
| 1954 | // the offer, but by default it is send only. |
| 1955 | auto transceivers = caller()->pc()->GetTransceivers(); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 1956 | ASSERT_EQ(3U, transceivers.size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1957 | ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO, |
| 1958 | transceivers[2]->receiver()->media_type()); |
| 1959 | transceivers[2]->sender()->SetTrack(caller()->CreateLocalVideoTrack()); |
| 1960 | transceivers[2]->SetDirection(RtpTransceiverDirection::kSendRecv); |
| 1961 | }); |
| 1962 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1963 | callee()->CreateAndSetAndSignalOffer(); |
| 1964 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1965 | { |
| 1966 | // Expect additional audio frames to be received after the upgrade. |
| 1967 | MediaExpectations media_expectations; |
| 1968 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1969 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 1970 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 1973 | // Simpler than the above test; just add an audio track to an established |
| 1974 | // video-only connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1975 | TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) { |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 1976 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1977 | ConnectFakeSignaling(); |
| 1978 | // Do initial offer/answer with just a video track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1979 | caller()->AddVideoTrack(); |
| 1980 | callee()->AddVideoTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 1981 | caller()->CreateAndSetAndSignalOffer(); |
| 1982 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1983 | // Now add an audio track and do another offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1984 | caller()->AddAudioTrack(); |
| 1985 | callee()->AddAudioTrack(); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 1986 | caller()->CreateAndSetAndSignalOffer(); |
| 1987 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1988 | // Ensure both audio and video frames are received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1989 | MediaExpectations media_expectations; |
| 1990 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 1991 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 4389b4d | 2017-09-07 09:07:36 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1994 | // This test sets up a call that's transferred to a new caller with a different |
| 1995 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 1996 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 1997 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1998 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 1999 | caller()->AddAudioVideoTracks(); |
| 2000 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2001 | caller()->CreateAndSetAndSignalOffer(); |
| 2002 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2003 | |
| 2004 | // Keep the original peer around which will still send packets to the |
| 2005 | // receiving client. These SRTP packets will be dropped. |
| 2006 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2007 | SetCallerPcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2008 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2009 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2010 | // directly above. |
| 2011 | original_peer->pc()->Close(); |
| 2012 | |
| 2013 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2014 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2015 | caller()->CreateAndSetAndSignalOffer(); |
| 2016 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2017 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2018 | MediaExpectations media_expectations; |
| 2019 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2020 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | // This test sets up a call that's transferred to a new callee with a different |
| 2024 | // DTLS fingerprint. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2025 | TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2026 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2027 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2028 | caller()->AddAudioVideoTracks(); |
| 2029 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2030 | caller()->CreateAndSetAndSignalOffer(); |
| 2031 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2032 | |
| 2033 | // Keep the original peer around which will still send packets to the |
| 2034 | // receiving client. These SRTP packets will be dropped. |
| 2035 | std::unique_ptr<PeerConnectionWrapper> original_peer( |
| 2036 | SetCalleePcWrapperAndReturnCurrent( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2037 | CreatePeerConnectionWrapperWithAlternateKey().release())); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2038 | // TODO(deadbeef): Why do we call Close here? That goes against the comment |
| 2039 | // directly above. |
| 2040 | original_peer->pc()->Close(); |
| 2041 | |
| 2042 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2043 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2044 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2045 | caller()->CreateAndSetAndSignalOffer(); |
| 2046 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2047 | // Wait for some additional frames to be transmitted end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2048 | MediaExpectations media_expectations; |
| 2049 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2050 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | // This test sets up a non-bundled call and negotiates bundling at the same |
| 2054 | // time as starting an ICE restart. When bundling is in effect in the restart, |
| 2055 | // the DTLS-SRTP context should be successfully reset. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2056 | TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2057 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2058 | ConnectFakeSignaling(); |
| 2059 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2060 | caller()->AddAudioVideoTracks(); |
| 2061 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2062 | // Remove the bundle group from the SDP received by the callee. |
| 2063 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2064 | desc->RemoveGroupByName("BUNDLE"); |
| 2065 | }); |
| 2066 | caller()->CreateAndSetAndSignalOffer(); |
| 2067 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2068 | { |
| 2069 | MediaExpectations media_expectations; |
| 2070 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2071 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2072 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2073 | // Now stop removing the BUNDLE group, and trigger an ICE restart. |
| 2074 | callee()->SetReceivedSdpMunger(nullptr); |
| 2075 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 2076 | caller()->CreateAndSetAndSignalOffer(); |
| 2077 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2078 | |
| 2079 | // Expect additional frames to be received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2080 | { |
| 2081 | MediaExpectations media_expectations; |
| 2082 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2083 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2084 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | // Test CVO (Coordination of Video Orientation). If a video source is rotated |
| 2088 | // and both peers support the CVO RTP header extension, the actual video frames |
| 2089 | // don't need to be encoded in different resolutions, since the rotation is |
| 2090 | // communicated through the RTP header extension. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2091 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2092 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2093 | ConnectFakeSignaling(); |
| 2094 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2095 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2096 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2097 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2098 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2099 | |
| 2100 | // Wait for video frames to be received by both sides. |
| 2101 | caller()->CreateAndSetAndSignalOffer(); |
| 2102 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2103 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2104 | callee()->min_video_frames_received_per_track() > 0, |
| 2105 | kMaxWaitForFramesMs); |
| 2106 | |
| 2107 | // Ensure that the aspect ratio is unmodified. |
| 2108 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2109 | // not just assumed. |
| 2110 | EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio()); |
| 2111 | EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio()); |
| 2112 | EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio()); |
| 2113 | EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio()); |
| 2114 | // Ensure that the CVO bits were surfaced to the renderer. |
| 2115 | EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation()); |
| 2116 | EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation()); |
| 2117 | } |
| 2118 | |
| 2119 | // Test that when the CVO extension isn't supported, video is rotated the |
| 2120 | // old-fashioned way, by encoding rotated frames. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2121 | TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2122 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2123 | ConnectFakeSignaling(); |
| 2124 | // Add rotated video tracks. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2125 | caller()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2126 | caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90)); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2127 | callee()->AddTrack( |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2128 | callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270)); |
| 2129 | |
| 2130 | // Remove the CVO extension from the offered SDP. |
| 2131 | callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) { |
| 2132 | cricket::VideoContentDescription* video = |
| 2133 | GetFirstVideoContentDescription(desc); |
| 2134 | video->ClearRtpHeaderExtensions(); |
| 2135 | }); |
| 2136 | // Wait for video frames to be received by both sides. |
| 2137 | caller()->CreateAndSetAndSignalOffer(); |
| 2138 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2139 | ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 && |
| 2140 | callee()->min_video_frames_received_per_track() > 0, |
| 2141 | kMaxWaitForFramesMs); |
| 2142 | |
| 2143 | // Expect that the aspect ratio is inversed to account for the 90/270 degree |
| 2144 | // rotation. |
| 2145 | // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test, |
| 2146 | // not just assumed. |
| 2147 | EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio()); |
| 2148 | EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio()); |
| 2149 | EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio()); |
| 2150 | EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio()); |
| 2151 | // Expect that each endpoint is unaware of the rotation of the other endpoint. |
| 2152 | EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation()); |
| 2153 | EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation()); |
| 2154 | } |
| 2155 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2156 | // Test that if the answerer rejects the audio m= section, no audio is sent or |
| 2157 | // received, but video still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2158 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2159 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2160 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2161 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2162 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2163 | // Only add video track for callee, and set offer_to_receive_audio to 0, so |
| 2164 | // it will reject the audio m= section completely. |
| 2165 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2166 | options.offer_to_receive_audio = 0; |
| 2167 | callee()->SetOfferAnswerOptions(options); |
| 2168 | } else { |
| 2169 | // Stopping the audio RtpTransceiver will cause the media section to be |
| 2170 | // rejected in the answer. |
| 2171 | callee()->SetRemoteOfferHandler([this] { |
| 2172 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)->Stop(); |
| 2173 | }); |
| 2174 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2175 | callee()->AddTrack(callee()->CreateLocalVideoTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2176 | // Do offer/answer and wait for successful end-to-end video frames. |
| 2177 | caller()->CreateAndSetAndSignalOffer(); |
| 2178 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2179 | MediaExpectations media_expectations; |
| 2180 | media_expectations.ExpectBidirectionalVideo(); |
| 2181 | media_expectations.ExpectNoAudio(); |
| 2182 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2183 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2184 | // Sanity check that the callee's description has a rejected audio section. |
| 2185 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2186 | const ContentInfo* callee_audio_content = |
| 2187 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2188 | ASSERT_NE(nullptr, callee_audio_content); |
| 2189 | EXPECT_TRUE(callee_audio_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2190 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2191 | // The caller's transceiver should have stopped after receiving the answer. |
| 2192 | EXPECT_TRUE(caller() |
| 2193 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO) |
| 2194 | ->stopped()); |
| 2195 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | // Test that if the answerer rejects the video m= section, no video is sent or |
| 2199 | // received, but audio still can be. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2200 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2201 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2202 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2203 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2204 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2205 | // Only add audio track for callee, and set offer_to_receive_video to 0, so |
| 2206 | // it will reject the video m= section completely. |
| 2207 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2208 | options.offer_to_receive_video = 0; |
| 2209 | callee()->SetOfferAnswerOptions(options); |
| 2210 | } else { |
| 2211 | // Stopping the video RtpTransceiver will cause the media section to be |
| 2212 | // rejected in the answer. |
| 2213 | callee()->SetRemoteOfferHandler([this] { |
| 2214 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2215 | }); |
| 2216 | } |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2217 | callee()->AddTrack(callee()->CreateLocalAudioTrack()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2218 | // Do offer/answer and wait for successful end-to-end audio frames. |
| 2219 | caller()->CreateAndSetAndSignalOffer(); |
| 2220 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2221 | MediaExpectations media_expectations; |
| 2222 | media_expectations.ExpectBidirectionalAudio(); |
| 2223 | media_expectations.ExpectNoVideo(); |
| 2224 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2225 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2226 | // Sanity check that the callee's description has a rejected video section. |
| 2227 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2228 | const ContentInfo* callee_video_content = |
| 2229 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2230 | ASSERT_NE(nullptr, callee_video_content); |
| 2231 | EXPECT_TRUE(callee_video_content->rejected); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2232 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 2233 | // The caller's transceiver should have stopped after receiving the answer. |
| 2234 | EXPECT_TRUE(caller() |
| 2235 | ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO) |
| 2236 | ->stopped()); |
| 2237 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | // Test that if the answerer rejects both audio and video m= sections, nothing |
| 2241 | // bad happens. |
| 2242 | // TODO(deadbeef): Test that a data channel still works. Currently this doesn't |
| 2243 | // test anything but the fact that negotiation succeeds, which doesn't mean |
| 2244 | // much. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2245 | TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2246 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2247 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2248 | caller()->AddAudioVideoTracks(); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2249 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2250 | // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it |
| 2251 | // will reject both audio and video m= sections. |
| 2252 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2253 | options.offer_to_receive_audio = 0; |
| 2254 | options.offer_to_receive_video = 0; |
| 2255 | callee()->SetOfferAnswerOptions(options); |
| 2256 | } else { |
| 2257 | callee()->SetRemoteOfferHandler([this] { |
| 2258 | // Stopping all transceivers will cause all media sections to be rejected. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2259 | for (const auto& transceiver : callee()->pc()->GetTransceivers()) { |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2260 | transceiver->Stop(); |
| 2261 | } |
| 2262 | }); |
| 2263 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2264 | // Do offer/answer and wait for stable signaling state. |
| 2265 | caller()->CreateAndSetAndSignalOffer(); |
| 2266 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2267 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2268 | // Sanity check that the callee's description has rejected m= sections. |
| 2269 | ASSERT_NE(nullptr, callee()->pc()->local_description()); |
| 2270 | const ContentInfo* callee_audio_content = |
| 2271 | GetFirstAudioContent(callee()->pc()->local_description()->description()); |
| 2272 | ASSERT_NE(nullptr, callee_audio_content); |
| 2273 | EXPECT_TRUE(callee_audio_content->rejected); |
| 2274 | const ContentInfo* callee_video_content = |
| 2275 | GetFirstVideoContent(callee()->pc()->local_description()->description()); |
| 2276 | ASSERT_NE(nullptr, callee_video_content); |
| 2277 | EXPECT_TRUE(callee_video_content->rejected); |
| 2278 | } |
| 2279 | |
| 2280 | // This test sets up an audio and video call between two parties. After the |
| 2281 | // call runs for a while, the caller sends an updated offer with video being |
| 2282 | // rejected. Once the re-negotiation is done, the video flow should stop and |
| 2283 | // the audio flow should continue. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2284 | TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2285 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2286 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2287 | caller()->AddAudioVideoTracks(); |
| 2288 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2289 | caller()->CreateAndSetAndSignalOffer(); |
| 2290 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2291 | { |
| 2292 | MediaExpectations media_expectations; |
| 2293 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2294 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2295 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2296 | // Renegotiate, rejecting the video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2297 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2298 | caller()->SetGeneratedSdpMunger( |
| 2299 | [](cricket::SessionDescription* description) { |
| 2300 | for (cricket::ContentInfo& content : description->contents()) { |
| 2301 | if (cricket::IsVideoContent(&content)) { |
| 2302 | content.rejected = true; |
| 2303 | } |
| 2304 | } |
| 2305 | }); |
| 2306 | } else { |
| 2307 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 2308 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2309 | caller()->CreateAndSetAndSignalOffer(); |
| 2310 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 2311 | |
| 2312 | // Sanity check that the caller's description has a rejected video section. |
| 2313 | ASSERT_NE(nullptr, caller()->pc()->local_description()); |
| 2314 | const ContentInfo* caller_video_content = |
| 2315 | GetFirstVideoContent(caller()->pc()->local_description()->description()); |
| 2316 | ASSERT_NE(nullptr, caller_video_content); |
| 2317 | EXPECT_TRUE(caller_video_content->rejected); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2318 | // Wait for some additional audio frames to be received. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2319 | { |
| 2320 | MediaExpectations media_expectations; |
| 2321 | media_expectations.ExpectBidirectionalAudio(); |
| 2322 | media_expectations.ExpectNoVideo(); |
| 2323 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2324 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Taylor Brandstetter | 60c8dc8 | 2018-04-11 15:20:27 -0700 | [diff] [blame] | 2327 | // Do one offer/answer with audio, another that disables it (rejecting the m= |
| 2328 | // section), and another that re-enables it. Regression test for: |
| 2329 | // bugs.webrtc.org/6023 |
| 2330 | TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) { |
| 2331 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2332 | ConnectFakeSignaling(); |
| 2333 | |
| 2334 | // Add audio track, do normal offer/answer. |
| 2335 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 2336 | caller()->CreateLocalAudioTrack(); |
| 2337 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
| 2338 | caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2339 | caller()->CreateAndSetAndSignalOffer(); |
| 2340 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2341 | |
| 2342 | // Remove audio track, and set offer_to_receive_audio to false to cause the |
| 2343 | // m= section to be completely disabled, not just "recvonly". |
| 2344 | caller()->pc()->RemoveTrack(sender); |
| 2345 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2346 | options.offer_to_receive_audio = 0; |
| 2347 | caller()->SetOfferAnswerOptions(options); |
| 2348 | caller()->CreateAndSetAndSignalOffer(); |
| 2349 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2350 | |
| 2351 | // Add the audio track again, expecting negotiation to succeed and frames to |
| 2352 | // flow. |
| 2353 | sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue(); |
| 2354 | options.offer_to_receive_audio = 1; |
| 2355 | caller()->SetOfferAnswerOptions(options); |
| 2356 | caller()->CreateAndSetAndSignalOffer(); |
| 2357 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2358 | |
| 2359 | MediaExpectations media_expectations; |
| 2360 | media_expectations.CalleeExpectsSomeAudio(); |
| 2361 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2362 | } |
| 2363 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2364 | // Basic end-to-end test, but without SSRC/MSID signaling. This functionality |
| 2365 | // is needed to support legacy endpoints. |
| 2366 | // TODO(deadbeef): When we support the MID extension and demuxing on MID, also |
| 2367 | // add a test for an end-to-end test without MID signaling either (basically, |
| 2368 | // the minimum acceptable SDP). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2369 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2370 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2371 | ConnectFakeSignaling(); |
| 2372 | // 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] | 2373 | caller()->AddAudioVideoTracks(); |
| 2374 | callee()->AddAudioVideoTracks(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2375 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2376 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2377 | caller()->CreateAndSetAndSignalOffer(); |
| 2378 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2379 | MediaExpectations media_expectations; |
| 2380 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2381 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 2384 | // Basic end-to-end test, without SSRC signaling. This means that the track |
| 2385 | // was created properly and frames are delivered when the MSIDs are communicated |
| 2386 | // with a=msid lines and no a=ssrc lines. |
| 2387 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2388 | EndToEndCallWithoutSsrcSignaling) { |
| 2389 | const char kStreamId[] = "streamId"; |
| 2390 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2391 | ConnectFakeSignaling(); |
| 2392 | // Add just audio tracks. |
| 2393 | caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId}); |
| 2394 | callee()->AddAudioTrack(); |
| 2395 | |
| 2396 | // Remove SSRCs from the received offer SDP. |
| 2397 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids); |
| 2398 | caller()->CreateAndSetAndSignalOffer(); |
| 2399 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2400 | MediaExpectations media_expectations; |
| 2401 | media_expectations.ExpectBidirectionalAudio(); |
| 2402 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2403 | } |
| 2404 | |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2405 | // Tests that video flows between multiple video tracks when SSRCs are not |
| 2406 | // signaled. This exercises the MID RTP header extension which is needed to |
| 2407 | // demux the incoming video tracks. |
| 2408 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2409 | EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) { |
| 2410 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2411 | ConnectFakeSignaling(); |
| 2412 | caller()->AddVideoTrack(); |
| 2413 | caller()->AddVideoTrack(); |
| 2414 | callee()->AddVideoTrack(); |
| 2415 | callee()->AddVideoTrack(); |
| 2416 | |
| 2417 | caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2418 | callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids); |
| 2419 | caller()->CreateAndSetAndSignalOffer(); |
| 2420 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2421 | ASSERT_EQ(2u, caller()->pc()->GetReceivers().size()); |
| 2422 | ASSERT_EQ(2u, callee()->pc()->GetReceivers().size()); |
| 2423 | |
| 2424 | // Expect video to be received in both directions on both tracks. |
| 2425 | MediaExpectations media_expectations; |
| 2426 | media_expectations.ExpectBidirectionalVideo(); |
| 2427 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 2428 | } |
| 2429 | |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 2430 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLinePresent) { |
| 2431 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2432 | ConnectFakeSignaling(); |
| 2433 | caller()->AddAudioTrack(); |
| 2434 | caller()->AddVideoTrack(); |
| 2435 | caller()->CreateAndSetAndSignalOffer(); |
| 2436 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2437 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2438 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2439 | EXPECT_TRUE(callee_receivers[0]->stream_ids().empty()); |
| 2440 | EXPECT_TRUE(callee_receivers[1]->stream_ids().empty()); |
| 2441 | } |
| 2442 | |
| 2443 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, NoStreamsMsidLineMissing) { |
| 2444 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2445 | ConnectFakeSignaling(); |
| 2446 | caller()->AddAudioTrack(); |
| 2447 | caller()->AddVideoTrack(); |
| 2448 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2449 | caller()->CreateAndSetAndSignalOffer(); |
| 2450 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2451 | auto callee_receivers = callee()->pc()->GetReceivers(); |
| 2452 | ASSERT_EQ(2u, callee_receivers.size()); |
| 2453 | ASSERT_EQ(1u, callee_receivers[0]->stream_ids().size()); |
| 2454 | ASSERT_EQ(1u, callee_receivers[1]->stream_ids().size()); |
| 2455 | EXPECT_EQ(callee_receivers[0]->stream_ids()[0], |
| 2456 | callee_receivers[1]->stream_ids()[0]); |
| 2457 | EXPECT_EQ(callee_receivers[0]->streams()[0], |
| 2458 | callee_receivers[1]->streams()[0]); |
| 2459 | } |
| 2460 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2461 | // Test that if two video tracks are sent (from caller to callee, in this test), |
| 2462 | // they're transmitted correctly end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2463 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2464 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2465 | ConnectFakeSignaling(); |
| 2466 | // Add one audio/video stream, and one video-only stream. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2467 | caller()->AddAudioVideoTracks(); |
| 2468 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2469 | caller()->CreateAndSetAndSignalOffer(); |
| 2470 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2471 | ASSERT_EQ(3u, callee()->pc()->GetReceivers().size()); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2472 | |
| 2473 | MediaExpectations media_expectations; |
| 2474 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2475 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) { |
| 2479 | bool first = true; |
| 2480 | for (cricket::ContentInfo& content : desc->contents()) { |
| 2481 | if (first) { |
| 2482 | first = false; |
| 2483 | continue; |
| 2484 | } |
| 2485 | content.bundle_only = true; |
| 2486 | } |
| 2487 | first = true; |
| 2488 | for (cricket::TransportInfo& transport : desc->transport_infos()) { |
| 2489 | if (first) { |
| 2490 | first = false; |
| 2491 | continue; |
| 2492 | } |
| 2493 | transport.description.ice_ufrag.clear(); |
| 2494 | transport.description.ice_pwd.clear(); |
| 2495 | transport.description.connection_role = cricket::CONNECTIONROLE_NONE; |
| 2496 | transport.description.identity_fingerprint.reset(nullptr); |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | // Test that if applying a true "max bundle" offer, which uses ports of 0, |
| 2501 | // "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and |
| 2502 | // "a=ice-pwd" for all but the audio "m=" section, negotiation still completes |
| 2503 | // successfully and media flows. |
| 2504 | // TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works. |
| 2505 | // TODO(deadbeef): Won't need this test once we start generating actual |
| 2506 | // standards-compliant SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2507 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2508 | EndToEndCallWithSpecCompliantMaxBundleOffer) { |
| 2509 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2510 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2511 | caller()->AddAudioVideoTracks(); |
| 2512 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2513 | // Do the equivalent of setting the port to 0, adding a=bundle-only, and |
| 2514 | // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all |
| 2515 | // but the first m= section. |
| 2516 | callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer); |
| 2517 | caller()->CreateAndSetAndSignalOffer(); |
| 2518 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2519 | MediaExpectations media_expectations; |
| 2520 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2521 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | // Test that we can receive the audio output level from a remote audio track. |
| 2525 | // TODO(deadbeef): Use a fake audio source and verify that the output level is |
| 2526 | // exactly what the source on the other side was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2527 | TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2528 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2529 | ConnectFakeSignaling(); |
| 2530 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2531 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2532 | caller()->CreateAndSetAndSignalOffer(); |
| 2533 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2534 | |
| 2535 | // Get the audio output level stats. Note that the level is not available |
| 2536 | // until an RTCP packet has been received. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2537 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2538 | kMaxWaitForFramesMs); |
| 2539 | } |
| 2540 | |
| 2541 | // Test that an audio input level is reported. |
| 2542 | // TODO(deadbeef): Use a fake audio source and verify that the input level is |
| 2543 | // exactly what the source was configured with. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2544 | TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2545 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2546 | ConnectFakeSignaling(); |
| 2547 | // Just add an audio track. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2548 | caller()->AddAudioTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2549 | caller()->CreateAndSetAndSignalOffer(); |
| 2550 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2551 | |
| 2552 | // Get the audio input level stats. The level should be available very |
| 2553 | // soon after the test starts. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2554 | EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2555 | kMaxWaitForStatsMs); |
| 2556 | } |
| 2557 | |
| 2558 | // 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] | 2559 | TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2560 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2561 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2562 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2563 | // Do offer/answer, wait for the callee to receive some frames. |
| 2564 | caller()->CreateAndSetAndSignalOffer(); |
| 2565 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2566 | |
| 2567 | MediaExpectations media_expectations; |
| 2568 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2569 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2570 | |
| 2571 | // Get a handle to the remote tracks created, so they can be used as GetStats |
| 2572 | // filters. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2573 | for (const auto& receiver : callee()->pc()->GetReceivers()) { |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2574 | // We received frames, so we definitely should have nonzero "received bytes" |
| 2575 | // stats at this point. |
| 2576 | EXPECT_GT(callee()->OldGetStatsForTrack(receiver->track())->BytesReceived(), |
| 2577 | 0); |
| 2578 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | // 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] | 2582 | TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2583 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2584 | ConnectFakeSignaling(); |
| 2585 | auto audio_track = caller()->CreateLocalAudioTrack(); |
| 2586 | auto video_track = caller()->CreateLocalVideoTrack(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2587 | caller()->AddTrack(audio_track); |
| 2588 | caller()->AddTrack(video_track); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2589 | // Do offer/answer, wait for the callee to receive some frames. |
| 2590 | caller()->CreateAndSetAndSignalOffer(); |
| 2591 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2592 | MediaExpectations media_expectations; |
| 2593 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2594 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2595 | |
| 2596 | // The callee received frames, so we definitely should have nonzero "sent |
| 2597 | // bytes" stats at this point. |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2598 | EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0); |
| 2599 | EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0); |
| 2600 | } |
| 2601 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2602 | // Test that we can get capture start ntp time. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2603 | TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) { |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2604 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2605 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2606 | caller()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2607 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2608 | callee()->AddAudioTrack(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2609 | |
| 2610 | // Do offer/answer, wait for the callee to receive some frames. |
| 2611 | caller()->CreateAndSetAndSignalOffer(); |
| 2612 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2613 | |
| 2614 | // Get the remote audio track created on the receiver, so they can be used as |
| 2615 | // GetStats filters. |
Steve Anton | fc85371 | 2018-03-01 13:48:58 -0800 | [diff] [blame] | 2616 | auto receivers = callee()->pc()->GetReceivers(); |
| 2617 | ASSERT_EQ(1u, receivers.size()); |
| 2618 | auto remote_audio_track = receivers[0]->track(); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2619 | |
| 2620 | // Get the audio output level stats. Note that the level is not available |
| 2621 | // until an RTCP packet has been received. |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 2622 | EXPECT_TRUE_WAIT( |
| 2623 | callee()->OldGetStatsForTrack(remote_audio_track)->CaptureStartNtpTime() > |
| 2624 | 0, |
| 2625 | 2 * kMaxWaitForFramesMs); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 2626 | } |
| 2627 | |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 2628 | // Test that the track ID is associated with all local and remote SSRC stats |
| 2629 | // using the old GetStats() and more than 1 audio and more than 1 video track. |
| 2630 | // This is a regression test for crbug.com/906988 |
| 2631 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 2632 | OldGetStatsAssociatesTrackIdForManyMediaSections) { |
| 2633 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2634 | ConnectFakeSignaling(); |
| 2635 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 2636 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 2637 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 2638 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 2639 | caller()->CreateAndSetAndSignalOffer(); |
| 2640 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2641 | |
| 2642 | MediaExpectations media_expectations; |
| 2643 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2644 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 2645 | |
| 2646 | std::vector<std::string> track_ids = { |
| 2647 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 2648 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 2649 | |
| 2650 | auto caller_stats = caller()->OldGetStats(); |
| 2651 | EXPECT_THAT(caller_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 2652 | auto callee_stats = callee()->OldGetStats(); |
| 2653 | EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids)); |
| 2654 | } |
| 2655 | |
Steve Anton | ffa6ce4 | 2018-11-30 09:26:08 -0800 | [diff] [blame] | 2656 | // Test that the new GetStats() returns stats for all outgoing/incoming streams |
| 2657 | // with the correct track IDs if there are more than one audio and more than one |
| 2658 | // video senders/receivers. |
| 2659 | TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) { |
| 2660 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2661 | ConnectFakeSignaling(); |
| 2662 | auto audio_sender_1 = caller()->AddAudioTrack(); |
| 2663 | auto video_sender_1 = caller()->AddVideoTrack(); |
| 2664 | auto audio_sender_2 = caller()->AddAudioTrack(); |
| 2665 | auto video_sender_2 = caller()->AddVideoTrack(); |
| 2666 | caller()->CreateAndSetAndSignalOffer(); |
| 2667 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2668 | |
| 2669 | MediaExpectations media_expectations; |
| 2670 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 2671 | ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout); |
| 2672 | |
| 2673 | std::vector<std::string> track_ids = { |
| 2674 | audio_sender_1->track()->id(), video_sender_1->track()->id(), |
| 2675 | audio_sender_2->track()->id(), video_sender_2->track()->id()}; |
| 2676 | |
| 2677 | rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report = |
| 2678 | caller()->NewGetStats(); |
| 2679 | ASSERT_TRUE(caller_report); |
| 2680 | auto outbound_stream_stats = |
| 2681 | caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>(); |
| 2682 | ASSERT_EQ(4u, outbound_stream_stats.size()); |
| 2683 | std::vector<std::string> outbound_track_ids; |
| 2684 | for (const auto& stat : outbound_stream_stats) { |
| 2685 | ASSERT_TRUE(stat->bytes_sent.is_defined()); |
| 2686 | EXPECT_LT(0u, *stat->bytes_sent); |
| 2687 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 2688 | const auto* track_stat = |
| 2689 | caller_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 2690 | ASSERT_TRUE(track_stat); |
| 2691 | outbound_track_ids.push_back(*track_stat->track_identifier); |
| 2692 | } |
| 2693 | EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 2694 | |
| 2695 | rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report = |
| 2696 | callee()->NewGetStats(); |
| 2697 | ASSERT_TRUE(callee_report); |
| 2698 | auto inbound_stream_stats = |
| 2699 | callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2700 | ASSERT_EQ(4u, inbound_stream_stats.size()); |
| 2701 | std::vector<std::string> inbound_track_ids; |
| 2702 | for (const auto& stat : inbound_stream_stats) { |
| 2703 | ASSERT_TRUE(stat->bytes_received.is_defined()); |
| 2704 | EXPECT_LT(0u, *stat->bytes_received); |
| 2705 | ASSERT_TRUE(stat->track_id.is_defined()); |
| 2706 | const auto* track_stat = |
| 2707 | callee_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id); |
| 2708 | ASSERT_TRUE(track_stat); |
| 2709 | inbound_track_ids.push_back(*track_stat->track_identifier); |
| 2710 | } |
| 2711 | EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids)); |
| 2712 | } |
| 2713 | |
| 2714 | // Test that we can get stats (using the new stats implementation) for |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2715 | // unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in |
| 2716 | // SDP. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2717 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2718 | GetStatsForUnsignaledStreamWithNewStatsApi) { |
| 2719 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2720 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2721 | caller()->AddAudioTrack(); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2722 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2723 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2724 | caller()->CreateAndSetAndSignalOffer(); |
| 2725 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2726 | MediaExpectations media_expectations; |
| 2727 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2728 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2729 | |
| 2730 | // We received a frame, so we should have nonzero "bytes received" stats for |
| 2731 | // the unsignaled stream, if stats are working for it. |
| 2732 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2733 | callee()->NewGetStats(); |
| 2734 | ASSERT_NE(nullptr, report); |
| 2735 | auto inbound_stream_stats = |
| 2736 | report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2737 | ASSERT_EQ(1U, inbound_stream_stats.size()); |
| 2738 | ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined()); |
| 2739 | ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2740 | ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined()); |
| 2741 | } |
| 2742 | |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 2743 | // Same as above but for the legacy stats implementation. |
| 2744 | TEST_P(PeerConnectionIntegrationTest, |
| 2745 | GetStatsForUnsignaledStreamWithOldStatsApi) { |
| 2746 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2747 | ConnectFakeSignaling(); |
| 2748 | caller()->AddAudioTrack(); |
| 2749 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2750 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2751 | caller()->CreateAndSetAndSignalOffer(); |
| 2752 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2753 | |
| 2754 | // Note that, since the old stats implementation associates SSRCs with tracks |
| 2755 | // using SDP, when SSRCs aren't signaled in SDP these stats won't have an |
| 2756 | // associated track ID. So we can't use the track "selector" argument. |
| 2757 | // |
| 2758 | // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to |
| 2759 | // 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] | 2760 | EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0, |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 2761 | kDefaultTimeout); |
| 2762 | } |
| 2763 | |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2764 | // Test that we can successfully get the media related stats (audio level |
| 2765 | // etc.) for the unsignaled stream. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2766 | TEST_P(PeerConnectionIntegrationTest, |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2767 | GetMediaStatsForUnsignaledStreamWithNewStatsApi) { |
| 2768 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2769 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2770 | caller()->AddAudioVideoTracks(); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2771 | // Remove SSRCs and MSIDs from the received offer SDP. |
| 2772 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2773 | caller()->CreateAndSetAndSignalOffer(); |
| 2774 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2775 | MediaExpectations media_expectations; |
| 2776 | media_expectations.CalleeExpectsSomeAudio(1); |
| 2777 | media_expectations.CalleeExpectsSomeVideo(1); |
| 2778 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
zhihuang | f816493 | 2017-05-19 13:09:47 -0700 | [diff] [blame] | 2779 | |
| 2780 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2781 | callee()->NewGetStats(); |
| 2782 | ASSERT_NE(nullptr, report); |
| 2783 | |
| 2784 | auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2785 | auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats); |
| 2786 | ASSERT_GE(audio_index, 0); |
| 2787 | EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2790 | // Helper for test below. |
| 2791 | void ModifySsrcs(cricket::SessionDescription* desc) { |
| 2792 | for (ContentInfo& content : desc->contents()) { |
Steve Anton | df527fd | 2018-04-27 15:52:03 -0700 | [diff] [blame] | 2793 | for (StreamParams& stream : |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2794 | content.media_description()->mutable_streams()) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2795 | for (uint32_t& ssrc : stream.ssrcs) { |
| 2796 | ssrc = rtc::CreateRandomId(); |
| 2797 | } |
| 2798 | } |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | // Test that the "RTCMediaSteamTrackStats" object is updated correctly when |
| 2803 | // SSRCs are unsignaled, and the SSRC of the received (audio) stream changes. |
| 2804 | // This should result in two "RTCInboundRTPStreamStats", but only one |
| 2805 | // "RTCMediaStreamTrackStats", whose counters go up continuously rather than |
| 2806 | // being reset to 0 once the SSRC change occurs. |
| 2807 | // |
| 2808 | // Regression test for this bug: |
| 2809 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8158 |
| 2810 | // |
| 2811 | // The bug causes the track stats to only represent one of the two streams: |
| 2812 | // whichever one has the higher SSRC. So with this bug, there was a 50% chance |
| 2813 | // that the track stat counters would reset to 0 when the new stream is |
| 2814 | // received, and a 50% chance that they'll stop updating (while |
| 2815 | // "concealed_samples" continues increasing, due to silence being generated for |
| 2816 | // the inactive stream). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2817 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2818 | TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) { |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2819 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 2820 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2821 | caller()->AddAudioTrack(); |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2822 | // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint |
| 2823 | // that doesn't signal SSRCs (from the callee's perspective). |
| 2824 | callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids); |
| 2825 | caller()->CreateAndSetAndSignalOffer(); |
| 2826 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2827 | // 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] | 2828 | { |
| 2829 | MediaExpectations media_expectations; |
| 2830 | media_expectations.CalleeExpectsSomeAudio(50); |
| 2831 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2832 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2833 | // Some audio frames were received, so we should have nonzero "samples |
| 2834 | // received" for the track. |
| 2835 | rtc::scoped_refptr<const webrtc::RTCStatsReport> report = |
| 2836 | callee()->NewGetStats(); |
| 2837 | ASSERT_NE(nullptr, report); |
| 2838 | auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2839 | ASSERT_EQ(1U, track_stats.size()); |
| 2840 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 2841 | ASSERT_GT(*track_stats[0]->total_samples_received, 0U); |
| 2842 | // uint64_t prev_samples_received = *track_stats[0]->total_samples_received; |
| 2843 | |
| 2844 | // Create a new offer and munge it to cause the caller to use a new SSRC. |
| 2845 | caller()->SetGeneratedSdpMunger(ModifySsrcs); |
| 2846 | caller()->CreateAndSetAndSignalOffer(); |
| 2847 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 2848 | // Wait for 25 more audio frames (250ms of audio) to be received, from the new |
| 2849 | // SSRC. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2850 | { |
| 2851 | MediaExpectations media_expectations; |
| 2852 | media_expectations.CalleeExpectsSomeAudio(25); |
| 2853 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 2854 | } |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2855 | |
| 2856 | report = callee()->NewGetStats(); |
| 2857 | ASSERT_NE(nullptr, report); |
| 2858 | track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 2859 | ASSERT_EQ(1U, track_stats.size()); |
| 2860 | ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined()); |
| 2861 | // The "total samples received" stat should only be greater than it was |
| 2862 | // before. |
| 2863 | // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed. |
| 2864 | // Right now, the new SSRC will cause the counters to reset to 0. |
| 2865 | // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received); |
| 2866 | |
| 2867 | // Additionally, the percentage of concealed samples (samples generated to |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2868 | // 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] | 2869 | // good sign that we're seeing stats from the old stream that's no longer |
| 2870 | // receiving packets, and is generating concealed samples of silence. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 2871 | constexpr double kAcceptableConcealedSamplesPercentage = 0.50; |
deadbeef | 4e2deab | 2017-09-20 13:56:21 -0700 | [diff] [blame] | 2872 | ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined()); |
| 2873 | EXPECT_LT(*track_stats[0]->concealed_samples, |
| 2874 | *track_stats[0]->total_samples_received * |
| 2875 | kAcceptableConcealedSamplesPercentage); |
| 2876 | |
| 2877 | // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a |
| 2878 | // sanity check that the SSRC really changed. |
| 2879 | // TODO(deadbeef): This isn't working right now, because we're not returning |
| 2880 | // *any* stats for the inactive stream. Uncomment when the bug is completely |
| 2881 | // fixed. |
| 2882 | // auto inbound_stream_stats = |
| 2883 | // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>(); |
| 2884 | // ASSERT_EQ(2U, inbound_stream_stats.size()); |
| 2885 | } |
| 2886 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2887 | // 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] | 2888 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2889 | PeerConnectionFactory::Options dtls_10_options; |
| 2890 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 2891 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 2892 | dtls_10_options)); |
| 2893 | ConnectFakeSignaling(); |
| 2894 | // Do normal offer/answer and wait for some frames to be received in each |
| 2895 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2896 | caller()->AddAudioVideoTracks(); |
| 2897 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2898 | caller()->CreateAndSetAndSignalOffer(); |
| 2899 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2900 | MediaExpectations media_expectations; |
| 2901 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2902 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | // 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] | 2906 | TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2907 | PeerConnectionFactory::Options dtls_10_options; |
| 2908 | dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 2909 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options, |
| 2910 | dtls_10_options)); |
| 2911 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2912 | caller()->AddAudioVideoTracks(); |
| 2913 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2914 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2915 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2916 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2917 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2918 | kDefaultTimeout); |
| 2919 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2920 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2921 | // TODO(bugs.webrtc.org/9456): Fix it. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 2922 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2923 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 2924 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | // 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] | 2928 | TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2929 | PeerConnectionFactory::Options dtls_12_options; |
| 2930 | dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 2931 | ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options, |
| 2932 | dtls_12_options)); |
| 2933 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2934 | caller()->AddAudioVideoTracks(); |
| 2935 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2936 | caller()->CreateAndSetAndSignalOffer(); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2937 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2938 | EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher( |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2939 | caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2940 | kDefaultTimeout); |
| 2941 | EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 2942 | caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout); |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2943 | // TODO(bugs.webrtc.org/9456): Fix it. |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 2944 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 2945 | "WebRTC.PeerConnection.SrtpCryptoSuite.Audio", |
| 2946 | kDefaultSrtpCryptoSuite)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | // Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the |
| 2950 | // callee only supports 1.0. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2951 | TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2952 | PeerConnectionFactory::Options caller_options; |
| 2953 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 2954 | PeerConnectionFactory::Options callee_options; |
| 2955 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 2956 | ASSERT_TRUE( |
| 2957 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 2958 | ConnectFakeSignaling(); |
| 2959 | // Do normal offer/answer and wait for some frames to be received in each |
| 2960 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2961 | caller()->AddAudioVideoTracks(); |
| 2962 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2963 | caller()->CreateAndSetAndSignalOffer(); |
| 2964 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2965 | MediaExpectations media_expectations; |
| 2966 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2967 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | // Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the |
| 2971 | // callee supports 1.2. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2972 | TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2973 | PeerConnectionFactory::Options caller_options; |
| 2974 | caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10; |
| 2975 | PeerConnectionFactory::Options callee_options; |
| 2976 | callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; |
| 2977 | ASSERT_TRUE( |
| 2978 | CreatePeerConnectionWrappersWithOptions(caller_options, callee_options)); |
| 2979 | ConnectFakeSignaling(); |
| 2980 | // Do normal offer/answer and wait for some frames to be received in each |
| 2981 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 2982 | caller()->AddAudioVideoTracks(); |
| 2983 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2984 | caller()->CreateAndSetAndSignalOffer(); |
| 2985 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 2986 | MediaExpectations media_expectations; |
| 2987 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 2988 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 2991 | // The three tests below verify that "enable_aes128_sha1_32_crypto_cipher" |
| 2992 | // works as expected; the cipher should only be used if enabled by both sides. |
| 2993 | TEST_P(PeerConnectionIntegrationTest, |
| 2994 | Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) { |
| 2995 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 2996 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 2997 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 2998 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 2999 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3000 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3001 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3002 | expected_cipher_suite); |
| 3003 | } |
| 3004 | |
| 3005 | TEST_P(PeerConnectionIntegrationTest, |
| 3006 | Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) { |
| 3007 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3008 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 3009 | false; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3010 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3011 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3012 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80; |
| 3013 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3014 | expected_cipher_suite); |
| 3015 | } |
| 3016 | |
| 3017 | TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) { |
| 3018 | PeerConnectionFactory::Options caller_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3019 | caller_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3020 | PeerConnectionFactory::Options callee_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3021 | callee_options.crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher = true; |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 3022 | int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_32; |
| 3023 | TestNegotiatedCipherSuite(caller_options, callee_options, |
| 3024 | expected_cipher_suite); |
| 3025 | } |
| 3026 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3027 | // 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] | 3028 | TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3029 | bool local_gcm_enabled = false; |
| 3030 | bool remote_gcm_enabled = false; |
| 3031 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 3032 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
| 3033 | expected_cipher_suite); |
| 3034 | } |
| 3035 | |
| 3036 | // Test that a GCM cipher is used if both ends support it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3037 | TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenGcmSupported) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3038 | bool local_gcm_enabled = true; |
| 3039 | bool remote_gcm_enabled = true; |
| 3040 | int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm; |
| 3041 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
| 3042 | expected_cipher_suite); |
| 3043 | } |
| 3044 | |
| 3045 | // Test that GCM isn't used if only the offerer supports it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3046 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3047 | NonGcmCipherUsedWhenOnlyCallerSupportsGcm) { |
| 3048 | bool local_gcm_enabled = true; |
| 3049 | bool remote_gcm_enabled = false; |
| 3050 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 3051 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
| 3052 | expected_cipher_suite); |
| 3053 | } |
| 3054 | |
| 3055 | // Test that GCM isn't used if only the answerer supports it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3056 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3057 | NonGcmCipherUsedWhenOnlyCalleeSupportsGcm) { |
| 3058 | bool local_gcm_enabled = false; |
| 3059 | bool remote_gcm_enabled = true; |
| 3060 | int expected_cipher_suite = kDefaultSrtpCryptoSuite; |
| 3061 | TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled, |
| 3062 | expected_cipher_suite); |
| 3063 | } |
| 3064 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3065 | // Verify that media can be transmitted end-to-end when GCM crypto suites are |
| 3066 | // enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported, |
| 3067 | // only verify that a GCM cipher is negotiated, and not necessarily that SRTP |
| 3068 | // works with it. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3069 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3070 | PeerConnectionFactory::Options gcm_options; |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 3071 | gcm_options.crypto_options.srtp.enable_gcm_crypto_suites = true; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3072 | ASSERT_TRUE( |
| 3073 | CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options)); |
| 3074 | ConnectFakeSignaling(); |
| 3075 | // Do normal offer/answer and wait for some frames to be received in each |
| 3076 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3077 | caller()->AddAudioVideoTracks(); |
| 3078 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3079 | caller()->CreateAndSetAndSignalOffer(); |
| 3080 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3081 | MediaExpectations media_expectations; |
| 3082 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3083 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3086 | // This test sets up a call between two parties with audio, video and an RTP |
| 3087 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3088 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithRtpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3089 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3090 | rtc_config.enable_rtp_data_channel = true; |
| 3091 | rtc_config.enable_dtls_srtp = false; |
| 3092 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3093 | ConnectFakeSignaling(); |
| 3094 | // Expect that data channel created on caller side will show up for callee as |
| 3095 | // well. |
| 3096 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3097 | caller()->AddAudioVideoTracks(); |
| 3098 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3099 | caller()->CreateAndSetAndSignalOffer(); |
| 3100 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3101 | // 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] | 3102 | MediaExpectations media_expectations; |
| 3103 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3104 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3105 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3106 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3107 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3108 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3109 | |
| 3110 | // Ensure data can be sent in both directions. |
| 3111 | std::string data = "hello world"; |
| 3112 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3113 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3114 | kDefaultTimeout); |
| 3115 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3116 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3117 | kDefaultTimeout); |
| 3118 | } |
| 3119 | |
| 3120 | // Ensure that an RTP data channel is signaled as closed for the caller when |
| 3121 | // the callee rejects it in a subsequent offer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3122 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3123 | RtpDataChannelSignaledClosedInCalleeOffer) { |
| 3124 | // Same procedure as above test. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3125 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3126 | rtc_config.enable_rtp_data_channel = true; |
| 3127 | rtc_config.enable_dtls_srtp = false; |
| 3128 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3129 | ConnectFakeSignaling(); |
| 3130 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3131 | caller()->AddAudioVideoTracks(); |
| 3132 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3133 | caller()->CreateAndSetAndSignalOffer(); |
| 3134 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3135 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3136 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3137 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3138 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3139 | |
| 3140 | // Close the data channel on the callee, and do an updated offer/answer. |
| 3141 | callee()->data_channel()->Close(); |
| 3142 | callee()->CreateAndSetAndSignalOffer(); |
| 3143 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3144 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3145 | EXPECT_FALSE(callee()->data_observer()->IsOpen()); |
| 3146 | } |
| 3147 | |
| 3148 | // Tests that data is buffered in an RTP data channel until an observer is |
| 3149 | // registered for it. |
| 3150 | // |
| 3151 | // NOTE: RTP data channels can receive data before the underlying |
| 3152 | // transport has detected that a channel is writable and thus data can be |
| 3153 | // received before the data channel state changes to open. That is hard to test |
| 3154 | // but the same buffering is expected to be used in that case. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3155 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3156 | DataBufferedUntilRtpDataChannelObserverRegistered) { |
| 3157 | // Use fake clock and simulated network delay so that we predictably can wait |
| 3158 | // until an SCTP message has been delivered without "sleep()"ing. |
| 3159 | rtc::ScopedFakeClock fake_clock; |
| 3160 | // Some things use a time of "0" as a special value, so we need to start out |
| 3161 | // the fake clock at a nonzero time. |
| 3162 | // TODO(deadbeef): Fix this. |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 3163 | fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3164 | virtual_socket_server()->set_delay_mean(5); // 5 ms per hop. |
| 3165 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3166 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3167 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3168 | rtc_config.enable_rtp_data_channel = true; |
| 3169 | rtc_config.enable_dtls_srtp = false; |
| 3170 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3171 | ConnectFakeSignaling(); |
| 3172 | caller()->CreateDataChannel(); |
| 3173 | caller()->CreateAndSetAndSignalOffer(); |
| 3174 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
| 3175 | ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr, |
| 3176 | kDefaultTimeout, fake_clock); |
| 3177 | ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(), |
| 3178 | kDefaultTimeout, fake_clock); |
| 3179 | ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen, |
| 3180 | callee()->data_channel()->state(), kDefaultTimeout, |
| 3181 | fake_clock); |
| 3182 | |
| 3183 | // Unregister the observer which is normally automatically registered. |
| 3184 | callee()->data_channel()->UnregisterObserver(); |
| 3185 | // Send data and advance fake clock until it should have been received. |
| 3186 | std::string data = "hello world"; |
| 3187 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3188 | SIMULATED_WAIT(false, 50, fake_clock); |
| 3189 | |
| 3190 | // Attach data channel and expect data to be received immediately. Note that |
| 3191 | // EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any |
| 3192 | // further, but data can be received even if the callback is asynchronous. |
| 3193 | MockDataChannelObserver new_observer(callee()->data_channel()); |
| 3194 | EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout, |
| 3195 | fake_clock); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 3196 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 3197 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 3198 | // negative number is calculated for the rtt due to the global clock changing. |
| 3199 | caller()->pc()->Close(); |
| 3200 | callee()->pc()->Close(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | // This test sets up a call between two parties with audio, video and but only |
| 3204 | // the caller client supports RTP data channels. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3205 | TEST_P(PeerConnectionIntegrationTest, RtpDataChannelsRejectedByCallee) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3206 | PeerConnectionInterface::RTCConfiguration rtc_config_1; |
| 3207 | rtc_config_1.enable_rtp_data_channel = true; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3208 | // Must disable DTLS to make negotiation succeed. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3209 | rtc_config_1.enable_dtls_srtp = false; |
| 3210 | PeerConnectionInterface::RTCConfiguration rtc_config_2; |
| 3211 | rtc_config_2.enable_dtls_srtp = false; |
| 3212 | rtc_config_2.enable_dtls_srtp = false; |
| 3213 | ASSERT_TRUE( |
| 3214 | CreatePeerConnectionWrappersWithConfig(rtc_config_1, rtc_config_2)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3215 | ConnectFakeSignaling(); |
| 3216 | caller()->CreateDataChannel(); |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 3217 | ASSERT_TRUE(caller()->data_channel() != nullptr); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3218 | caller()->AddAudioVideoTracks(); |
| 3219 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3220 | caller()->CreateAndSetAndSignalOffer(); |
| 3221 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3222 | // The caller should still have a data channel, but it should be closed, and |
| 3223 | // one should ever have been created for the callee. |
| 3224 | EXPECT_TRUE(caller()->data_channel() != nullptr); |
| 3225 | EXPECT_FALSE(caller()->data_observer()->IsOpen()); |
| 3226 | EXPECT_EQ(nullptr, callee()->data_channel()); |
| 3227 | } |
| 3228 | |
| 3229 | // This test sets up a call between two parties with audio, and video. When |
| 3230 | // 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] | 3231 | TEST_P(PeerConnectionIntegrationTest, AddRtpDataChannelInSubsequentOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3232 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3233 | rtc_config.enable_rtp_data_channel = true; |
| 3234 | rtc_config.enable_dtls_srtp = false; |
| 3235 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(rtc_config, rtc_config)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3236 | ConnectFakeSignaling(); |
| 3237 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3238 | caller()->AddAudioVideoTracks(); |
| 3239 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3240 | caller()->CreateAndSetAndSignalOffer(); |
| 3241 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3242 | // Create data channel and do new offer and answer. |
| 3243 | caller()->CreateDataChannel(); |
| 3244 | caller()->CreateAndSetAndSignalOffer(); |
| 3245 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3246 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3247 | ASSERT_NE(nullptr, callee()->data_channel()); |
| 3248 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3249 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3250 | // Ensure data can be sent in both directions. |
| 3251 | std::string data = "hello world"; |
| 3252 | SendRtpDataWithRetries(caller()->data_channel(), data, 5); |
| 3253 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3254 | kDefaultTimeout); |
| 3255 | SendRtpDataWithRetries(callee()->data_channel(), data, 5); |
| 3256 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3257 | kDefaultTimeout); |
| 3258 | } |
| 3259 | |
| 3260 | #ifdef HAVE_SCTP |
| 3261 | |
| 3262 | // This test sets up a call between two parties with audio, video and an SCTP |
| 3263 | // data channel. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3264 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3265 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3266 | ConnectFakeSignaling(); |
| 3267 | // Expect that data channel created on caller side will show up for callee as |
| 3268 | // well. |
| 3269 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3270 | caller()->AddAudioVideoTracks(); |
| 3271 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3272 | caller()->CreateAndSetAndSignalOffer(); |
| 3273 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3274 | // 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] | 3275 | MediaExpectations media_expectations; |
| 3276 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3277 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3278 | // Caller data channel should already exist (it created one). Callee data |
| 3279 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3280 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3281 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3282 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3283 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3284 | |
| 3285 | // Ensure data can be sent in both directions. |
| 3286 | std::string data = "hello world"; |
| 3287 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3288 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3289 | kDefaultTimeout); |
| 3290 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3291 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3292 | kDefaultTimeout); |
| 3293 | } |
| 3294 | |
| 3295 | // Ensure that when the callee closes an SCTP data channel, the closing |
| 3296 | // 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] | 3297 | TEST_P(PeerConnectionIntegrationTest, CalleeClosesSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3298 | // Same procedure as above test. |
| 3299 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3300 | ConnectFakeSignaling(); |
| 3301 | caller()->CreateDataChannel(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3302 | caller()->AddAudioVideoTracks(); |
| 3303 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3304 | caller()->CreateAndSetAndSignalOffer(); |
| 3305 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3306 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3307 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3308 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3309 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3310 | |
| 3311 | // Close the data channel on the callee side, and wait for it to reach the |
| 3312 | // "closed" state on both sides. |
| 3313 | callee()->data_channel()->Close(); |
| 3314 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3315 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3316 | } |
| 3317 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3318 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelConfigSentToOtherSide) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3319 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3320 | ConnectFakeSignaling(); |
| 3321 | webrtc::DataChannelInit init; |
| 3322 | init.id = 53; |
| 3323 | init.maxRetransmits = 52; |
| 3324 | caller()->CreateDataChannel("data-channel", &init); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3325 | caller()->AddAudioVideoTracks(); |
| 3326 | callee()->AddAudioVideoTracks(); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3327 | caller()->CreateAndSetAndSignalOffer(); |
| 3328 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | 074dece | 2017-10-24 13:04:12 -0700 | [diff] [blame] | 3329 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3330 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 3331 | // Since "negotiated" is false, the "id" parameter should be ignored. |
| 3332 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 3333 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 3334 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 3335 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 3336 | } |
| 3337 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3338 | // Test usrsctp's ability to process unordered data stream, where data actually |
| 3339 | // arrives out of order using simulated delays. Previously there have been some |
| 3340 | // bugs in this area. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3341 | TEST_P(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3342 | // Introduce random network delays. |
| 3343 | // Otherwise it's not a true "unordered" test. |
| 3344 | virtual_socket_server()->set_delay_mean(20); |
| 3345 | virtual_socket_server()->set_delay_stddev(5); |
| 3346 | virtual_socket_server()->UpdateDelayDistribution(); |
| 3347 | // Normal procedure, but with unordered data channel config. |
| 3348 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3349 | ConnectFakeSignaling(); |
| 3350 | webrtc::DataChannelInit init; |
| 3351 | init.ordered = false; |
| 3352 | caller()->CreateDataChannel(&init); |
| 3353 | caller()->CreateAndSetAndSignalOffer(); |
| 3354 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3355 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3356 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3357 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3358 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3359 | |
| 3360 | static constexpr int kNumMessages = 100; |
| 3361 | // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 3362 | static constexpr size_t kMaxMessageSize = 4096; |
| 3363 | // Create and send random messages. |
| 3364 | std::vector<std::string> sent_messages; |
| 3365 | for (int i = 0; i < kNumMessages; ++i) { |
| 3366 | size_t length = |
| 3367 | (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand) |
| 3368 | std::string message; |
| 3369 | ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 3370 | caller()->data_channel()->Send(DataBuffer(message)); |
| 3371 | callee()->data_channel()->Send(DataBuffer(message)); |
| 3372 | sent_messages.push_back(message); |
| 3373 | } |
| 3374 | |
| 3375 | // Wait for all messages to be received. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3376 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3377 | caller()->data_observer()->received_message_count(), |
| 3378 | kDefaultTimeout); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3379 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3380 | callee()->data_observer()->received_message_count(), |
| 3381 | kDefaultTimeout); |
| 3382 | |
| 3383 | // Sort and compare to make sure none of the messages were corrupted. |
| 3384 | std::vector<std::string> caller_received_messages = |
| 3385 | caller()->data_observer()->messages(); |
| 3386 | std::vector<std::string> callee_received_messages = |
| 3387 | callee()->data_observer()->messages(); |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 3388 | absl::c_sort(sent_messages); |
| 3389 | absl::c_sort(caller_received_messages); |
| 3390 | absl::c_sort(callee_received_messages); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3391 | EXPECT_EQ(sent_messages, caller_received_messages); |
| 3392 | EXPECT_EQ(sent_messages, callee_received_messages); |
| 3393 | } |
| 3394 | |
| 3395 | // This test sets up a call between two parties with audio, and video. When |
| 3396 | // 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] | 3397 | TEST_P(PeerConnectionIntegrationTest, AddSctpDataChannelInSubsequentOffer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3398 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3399 | ConnectFakeSignaling(); |
| 3400 | // Do initial offer/answer with audio/video. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3401 | caller()->AddAudioVideoTracks(); |
| 3402 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3403 | caller()->CreateAndSetAndSignalOffer(); |
| 3404 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3405 | // Create data channel and do new offer and answer. |
| 3406 | caller()->CreateDataChannel(); |
| 3407 | caller()->CreateAndSetAndSignalOffer(); |
| 3408 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3409 | // Caller data channel should already exist (it created one). Callee data |
| 3410 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3411 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3412 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3413 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3414 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3415 | // Ensure data can be sent in both directions. |
| 3416 | std::string data = "hello world"; |
| 3417 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3418 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3419 | kDefaultTimeout); |
| 3420 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3421 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3422 | kDefaultTimeout); |
| 3423 | } |
| 3424 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3425 | // Set up a connection initially just using SCTP data channels, later upgrading |
| 3426 | // to audio/video, ensuring frames are received end-to-end. Effectively the |
| 3427 | // inverse of the test above. |
| 3428 | // This was broken in M57; see https://crbug.com/711243 |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3429 | TEST_P(PeerConnectionIntegrationTest, SctpDataChannelToAudioVideoUpgrade) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3430 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3431 | ConnectFakeSignaling(); |
| 3432 | // Do initial offer/answer with just data channel. |
| 3433 | caller()->CreateDataChannel(); |
| 3434 | caller()->CreateAndSetAndSignalOffer(); |
| 3435 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3436 | // Wait until data can be sent over the data channel. |
| 3437 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3438 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3439 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3440 | |
| 3441 | // Do subsequent offer/answer with two-way audio and video. Audio and video |
| 3442 | // 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] | 3443 | caller()->AddAudioVideoTracks(); |
| 3444 | callee()->AddAudioVideoTracks(); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3445 | caller()->CreateAndSetAndSignalOffer(); |
| 3446 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3447 | MediaExpectations media_expectations; |
| 3448 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3449 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3452 | static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) { |
Harald Alvestrand | 141c0ad | 2019-05-05 19:00:00 +0000 | [diff] [blame] | 3453 | cricket::DataContentDescription* dcd_offer = |
| 3454 | GetFirstDataContentDescription(desc); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 3455 | ASSERT_TRUE(dcd_offer); |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3456 | dcd_offer->set_use_sctpmap(false); |
| 3457 | dcd_offer->set_protocol("UDP/DTLS/SCTP"); |
| 3458 | } |
| 3459 | |
| 3460 | // Test that the data channel works when a spec-compliant SCTP m= section is |
| 3461 | // offered (using "a=sctp-port" instead of "a=sctpmap", and using |
| 3462 | // "UDP/DTLS/SCTP" as the protocol). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3463 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 3464 | DataChannelWorksWhenSpecCompliantSctpOfferReceived) { |
| 3465 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3466 | ConnectFakeSignaling(); |
| 3467 | caller()->CreateDataChannel(); |
| 3468 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 3469 | caller()->CreateAndSetAndSignalOffer(); |
| 3470 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3471 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3472 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3473 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3474 | |
| 3475 | // Ensure data can be sent in both directions. |
| 3476 | std::string data = "hello world"; |
| 3477 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3478 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3479 | kDefaultTimeout); |
| 3480 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3481 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3482 | kDefaultTimeout); |
| 3483 | } |
| 3484 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3485 | #endif // HAVE_SCTP |
| 3486 | |
Bjorn Mellem | a2eb0a7 | 2018-11-09 10:13:51 -0800 | [diff] [blame] | 3487 | // This test sets up a call between two parties with a media transport data |
| 3488 | // channel. |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 3489 | TEST_P(PeerConnectionIntegrationTest, MediaTransportDataChannelEndToEnd) { |
| 3490 | PeerConnectionInterface::RTCConfiguration rtc_config; |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 3491 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3492 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 3493 | rtc_config.use_media_transport_for_data_channels = true; |
| 3494 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3495 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3496 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3497 | loopback_media_transports()->second_factory())); |
| 3498 | ConnectFakeSignaling(); |
| 3499 | |
| 3500 | // Expect that data channel created on caller side will show up for callee as |
| 3501 | // well. |
| 3502 | caller()->CreateDataChannel(); |
| 3503 | caller()->CreateAndSetAndSignalOffer(); |
| 3504 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3505 | |
| 3506 | // Ensure that the media transport is ready. |
| 3507 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3508 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3509 | |
| 3510 | // Caller data channel should already exist (it created one). Callee data |
| 3511 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 3512 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3513 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3514 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3515 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3516 | |
| 3517 | // Ensure data can be sent in both directions. |
| 3518 | std::string data = "hello world"; |
| 3519 | caller()->data_channel()->Send(DataBuffer(data)); |
| 3520 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 3521 | kDefaultTimeout); |
| 3522 | callee()->data_channel()->Send(DataBuffer(data)); |
| 3523 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 3524 | kDefaultTimeout); |
| 3525 | } |
| 3526 | |
| 3527 | // Ensure that when the callee closes a media transport data channel, the |
| 3528 | // closing procedure results in the data channel being closed for the caller |
| 3529 | // as well. |
| 3530 | TEST_P(PeerConnectionIntegrationTest, MediaTransportDataChannelCalleeCloses) { |
| 3531 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3532 | rtc_config.use_media_transport_for_data_channels = true; |
| 3533 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3534 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3535 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3536 | loopback_media_transports()->second_factory())); |
| 3537 | ConnectFakeSignaling(); |
| 3538 | |
| 3539 | // Create a data channel on the caller and signal it to the callee. |
| 3540 | caller()->CreateDataChannel(); |
| 3541 | caller()->CreateAndSetAndSignalOffer(); |
| 3542 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3543 | |
| 3544 | // Ensure that the media transport is ready. |
| 3545 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3546 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3547 | |
| 3548 | // Data channels exist and open on both ends of the connection. |
| 3549 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 3550 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3551 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3552 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3553 | |
| 3554 | // Close the data channel on the callee side, and wait for it to reach the |
| 3555 | // "closed" state on both sides. |
| 3556 | callee()->data_channel()->Close(); |
| 3557 | EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3558 | EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 3559 | } |
| 3560 | |
| 3561 | TEST_P(PeerConnectionIntegrationTest, |
| 3562 | MediaTransportDataChannelConfigSentToOtherSide) { |
| 3563 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3564 | rtc_config.use_media_transport_for_data_channels = true; |
| 3565 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3566 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3567 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3568 | loopback_media_transports()->second_factory())); |
| 3569 | ConnectFakeSignaling(); |
| 3570 | |
| 3571 | // Create a data channel with a non-default configuration and signal it to the |
| 3572 | // callee. |
| 3573 | webrtc::DataChannelInit init; |
| 3574 | init.id = 53; |
| 3575 | init.maxRetransmits = 52; |
| 3576 | caller()->CreateDataChannel("data-channel", &init); |
| 3577 | caller()->CreateAndSetAndSignalOffer(); |
| 3578 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3579 | |
| 3580 | // Ensure that the media transport is ready. |
| 3581 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3582 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3583 | |
| 3584 | // Ensure that the data channel exists on the callee with the correct |
| 3585 | // configuration. |
| 3586 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 3587 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 3588 | // Since "negotiate" is false, the "id" parameter is ignored. |
| 3589 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 3590 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 3591 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 3592 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 3593 | } |
| 3594 | |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 3595 | TEST_P(PeerConnectionIntegrationTest, MediaTransportOfferUpgrade) { |
| 3596 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3597 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3598 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3599 | rtc_config.use_media_transport = true; |
| 3600 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3601 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3602 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3603 | loopback_media_transports()->second_factory())); |
| 3604 | ConnectFakeSignaling(); |
| 3605 | |
| 3606 | // Do initial offer/answer with just a video track. |
| 3607 | caller()->AddVideoTrack(); |
| 3608 | callee()->AddVideoTrack(); |
| 3609 | caller()->CreateAndSetAndSignalOffer(); |
| 3610 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3611 | |
| 3612 | // Ensure that the media transport is ready. |
| 3613 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3614 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3615 | |
| 3616 | // Now add an audio track and do another offer/answer. |
| 3617 | caller()->AddAudioTrack(); |
| 3618 | callee()->AddAudioTrack(); |
| 3619 | caller()->CreateAndSetAndSignalOffer(); |
| 3620 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3621 | |
| 3622 | // Ensure both audio and video frames are received end-to-end. |
| 3623 | MediaExpectations media_expectations; |
| 3624 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3625 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3626 | |
| 3627 | // The second offer should not have generated another media transport. |
| 3628 | // Media transport was kept alive, and was not recreated. |
| 3629 | EXPECT_EQ(1, loopback_media_transports()->first_factory_transport_count()); |
| 3630 | EXPECT_EQ(1, loopback_media_transports()->second_factory_transport_count()); |
| 3631 | } |
| 3632 | |
| 3633 | TEST_P(PeerConnectionIntegrationTest, MediaTransportOfferUpgradeOnTheCallee) { |
| 3634 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3635 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3636 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3637 | rtc_config.use_media_transport = true; |
| 3638 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3639 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3640 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3641 | loopback_media_transports()->second_factory())); |
| 3642 | ConnectFakeSignaling(); |
| 3643 | |
| 3644 | // Do initial offer/answer with just a video track. |
| 3645 | caller()->AddVideoTrack(); |
| 3646 | callee()->AddVideoTrack(); |
| 3647 | caller()->CreateAndSetAndSignalOffer(); |
| 3648 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3649 | |
| 3650 | // Ensure that the media transport is ready. |
| 3651 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3652 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3653 | |
| 3654 | // Now add an audio track and do another offer/answer. |
| 3655 | caller()->AddAudioTrack(); |
| 3656 | callee()->AddAudioTrack(); |
| 3657 | callee()->CreateAndSetAndSignalOffer(); |
| 3658 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3659 | |
| 3660 | // Ensure both audio and video frames are received end-to-end. |
| 3661 | MediaExpectations media_expectations; |
| 3662 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 3663 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3664 | |
| 3665 | // The second offer should not have generated another media transport. |
| 3666 | // Media transport was kept alive, and was not recreated. |
| 3667 | EXPECT_EQ(1, loopback_media_transports()->first_factory_transport_count()); |
| 3668 | EXPECT_EQ(1, loopback_media_transports()->second_factory_transport_count()); |
| 3669 | } |
| 3670 | |
Niels Möller | c68d282 | 2018-11-20 14:52:05 +0100 | [diff] [blame] | 3671 | TEST_P(PeerConnectionIntegrationTest, MediaTransportBidirectionalAudio) { |
| 3672 | PeerConnectionInterface::RTCConfiguration rtc_config; |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 3673 | rtc_config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3674 | rtc_config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
Niels Möller | c68d282 | 2018-11-20 14:52:05 +0100 | [diff] [blame] | 3675 | rtc_config.use_media_transport = true; |
| 3676 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3677 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3678 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3679 | loopback_media_transports()->second_factory())); |
| 3680 | ConnectFakeSignaling(); |
| 3681 | |
| 3682 | caller()->AddAudioTrack(); |
| 3683 | callee()->AddAudioTrack(); |
| 3684 | // Start offer/answer exchange and wait for it to complete. |
| 3685 | caller()->CreateAndSetAndSignalOffer(); |
| 3686 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3687 | |
| 3688 | // Ensure that the media transport is ready. |
| 3689 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3690 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3691 | |
| 3692 | MediaExpectations media_expectations; |
| 3693 | media_expectations.ExpectBidirectionalAudio(); |
| 3694 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3695 | |
| 3696 | webrtc::MediaTransportPair::Stats first_stats = |
| 3697 | loopback_media_transports()->FirstStats(); |
| 3698 | webrtc::MediaTransportPair::Stats second_stats = |
| 3699 | loopback_media_transports()->SecondStats(); |
| 3700 | |
| 3701 | EXPECT_GT(first_stats.received_audio_frames, 0); |
| 3702 | EXPECT_GE(second_stats.sent_audio_frames, first_stats.received_audio_frames); |
| 3703 | |
| 3704 | EXPECT_GT(second_stats.received_audio_frames, 0); |
| 3705 | EXPECT_GE(first_stats.sent_audio_frames, second_stats.received_audio_frames); |
| 3706 | } |
| 3707 | |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 3708 | TEST_P(PeerConnectionIntegrationTest, MediaTransportBidirectionalVideo) { |
| 3709 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3710 | rtc_config.use_media_transport = true; |
| 3711 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3712 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3713 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3714 | loopback_media_transports()->second_factory())); |
| 3715 | ConnectFakeSignaling(); |
| 3716 | |
| 3717 | caller()->AddVideoTrack(); |
| 3718 | callee()->AddVideoTrack(); |
| 3719 | // Start offer/answer exchange and wait for it to complete. |
| 3720 | caller()->CreateAndSetAndSignalOffer(); |
| 3721 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3722 | |
| 3723 | // Ensure that the media transport is ready. |
| 3724 | loopback_media_transports()->SetState(webrtc::MediaTransportState::kWritable); |
| 3725 | loopback_media_transports()->FlushAsyncInvokes(); |
| 3726 | |
| 3727 | MediaExpectations media_expectations; |
| 3728 | media_expectations.ExpectBidirectionalVideo(); |
| 3729 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3730 | |
| 3731 | webrtc::MediaTransportPair::Stats first_stats = |
| 3732 | loopback_media_transports()->FirstStats(); |
| 3733 | webrtc::MediaTransportPair::Stats second_stats = |
| 3734 | loopback_media_transports()->SecondStats(); |
| 3735 | |
| 3736 | EXPECT_GT(first_stats.received_video_frames, 0); |
| 3737 | EXPECT_GE(second_stats.sent_video_frames, first_stats.received_video_frames); |
| 3738 | |
| 3739 | EXPECT_GT(second_stats.received_video_frames, 0); |
| 3740 | EXPECT_GE(first_stats.sent_video_frames, second_stats.received_video_frames); |
| 3741 | } |
| 3742 | |
Piotr (Peter) Slatala | 55b91b9 | 2019-01-25 13:31:15 -0800 | [diff] [blame] | 3743 | TEST_P(PeerConnectionIntegrationTest, |
| 3744 | MediaTransportDataChannelUsesRtpBidirectionalVideo) { |
| 3745 | PeerConnectionInterface::RTCConfiguration rtc_config; |
| 3746 | rtc_config.use_media_transport = false; |
| 3747 | rtc_config.use_media_transport_for_data_channels = true; |
| 3748 | rtc_config.enable_dtls_srtp = false; // SDES is required for media transport. |
| 3749 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndMediaTransportFactory( |
| 3750 | rtc_config, rtc_config, loopback_media_transports()->first_factory(), |
| 3751 | loopback_media_transports()->second_factory())); |
| 3752 | ConnectFakeSignaling(); |
| 3753 | |
| 3754 | caller()->AddVideoTrack(); |
| 3755 | callee()->AddVideoTrack(); |
| 3756 | // Start offer/answer exchange and wait for it to complete. |
| 3757 | caller()->CreateAndSetAndSignalOffer(); |
| 3758 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3759 | |
| 3760 | MediaExpectations media_expectations; |
| 3761 | media_expectations.ExpectBidirectionalVideo(); |
| 3762 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 3763 | } |
| 3764 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3765 | // Test that the ICE connection and gathering states eventually reach |
| 3766 | // "complete". |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3767 | TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3768 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 3769 | ConnectFakeSignaling(); |
| 3770 | // Do normal offer/answer. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3771 | caller()->AddAudioVideoTracks(); |
| 3772 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3773 | caller()->CreateAndSetAndSignalOffer(); |
| 3774 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3775 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 3776 | caller()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 3777 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 3778 | callee()->ice_gathering_state(), kMaxWaitForFramesMs); |
| 3779 | // After the best candidate pair is selected and all candidates are signaled, |
| 3780 | // the ICE connection state should reach "complete". |
| 3781 | // TODO(deadbeef): Currently, the ICE "controlled" agent (the |
| 3782 | // answerer/"callee" by default) only reaches "connected". When this is |
| 3783 | // fixed, this test should be updated. |
| 3784 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 3785 | caller()->ice_connection_state(), kDefaultTimeout); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 3786 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 3787 | callee()->ice_connection_state(), kDefaultTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 3790 | constexpr int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3791 | cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 3792 | cricket::PORTALLOCATOR_DISABLE_TCP; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 3793 | |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 3794 | // Use a mock resolver to resolve the hostname back to the original IP on both |
| 3795 | // sides and check that the ICE connection connects. |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 3796 | TEST_P(PeerConnectionIntegrationTest, |
| 3797 | IceStatesReachCompletionWithRemoteHostname) { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 3798 | auto caller_resolver_factory = |
| 3799 | absl::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
| 3800 | auto callee_resolver_factory = |
| 3801 | absl::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>(); |
| 3802 | NiceMock<rtc::MockAsyncResolver> callee_async_resolver; |
| 3803 | NiceMock<rtc::MockAsyncResolver> caller_async_resolver; |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 3804 | |
| 3805 | // This also verifies that the injected AsyncResolverFactory is used by |
| 3806 | // P2PTransportChannel. |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 3807 | EXPECT_CALL(*caller_resolver_factory, Create()) |
| 3808 | .WillOnce(Return(&caller_async_resolver)); |
| 3809 | webrtc::PeerConnectionDependencies caller_deps(nullptr); |
| 3810 | caller_deps.async_resolver_factory = std::move(caller_resolver_factory); |
| 3811 | |
| 3812 | EXPECT_CALL(*callee_resolver_factory, Create()) |
| 3813 | .WillOnce(Return(&callee_async_resolver)); |
| 3814 | webrtc::PeerConnectionDependencies callee_deps(nullptr); |
| 3815 | callee_deps.async_resolver_factory = std::move(callee_resolver_factory); |
| 3816 | |
| 3817 | PeerConnectionInterface::RTCConfiguration config; |
| 3818 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3819 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 3820 | |
| 3821 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 3822 | config, std::move(caller_deps), config, std::move(callee_deps))); |
| 3823 | |
| 3824 | caller()->SetRemoteAsyncResolver(&callee_async_resolver); |
| 3825 | callee()->SetRemoteAsyncResolver(&caller_async_resolver); |
| 3826 | |
| 3827 | // Enable hostname candidates with mDNS names. |
| 3828 | caller()->network()->CreateMdnsResponder(network_thread()); |
| 3829 | callee()->network()->CreateMdnsResponder(network_thread()); |
| 3830 | |
| 3831 | SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 3832 | |
| 3833 | ConnectFakeSignaling(); |
| 3834 | caller()->AddAudioVideoTracks(); |
| 3835 | callee()->AddAudioVideoTracks(); |
| 3836 | caller()->CreateAndSetAndSignalOffer(); |
| 3837 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 3838 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 3839 | caller()->ice_connection_state(), kDefaultTimeout); |
| 3840 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 3841 | callee()->ice_connection_state(), kDefaultTimeout); |
Jeroen de Borst | 833979f | 2018-12-13 08:25:54 -0800 | [diff] [blame] | 3842 | |
| 3843 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
| 3844 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 3845 | webrtc::kIceCandidatePairHostNameHostName)); |
Zach Stein | 6fcdc2f | 2018-08-23 16:25:55 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3848 | // Test that firewalling the ICE connection causes the clients to identify the |
| 3849 | // disconnected state and then removing the firewall causes them to reconnect. |
| 3850 | class PeerConnectionIntegrationIceStatesTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3851 | : public PeerConnectionIntegrationBaseTest, |
| 3852 | public ::testing::WithParamInterface< |
| 3853 | std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3854 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 3855 | PeerConnectionIntegrationIceStatesTest() |
| 3856 | : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) { |
| 3857 | port_allocator_flags_ = std::get<1>(std::get<1>(GetParam())); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | void StartStunServer(const SocketAddress& server_address) { |
| 3861 | stun_server_.reset( |
| 3862 | cricket::TestStunServer::Create(network_thread(), server_address)); |
| 3863 | } |
| 3864 | |
| 3865 | bool TestIPv6() { |
| 3866 | return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 3867 | } |
| 3868 | |
| 3869 | void SetPortAllocatorFlags() { |
Qingsi Wang | 1dac6d8 | 2018-12-12 15:28:47 -0800 | [diff] [blame] | 3870 | PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( |
| 3871 | port_allocator_flags_, port_allocator_flags_); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | std::vector<SocketAddress> CallerAddresses() { |
| 3875 | std::vector<SocketAddress> addresses; |
| 3876 | addresses.push_back(SocketAddress("1.1.1.1", 0)); |
| 3877 | if (TestIPv6()) { |
| 3878 | addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0)); |
| 3879 | } |
| 3880 | return addresses; |
| 3881 | } |
| 3882 | |
| 3883 | std::vector<SocketAddress> CalleeAddresses() { |
| 3884 | std::vector<SocketAddress> addresses; |
| 3885 | addresses.push_back(SocketAddress("2.2.2.2", 0)); |
| 3886 | if (TestIPv6()) { |
| 3887 | addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0)); |
| 3888 | } |
| 3889 | return addresses; |
| 3890 | } |
| 3891 | |
| 3892 | void SetUpNetworkInterfaces() { |
| 3893 | // Remove the default interfaces added by the test infrastructure. |
| 3894 | caller()->network()->RemoveInterface(kDefaultLocalAddress); |
| 3895 | callee()->network()->RemoveInterface(kDefaultLocalAddress); |
| 3896 | |
| 3897 | // Add network addresses for test. |
| 3898 | for (const auto& caller_address : CallerAddresses()) { |
| 3899 | caller()->network()->AddInterface(caller_address); |
| 3900 | } |
| 3901 | for (const auto& callee_address : CalleeAddresses()) { |
| 3902 | callee()->network()->AddInterface(callee_address); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | private: |
| 3907 | uint32_t port_allocator_flags_; |
| 3908 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
| 3909 | }; |
| 3910 | |
| 3911 | // Tests that the PeerConnection goes through all the ICE gathering/connection |
| 3912 | // states over the duration of the call. This includes Disconnected and Failed |
| 3913 | // states, induced by putting a firewall between the peers and waiting for them |
| 3914 | // to time out. |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 3915 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) { |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 3916 | rtc::ScopedFakeClock fake_clock; |
| 3917 | // Some things use a time of "0" as a special value, so we need to start out |
| 3918 | // the fake clock at a nonzero time. |
| 3919 | fake_clock.AdvanceTime(TimeDelta::seconds(1)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3920 | |
| 3921 | const SocketAddress kStunServerAddress = |
| 3922 | SocketAddress("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 3923 | StartStunServer(kStunServerAddress); |
| 3924 | |
| 3925 | PeerConnectionInterface::RTCConfiguration config; |
| 3926 | PeerConnectionInterface::IceServer ice_stun_server; |
| 3927 | ice_stun_server.urls.push_back( |
| 3928 | "stun:" + kStunServerAddress.HostAsURIString() + ":" + |
| 3929 | kStunServerAddress.PortAsString()); |
| 3930 | config.servers.push_back(ice_stun_server); |
| 3931 | |
| 3932 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 3933 | ConnectFakeSignaling(); |
| 3934 | SetPortAllocatorFlags(); |
| 3935 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 3936 | caller()->AddAudioVideoTracks(); |
| 3937 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3938 | |
| 3939 | // Initial state before anything happens. |
| 3940 | ASSERT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 3941 | caller()->ice_gathering_state()); |
| 3942 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 3943 | caller()->ice_connection_state()); |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 3944 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 3945 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3946 | |
| 3947 | // Start the call by creating the offer, setting it as the local description, |
| 3948 | // then sending it to the peer who will respond with an answer. This happens |
| 3949 | // asynchronously so that we can watch the states as it runs in the |
| 3950 | // background. |
| 3951 | caller()->CreateAndSetAndSignalOffer(); |
| 3952 | |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 3953 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, |
| 3954 | caller()->ice_connection_state()); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 3955 | ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | 7a6739e | 2019-01-15 16:31:55 +0100 | [diff] [blame] | 3956 | caller()->standardized_ice_connection_state()); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3957 | |
| 3958 | // Verify that the observer was notified of the intermediate transitions. |
| 3959 | EXPECT_THAT(caller()->ice_connection_state_history(), |
| 3960 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 3961 | PeerConnectionInterface::kIceConnectionConnected, |
| 3962 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 3963 | EXPECT_THAT(caller()->standardized_ice_connection_state_history(), |
| 3964 | ElementsAre(PeerConnectionInterface::kIceConnectionChecking, |
| 3965 | PeerConnectionInterface::kIceConnectionConnected, |
| 3966 | PeerConnectionInterface::kIceConnectionCompleted)); |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 3967 | EXPECT_THAT( |
| 3968 | caller()->peer_connection_state_history(), |
| 3969 | ElementsAre(PeerConnectionInterface::PeerConnectionState::kConnecting, |
Jonas Olsson | 635474e | 2018-10-18 15:58:17 +0200 | [diff] [blame] | 3970 | PeerConnectionInterface::PeerConnectionState::kConnected)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3971 | EXPECT_THAT(caller()->ice_gathering_state_history(), |
| 3972 | ElementsAre(PeerConnectionInterface::kIceGatheringGathering, |
| 3973 | PeerConnectionInterface::kIceGatheringComplete)); |
| 3974 | |
| 3975 | // Block connections to/from the caller and wait for ICE to become |
| 3976 | // disconnected. |
| 3977 | for (const auto& caller_address : CallerAddresses()) { |
| 3978 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 3979 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 3980 | RTC_LOG(LS_INFO) << "Firewall rules applied"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 3981 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 3982 | caller()->ice_connection_state(), kDefaultTimeout, |
| 3983 | fake_clock); |
| 3984 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 3985 | caller()->standardized_ice_connection_state(), |
| 3986 | kDefaultTimeout, fake_clock); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3987 | |
| 3988 | // Let ICE re-establish by removing the firewall rules. |
| 3989 | firewall()->ClearRules(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 3990 | RTC_LOG(LS_INFO) << "Firewall rules cleared"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 3991 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 3992 | caller()->ice_connection_state(), kDefaultTimeout, |
| 3993 | fake_clock); |
Jonas Olsson | acd8ae7 | 2019-02-25 15:26:24 +0100 | [diff] [blame] | 3994 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 3995 | caller()->standardized_ice_connection_state(), |
| 3996 | kDefaultTimeout, fake_clock); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 3997 | |
| 3998 | // According to RFC7675, if there is no response within 30 seconds then the |
| 3999 | // peer should consider the other side to have rejected the connection. This |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4000 | // is signaled by the state transitioning to "failed". |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4001 | constexpr int kConsentTimeout = 30000; |
| 4002 | for (const auto& caller_address : CallerAddresses()) { |
| 4003 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4004 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 4005 | RTC_LOG(LS_INFO) << "Firewall rules applied again"; |
Jonas Olsson | b75d9e9 | 2019-02-22 10:33:29 +0100 | [diff] [blame] | 4006 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4007 | caller()->ice_connection_state(), kConsentTimeout, |
| 4008 | fake_clock); |
| 4009 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4010 | caller()->standardized_ice_connection_state(), |
| 4011 | kConsentTimeout, fake_clock); |
| 4012 | |
| 4013 | // We need to manually close the peerconnections before the fake clock goes |
| 4014 | // out of scope, or we trigger a DCHECK in rtp_sender.cc when we briefly |
| 4015 | // return to using non-faked time. |
| 4016 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 4017 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
| 4018 | } |
| 4019 | |
| 4020 | // Tests that if the connection doesn't get set up properly we eventually reach |
| 4021 | // the "failed" iceConnectionState. |
| 4022 | TEST_P(PeerConnectionIntegrationIceStatesTest, IceStateSetupFailure) { |
| 4023 | rtc::ScopedFakeClock fake_clock; |
| 4024 | // Some things use a time of "0" as a special value, so we need to start out |
| 4025 | // the fake clock at a nonzero time. |
| 4026 | fake_clock.AdvanceTime(TimeDelta::seconds(1)); |
| 4027 | |
| 4028 | // Block connections to/from the caller and wait for ICE to become |
| 4029 | // disconnected. |
| 4030 | for (const auto& caller_address : CallerAddresses()) { |
| 4031 | firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); |
| 4032 | } |
| 4033 | |
| 4034 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4035 | ConnectFakeSignaling(); |
| 4036 | SetPortAllocatorFlags(); |
| 4037 | SetUpNetworkInterfaces(); |
| 4038 | caller()->AddAudioVideoTracks(); |
| 4039 | caller()->CreateAndSetAndSignalOffer(); |
| 4040 | |
| 4041 | // According to RFC7675, if there is no response within 30 seconds then the |
| 4042 | // peer should consider the other side to have rejected the connection. This |
| 4043 | // is signaled by the state transitioning to "failed". |
| 4044 | constexpr int kConsentTimeout = 30000; |
| 4045 | ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionFailed, |
| 4046 | caller()->standardized_ice_connection_state(), |
| 4047 | kConsentTimeout, fake_clock); |
| 4048 | |
| 4049 | // We need to manually close the peerconnections before the fake clock goes |
| 4050 | // out of scope, or we trigger a DCHECK in rtp_sender.cc when we briefly |
| 4051 | // return to using non-faked time. |
| 4052 | delete SetCallerPcWrapperAndReturnCurrent(nullptr); |
| 4053 | delete SetCalleePcWrapperAndReturnCurrent(nullptr); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | // Tests that the best connection is set to the appropriate IPv4/IPv6 connection |
| 4057 | // and that the statistics in the metric observers are updated correctly. |
| 4058 | TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyBestConnection) { |
| 4059 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4060 | ConnectFakeSignaling(); |
| 4061 | SetPortAllocatorFlags(); |
| 4062 | SetUpNetworkInterfaces(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4063 | caller()->AddAudioVideoTracks(); |
| 4064 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4065 | caller()->CreateAndSetAndSignalOffer(); |
| 4066 | |
| 4067 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4068 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 4069 | // TODO(bugs.webrtc.org/9456): Fix it. |
| 4070 | const int num_best_ipv4 = webrtc::metrics::NumEvents( |
| 4071 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv4); |
| 4072 | const int num_best_ipv6 = webrtc::metrics::NumEvents( |
| 4073 | "WebRTC.PeerConnection.IPMetrics", webrtc::kBestConnections_IPv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4074 | if (TestIPv6()) { |
| 4075 | // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4 |
| 4076 | // connection. |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 4077 | EXPECT_EQ(0, num_best_ipv4); |
| 4078 | EXPECT_EQ(1, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4079 | } else { |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 4080 | EXPECT_EQ(1, num_best_ipv4); |
| 4081 | EXPECT_EQ(0, num_best_ipv6); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4082 | } |
| 4083 | |
Qingsi Wang | 7fc821d | 2018-07-12 12:54:53 -0700 | [diff] [blame] | 4084 | EXPECT_EQ(0, webrtc::metrics::NumEvents( |
| 4085 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4086 | webrtc::kIceCandidatePairHostHost)); |
| 4087 | EXPECT_EQ(1, webrtc::metrics::NumEvents( |
| 4088 | "WebRTC.PeerConnection.CandidatePairType_UDP", |
| 4089 | webrtc::kIceCandidatePairHostPublicHostPublic)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP | |
| 4093 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4094 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4095 | constexpr uint32_t kFlagsIPv6NoStun = |
| 4096 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 4097 | cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4098 | constexpr uint32_t kFlagsIPv4Stun = |
| 4099 | cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY; |
| 4100 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 4101 | INSTANTIATE_TEST_SUITE_P( |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4102 | PeerConnectionIntegrationTest, |
| 4103 | PeerConnectionIntegrationIceStatesTest, |
| 4104 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 4105 | Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun), |
| 4106 | std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun), |
| 4107 | std::make_pair("IPv4 with STUN", kFlagsIPv4Stun)))); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4108 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4109 | // This test sets up a call between two parties with audio and video. |
| 4110 | // During the call, the caller restarts ICE and the test verifies that |
| 4111 | // new ICE candidates are generated and audio and video still can flow, and the |
| 4112 | // ICE state reaches completed again. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4113 | TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4114 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4115 | ConnectFakeSignaling(); |
| 4116 | // Do normal offer/answer and wait for ICE to complete. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4117 | caller()->AddAudioVideoTracks(); |
| 4118 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4119 | caller()->CreateAndSetAndSignalOffer(); |
| 4120 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4121 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4122 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4123 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4124 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4125 | |
| 4126 | // To verify that the ICE restart actually occurs, get |
| 4127 | // ufrag/password/candidates before and after restart. |
| 4128 | // Create an SDP string of the first audio candidate for both clients. |
| 4129 | const webrtc::IceCandidateCollection* audio_candidates_caller = |
| 4130 | caller()->pc()->local_description()->candidates(0); |
| 4131 | const webrtc::IceCandidateCollection* audio_candidates_callee = |
| 4132 | callee()->pc()->local_description()->candidates(0); |
| 4133 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 4134 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 4135 | std::string caller_candidate_pre_restart; |
| 4136 | ASSERT_TRUE( |
| 4137 | audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart)); |
| 4138 | std::string callee_candidate_pre_restart; |
| 4139 | ASSERT_TRUE( |
| 4140 | audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart)); |
| 4141 | const cricket::SessionDescription* desc = |
| 4142 | caller()->pc()->local_description()->description(); |
| 4143 | std::string caller_ufrag_pre_restart = |
| 4144 | desc->transport_infos()[0].description.ice_ufrag; |
| 4145 | desc = callee()->pc()->local_description()->description(); |
| 4146 | std::string callee_ufrag_pre_restart = |
| 4147 | desc->transport_infos()[0].description.ice_ufrag; |
| 4148 | |
| 4149 | // Have the caller initiate an ICE restart. |
| 4150 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 4151 | caller()->CreateAndSetAndSignalOffer(); |
| 4152 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4153 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4154 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
Alex Loiko | 9289eda | 2018-11-23 16:18:59 +0000 | [diff] [blame] | 4155 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4156 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4157 | |
| 4158 | // Grab the ufrags/candidates again. |
| 4159 | audio_candidates_caller = caller()->pc()->local_description()->candidates(0); |
| 4160 | audio_candidates_callee = callee()->pc()->local_description()->candidates(0); |
| 4161 | ASSERT_GT(audio_candidates_caller->count(), 0u); |
| 4162 | ASSERT_GT(audio_candidates_callee->count(), 0u); |
| 4163 | std::string caller_candidate_post_restart; |
| 4164 | ASSERT_TRUE( |
| 4165 | audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart)); |
| 4166 | std::string callee_candidate_post_restart; |
| 4167 | ASSERT_TRUE( |
| 4168 | audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart)); |
| 4169 | desc = caller()->pc()->local_description()->description(); |
| 4170 | std::string caller_ufrag_post_restart = |
| 4171 | desc->transport_infos()[0].description.ice_ufrag; |
| 4172 | desc = callee()->pc()->local_description()->description(); |
| 4173 | std::string callee_ufrag_post_restart = |
| 4174 | desc->transport_infos()[0].description.ice_ufrag; |
| 4175 | // Sanity check that an ICE restart was actually negotiated in SDP. |
| 4176 | ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart); |
| 4177 | ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart); |
| 4178 | ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart); |
| 4179 | ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart); |
| 4180 | |
| 4181 | // Ensure that additional frames are received after the ICE restart. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4182 | MediaExpectations media_expectations; |
| 4183 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4184 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | // Verify that audio/video can be received end-to-end when ICE renomination is |
| 4188 | // enabled. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4189 | TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4190 | PeerConnectionInterface::RTCConfiguration config; |
| 4191 | config.enable_ice_renomination = true; |
| 4192 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 4193 | ConnectFakeSignaling(); |
| 4194 | // Do normal offer/answer and wait for some frames to be received in each |
| 4195 | // direction. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4196 | caller()->AddAudioVideoTracks(); |
| 4197 | callee()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4198 | caller()->CreateAndSetAndSignalOffer(); |
| 4199 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4200 | // Sanity check that ICE renomination was actually negotiated. |
| 4201 | const cricket::SessionDescription* desc = |
| 4202 | caller()->pc()->local_description()->description(); |
| 4203 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4204 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4205 | } |
| 4206 | desc = callee()->pc()->local_description()->description(); |
| 4207 | for (const cricket::TransportInfo& info : desc->transport_infos()) { |
Steve Anton | 64b626b | 2019-01-28 17:25:26 -0800 | [diff] [blame] | 4208 | ASSERT_THAT(info.description.transport_options, Contains("renomination")); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4209 | } |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4210 | MediaExpectations media_expectations; |
| 4211 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4212 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4215 | // With a max bundle policy and RTCP muxing, adding a new media description to |
| 4216 | // the connection should not affect ICE at all because the new media will use |
| 4217 | // the existing connection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4218 | TEST_P(PeerConnectionIntegrationTest, |
Steve Anton | 83119dd | 2017-11-10 16:19:52 -0800 | [diff] [blame] | 4219 | AddMediaToConnectedBundleDoesNotRestartIce) { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4220 | PeerConnectionInterface::RTCConfiguration config; |
| 4221 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 4222 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 4223 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig( |
| 4224 | config, PeerConnectionInterface::RTCConfiguration())); |
| 4225 | ConnectFakeSignaling(); |
| 4226 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4227 | caller()->AddAudioTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4228 | caller()->CreateAndSetAndSignalOffer(); |
| 4229 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Steve Anton | ff52f1b | 2017-10-26 12:24:50 -0700 | [diff] [blame] | 4230 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 4231 | caller()->ice_connection_state(), kDefaultTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4232 | |
| 4233 | caller()->clear_ice_connection_state_history(); |
| 4234 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4235 | caller()->AddVideoTrack(); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 4236 | caller()->CreateAndSetAndSignalOffer(); |
| 4237 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4238 | |
| 4239 | EXPECT_EQ(0u, caller()->ice_connection_state_history().size()); |
| 4240 | } |
| 4241 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4242 | // This test sets up a call between two parties with audio and video. It then |
| 4243 | // renegotiates setting the video m-line to "port 0", then later renegotiates |
| 4244 | // again, enabling video. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4245 | TEST_P(PeerConnectionIntegrationTest, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4246 | VideoFlowsAfterMediaSectionIsRejectedAndRecycled) { |
| 4247 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4248 | ConnectFakeSignaling(); |
| 4249 | |
| 4250 | // Do initial negotiation, only sending media from the caller. Will result in |
| 4251 | // video and audio recvonly "m=" sections. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4252 | caller()->AddAudioVideoTracks(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4253 | caller()->CreateAndSetAndSignalOffer(); |
| 4254 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4255 | |
| 4256 | // Negotiate again, disabling the video "m=" section (the callee will set the |
| 4257 | // port to 0 due to offer_to_receive_video = 0). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4258 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 4259 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4260 | options.offer_to_receive_video = 0; |
| 4261 | callee()->SetOfferAnswerOptions(options); |
| 4262 | } else { |
| 4263 | callee()->SetRemoteOfferHandler([this] { |
| 4264 | callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop(); |
| 4265 | }); |
| 4266 | } |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4267 | caller()->CreateAndSetAndSignalOffer(); |
| 4268 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4269 | // Sanity check that video "m=" section was actually rejected. |
| 4270 | const ContentInfo* answer_video_content = cricket::GetFirstVideoContent( |
| 4271 | callee()->pc()->local_description()->description()); |
| 4272 | ASSERT_NE(nullptr, answer_video_content); |
| 4273 | ASSERT_TRUE(answer_video_content->rejected); |
| 4274 | |
| 4275 | // Enable video and do negotiation again, making sure video is received |
| 4276 | // end-to-end, also adding media stream to callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4277 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 4278 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4279 | options.offer_to_receive_video = 1; |
| 4280 | callee()->SetOfferAnswerOptions(options); |
| 4281 | } else { |
| 4282 | // The caller's transceiver is stopped, so we need to add another track. |
| 4283 | auto caller_transceiver = |
| 4284 | caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 4285 | EXPECT_TRUE(caller_transceiver->stopped()); |
| 4286 | caller()->AddVideoTrack(); |
| 4287 | } |
| 4288 | callee()->AddVideoTrack(); |
| 4289 | callee()->SetRemoteOfferHandler(nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4290 | caller()->CreateAndSetAndSignalOffer(); |
| 4291 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4292 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4293 | // Verify the caller receives frames from the newly added stream, and the |
| 4294 | // callee receives additional frames from the re-enabled video m= section. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4295 | MediaExpectations media_expectations; |
| 4296 | media_expectations.CalleeExpectsSomeAudio(); |
| 4297 | media_expectations.ExpectBidirectionalVideo(); |
| 4298 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4301 | // This tests that if we negotiate after calling CreateSender but before we |
| 4302 | // have a track, then set a track later, frames from the newly-set track are |
| 4303 | // received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4304 | TEST_F(PeerConnectionIntegrationTestPlanB, |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4305 | MediaFlowsAfterEarlyWarmupWithCreateSender) { |
| 4306 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4307 | ConnectFakeSignaling(); |
| 4308 | auto caller_audio_sender = |
| 4309 | caller()->pc()->CreateSender("audio", "caller_stream"); |
| 4310 | auto caller_video_sender = |
| 4311 | caller()->pc()->CreateSender("video", "caller_stream"); |
| 4312 | auto callee_audio_sender = |
| 4313 | callee()->pc()->CreateSender("audio", "callee_stream"); |
| 4314 | auto callee_video_sender = |
| 4315 | callee()->pc()->CreateSender("video", "callee_stream"); |
| 4316 | caller()->CreateAndSetAndSignalOffer(); |
| 4317 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 4318 | // Wait for ICE to complete, without any tracks being set. |
| 4319 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4320 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4321 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4322 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4323 | // Now set the tracks, and expect frames to immediately start flowing. |
| 4324 | EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 4325 | EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 4326 | EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 4327 | EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4328 | MediaExpectations media_expectations; |
| 4329 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4330 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4331 | } |
| 4332 | |
| 4333 | // This tests that if we negotiate after calling AddTransceiver but before we |
| 4334 | // have a track, then set a track later, frames from the newly-set tracks are |
| 4335 | // received end-to-end. |
| 4336 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 4337 | MediaFlowsAfterEarlyWarmupWithAddTransceiver) { |
| 4338 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4339 | ConnectFakeSignaling(); |
| 4340 | auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 4341 | ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type()); |
| 4342 | auto caller_audio_sender = audio_result.MoveValue()->sender(); |
| 4343 | auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 4344 | ASSERT_EQ(RTCErrorType::NONE, video_result.error().type()); |
| 4345 | auto caller_video_sender = video_result.MoveValue()->sender(); |
| 4346 | callee()->SetRemoteOfferHandler([this] { |
| 4347 | ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size()); |
| 4348 | callee()->pc()->GetTransceivers()[0]->SetDirection( |
| 4349 | RtpTransceiverDirection::kSendRecv); |
| 4350 | callee()->pc()->GetTransceivers()[1]->SetDirection( |
| 4351 | RtpTransceiverDirection::kSendRecv); |
| 4352 | }); |
| 4353 | caller()->CreateAndSetAndSignalOffer(); |
| 4354 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 4355 | // Wait for ICE to complete, without any tracks being set. |
| 4356 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
| 4357 | caller()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4358 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4359 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4360 | // Now set the tracks, and expect frames to immediately start flowing. |
| 4361 | auto callee_audio_sender = callee()->pc()->GetSenders()[0]; |
| 4362 | auto callee_video_sender = callee()->pc()->GetSenders()[1]; |
| 4363 | ASSERT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack())); |
| 4364 | ASSERT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack())); |
| 4365 | ASSERT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack())); |
| 4366 | ASSERT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack())); |
| 4367 | MediaExpectations media_expectations; |
| 4368 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4369 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | // This test verifies that a remote video track can be added via AddStream, |
| 4373 | // and sent end-to-end. For this particular test, it's simply echoed back |
| 4374 | // from the caller to the callee, rather than being forwarded to a third |
| 4375 | // PeerConnection. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4376 | TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4377 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4378 | ConnectFakeSignaling(); |
| 4379 | // Just send a video track from the caller. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4380 | caller()->AddVideoTrack(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4381 | caller()->CreateAndSetAndSignalOffer(); |
| 4382 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 4383 | ASSERT_EQ(1U, callee()->remote_streams()->count()); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4384 | |
| 4385 | // Echo the stream back, and do a new offer/anwer (initiated by callee this |
| 4386 | // time). |
| 4387 | callee()->pc()->AddStream(callee()->remote_streams()->at(0)); |
| 4388 | callee()->CreateAndSetAndSignalOffer(); |
| 4389 | ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs); |
| 4390 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4391 | MediaExpectations media_expectations; |
| 4392 | media_expectations.ExpectBidirectionalVideo(); |
| 4393 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | // Test that we achieve the expected end-to-end connection time, using a |
| 4397 | // fake clock and simulated latency on the media and signaling paths. |
| 4398 | // We use a TURN<->TURN connection because this is usually the quickest to |
| 4399 | // set up initially, especially when we're confident the connection will work |
| 4400 | // and can start sending media before we get a STUN response. |
| 4401 | // |
| 4402 | // With various optimizations enabled, here are the network delays we expect to |
| 4403 | // be on the critical path: |
| 4404 | // 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then |
| 4405 | // signaling answer (with DTLS fingerprint). |
| 4406 | // 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when |
| 4407 | // using TURN<->TURN pair, and DTLS exchange is 4 packets, |
| 4408 | // the first of which should have arrived before the answer. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4409 | TEST_P(PeerConnectionIntegrationTest, EndToEndConnectionTimeWithTurnTurnPair) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4410 | rtc::ScopedFakeClock fake_clock; |
| 4411 | // Some things use a time of "0" as a special value, so we need to start out |
| 4412 | // the fake clock at a nonzero time. |
| 4413 | // TODO(deadbeef): Fix this. |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 4414 | fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4415 | |
| 4416 | static constexpr int media_hop_delay_ms = 50; |
| 4417 | static constexpr int signaling_trip_delay_ms = 500; |
| 4418 | // For explanation of these values, see comment above. |
| 4419 | static constexpr int required_media_hops = 9; |
| 4420 | static constexpr int required_signaling_trips = 2; |
| 4421 | // For internal delays (such as posting an event asychronously). |
| 4422 | static constexpr int allowed_internal_delay_ms = 20; |
| 4423 | static constexpr int total_connection_time_ms = |
| 4424 | media_hop_delay_ms * required_media_hops + |
| 4425 | signaling_trip_delay_ms * required_signaling_trips + |
| 4426 | allowed_internal_delay_ms; |
| 4427 | |
| 4428 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 4429 | 3478}; |
| 4430 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 4431 | 0}; |
| 4432 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 4433 | 3478}; |
| 4434 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 4435 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4436 | cricket::TestTurnServer* turn_server_1 = CreateTurnServer( |
| 4437 | turn_server_1_internal_address, turn_server_1_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4438 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4439 | cricket::TestTurnServer* turn_server_2 = CreateTurnServer( |
| 4440 | turn_server_2_internal_address, turn_server_2_external_address); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4441 | // Bypass permission check on received packets so media can be sent before |
| 4442 | // the candidate is signaled. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4443 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_1] { |
| 4444 | turn_server_1->set_enable_permission_checks(false); |
| 4445 | }); |
| 4446 | network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_2] { |
| 4447 | turn_server_2->set_enable_permission_checks(false); |
| 4448 | }); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4449 | |
| 4450 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 4451 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 4452 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 4453 | ice_server_1.username = "test"; |
| 4454 | ice_server_1.password = "test"; |
| 4455 | client_1_config.servers.push_back(ice_server_1); |
| 4456 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4457 | client_1_config.presume_writable_when_fully_relayed = true; |
| 4458 | |
| 4459 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 4460 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 4461 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 4462 | ice_server_2.username = "test"; |
| 4463 | ice_server_2.password = "test"; |
| 4464 | client_2_config.servers.push_back(ice_server_2); |
| 4465 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4466 | client_2_config.presume_writable_when_fully_relayed = true; |
| 4467 | |
| 4468 | ASSERT_TRUE( |
| 4469 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 4470 | // Set up the simulated delays. |
| 4471 | SetSignalingDelayMs(signaling_trip_delay_ms); |
| 4472 | ConnectFakeSignaling(); |
| 4473 | virtual_socket_server()->set_delay_mean(media_hop_delay_ms); |
| 4474 | virtual_socket_server()->UpdateDelayDistribution(); |
| 4475 | |
| 4476 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 4477 | // set up ICE/DTLS with no media. |
| 4478 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4479 | options.offer_to_receive_audio = 1; |
| 4480 | options.offer_to_receive_video = 1; |
| 4481 | caller()->SetOfferAnswerOptions(options); |
| 4482 | caller()->CreateAndSetAndSignalOffer(); |
deadbeef | 7145280 | 2017-05-07 17:21:01 -0700 | [diff] [blame] | 4483 | EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms, |
| 4484 | fake_clock); |
Seth Hampson | 1d4a76d | 2018-06-19 14:31:41 -0700 | [diff] [blame] | 4485 | // Closing the PeerConnections destroys the ports before the ScopedFakeClock. |
| 4486 | // If this is not done a DCHECK can be hit in ports.cc, because a large |
| 4487 | // negative number is calculated for the rtt due to the global clock changing. |
| 4488 | caller()->pc()->Close(); |
| 4489 | callee()->pc()->Close(); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4492 | // Verify that a TurnCustomizer passed in through RTCConfiguration |
| 4493 | // is actually used by the underlying TURN candidate pair. |
| 4494 | // Note that turnport_unittest.cc contains more detailed, lower-level tests. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4495 | TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) { |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4496 | static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0", |
| 4497 | 3478}; |
| 4498 | static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1", |
| 4499 | 0}; |
| 4500 | static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0", |
| 4501 | 3478}; |
| 4502 | static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1", |
| 4503 | 0}; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4504 | CreateTurnServer(turn_server_1_internal_address, |
| 4505 | turn_server_1_external_address); |
| 4506 | CreateTurnServer(turn_server_2_internal_address, |
| 4507 | turn_server_2_external_address); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4508 | |
| 4509 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 4510 | webrtc::PeerConnectionInterface::IceServer ice_server_1; |
| 4511 | ice_server_1.urls.push_back("turn:88.88.88.0:3478"); |
| 4512 | ice_server_1.username = "test"; |
| 4513 | ice_server_1.password = "test"; |
| 4514 | client_1_config.servers.push_back(ice_server_1); |
| 4515 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4516 | auto* customizer1 = CreateTurnCustomizer(); |
| 4517 | client_1_config.turn_customizer = customizer1; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4518 | |
| 4519 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 4520 | webrtc::PeerConnectionInterface::IceServer ice_server_2; |
| 4521 | ice_server_2.urls.push_back("turn:99.99.99.0:3478"); |
| 4522 | ice_server_2.username = "test"; |
| 4523 | ice_server_2.password = "test"; |
| 4524 | client_2_config.servers.push_back(ice_server_2); |
| 4525 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4526 | auto* customizer2 = CreateTurnCustomizer(); |
| 4527 | client_2_config.turn_customizer = customizer2; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4528 | |
| 4529 | ASSERT_TRUE( |
| 4530 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 4531 | ConnectFakeSignaling(); |
| 4532 | |
| 4533 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 4534 | // set up ICE/DTLS with no media. |
| 4535 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4536 | options.offer_to_receive_audio = 1; |
| 4537 | options.offer_to_receive_video = 1; |
| 4538 | caller()->SetOfferAnswerOptions(options); |
| 4539 | caller()->CreateAndSetAndSignalOffer(); |
| 4540 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 4541 | |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4542 | ExpectTurnCustomizerCountersIncremented(customizer1); |
| 4543 | ExpectTurnCustomizerCountersIncremented(customizer2); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 4544 | } |
| 4545 | |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 4546 | // Verifies that you can use TCP instead of UDP to connect to a TURN server and |
| 4547 | // send media between the caller and the callee. |
| 4548 | TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) { |
| 4549 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 4550 | 3478}; |
| 4551 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 4552 | |
| 4553 | // Enable TCP for the fake turn server. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4554 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 4555 | cricket::PROTO_TCP); |
Benjamin Wright | 2d5f3cb | 2018-05-22 14:46:06 -0700 | [diff] [blame] | 4556 | |
| 4557 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 4558 | ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp"); |
| 4559 | ice_server.username = "test"; |
| 4560 | ice_server.password = "test"; |
| 4561 | |
| 4562 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 4563 | client_1_config.servers.push_back(ice_server); |
| 4564 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4565 | |
| 4566 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 4567 | client_2_config.servers.push_back(ice_server); |
| 4568 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4569 | |
| 4570 | ASSERT_TRUE( |
| 4571 | CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config)); |
| 4572 | |
| 4573 | // Do normal offer/answer and wait for ICE to complete. |
| 4574 | ConnectFakeSignaling(); |
| 4575 | caller()->AddAudioVideoTracks(); |
| 4576 | callee()->AddAudioVideoTracks(); |
| 4577 | caller()->CreateAndSetAndSignalOffer(); |
| 4578 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4579 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 4580 | callee()->ice_connection_state(), kMaxWaitForFramesMs); |
| 4581 | |
| 4582 | MediaExpectations media_expectations; |
| 4583 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4584 | EXPECT_TRUE(ExpectNewFrames(media_expectations)); |
| 4585 | } |
| 4586 | |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 4587 | // Verify that a SSLCertificateVerifier passed in through |
| 4588 | // PeerConnectionDependencies is actually used by the underlying SSL |
| 4589 | // implementation to determine whether a certificate presented by the TURN |
| 4590 | // server is accepted by the client. Note that openssladapter_unittest.cc |
| 4591 | // contains more detailed, lower-level tests. |
| 4592 | TEST_P(PeerConnectionIntegrationTest, |
| 4593 | SSLCertificateVerifierUsedForTurnConnections) { |
| 4594 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 4595 | 3478}; |
| 4596 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 4597 | |
| 4598 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 4599 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4600 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 4601 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 4602 | |
| 4603 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 4604 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 4605 | ice_server.username = "test"; |
| 4606 | ice_server.password = "test"; |
| 4607 | |
| 4608 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 4609 | client_1_config.servers.push_back(ice_server); |
| 4610 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4611 | |
| 4612 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 4613 | client_2_config.servers.push_back(ice_server); |
| 4614 | // Setting the type to kRelay forces the connection to go through a TURN |
| 4615 | // server. |
| 4616 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4617 | |
| 4618 | // Get a copy to the pointer so we can verify calls later. |
| 4619 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 4620 | new rtc::TestCertificateVerifier(); |
| 4621 | client_1_cert_verifier->verify_certificate_ = true; |
| 4622 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 4623 | new rtc::TestCertificateVerifier(); |
| 4624 | client_2_cert_verifier->verify_certificate_ = true; |
| 4625 | |
| 4626 | // Create the dependencies with the test certificate verifier. |
| 4627 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 4628 | client_1_deps.tls_cert_verifier = |
| 4629 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 4630 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 4631 | client_2_deps.tls_cert_verifier = |
| 4632 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 4633 | |
| 4634 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 4635 | client_1_config, std::move(client_1_deps), client_2_config, |
| 4636 | std::move(client_2_deps))); |
| 4637 | ConnectFakeSignaling(); |
| 4638 | |
| 4639 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 4640 | // set up ICE/DTLS with no media. |
| 4641 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4642 | options.offer_to_receive_audio = 1; |
| 4643 | options.offer_to_receive_video = 1; |
| 4644 | caller()->SetOfferAnswerOptions(options); |
| 4645 | caller()->CreateAndSetAndSignalOffer(); |
| 4646 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 4647 | |
| 4648 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 4649 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | TEST_P(PeerConnectionIntegrationTest, |
| 4653 | SSLCertificateVerifierFailureUsedForTurnConnectionsFailsConnection) { |
| 4654 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 4655 | 3478}; |
| 4656 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 4657 | |
| 4658 | // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so |
| 4659 | // that host name verification passes on the fake certificate. |
Seth Hampson | aed7164 | 2018-06-11 07:41:32 -0700 | [diff] [blame] | 4660 | CreateTurnServer(turn_server_internal_address, turn_server_external_address, |
| 4661 | cricket::PROTO_TLS, "88.88.88.0"); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 4662 | |
| 4663 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 4664 | ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp"); |
| 4665 | ice_server.username = "test"; |
| 4666 | ice_server.password = "test"; |
| 4667 | |
| 4668 | PeerConnectionInterface::RTCConfiguration client_1_config; |
| 4669 | client_1_config.servers.push_back(ice_server); |
| 4670 | client_1_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4671 | |
| 4672 | PeerConnectionInterface::RTCConfiguration client_2_config; |
| 4673 | client_2_config.servers.push_back(ice_server); |
| 4674 | // Setting the type to kRelay forces the connection to go through a TURN |
| 4675 | // server. |
| 4676 | client_2_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 4677 | |
| 4678 | // Get a copy to the pointer so we can verify calls later. |
| 4679 | rtc::TestCertificateVerifier* client_1_cert_verifier = |
| 4680 | new rtc::TestCertificateVerifier(); |
| 4681 | client_1_cert_verifier->verify_certificate_ = false; |
| 4682 | rtc::TestCertificateVerifier* client_2_cert_verifier = |
| 4683 | new rtc::TestCertificateVerifier(); |
| 4684 | client_2_cert_verifier->verify_certificate_ = false; |
| 4685 | |
| 4686 | // Create the dependencies with the test certificate verifier. |
| 4687 | webrtc::PeerConnectionDependencies client_1_deps(nullptr); |
| 4688 | client_1_deps.tls_cert_verifier = |
| 4689 | std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier); |
| 4690 | webrtc::PeerConnectionDependencies client_2_deps(nullptr); |
| 4691 | client_2_deps.tls_cert_verifier = |
| 4692 | std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier); |
| 4693 | |
| 4694 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( |
| 4695 | client_1_config, std::move(client_1_deps), client_2_config, |
| 4696 | std::move(client_2_deps))); |
| 4697 | ConnectFakeSignaling(); |
| 4698 | |
| 4699 | // Set "offer to receive audio/video" without adding any tracks, so we just |
| 4700 | // set up ICE/DTLS with no media. |
| 4701 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4702 | options.offer_to_receive_audio = 1; |
| 4703 | options.offer_to_receive_video = 1; |
| 4704 | caller()->SetOfferAnswerOptions(options); |
| 4705 | caller()->CreateAndSetAndSignalOffer(); |
| 4706 | bool wait_res = true; |
| 4707 | // TODO(bugs.webrtc.org/9219): When IceConnectionState is implemented |
| 4708 | // properly, should be able to just wait for a state of "failed" instead of |
| 4709 | // waiting a fixed 10 seconds. |
| 4710 | WAIT_(DtlsConnected(), kDefaultTimeout, wait_res); |
| 4711 | ASSERT_FALSE(wait_res); |
| 4712 | |
| 4713 | EXPECT_GT(client_1_cert_verifier->call_count_, 0u); |
| 4714 | EXPECT_GT(client_2_cert_verifier->call_count_, 0u); |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 4717 | // Test that audio and video flow end-to-end when codec names don't use the |
| 4718 | // expected casing, given that they're supposed to be case insensitive. To test |
| 4719 | // this, all but one codec is removed from each media description, and its |
| 4720 | // casing is changed. |
| 4721 | // |
| 4722 | // In the past, this has regressed and caused crashes/black video, due to the |
| 4723 | // fact that code at some layers was doing case-insensitive comparisons and |
| 4724 | // code at other layers was not. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4725 | TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) { |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 4726 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4727 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4728 | caller()->AddAudioVideoTracks(); |
| 4729 | callee()->AddAudioVideoTracks(); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 4730 | |
| 4731 | // Remove all but one audio/video codec (opus and VP8), and change the |
| 4732 | // casing of the caller's generated offer. |
| 4733 | caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) { |
| 4734 | cricket::AudioContentDescription* audio = |
| 4735 | GetFirstAudioContentDescription(description); |
| 4736 | ASSERT_NE(nullptr, audio); |
| 4737 | auto audio_codecs = audio->codecs(); |
| 4738 | audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(), |
| 4739 | [](const cricket::AudioCodec& codec) { |
| 4740 | return codec.name != "opus"; |
| 4741 | }), |
| 4742 | audio_codecs.end()); |
| 4743 | ASSERT_EQ(1u, audio_codecs.size()); |
| 4744 | audio_codecs[0].name = "OpUs"; |
| 4745 | audio->set_codecs(audio_codecs); |
| 4746 | |
| 4747 | cricket::VideoContentDescription* video = |
| 4748 | GetFirstVideoContentDescription(description); |
| 4749 | ASSERT_NE(nullptr, video); |
| 4750 | auto video_codecs = video->codecs(); |
| 4751 | video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(), |
| 4752 | [](const cricket::VideoCodec& codec) { |
| 4753 | return codec.name != "VP8"; |
| 4754 | }), |
| 4755 | video_codecs.end()); |
| 4756 | ASSERT_EQ(1u, video_codecs.size()); |
| 4757 | video_codecs[0].name = "vP8"; |
| 4758 | video->set_codecs(video_codecs); |
| 4759 | }); |
| 4760 | |
| 4761 | caller()->CreateAndSetAndSignalOffer(); |
| 4762 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4763 | |
| 4764 | // Verify frames are still received end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4765 | MediaExpectations media_expectations; |
| 4766 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4767 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
deadbeef | c964d0b | 2017-04-03 10:03:35 -0700 | [diff] [blame] | 4768 | } |
| 4769 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 4770 | TEST_P(PeerConnectionIntegrationTest, GetSourcesAudio) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 4771 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4772 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4773 | caller()->AddAudioTrack(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 4774 | caller()->CreateAndSetAndSignalOffer(); |
| 4775 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
deadbeef | d8ad788 | 2017-04-18 16:01:17 -0700 | [diff] [blame] | 4776 | // Wait for one audio frame to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4777 | MediaExpectations media_expectations; |
| 4778 | media_expectations.CalleeExpectsSomeAudio(1); |
| 4779 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 4780 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 4781 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 4782 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO); |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 4783 | auto sources = receiver->GetSources(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 4784 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
| 4785 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 4786 | sources[0].source_id()); |
| 4787 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
| 4788 | } |
| 4789 | |
| 4790 | TEST_P(PeerConnectionIntegrationTest, GetSourcesVideo) { |
| 4791 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4792 | ConnectFakeSignaling(); |
| 4793 | caller()->AddVideoTrack(); |
| 4794 | caller()->CreateAndSetAndSignalOffer(); |
| 4795 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4796 | // Wait for one video frame to be received by the callee. |
| 4797 | MediaExpectations media_expectations; |
| 4798 | media_expectations.CalleeExpectsSomeVideo(1); |
| 4799 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4800 | ASSERT_EQ(callee()->pc()->GetReceivers().size(), 1u); |
| 4801 | auto receiver = callee()->pc()->GetReceivers()[0]; |
| 4802 | ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_VIDEO); |
| 4803 | auto sources = receiver->GetSources(); |
| 4804 | ASSERT_GT(receiver->GetParameters().encodings.size(), 0u); |
| 4805 | EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc, |
| 4806 | sources[0].source_id()); |
| 4807 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 4808 | } |
| 4809 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4810 | // Test that if a track is removed and added again with a different stream ID, |
| 4811 | // the new stream ID is successfully communicated in SDP and media continues to |
| 4812 | // flow end-to-end. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4813 | // TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because |
| 4814 | // it will not reuse a transceiver that has already been sending. After creating |
| 4815 | // a new transceiver it tries to create an offer with two senders of the same |
| 4816 | // track ids and it fails. |
| 4817 | TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4818 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4819 | ConnectFakeSignaling(); |
| 4820 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4821 | // Add track using stream 1, do offer/answer. |
| 4822 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
| 4823 | caller()->CreateLocalAudioTrack(); |
| 4824 | rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 4825 | caller()->AddTrack(track, {"stream_1"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4826 | caller()->CreateAndSetAndSignalOffer(); |
| 4827 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4828 | { |
| 4829 | MediaExpectations media_expectations; |
| 4830 | media_expectations.CalleeExpectsSomeAudio(1); |
| 4831 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4832 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4833 | // Remove the sender, and create a new one with the new stream. |
| 4834 | caller()->pc()->RemoveTrack(sender); |
Steve Anton | d78323f | 2018-07-11 11:13:44 -0700 | [diff] [blame] | 4835 | sender = caller()->AddTrack(track, {"stream_2"}); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4836 | caller()->CreateAndSetAndSignalOffer(); |
| 4837 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4838 | // Wait for additional audio frames to be received by the callee. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4839 | { |
| 4840 | MediaExpectations media_expectations; |
| 4841 | media_expectations.CalleeExpectsSomeAudio(); |
| 4842 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 4843 | } |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 4844 | } |
| 4845 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4846 | TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) { |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 4847 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4848 | ConnectFakeSignaling(); |
| 4849 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 4850 | auto output = absl::make_unique<testing::NiceMock<MockRtcEventLogOutput>>(); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 4851 | ON_CALL(*output, IsActive()).WillByDefault(::testing::Return(true)); |
| 4852 | ON_CALL(*output, Write(::testing::_)).WillByDefault(::testing::Return(true)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 4853 | EXPECT_CALL(*output, Write(::testing::_)).Times(::testing::AtLeast(1)); |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 4854 | EXPECT_TRUE(caller()->pc()->StartRtcEventLog( |
| 4855 | std::move(output), webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 4856 | |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4857 | caller()->AddAudioVideoTracks(); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 4858 | caller()->CreateAndSetAndSignalOffer(); |
| 4859 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4860 | } |
| 4861 | |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4862 | // Test that if candidates are only signaled by applying full session |
| 4863 | // descriptions (instead of using AddIceCandidate), the peers can connect to |
| 4864 | // each other and exchange media. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4865 | TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4866 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4867 | // Each side will signal the session descriptions but not candidates. |
| 4868 | ConnectFakeSignalingForSdpOnly(); |
| 4869 | |
| 4870 | // Add audio video track and exchange the initial offer/answer with media |
| 4871 | // information only. This will start ICE gathering on each side. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4872 | caller()->AddAudioVideoTracks(); |
| 4873 | callee()->AddAudioVideoTracks(); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4874 | caller()->CreateAndSetAndSignalOffer(); |
| 4875 | |
| 4876 | // Wait for all candidates to be gathered on both the caller and callee. |
| 4877 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 4878 | caller()->ice_gathering_state(), kDefaultTimeout); |
| 4879 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 4880 | callee()->ice_gathering_state(), kDefaultTimeout); |
| 4881 | |
| 4882 | // The candidates will now be included in the session description, so |
| 4883 | // signaling them will start the ICE connection. |
| 4884 | caller()->CreateAndSetAndSignalOffer(); |
| 4885 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4886 | |
| 4887 | // Ensure that media flows in both directions. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4888 | MediaExpectations media_expectations; |
| 4889 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 4890 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 4893 | // Test that SetAudioPlayout can be used to disable audio playout from the |
| 4894 | // start, then later enable it. This may be useful, for example, if the caller |
| 4895 | // needs to play a local ringtone until some event occurs, after which it |
| 4896 | // switches to playing the received audio. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4897 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 4898 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4899 | ConnectFakeSignaling(); |
| 4900 | |
| 4901 | // Set up audio-only call where audio playout is disabled on caller's side. |
| 4902 | caller()->pc()->SetAudioPlayout(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4903 | caller()->AddAudioTrack(); |
| 4904 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 4905 | caller()->CreateAndSetAndSignalOffer(); |
| 4906 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4907 | |
| 4908 | // Pump messages for a second. |
| 4909 | WAIT(false, 1000); |
| 4910 | // Since audio playout is disabled, the caller shouldn't have received |
| 4911 | // anything (at the playout level, at least). |
| 4912 | EXPECT_EQ(0, caller()->audio_frames_received()); |
| 4913 | // As a sanity check, make sure the callee (for which playout isn't disabled) |
| 4914 | // did still see frames on its audio level. |
| 4915 | ASSERT_GT(callee()->audio_frames_received(), 0); |
| 4916 | |
| 4917 | // Enable playout again, and ensure audio starts flowing. |
| 4918 | caller()->pc()->SetAudioPlayout(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4919 | MediaExpectations media_expectations; |
| 4920 | media_expectations.ExpectBidirectionalAudio(); |
| 4921 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | double GetAudioEnergyStat(PeerConnectionWrapper* pc) { |
| 4925 | auto report = pc->NewGetStats(); |
| 4926 | auto track_stats_list = |
| 4927 | report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>(); |
| 4928 | const webrtc::RTCMediaStreamTrackStats* remote_track_stats = nullptr; |
| 4929 | for (const auto* track_stats : track_stats_list) { |
| 4930 | if (track_stats->remote_source.is_defined() && |
| 4931 | *track_stats->remote_source) { |
| 4932 | remote_track_stats = track_stats; |
| 4933 | break; |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | if (!remote_track_stats->total_audio_energy.is_defined()) { |
| 4938 | return 0.0; |
| 4939 | } |
| 4940 | return *remote_track_stats->total_audio_energy; |
| 4941 | } |
| 4942 | |
| 4943 | // Test that if audio playout is disabled via the SetAudioPlayout() method, then |
| 4944 | // incoming audio is still processed and statistics are generated. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4945 | TEST_P(PeerConnectionIntegrationTest, |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 4946 | DisableAudioPlayoutStillGeneratesAudioStats) { |
| 4947 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4948 | ConnectFakeSignaling(); |
| 4949 | |
| 4950 | // Set up audio-only call where playout is disabled but audio-processing is |
| 4951 | // still active. |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4952 | caller()->AddAudioTrack(); |
| 4953 | callee()->AddAudioTrack(); |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 4954 | caller()->pc()->SetAudioPlayout(false); |
| 4955 | |
| 4956 | caller()->CreateAndSetAndSignalOffer(); |
| 4957 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4958 | |
| 4959 | // Wait for the callee to receive audio stats. |
| 4960 | EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs); |
| 4961 | } |
| 4962 | |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 4963 | // Test that SetAudioRecording can be used to disable audio recording from the |
| 4964 | // start, then later enable it. This may be useful, for example, if the caller |
| 4965 | // wants to ensure that no audio resources are active before a certain state |
| 4966 | // is reached. |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4967 | TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) { |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 4968 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4969 | ConnectFakeSignaling(); |
| 4970 | |
| 4971 | // Set up audio-only call where audio recording is disabled on caller's side. |
| 4972 | caller()->pc()->SetAudioRecording(false); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 4973 | caller()->AddAudioTrack(); |
| 4974 | callee()->AddAudioTrack(); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 4975 | caller()->CreateAndSetAndSignalOffer(); |
| 4976 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 4977 | |
| 4978 | // Pump messages for a second. |
| 4979 | WAIT(false, 1000); |
| 4980 | // Since caller has disabled audio recording, the callee shouldn't have |
| 4981 | // received anything. |
| 4982 | EXPECT_EQ(0, callee()->audio_frames_received()); |
| 4983 | // As a sanity check, make sure the caller did still see frames on its |
| 4984 | // audio level since audio recording is enabled on the calle side. |
| 4985 | ASSERT_GT(caller()->audio_frames_received(), 0); |
| 4986 | |
| 4987 | // Enable audio recording again, and ensure audio starts flowing. |
| 4988 | caller()->pc()->SetAudioRecording(true); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4989 | MediaExpectations media_expectations; |
| 4990 | media_expectations.ExpectBidirectionalAudio(); |
| 4991 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
henrika | 4f167df | 2017-11-01 14:45:55 +0100 | [diff] [blame] | 4992 | } |
| 4993 | |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 4994 | // Test that after closing PeerConnections, they stop sending any packets (ICE, |
| 4995 | // DTLS, RTP...). |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 4996 | TEST_P(PeerConnectionIntegrationTest, ClosingConnectionStopsPacketFlow) { |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 4997 | // Set up audio/video/data, wait for some frames to be received. |
| 4998 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 4999 | ConnectFakeSignaling(); |
Steve Anton | 1532477 | 2018-01-16 10:26:49 -0800 | [diff] [blame] | 5000 | caller()->AddAudioVideoTracks(); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5001 | #ifdef HAVE_SCTP |
| 5002 | caller()->CreateDataChannel(); |
| 5003 | #endif |
| 5004 | caller()->CreateAndSetAndSignalOffer(); |
| 5005 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5006 | MediaExpectations media_expectations; |
| 5007 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 5008 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Taylor Brandstetter | 389a97c | 2018-01-03 16:26:06 -0800 | [diff] [blame] | 5009 | // Close PeerConnections. |
| 5010 | caller()->pc()->Close(); |
| 5011 | callee()->pc()->Close(); |
| 5012 | // Pump messages for a second, and ensure no new packets end up sent. |
| 5013 | uint32_t sent_packets_a = virtual_socket_server()->sent_packets(); |
| 5014 | WAIT(false, 1000); |
| 5015 | uint32_t sent_packets_b = virtual_socket_server()->sent_packets(); |
| 5016 | EXPECT_EQ(sent_packets_a, sent_packets_b); |
| 5017 | } |
| 5018 | |
Steve Anton | 7eca093 | 2018-03-30 15:18:41 -0700 | [diff] [blame] | 5019 | // Test that transport stats are generated by the RTCStatsCollector for a |
| 5020 | // connection that only involves data channels. This is a regression test for |
| 5021 | // crbug.com/826972. |
| 5022 | #ifdef HAVE_SCTP |
| 5023 | TEST_P(PeerConnectionIntegrationTest, |
| 5024 | TransportStatsReportedForDataChannelOnlyConnection) { |
| 5025 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5026 | ConnectFakeSignaling(); |
| 5027 | caller()->CreateDataChannel(); |
| 5028 | |
| 5029 | caller()->CreateAndSetAndSignalOffer(); |
| 5030 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5031 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 5032 | |
| 5033 | auto caller_report = caller()->NewGetStats(); |
| 5034 | EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size()); |
| 5035 | auto callee_report = callee()->NewGetStats(); |
| 5036 | EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size()); |
| 5037 | } |
| 5038 | #endif // HAVE_SCTP |
| 5039 | |
Qingsi Wang | 7685e86 | 2018-06-11 20:15:46 -0700 | [diff] [blame] | 5040 | TEST_P(PeerConnectionIntegrationTest, |
| 5041 | IceEventsGeneratedAndLoggedInRtcEventLog) { |
| 5042 | ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog()); |
| 5043 | ConnectFakeSignaling(); |
| 5044 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 5045 | options.offer_to_receive_audio = 1; |
| 5046 | caller()->SetOfferAnswerOptions(options); |
| 5047 | caller()->CreateAndSetAndSignalOffer(); |
| 5048 | ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout); |
| 5049 | ASSERT_NE(nullptr, caller()->event_log_factory()); |
| 5050 | ASSERT_NE(nullptr, callee()->event_log_factory()); |
| 5051 | webrtc::FakeRtcEventLog* caller_event_log = |
| 5052 | static_cast<webrtc::FakeRtcEventLog*>( |
| 5053 | caller()->event_log_factory()->last_log_created()); |
| 5054 | webrtc::FakeRtcEventLog* callee_event_log = |
| 5055 | static_cast<webrtc::FakeRtcEventLog*>( |
| 5056 | callee()->event_log_factory()->last_log_created()); |
| 5057 | ASSERT_NE(nullptr, caller_event_log); |
| 5058 | ASSERT_NE(nullptr, callee_event_log); |
| 5059 | int caller_ice_config_count = caller_event_log->GetEventCount( |
| 5060 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 5061 | int caller_ice_event_count = caller_event_log->GetEventCount( |
| 5062 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 5063 | int callee_ice_config_count = callee_event_log->GetEventCount( |
| 5064 | webrtc::RtcEvent::Type::IceCandidatePairConfig); |
| 5065 | int callee_ice_event_count = callee_event_log->GetEventCount( |
| 5066 | webrtc::RtcEvent::Type::IceCandidatePairEvent); |
| 5067 | EXPECT_LT(0, caller_ice_config_count); |
| 5068 | EXPECT_LT(0, caller_ice_event_count); |
| 5069 | EXPECT_LT(0, callee_ice_config_count); |
| 5070 | EXPECT_LT(0, callee_ice_event_count); |
| 5071 | } |
| 5072 | |
Qingsi Wang | c129c35 | 2019-04-18 10:41:58 -0700 | [diff] [blame] | 5073 | TEST_P(PeerConnectionIntegrationTest, RegatherAfterChangingIceTransportType) { |
| 5074 | webrtc::test::ScopedFieldTrials field_trials( |
| 5075 | "WebRTC-GatherOnCandidateFilterChanged/Enabled/"); |
| 5076 | static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0", |
| 5077 | 3478}; |
| 5078 | static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0}; |
| 5079 | |
| 5080 | CreateTurnServer(turn_server_internal_address, turn_server_external_address); |
| 5081 | |
| 5082 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 5083 | ice_server.urls.push_back("turn:88.88.88.0:3478"); |
| 5084 | ice_server.username = "test"; |
| 5085 | ice_server.password = "test"; |
| 5086 | |
| 5087 | PeerConnectionInterface::RTCConfiguration caller_config; |
| 5088 | caller_config.servers.push_back(ice_server); |
| 5089 | caller_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5090 | caller_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 5091 | |
| 5092 | PeerConnectionInterface::RTCConfiguration callee_config; |
| 5093 | callee_config.servers.push_back(ice_server); |
| 5094 | callee_config.type = webrtc::PeerConnectionInterface::kRelay; |
| 5095 | callee_config.continual_gathering_policy = PeerConnection::GATHER_CONTINUALLY; |
| 5096 | |
| 5097 | ASSERT_TRUE( |
| 5098 | CreatePeerConnectionWrappersWithConfig(caller_config, callee_config)); |
| 5099 | |
| 5100 | // Do normal offer/answer and wait for ICE to complete. |
| 5101 | ConnectFakeSignaling(); |
| 5102 | caller()->AddAudioVideoTracks(); |
| 5103 | callee()->AddAudioVideoTracks(); |
| 5104 | caller()->CreateAndSetAndSignalOffer(); |
| 5105 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5106 | // Since we are doing continual gathering, the ICE transport does not reach |
| 5107 | // kIceGatheringComplete (see |
| 5108 | // P2PTransportChannel::OnCandidatesAllocationDone), and consequently not |
| 5109 | // kIceConnectionComplete. |
| 5110 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5111 | caller()->ice_connection_state(), kDefaultTimeout); |
| 5112 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 5113 | callee()->ice_connection_state(), kDefaultTimeout); |
| 5114 | // Note that we cannot use the metric |
| 5115 | // |WebRTC.PeerConnection.CandidatePairType_UDP| in this test since this |
| 5116 | // metric is only populated when we reach kIceConnectionComplete in the |
| 5117 | // current implementation. |
| 5118 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 5119 | caller()->last_candidate_gathered().type()); |
| 5120 | EXPECT_EQ(cricket::RELAY_PORT_TYPE, |
| 5121 | callee()->last_candidate_gathered().type()); |
| 5122 | |
| 5123 | // Loosen the caller's candidate filter. |
| 5124 | caller_config = caller()->pc()->GetConfiguration(); |
| 5125 | caller_config.type = webrtc::PeerConnectionInterface::kAll; |
| 5126 | caller()->pc()->SetConfiguration(caller_config); |
| 5127 | // We should have gathered a new host candidate. |
| 5128 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 5129 | caller()->last_candidate_gathered().type(), kDefaultTimeout); |
| 5130 | |
| 5131 | // Loosen the callee's candidate filter. |
| 5132 | callee_config = callee()->pc()->GetConfiguration(); |
| 5133 | callee_config.type = webrtc::PeerConnectionInterface::kAll; |
| 5134 | callee()->pc()->SetConfiguration(callee_config); |
| 5135 | EXPECT_EQ_WAIT(cricket::LOCAL_PORT_TYPE, |
| 5136 | callee()->last_candidate_gathered().type(), kDefaultTimeout); |
| 5137 | } |
| 5138 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 5139 | INSTANTIATE_TEST_SUITE_P(PeerConnectionIntegrationTest, |
| 5140 | PeerConnectionIntegrationTest, |
| 5141 | Values(SdpSemantics::kPlanB, |
| 5142 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 5143 | |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5144 | // Tests that verify interoperability between Plan B and Unified Plan |
| 5145 | // PeerConnections. |
| 5146 | class PeerConnectionIntegrationInteropTest |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5147 | : public PeerConnectionIntegrationBaseTest, |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5148 | public ::testing::WithParamInterface< |
| 5149 | std::tuple<SdpSemantics, SdpSemantics>> { |
| 5150 | protected: |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5151 | // Setting the SdpSemantics for the base test to kDefault does not matter |
| 5152 | // because we specify not to use the test semantics when creating |
| 5153 | // PeerConnectionWrappers. |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5154 | PeerConnectionIntegrationInteropTest() |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 5155 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB), |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5156 | caller_semantics_(std::get<0>(GetParam())), |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5157 | callee_semantics_(std::get<1>(GetParam())) {} |
| 5158 | |
| 5159 | bool CreatePeerConnectionWrappersWithSemantics() { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 5160 | return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_, |
| 5161 | callee_semantics_); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | const SdpSemantics caller_semantics_; |
| 5165 | const SdpSemantics callee_semantics_; |
| 5166 | }; |
| 5167 | |
| 5168 | TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) { |
| 5169 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5170 | ConnectFakeSignaling(); |
| 5171 | |
| 5172 | caller()->CreateAndSetAndSignalOffer(); |
| 5173 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5174 | } |
| 5175 | |
| 5176 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) { |
| 5177 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5178 | ConnectFakeSignaling(); |
| 5179 | auto audio_sender = caller()->AddAudioTrack(); |
| 5180 | |
| 5181 | caller()->CreateAndSetAndSignalOffer(); |
| 5182 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5183 | |
| 5184 | // Verify that one audio receiver has been created on the remote and that it |
| 5185 | // has the same track ID as the sending track. |
| 5186 | auto receivers = callee()->pc()->GetReceivers(); |
| 5187 | ASSERT_EQ(1u, receivers.size()); |
| 5188 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type()); |
| 5189 | EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id()); |
| 5190 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5191 | MediaExpectations media_expectations; |
| 5192 | media_expectations.CalleeExpectsSomeAudio(); |
| 5193 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) { |
| 5197 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5198 | ConnectFakeSignaling(); |
| 5199 | auto video_sender = caller()->AddVideoTrack(); |
| 5200 | auto audio_sender = caller()->AddAudioTrack(); |
| 5201 | |
| 5202 | caller()->CreateAndSetAndSignalOffer(); |
| 5203 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5204 | |
| 5205 | // Verify that one audio and one video receiver have been created on the |
| 5206 | // remote and that they have the same track IDs as the sending tracks. |
| 5207 | auto audio_receivers = |
| 5208 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO); |
| 5209 | ASSERT_EQ(1u, audio_receivers.size()); |
| 5210 | EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id()); |
| 5211 | auto video_receivers = |
| 5212 | callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO); |
| 5213 | ASSERT_EQ(1u, video_receivers.size()); |
| 5214 | EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id()); |
| 5215 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5216 | MediaExpectations media_expectations; |
| 5217 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 5218 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 5222 | OneAudioOneVideoLocalToOneAudioOneVideoRemote) { |
| 5223 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5224 | ConnectFakeSignaling(); |
| 5225 | caller()->AddAudioVideoTracks(); |
| 5226 | callee()->AddAudioVideoTracks(); |
| 5227 | |
| 5228 | caller()->CreateAndSetAndSignalOffer(); |
| 5229 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5230 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5231 | MediaExpectations media_expectations; |
| 5232 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 5233 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | TEST_P(PeerConnectionIntegrationInteropTest, |
| 5237 | ReverseRolesOneAudioLocalToOneVideoRemote) { |
| 5238 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics()); |
| 5239 | ConnectFakeSignaling(); |
| 5240 | caller()->AddAudioTrack(); |
| 5241 | callee()->AddVideoTrack(); |
| 5242 | |
| 5243 | caller()->CreateAndSetAndSignalOffer(); |
| 5244 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5245 | |
| 5246 | // Verify that only the audio track has been negotiated. |
| 5247 | EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size()); |
| 5248 | // Might also check that the callee's NegotiationNeeded flag is set. |
| 5249 | |
| 5250 | // Reverse roles. |
| 5251 | callee()->CreateAndSetAndSignalOffer(); |
| 5252 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5253 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5254 | MediaExpectations media_expectations; |
| 5255 | media_expectations.CallerExpectsSomeVideo(); |
| 5256 | media_expectations.CalleeExpectsSomeAudio(); |
| 5257 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5258 | } |
| 5259 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 5260 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | ba42e99 | 2018-04-09 14:10:01 -0700 | [diff] [blame] | 5261 | PeerConnectionIntegrationTest, |
| 5262 | PeerConnectionIntegrationInteropTest, |
| 5263 | Values(std::make_tuple(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 5264 | std::make_tuple(SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB))); |
| 5265 | |
| 5266 | // Test that if the Unified Plan side offers two video tracks then the Plan B |
| 5267 | // side will only see the first one and ignore the second. |
| 5268 | TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) { |
Steve Anton | 3acffc3 | 2018-04-12 17:21:03 -0700 | [diff] [blame] | 5269 | ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics( |
| 5270 | SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5271 | ConnectFakeSignaling(); |
| 5272 | auto first_sender = caller()->AddVideoTrack(); |
| 5273 | caller()->AddVideoTrack(); |
| 5274 | |
| 5275 | caller()->CreateAndSetAndSignalOffer(); |
| 5276 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5277 | |
| 5278 | // Verify that there is only one receiver and it corresponds to the first |
| 5279 | // added track. |
| 5280 | auto receivers = callee()->pc()->GetReceivers(); |
| 5281 | ASSERT_EQ(1u, receivers.size()); |
| 5282 | EXPECT_TRUE(receivers[0]->track()->enabled()); |
| 5283 | EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id()); |
| 5284 | |
Seth Hampson | 2f0d702 | 2018-02-20 11:54:42 -0800 | [diff] [blame] | 5285 | MediaExpectations media_expectations; |
| 5286 | media_expectations.CalleeExpectsSomeVideo(); |
| 5287 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
Steve Anton | 74255ff | 2018-01-24 18:32:57 -0800 | [diff] [blame] | 5288 | } |
| 5289 | |
Steve Anton | 2bed397 | 2019-01-04 17:04:30 -0800 | [diff] [blame] | 5290 | // Test that if the initial offer tagged BUNDLE section is rejected due to its |
| 5291 | // associated RtpTransceiver being stopped and another transceiver is added, |
| 5292 | // then renegotiation causes the callee to receive the new video track without |
| 5293 | // error. |
| 5294 | // This is a regression test for bugs.webrtc.org/9954 |
| 5295 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5296 | ReOfferWithStoppedBundleTaggedTransceiver) { |
| 5297 | RTCConfiguration config; |
| 5298 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 5299 | ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); |
| 5300 | ConnectFakeSignaling(); |
| 5301 | auto audio_transceiver_or_error = |
| 5302 | caller()->pc()->AddTransceiver(caller()->CreateLocalAudioTrack()); |
| 5303 | ASSERT_TRUE(audio_transceiver_or_error.ok()); |
| 5304 | auto audio_transceiver = audio_transceiver_or_error.MoveValue(); |
| 5305 | |
| 5306 | caller()->CreateAndSetAndSignalOffer(); |
| 5307 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5308 | { |
| 5309 | MediaExpectations media_expectations; |
| 5310 | media_expectations.CalleeExpectsSomeAudio(); |
| 5311 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5312 | } |
| 5313 | |
| 5314 | audio_transceiver->Stop(); |
| 5315 | caller()->pc()->AddTransceiver(caller()->CreateLocalVideoTrack()); |
| 5316 | |
| 5317 | caller()->CreateAndSetAndSignalOffer(); |
| 5318 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5319 | { |
| 5320 | MediaExpectations media_expectations; |
| 5321 | media_expectations.CalleeExpectsSomeVideo(); |
| 5322 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 5323 | } |
| 5324 | } |
| 5325 | |
Harald Alvestrand | d61f2a7 | 2019-05-08 20:20:59 +0200 | [diff] [blame^] | 5326 | #ifdef HAVE_SCTP |
| 5327 | |
| 5328 | TEST_F(PeerConnectionIntegrationTestUnifiedPlan, |
| 5329 | EndToEndCallWithBundledSctpDataChannel) { |
| 5330 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 5331 | ConnectFakeSignaling(); |
| 5332 | caller()->CreateDataChannel(); |
| 5333 | caller()->AddAudioVideoTracks(); |
| 5334 | callee()->AddAudioVideoTracks(); |
| 5335 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 5336 | caller()->CreateAndSetAndSignalOffer(); |
| 5337 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 5338 | // Ensure that media and data are multiplexed on the same DTLS transport. |
| 5339 | // This only works on Unified Plan, because transports are not exposed in plan |
| 5340 | // B. |
| 5341 | auto sctp_info = caller()->pc()->GetSctpTransport()->Information(); |
| 5342 | EXPECT_EQ(sctp_info.dtls_transport(), |
| 5343 | caller()->pc()->GetSenders()[0]->dtls_transport()); |
| 5344 | } |
| 5345 | |
| 5346 | #endif // HAVE_SCTP |
| 5347 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5348 | } // namespace |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 5349 | } // namespace webrtc |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 5350 | |
| 5351 | #endif // if !defined(THREAD_SANITIZER) |