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