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