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