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