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