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