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