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