henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 11 | #include <memory> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 12 | #include <utility> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "api/fakemetricsobserver.h" |
| 16 | #include "api/jsepicecandidate.h" |
| 17 | #include "api/jsepsessiondescription.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "media/base/fakemediaengine.h" |
| 19 | #include "media/base/fakevideorenderer.h" |
| 20 | #include "media/base/mediachannel.h" |
| 21 | #include "media/engine/fakewebrtccall.h" |
| 22 | #include "media/sctp/sctptransportinternal.h" |
| 23 | #include "p2p/base/packettransportinternal.h" |
| 24 | #include "p2p/base/stunserver.h" |
| 25 | #include "p2p/base/teststunserver.h" |
| 26 | #include "p2p/base/testturnserver.h" |
| 27 | #include "p2p/client/basicportallocator.h" |
| 28 | #include "pc/audiotrack.h" |
| 29 | #include "pc/channelmanager.h" |
| 30 | #include "pc/mediasession.h" |
| 31 | #include "pc/peerconnection.h" |
| 32 | #include "pc/sctputils.h" |
| 33 | #include "pc/test/fakertccertificategenerator.h" |
| 34 | #include "pc/videotrack.h" |
| 35 | #include "pc/webrtcsession.h" |
| 36 | #include "pc/webrtcsessiondescriptionfactory.h" |
| 37 | #include "rtc_base/checks.h" |
| 38 | #include "rtc_base/fakenetwork.h" |
| 39 | #include "rtc_base/firewallsocketserver.h" |
| 40 | #include "rtc_base/gunit.h" |
| 41 | #include "rtc_base/logging.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 42 | #include "rtc_base/stringutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "rtc_base/virtualsocketserver.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | using cricket::TransportInfo; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 47 | using rtc::SocketAddress; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 48 | using rtc::Thread; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | using webrtc::CreateSessionDescription; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 50 | using webrtc::CreateSessionDescriptionObserver; |
| 51 | using webrtc::CreateSessionDescriptionRequest; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 52 | using webrtc::DataChannel; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 53 | using webrtc::FakeMetricsObserver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | using webrtc::IceCandidateCollection; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 55 | using webrtc::InternalDataChannelInit; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | using webrtc::JsepIceCandidate; |
| 57 | using webrtc::JsepSessionDescription; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 58 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | using webrtc::PeerConnectionInterface; |
| 60 | using webrtc::SessionDescriptionInterface; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 61 | using webrtc::SessionStats; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | using webrtc::StreamCollection; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 63 | using webrtc::WebRtcSession; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 64 | using webrtc::kBundleWithoutRtcpMux; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 65 | using webrtc::kCreateChannelFailed; |
| 66 | using webrtc::kInvalidSdp; |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 67 | using webrtc::kMlineMismatchInAnswer; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 68 | using webrtc::kPushDownTDFailed; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 69 | using webrtc::kSdpWithoutIceUfragPwd; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 70 | using webrtc::kSdpWithoutDtlsFingerprint; |
| 71 | using webrtc::kSdpWithoutSdesCrypto; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | using webrtc::kSessionError; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 73 | using webrtc::kSessionErrorDesc; |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 74 | using webrtc::kMaxUnsignalledRecvStreams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 76 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 77 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 78 | static const int kClientAddrPort = 0; |
| 79 | static const char kClientAddrHost1[] = "11.11.11.11"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 80 | static const char kStunAddrHost[] = "99.99.99.1"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | |
| 82 | static const char kSessionVersion[] = "1"; |
| 83 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | // Media index of candidates belonging to the first media content. |
| 85 | static const int kMediaContentIndex0 = 0; |
Olga Sharonova | b49b661 | 2017-10-20 12:56:51 +0000 | [diff] [blame^] | 86 | static const char kMediaContentName0[] = "audio"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | |
| 88 | // Media index of candidates belonging to the second media content. |
| 89 | static const int kMediaContentIndex1 = 1; |
Olga Sharonova | b49b661 | 2017-10-20 12:56:51 +0000 | [diff] [blame^] | 90 | static const char kMediaContentName1[] = "video"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 92 | static const int kDefaultTimeout = 10000; // 10 seconds. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | static const int kIceCandidatesTimeout = 10000; |
| 94 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 95 | static const char kStream1[] = "stream1"; |
| 96 | static const char kVideoTrack1[] = "video1"; |
| 97 | static const char kAudioTrack1[] = "audio1"; |
| 98 | |
| 99 | static const char kStream2[] = "stream2"; |
| 100 | static const char kVideoTrack2[] = "video2"; |
| 101 | static const char kAudioTrack2[] = "audio2"; |
| 102 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 103 | static constexpr bool kActive = false; |
| 104 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 105 | enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; |
| 106 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | class MockIceObserver : public webrtc::IceObserver { |
| 108 | public: |
| 109 | MockIceObserver() |
| 110 | : oncandidatesready_(false), |
| 111 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 112 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 113 | } |
| 114 | |
Henrik Kjellander | 3fe372d | 2016-05-12 08:10:52 +0200 | [diff] [blame] | 115 | virtual ~MockIceObserver() = default; |
| 116 | |
zstein | 6dfd53a | 2017-03-06 13:49:03 -0800 | [diff] [blame] | 117 | void OnIceConnectionStateChange( |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 118 | PeerConnectionInterface::IceConnectionState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | ice_connection_state_ = new_state; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 120 | ice_connection_state_history_.push_back(new_state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 122 | void OnIceGatheringChange( |
| 123 | PeerConnectionInterface::IceGatheringState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | // We can never transition back to "new". |
| 125 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 126 | ice_gathering_state_ = new_state; |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 127 | oncandidatesready_ = |
| 128 | new_state == PeerConnectionInterface::kIceGatheringComplete; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // Found a new candidate. |
jbauch | 81bf7b0 | 2017-03-25 08:31:12 -0700 | [diff] [blame] | 132 | void OnIceCandidate( |
| 133 | std::unique_ptr<webrtc::IceCandidateInterface> candidate) override { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 134 | switch (candidate->sdp_mline_index()) { |
| 135 | case kMediaContentIndex0: |
| 136 | mline_0_candidates_.push_back(candidate->candidate()); |
| 137 | break; |
| 138 | case kMediaContentIndex1: |
| 139 | mline_1_candidates_.push_back(candidate->candidate()); |
| 140 | break; |
| 141 | default: |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 142 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 144 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | // The ICE gathering state should always be Gathering when a candidate is |
| 146 | // received (or possibly Completed in the case of the final candidate). |
| 147 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 148 | } |
| 149 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 150 | // Some local candidates are removed. |
| 151 | void OnIceCandidatesRemoved( |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 152 | const std::vector<cricket::Candidate>& candidates) override { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 153 | num_candidates_removed_ += candidates.size(); |
| 154 | } |
| 155 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | bool oncandidatesready_; |
| 157 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 158 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 159 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 160 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 161 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 162 | ice_connection_state_history_; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 163 | size_t num_candidates_removed_ = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | }; |
| 165 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 166 | // Used for tests in this file to verify that WebRtcSession responds to signals |
| 167 | // from the SctpTransport correctly, and calls Start with the correct |
| 168 | // local/remote ports. |
| 169 | class FakeSctpTransport : public cricket::SctpTransportInternal { |
| 170 | public: |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 171 | void SetTransportChannel(rtc::PacketTransportInternal* channel) override {} |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 172 | bool Start(int local_port, int remote_port) override { |
| 173 | local_port_ = local_port; |
| 174 | remote_port_ = remote_port; |
| 175 | return true; |
| 176 | } |
| 177 | bool OpenStream(int sid) override { return true; } |
| 178 | bool ResetStream(int sid) override { return true; } |
| 179 | bool SendData(const cricket::SendDataParams& params, |
| 180 | const rtc::CopyOnWriteBuffer& payload, |
| 181 | cricket::SendDataResult* result = nullptr) override { |
| 182 | return true; |
| 183 | } |
| 184 | bool ReadyToSendData() override { return true; } |
| 185 | void set_debug_name_for_testing(const char* debug_name) override {} |
| 186 | |
| 187 | int local_port() const { return local_port_; } |
| 188 | int remote_port() const { return remote_port_; } |
| 189 | |
| 190 | private: |
| 191 | int local_port_ = -1; |
| 192 | int remote_port_ = -1; |
| 193 | }; |
| 194 | |
| 195 | class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory { |
| 196 | public: |
| 197 | std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport( |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 198 | rtc::PacketTransportInternal*) override { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 199 | last_fake_sctp_transport_ = new FakeSctpTransport(); |
| 200 | return std::unique_ptr<cricket::SctpTransportInternal>( |
| 201 | last_fake_sctp_transport_); |
| 202 | } |
| 203 | |
| 204 | FakeSctpTransport* last_fake_sctp_transport() { |
| 205 | return last_fake_sctp_transport_; |
| 206 | } |
| 207 | |
| 208 | private: |
| 209 | FakeSctpTransport* last_fake_sctp_transport_ = nullptr; |
| 210 | }; |
| 211 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 213 | public: |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 214 | WebRtcSessionForTest( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 215 | webrtc::Call* fake_call, |
| 216 | cricket::ChannelManager* channel_manager, |
| 217 | const cricket::MediaConfig& media_config, |
| 218 | webrtc::RtcEventLog* event_log, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 219 | rtc::Thread* network_thread, |
| 220 | rtc::Thread* worker_thread, |
| 221 | rtc::Thread* signaling_thread, |
| 222 | cricket::PortAllocator* port_allocator, |
| 223 | webrtc::IceObserver* ice_observer, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 224 | std::unique_ptr<cricket::TransportController> transport_controller, |
| 225 | std::unique_ptr<FakeSctpTransportFactory> sctp_factory) |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 226 | : WebRtcSession(fake_call, channel_manager, media_config, event_log, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 227 | network_thread, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 228 | worker_thread, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 229 | signaling_thread, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 230 | port_allocator, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 231 | std::move(transport_controller), |
| 232 | std::move(sctp_factory)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | RegisterIceObserver(ice_observer); |
| 234 | } |
| 235 | virtual ~WebRtcSessionForTest() {} |
| 236 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 237 | // Note that these methods are only safe to use if the signaling thread |
| 238 | // is the same as the worker thread |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 239 | rtc::PacketTransportInternal* voice_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 240 | return rtp_transport_channel(voice_channel()); |
| 241 | } |
| 242 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 243 | rtc::PacketTransportInternal* voice_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 244 | return rtcp_transport_channel(voice_channel()); |
| 245 | } |
| 246 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 247 | rtc::PacketTransportInternal* video_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 248 | return rtp_transport_channel(video_channel()); |
| 249 | } |
| 250 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 251 | rtc::PacketTransportInternal* video_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 252 | return rtcp_transport_channel(video_channel()); |
| 253 | } |
| 254 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 255 | private: |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 256 | rtc::PacketTransportInternal* rtp_transport_channel( |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 257 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 258 | if (!ch) { |
| 259 | return nullptr; |
| 260 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 261 | return ch->rtp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 262 | } |
| 263 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 264 | rtc::PacketTransportInternal* rtcp_transport_channel( |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 265 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 266 | if (!ch) { |
| 267 | return nullptr; |
| 268 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 269 | return ch->rtcp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 270 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | }; |
| 272 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 273 | class WebRtcSessionCreateSDPObserverForTest |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 274 | : public rtc::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 275 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 276 | enum State { |
| 277 | kInit, |
| 278 | kFailed, |
| 279 | kSucceeded, |
| 280 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 281 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 282 | |
| 283 | // CreateSessionDescriptionObserver implementation. |
| 284 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 285 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 286 | state_ = kSucceeded; |
| 287 | } |
| 288 | virtual void OnFailure(const std::string& error) { |
| 289 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 290 | } |
| 291 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 292 | SessionDescriptionInterface* description() { return description_.get(); } |
| 293 | |
| 294 | SessionDescriptionInterface* ReleaseDescription() { |
| 295 | return description_.release(); |
| 296 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 298 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 299 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 300 | protected: |
| 301 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | |
| 303 | private: |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 304 | std::unique_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 305 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 306 | }; |
| 307 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 308 | class WebRtcSessionTest |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 309 | : public testing::TestWithParam<RTCCertificateGenerationMethod>, |
| 310 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 311 | protected: |
| 312 | // TODO Investigate why ChannelManager crashes, if it's created |
| 313 | // after stun_server. |
| 314 | WebRtcSessionTest() |
deadbeef | 98e186c | 2017-05-16 18:00:06 -0700 | [diff] [blame] | 315 | : vss_(new rtc::VirtualSocketServer()), |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 316 | fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 317 | thread_(fss_.get()), |
| 318 | media_engine_(new cricket::FakeMediaEngine()), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 319 | data_engine_(new cricket::FakeDataEngine()), |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 320 | channel_manager_(new cricket::ChannelManager( |
| 321 | std::unique_ptr<cricket::MediaEngineInterface>(media_engine_), |
| 322 | std::unique_ptr<cricket::DataEngineInterface>(data_engine_), |
| 323 | rtc::Thread::Current())), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 324 | fake_call_(webrtc::Call::Config(&event_log_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 325 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 326 | desc_factory_( |
| 327 | new cricket::MediaSessionDescriptionFactory(channel_manager_.get(), |
| 328 | tdesc_factory_.get())), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 329 | stun_socket_addr_( |
| 330 | rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)), |
| 331 | stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 332 | stun_socket_addr_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 333 | metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 334 | cricket::ServerAddresses stun_servers; |
| 335 | stun_servers.insert(stun_socket_addr_); |
| 336 | allocator_.reset(new cricket::BasicPortAllocator( |
| 337 | &network_manager_, |
| 338 | stun_servers, |
| 339 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 340 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 341 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | EXPECT_TRUE(channel_manager_->Init()); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 343 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void AddInterface(const SocketAddress& addr) { |
| 347 | network_manager_.AddInterface(addr); |
| 348 | } |
| 349 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 350 | // If |cert_generator| != null or |rtc_configuration| contains |certificates| |
| 351 | // then DTLS will be enabled unless explicitly disabled by |rtc_configuration| |
| 352 | // options. When DTLS is enabled a certificate will be used if provided, |
| 353 | // otherwise one will be generated using the |cert_generator|. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 354 | void Init( |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 355 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 356 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy, |
| 357 | const rtc::CryptoOptions& crypto_options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 358 | ASSERT_TRUE(session_.get() == NULL); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 359 | fake_sctp_transport_factory_ = new FakeSctpTransportFactory(); |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 360 | session_.reset(new WebRtcSessionForTest(&fake_call_, |
| 361 | channel_manager_.get(), cricket::MediaConfig(), &event_log_, |
| 362 | rtc::Thread::Current(), rtc::Thread::Current(), |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 363 | rtc::Thread::Current(), allocator_.get(), &observer_, |
| 364 | std::unique_ptr<cricket::TransportController>( |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 365 | new cricket::TransportController( |
| 366 | rtc::Thread::Current(), rtc::Thread::Current(), |
| 367 | allocator_.get(), |
| 368 | /*redetermine_role_on_ice_restart=*/true, crypto_options)), |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 369 | std::unique_ptr<FakeSctpTransportFactory>( |
| 370 | fake_sctp_transport_factory_))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 371 | session_->SignalDataChannelOpenMessage.connect( |
| 372 | this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 373 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 374 | configuration_.rtcp_mux_policy = rtcp_mux_policy; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 375 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 376 | observer_.ice_connection_state_); |
| 377 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 378 | observer_.ice_gathering_state_); |
| 379 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 380 | EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 381 | configuration_)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 382 | session_->set_metrics_observer(metrics_observer_); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 383 | crypto_options_ = crypto_options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | } |
| 385 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 386 | void OnDataChannelOpenMessage(const std::string& label, |
| 387 | const InternalDataChannelInit& config) { |
| 388 | last_data_channel_label_ = label; |
| 389 | last_data_channel_config_ = config; |
| 390 | } |
| 391 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 392 | void Init() { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 393 | Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 394 | rtc::CryptoOptions()); |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 395 | } |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 396 | |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 397 | void InitWithBundlePolicy( |
| 398 | PeerConnectionInterface::BundlePolicy bundle_policy) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 399 | configuration_.bundle_policy = bundle_policy; |
| 400 | Init(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Olga Sharonova | b49b661 | 2017-10-20 12:56:51 +0000 | [diff] [blame^] | 403 | void InitWithRtcpMuxPolicy( |
| 404 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 405 | PeerConnectionInterface::RTCConfiguration configuration; |
| 406 | Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions()); |
| 407 | } |
| 408 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 409 | // Successfully init with DTLS; with a certificate generated and supplied or |
| 410 | // with a store that generates it for us. |
| 411 | void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 412 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 413 | if (cert_gen_method == ALREADY_GENERATED) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 414 | configuration_.certificates.push_back( |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 415 | FakeRTCCertificateGenerator::GenerateCertificate()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 416 | } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 417 | cert_generator.reset(new FakeRTCCertificateGenerator()); |
| 418 | cert_generator->set_should_fail(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 419 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 420 | RTC_CHECK(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 421 | } |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 422 | Init(std::move(cert_generator), |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 423 | PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 424 | rtc::CryptoOptions()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 425 | } |
| 426 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 427 | // The following convenience functions can be applied for both local side and |
| 428 | // remote side. The flags can be overwritten for different use cases. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 429 | void SendAudioVideoStream1() { |
| 430 | send_stream_1_ = true; |
| 431 | send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 432 | local_send_audio_ = true; |
| 433 | local_send_video_ = true; |
| 434 | remote_send_audio_ = true; |
| 435 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void SendAudioVideoStream2() { |
| 439 | send_stream_1_ = false; |
| 440 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 441 | local_send_audio_ = true; |
| 442 | local_send_video_ = true; |
| 443 | remote_send_audio_ = true; |
| 444 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 445 | } |
| 446 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 447 | void SendAudioOnlyStream2() { |
| 448 | send_stream_1_ = false; |
| 449 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 450 | local_send_audio_ = true; |
| 451 | local_send_video_ = false; |
| 452 | remote_send_audio_ = true; |
| 453 | remote_send_video_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void SendVideoOnlyStream2() { |
| 457 | send_stream_1_ = false; |
| 458 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 459 | local_send_audio_ = false; |
| 460 | local_send_video_ = true; |
| 461 | remote_send_audio_ = false; |
| 462 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 463 | } |
| 464 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 465 | // Add the media sections to the options from |offered_media_sections_| when |
| 466 | // creating an answer or a new offer. |
| 467 | // This duplicates a lot of logic from PeerConnection but this can be fixed |
| 468 | // when PeerConnection and WebRtcSession are merged. |
| 469 | void AddExistingMediaSectionsAndSendersToOptions( |
| 470 | cricket::MediaSessionOptions* session_options, |
| 471 | bool send_audio, |
| 472 | bool recv_audio, |
| 473 | bool send_video, |
| 474 | bool recv_video) { |
| 475 | int num_sim_layer = 1; |
| 476 | for (auto media_description_options : offered_media_sections_) { |
| 477 | if (media_description_options.type == cricket::MEDIA_TYPE_AUDIO) { |
| 478 | bool stopped = !send_audio && !recv_audio; |
| 479 | auto media_desc_options = cricket::MediaDescriptionOptions( |
| 480 | cricket::MEDIA_TYPE_AUDIO, media_description_options.mid, |
| 481 | cricket::RtpTransceiverDirection(send_audio, recv_audio), stopped); |
| 482 | if (send_stream_1_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 483 | media_desc_options.AddAudioSender(kAudioTrack1, {kStream1}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 484 | } |
| 485 | if (send_stream_2_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 486 | media_desc_options.AddAudioSender(kAudioTrack2, {kStream2}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 487 | } |
| 488 | session_options->media_description_options.push_back( |
| 489 | media_desc_options); |
| 490 | } else if (media_description_options.type == cricket::MEDIA_TYPE_VIDEO) { |
| 491 | bool stopped = !send_video && !recv_video; |
| 492 | auto media_desc_options = cricket::MediaDescriptionOptions( |
| 493 | cricket::MEDIA_TYPE_VIDEO, media_description_options.mid, |
| 494 | cricket::RtpTransceiverDirection(send_video, recv_video), stopped); |
| 495 | if (send_stream_1_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 496 | media_desc_options.AddVideoSender(kVideoTrack1, {kStream1}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 497 | num_sim_layer); |
| 498 | } |
| 499 | if (send_stream_2_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 500 | media_desc_options.AddVideoSender(kVideoTrack2, {kStream2}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 501 | num_sim_layer); |
| 502 | } |
| 503 | session_options->media_description_options.push_back( |
| 504 | media_desc_options); |
| 505 | } else if (media_description_options.type == cricket::MEDIA_TYPE_DATA) { |
| 506 | session_options->media_description_options.push_back( |
| 507 | cricket::MediaDescriptionOptions( |
| 508 | cricket::MEDIA_TYPE_DATA, media_description_options.mid, |
| 509 | // Direction for data sections is meaningless, but legacy |
| 510 | // endpoints might expect sendrecv. |
| 511 | cricket::RtpTransceiverDirection(true, true), false)); |
| 512 | } else { |
| 513 | RTC_NOTREACHED(); |
| 514 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 515 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // Add the existing media sections first and then add new media sections if |
| 519 | // needed. |
| 520 | void AddMediaSectionsAndSendersToOptions( |
| 521 | cricket::MediaSessionOptions* session_options, |
| 522 | bool send_audio, |
| 523 | bool recv_audio, |
| 524 | bool send_video, |
| 525 | bool recv_video) { |
| 526 | AddExistingMediaSectionsAndSendersToOptions( |
| 527 | session_options, send_audio, recv_audio, send_video, recv_video); |
| 528 | |
| 529 | if (!session_options->has_audio() && (send_audio || recv_audio)) { |
| 530 | cricket::MediaDescriptionOptions media_desc_options = |
| 531 | cricket::MediaDescriptionOptions( |
| 532 | cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 533 | cricket::RtpTransceiverDirection(send_audio, recv_audio), |
| 534 | kActive); |
| 535 | if (send_stream_1_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 536 | media_desc_options.AddAudioSender(kAudioTrack1, {kStream1}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 537 | } |
| 538 | if (send_stream_2_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 539 | media_desc_options.AddAudioSender(kAudioTrack2, {kStream2}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 540 | } |
| 541 | session_options->media_description_options.push_back(media_desc_options); |
| 542 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 543 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 544 | |
| 545 | if (!session_options->has_video() && (send_video || recv_video)) { |
| 546 | cricket::MediaDescriptionOptions media_desc_options = |
| 547 | cricket::MediaDescriptionOptions( |
| 548 | cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 549 | cricket::RtpTransceiverDirection(send_video, recv_video), |
| 550 | kActive); |
| 551 | int num_sim_layer = 1; |
| 552 | if (send_stream_1_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 553 | media_desc_options.AddVideoSender(kVideoTrack1, {kStream1}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 554 | num_sim_layer); |
| 555 | } |
| 556 | if (send_stream_2_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 557 | media_desc_options.AddVideoSender(kVideoTrack2, {kStream2}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 558 | num_sim_layer); |
| 559 | } |
| 560 | session_options->media_description_options.push_back(media_desc_options); |
| 561 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 562 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 563 | |
| 564 | if (!session_options->has_data() && |
| 565 | (data_channel_ || |
| 566 | session_options->data_channel_type != cricket::DCT_NONE)) { |
| 567 | cricket::MediaDescriptionOptions media_desc_options = |
| 568 | cricket::MediaDescriptionOptions( |
| 569 | cricket::MEDIA_TYPE_DATA, cricket::CN_DATA, |
| 570 | cricket::RtpTransceiverDirection(true, true), kActive); |
| 571 | if (session_options->data_channel_type == cricket::DCT_RTP) { |
| 572 | media_desc_options.AddRtpDataChannel(data_channel_->label(), |
| 573 | data_channel_->label()); |
| 574 | } |
| 575 | session_options->media_description_options.push_back(media_desc_options); |
| 576 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
| 580 | void GetOptionsForOffer( |
| 581 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 582 | cricket::MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 583 | ExtractSharedMediaSessionOptions(rtc_options, session_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 584 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 585 | // |recv_X| is true by default if |offer_to_receive_X| is undefined. |
| 586 | bool recv_audio = rtc_options.offer_to_receive_audio != 0; |
| 587 | bool recv_video = rtc_options.offer_to_receive_video != 0; |
| 588 | |
| 589 | AddMediaSectionsAndSendersToOptions(session_options, local_send_audio_, |
| 590 | recv_audio, local_send_video_, |
| 591 | recv_video); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 592 | session_options->bundle_enabled = |
| 593 | session_options->bundle_enabled && |
| 594 | (session_options->has_audio() || session_options->has_video() || |
| 595 | session_options->has_data()); |
| 596 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 597 | session_options->crypto_options = crypto_options_; |
| 598 | } |
| 599 | |
| 600 | void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 601 | AddExistingMediaSectionsAndSendersToOptions( |
| 602 | session_options, local_send_audio_, local_recv_audio_, |
| 603 | local_send_video_, local_recv_video_); |
| 604 | |
| 605 | session_options->bundle_enabled = |
| 606 | session_options->bundle_enabled && |
| 607 | (session_options->has_audio() || session_options->has_video() || |
| 608 | session_options->has_data()); |
| 609 | |
| 610 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 611 | session_options->data_channel_type = session_->data_channel_type(); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 612 | } |
| 613 | |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 614 | session_options->crypto_options = crypto_options_; |
| 615 | } |
| 616 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 617 | void GetOptionsForRemoteAnswer( |
| 618 | cricket::MediaSessionOptions* session_options) { |
| 619 | bool recv_audio = local_send_audio_ || remote_recv_audio_; |
| 620 | bool recv_video = local_send_video_ || remote_recv_video_; |
| 621 | bool send_audio = false; |
| 622 | bool send_video = false; |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 623 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 624 | AddExistingMediaSectionsAndSendersToOptions( |
| 625 | session_options, send_audio, recv_audio, send_video, recv_video); |
| 626 | |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 627 | session_options->bundle_enabled = |
| 628 | session_options->bundle_enabled && |
| 629 | (session_options->has_audio() || session_options->has_video() || |
| 630 | session_options->has_data()); |
| 631 | |
| 632 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 633 | session_options->data_channel_type = session_->data_channel_type(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 634 | } |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 635 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 636 | session_options->crypto_options = crypto_options_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 637 | } |
| 638 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 639 | void GetOptionsForRemoteOffer(cricket::MediaSessionOptions* session_options) { |
| 640 | AddMediaSectionsAndSendersToOptions(session_options, remote_send_audio_, |
| 641 | remote_recv_audio_, remote_send_video_, |
| 642 | remote_recv_video_); |
| 643 | session_options->bundle_enabled = |
| 644 | (session_options->has_audio() || session_options->has_video() || |
| 645 | session_options->has_data()); |
| 646 | |
| 647 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 648 | session_options->data_channel_type = session_->data_channel_type(); |
| 649 | } |
| 650 | |
| 651 | session_options->crypto_options = crypto_options_; |
| 652 | } |
| 653 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 654 | // Creates a local offer and applies it. Starts ICE. |
| 655 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 656 | // to decide which streams to create. |
| 657 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 658 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 659 | SetLocalDescriptionWithoutError(offer); |
| 660 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 661 | observer_.ice_gathering_state_, |
| 662 | kIceCandidatesTimeout); |
| 663 | } |
| 664 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 665 | SessionDescriptionInterface* CreateOffer() { |
| 666 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 667 | options.offer_to_receive_audio = |
| 668 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 669 | return CreateOffer(options); |
| 670 | } |
| 671 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 672 | SessionDescriptionInterface* CreateOffer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 673 | const PeerConnectionInterface::RTCOfferAnswerOptions options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 674 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 675 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 676 | cricket::MediaSessionOptions session_options; |
| 677 | GetOptionsForOffer(options, &session_options); |
| 678 | session_->CreateOffer(observer, options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 679 | EXPECT_TRUE_WAIT( |
| 680 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 681 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 682 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | SessionDescriptionInterface* CreateAnswer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 686 | const cricket::MediaSessionOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 687 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 688 | = new WebRtcSessionCreateSDPObserverForTest(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 689 | cricket::MediaSessionOptions session_options = options; |
| 690 | GetOptionsForAnswer(&session_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 691 | session_->CreateAnswer(observer, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 692 | EXPECT_TRUE_WAIT( |
| 693 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 694 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 695 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 696 | } |
| 697 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 698 | SessionDescriptionInterface* CreateAnswer() { |
| 699 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 700 | options.bundle_enabled = true; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 701 | return CreateAnswer(options); |
| 702 | } |
| 703 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | // Set the internal fake description factories to do DTLS-SRTP. |
| 705 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 706 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 707 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 708 | rtc::ToString(rtc::CreateRandomId()); |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 709 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 710 | tdesc_factory_->set_certificate( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 711 | rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 712 | rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 713 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 714 | } |
| 715 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 716 | // Compares ufrag/password only for the specified |media_type|. |
| 717 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 718 | const cricket::SessionDescription* desc2, |
| 719 | cricket::MediaType media_type) { |
| 720 | if (desc1->contents().size() != desc2->contents().size()) { |
| 721 | return false; |
| 722 | } |
| 723 | |
| 724 | const cricket::ContentInfo* cinfo = |
| 725 | cricket::GetFirstMediaContent(desc1->contents(), media_type); |
| 726 | const cricket::TransportDescription* transport_desc1 = |
| 727 | desc1->GetTransportDescriptionByName(cinfo->name); |
| 728 | const cricket::TransportDescription* transport_desc2 = |
| 729 | desc2->GetTransportDescriptionByName(cinfo->name); |
| 730 | if (!transport_desc1 || !transport_desc2) { |
| 731 | return false; |
| 732 | } |
| 733 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 734 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 735 | return false; |
| 736 | } |
| 737 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 738 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 739 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 740 | // Sets ufrag/pwd for specified |media_type|. |
| 741 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 742 | cricket::MediaType media_type, |
| 743 | const std::string& ufrag, |
| 744 | const std::string& pwd) { |
| 745 | cricket::SessionDescription* desc = current_desc->description(); |
| 746 | const cricket::ContentInfo* cinfo = |
| 747 | cricket::GetFirstMediaContent(desc->contents(), media_type); |
| 748 | TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name); |
| 749 | cricket::TransportDescription* transport_desc = |
| 750 | &transport_info->description; |
| 751 | transport_desc->ice_ufrag = ufrag; |
| 752 | transport_desc->ice_pwd = pwd; |
| 753 | } |
| 754 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 755 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
Steve Anton | 3df5dca | 2017-10-19 16:11:30 -0700 | [diff] [blame] | 756 | ASSERT_TRUE(session_->SetLocalDescription(rtc::WrapUnique(desc), nullptr)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 757 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 758 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 759 | void SetLocalDescriptionExpectError(const std::string& action, |
| 760 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | SessionDescriptionInterface* desc) { |
| 762 | std::string error; |
Steve Anton | 3df5dca | 2017-10-19 16:11:30 -0700 | [diff] [blame] | 763 | EXPECT_FALSE(session_->SetLocalDescription(rtc::WrapUnique(desc), &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 764 | std::string sdp_type = "local "; |
| 765 | sdp_type.append(action); |
| 766 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 767 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 768 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 769 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 770 | SessionDescriptionInterface* desc) { |
| 771 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 772 | expected_error, desc); |
| 773 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 774 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
Steve Anton | 3df5dca | 2017-10-19 16:11:30 -0700 | [diff] [blame] | 775 | ASSERT_TRUE(session_->SetRemoteDescription(rtc::WrapUnique(desc), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 776 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 777 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 778 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 779 | SessionDescriptionInterface* desc) { |
| 780 | std::string error; |
Steve Anton | 3df5dca | 2017-10-19 16:11:30 -0700 | [diff] [blame] | 781 | EXPECT_FALSE(session_->SetRemoteDescription(rtc::WrapUnique(desc), &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 782 | std::string sdp_type = "remote "; |
| 783 | sdp_type.append(action); |
| 784 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 786 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 787 | void SetRemoteDescriptionOfferExpectError( |
| 788 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 789 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 790 | expected_error, desc); |
| 791 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 792 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 793 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 794 | cricket::MediaSessionOptions options, |
| 795 | cricket::SecurePolicy secure_policy, |
| 796 | const std::string& session_version, |
| 797 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 798 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 799 | const cricket::SessionDescription* cricket_desc = NULL; |
| 800 | if (current_desc) { |
| 801 | cricket_desc = current_desc->description(); |
| 802 | session_id = current_desc->session_id(); |
| 803 | } |
| 804 | |
| 805 | desc_factory_->set_secure(secure_policy); |
| 806 | JsepSessionDescription* offer( |
| 807 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 808 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 809 | session_id, session_version)) { |
| 810 | delete offer; |
| 811 | offer = NULL; |
| 812 | } |
| 813 | return offer; |
| 814 | } |
| 815 | JsepSessionDescription* CreateRemoteOffer( |
| 816 | cricket::MediaSessionOptions options) { |
| 817 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 818 | kSessionVersion, NULL); |
| 819 | } |
| 820 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 821 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 822 | return CreateRemoteOfferWithVersion( |
| 823 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 824 | } |
| 825 | JsepSessionDescription* CreateRemoteOffer( |
| 826 | cricket::MediaSessionOptions options, |
| 827 | const SessionDescriptionInterface* current_desc) { |
| 828 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 829 | kSessionVersion, current_desc); |
| 830 | } |
| 831 | |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 832 | SessionDescriptionInterface* CreateRemoteOfferWithSctpPort( |
| 833 | const char* sctp_stream_name, |
| 834 | int new_port, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 835 | cricket::MediaSessionOptions options) { |
| 836 | options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 837 | GetOptionsForRemoteOffer(&options); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 838 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 839 | } |
| 840 | |
| 841 | // Takes ownership of offer_basis (and deletes it). |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 842 | SessionDescriptionInterface* ChangeSDPSctpPort( |
| 843 | int new_port, |
| 844 | webrtc::SessionDescriptionInterface* offer_basis) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 845 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 846 | // SessionDescription from the mutated string. |
| 847 | const char* default_port_str = "5000"; |
| 848 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 849 | rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 850 | std::string offer_str; |
| 851 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 852 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 853 | new_port_str, strlen(new_port_str), |
| 854 | &offer_str); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 855 | SessionDescriptionInterface* offer = |
| 856 | CreateSessionDescription(offer_basis->type(), offer_str, nullptr); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 857 | delete offer_basis; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 858 | return offer; |
| 859 | } |
| 860 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 861 | // Create a remote offer. Call SendAudioVideoStreamX() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | // before this function to decide which streams to create. |
| 863 | JsepSessionDescription* CreateRemoteOffer() { |
| 864 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 865 | GetOptionsForRemoteOffer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | return CreateRemoteOffer(options, session_->remote_description()); |
| 867 | } |
| 868 | |
| 869 | JsepSessionDescription* CreateRemoteAnswer( |
| 870 | const SessionDescriptionInterface* offer, |
| 871 | cricket::MediaSessionOptions options, |
| 872 | cricket::SecurePolicy policy) { |
| 873 | desc_factory_->set_secure(policy); |
| 874 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 875 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 876 | JsepSessionDescription* answer( |
| 877 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 878 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 879 | options, NULL), |
| 880 | session_id, kSessionVersion)) { |
| 881 | delete answer; |
| 882 | answer = NULL; |
| 883 | } |
| 884 | return answer; |
| 885 | } |
| 886 | |
| 887 | JsepSessionDescription* CreateRemoteAnswer( |
| 888 | const SessionDescriptionInterface* offer, |
| 889 | cricket::MediaSessionOptions options) { |
| 890 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 891 | } |
| 892 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 893 | // Creates an answer session description. |
| 894 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 895 | // to decide which streams to create. |
| 896 | JsepSessionDescription* CreateRemoteAnswer( |
| 897 | const SessionDescriptionInterface* offer) { |
| 898 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 899 | GetOptionsForAnswer(&options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 900 | options.bundle_enabled = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 901 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 902 | } |
| 903 | |
Olga Sharonova | b49b661 | 2017-10-20 12:56:51 +0000 | [diff] [blame^] | 904 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
| 905 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 906 | Init(); |
| 907 | SendAudioVideoStream1(); |
| 908 | |
| 909 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 910 | options.use_rtp_mux = bundle; |
| 911 | |
| 912 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 913 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 914 | // and answer. |
| 915 | SetLocalDescriptionWithoutError(offer); |
| 916 | |
| 917 | std::unique_ptr<SessionDescriptionInterface> answer( |
| 918 | CreateRemoteAnswer(session_->local_description())); |
| 919 | std::string sdp; |
| 920 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 921 | |
| 922 | size_t expected_candidate_num = 2; |
| 923 | if (!rtcp_mux) { |
| 924 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 925 | // for rtp and rtcp. |
| 926 | expected_candidate_num = 4; |
| 927 | // Disable rtcp-mux from the answer |
| 928 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 929 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
| 930 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
| 931 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 932 | &sdp); |
| 933 | } |
| 934 | |
| 935 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 936 | JsepSessionDescription::kAnswer, sdp, NULL); |
| 937 | |
| 938 | // SetRemoteDescription to enable rtcp mux. |
| 939 | SetRemoteDescriptionWithoutError(new_answer); |
| 940 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 941 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
| 942 | if (bundle) { |
| 943 | EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
| 944 | } else { |
| 945 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
| 946 | } |
| 947 | } |
| 948 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 949 | // The method sets up a call from the session to itself, in a loopback |
| 950 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 951 | // disconnection, and then a permanent disconnection. |
| 952 | // This code is placed in a method so that it can be invoked |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 953 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 954 | // While running the call, this method also checks if the session goes through |
| 955 | // the correct sequence of ICE states when a connection is established, |
| 956 | // broken, and re-established. |
| 957 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 958 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 959 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 960 | // The Gathering state should go: New -> Gathering -> Completed. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 961 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 962 | void SetupLoopbackCall() { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 963 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 964 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 965 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 966 | |
| 967 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 968 | observer_.ice_gathering_state_); |
| 969 | SetLocalDescriptionWithoutError(offer); |
| 970 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 971 | observer_.ice_connection_state_); |
| 972 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 973 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 974 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 975 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 976 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 977 | |
| 978 | std::string sdp; |
| 979 | offer->ToString(&sdp); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 980 | SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( |
| 981 | JsepSessionDescription::kAnswer, sdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 982 | ASSERT_TRUE(desc != NULL); |
| 983 | SetRemoteDescriptionWithoutError(desc); |
| 984 | |
| 985 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 986 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 987 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 988 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 989 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 990 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 991 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 992 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 993 | void TestPacketOptions() { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 994 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 995 | |
| 996 | SetupLoopbackCall(); |
| 997 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 998 | // Wait for channel to be ready for sending. |
| 999 | EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1000 | uint8_t test_packet[15] = {0}; |
| 1001 | rtc::PacketOptions options; |
| 1002 | options.packet_id = 10; |
| 1003 | media_engine_->GetVideoChannel(0) |
| 1004 | ->SendRtp(test_packet, sizeof(test_packet), options); |
| 1005 | |
| 1006 | const int kPacketTimeout = 2000; |
deadbeef | 14461d4 | 2016-06-15 11:06:57 -0700 | [diff] [blame] | 1007 | EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(), |
| 1008 | kPacketTimeout); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1009 | EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1); |
| 1010 | } |
| 1011 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1012 | void CreateDataChannel() { |
deadbeef | fc648b6 | 2015-10-13 16:42:33 -0700 | [diff] [blame] | 1013 | webrtc::InternalDataChannelInit dci; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1014 | RTC_CHECK(session_.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1015 | dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP; |
| 1016 | data_channel_ = DataChannel::Create( |
| 1017 | session_.get(), session_->data_channel_type(), "datachannel", dci); |
| 1018 | } |
| 1019 | |
| 1020 | void SetLocalDescriptionWithDataChannel() { |
| 1021 | CreateDataChannel(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1022 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1023 | SetLocalDescriptionWithoutError(offer); |
| 1024 | } |
| 1025 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1026 | webrtc::RtcEventLogNullImpl event_log_; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 1027 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 1028 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
| 1029 | rtc::AutoSocketServerThread thread_; |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 1030 | // |media_engine_| and |data_engine_| are actually owned by |
| 1031 | // |channel_manager_|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1032 | cricket::FakeMediaEngine* media_engine_; |
| 1033 | cricket::FakeDataEngine* data_engine_; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1034 | // Actually owned by session_. |
| 1035 | FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1036 | std::unique_ptr<cricket::ChannelManager> channel_manager_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1037 | cricket::FakeCall fake_call_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1038 | std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
| 1039 | std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1040 | rtc::SocketAddress stun_socket_addr_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1041 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1042 | rtc::FakeNetworkManager network_manager_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1043 | std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1044 | PeerConnectionFactoryInterface::Options options_; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1045 | PeerConnectionInterface::RTCConfiguration configuration_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1046 | std::unique_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1047 | MockIceObserver observer_; |
| 1048 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1049 | cricket::FakeVoiceMediaChannel* voice_channel_; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1050 | rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1051 | // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1052 | bool send_stream_1_ = false; |
| 1053 | bool send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1054 | bool local_send_audio_ = false; |
| 1055 | bool local_send_video_ = false; |
| 1056 | bool local_recv_audio_ = true; |
| 1057 | bool local_recv_video_ = true; |
| 1058 | bool remote_send_audio_ = false; |
| 1059 | bool remote_send_video_ = false; |
| 1060 | bool remote_recv_audio_ = true; |
| 1061 | bool remote_recv_video_ = true; |
| 1062 | std::vector<cricket::MediaDescriptionOptions> offered_media_sections_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1063 | rtc::scoped_refptr<DataChannel> data_channel_; |
| 1064 | // Last values received from data channel creation signal. |
| 1065 | std::string last_data_channel_label_; |
| 1066 | InternalDataChannelInit last_data_channel_config_; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1067 | rtc::CryptoOptions crypto_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1068 | }; |
| 1069 | |
Olga Sharonova | b49b661 | 2017-10-20 12:56:51 +0000 | [diff] [blame^] | 1070 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1071 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1072 | } |
| 1073 | |
| 1074 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1075 | // with rtcp-mux and/or bundle. |
| 1076 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1077 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1078 | } |
| 1079 | |
| 1080 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1081 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1082 | } |
| 1083 | |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1084 | // Test that we can create and set an answer correctly when different |
| 1085 | // SSL roles have been negotiated for different transports. |
| 1086 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525 |
| 1087 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) { |
| 1088 | SendAudioVideoStream1(); |
| 1089 | InitWithDtls(GetParam()); |
| 1090 | SetFactoryDtlsSrtp(); |
| 1091 | |
| 1092 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1093 | SetLocalDescriptionWithoutError(offer); |
| 1094 | |
| 1095 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1096 | GetOptionsForAnswer(&options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1097 | |
| 1098 | // First, negotiate different SSL roles. |
| 1099 | SessionDescriptionInterface* answer = |
| 1100 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1101 | TransportInfo* audio_transport_info = |
| 1102 | answer->description()->GetTransportInfoByName("audio"); |
| 1103 | audio_transport_info->description.connection_role = |
| 1104 | cricket::CONNECTIONROLE_ACTIVE; |
| 1105 | TransportInfo* video_transport_info = |
| 1106 | answer->description()->GetTransportInfoByName("video"); |
| 1107 | video_transport_info->description.connection_role = |
| 1108 | cricket::CONNECTIONROLE_PASSIVE; |
| 1109 | SetRemoteDescriptionWithoutError(answer); |
| 1110 | |
| 1111 | // Now create an offer in the reverse direction, and ensure the initial |
| 1112 | // offerer responds with an answer with correct SSL roles. |
| 1113 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1114 | kSessionVersion, |
| 1115 | session_->remote_description()); |
| 1116 | SetRemoteDescriptionWithoutError(offer); |
| 1117 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1118 | cricket::MediaSessionOptions answer_options; |
| 1119 | answer_options.bundle_enabled = true; |
| 1120 | answer = CreateAnswer(answer_options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1121 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1122 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1123 | audio_transport_info->description.connection_role); |
| 1124 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1125 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 1126 | video_transport_info->description.connection_role); |
| 1127 | SetLocalDescriptionWithoutError(answer); |
| 1128 | |
| 1129 | // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of |
| 1130 | // audio is transferred over to video in the answer that completes the BUNDLE |
| 1131 | // negotiation. |
| 1132 | options.bundle_enabled = true; |
| 1133 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1134 | kSessionVersion, |
| 1135 | session_->remote_description()); |
| 1136 | SetRemoteDescriptionWithoutError(offer); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1137 | answer = CreateAnswer(answer_options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1138 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1139 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1140 | audio_transport_info->description.connection_role); |
| 1141 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1142 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1143 | video_transport_info->description.connection_role); |
| 1144 | SetLocalDescriptionWithoutError(answer); |
| 1145 | } |
| 1146 | |
Olga Sharonova | b49b661 | 2017-10-20 12:56:51 +0000 | [diff] [blame^] | 1147 | // Test that candidates sent to the "video" transport do not get pushed down to |
| 1148 | // the "audio" transport channel when bundling. |
| 1149 | TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { |
| 1150 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1151 | |
| 1152 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
| 1153 | SendAudioVideoStream1(); |
| 1154 | |
| 1155 | cricket::MediaSessionOptions offer_options; |
| 1156 | GetOptionsForRemoteOffer(&offer_options); |
| 1157 | offer_options.bundle_enabled = true; |
| 1158 | |
| 1159 | SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options); |
| 1160 | SetRemoteDescriptionWithoutError(offer); |
| 1161 | |
| 1162 | cricket::MediaSessionOptions answer_options; |
| 1163 | answer_options.bundle_enabled = true; |
| 1164 | SessionDescriptionInterface* answer = CreateAnswer(answer_options); |
| 1165 | SetLocalDescriptionWithoutError(answer); |
| 1166 | |
| 1167 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1168 | session_->video_rtp_transport_channel()); |
| 1169 | |
| 1170 | cricket::BaseChannel* voice_channel = session_->voice_channel(); |
| 1171 | ASSERT_TRUE(voice_channel != NULL); |
| 1172 | |
| 1173 | // Checks if one of the transport channels contains a connection using a given |
| 1174 | // port. |
| 1175 | auto connection_with_remote_port = [this](int port) { |
| 1176 | std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s(); |
| 1177 | for (auto& kv : stats->transport_stats) { |
| 1178 | for (auto& chan_stat : kv.second.channel_stats) { |
| 1179 | for (auto& conn_info : chan_stat.connection_infos) { |
| 1180 | if (conn_info.remote_candidate.address().port() == port) { |
| 1181 | return true; |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | return false; |
| 1187 | }; |
| 1188 | |
| 1189 | EXPECT_FALSE(connection_with_remote_port(5000)); |
| 1190 | EXPECT_FALSE(connection_with_remote_port(5001)); |
| 1191 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 1192 | |
| 1193 | // The way the *_WAIT checks work is they only wait if the condition fails, |
| 1194 | // which does not help in the case where state is not changing. This is |
| 1195 | // problematic in this test since we want to verify that adding a video |
| 1196 | // candidate does _not_ change state. So we interleave candidates and assume |
| 1197 | // that messages are executed in the order they were posted. |
| 1198 | |
| 1199 | // First audio candidate. |
| 1200 | cricket::Candidate candidate0; |
| 1201 | candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
| 1202 | candidate0.set_component(1); |
| 1203 | candidate0.set_protocol("udp"); |
| 1204 | candidate0.set_type("local"); |
| 1205 | JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0, |
| 1206 | candidate0); |
| 1207 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0)); |
| 1208 | |
| 1209 | // Video candidate. |
| 1210 | cricket::Candidate candidate1; |
| 1211 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 1212 | candidate1.set_component(1); |
| 1213 | candidate1.set_protocol("udp"); |
| 1214 | candidate1.set_type("local"); |
| 1215 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 1216 | candidate1); |
| 1217 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 1218 | |
| 1219 | // Second audio candidate. |
| 1220 | cricket::Candidate candidate2; |
| 1221 | candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001)); |
| 1222 | candidate2.set_component(1); |
| 1223 | candidate2.set_protocol("udp"); |
| 1224 | candidate2.set_type("local"); |
| 1225 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 1226 | candidate2); |
| 1227 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 1228 | |
| 1229 | EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000); |
| 1230 | EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000); |
| 1231 | |
| 1232 | // No need here for a _WAIT check since we are checking that state hasn't |
| 1233 | // changed: if this is false we would be doing waits for nothing and if this |
| 1234 | // is true then there will be no messages processed anyways. |
| 1235 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 1236 | } |
| 1237 | |
| 1238 | // kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE. |
| 1239 | TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) { |
| 1240 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
| 1241 | SendAudioVideoStream1(); |
| 1242 | |
| 1243 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1244 | options.use_rtp_mux = true; |
| 1245 | |
| 1246 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1247 | SetLocalDescriptionWithoutError(offer); |
| 1248 | |
| 1249 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1250 | session_->video_rtp_transport_channel()); |
| 1251 | |
| 1252 | SendAudioVideoStream2(); |
| 1253 | SessionDescriptionInterface* answer = |
| 1254 | CreateRemoteAnswer(session_->local_description()); |
| 1255 | SetRemoteDescriptionWithoutError(answer); |
| 1256 | |
| 1257 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1258 | session_->video_rtp_transport_channel()); |
| 1259 | } |
| 1260 | |
| 1261 | // kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer. |
| 1262 | TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) { |
| 1263 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
| 1264 | SendAudioVideoStream1(); |
| 1265 | |
| 1266 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1267 | options.use_rtp_mux = true; |
| 1268 | |
| 1269 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1270 | SetLocalDescriptionWithoutError(offer); |
| 1271 | |
| 1272 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1273 | session_->video_rtp_transport_channel()); |
| 1274 | |
| 1275 | SendAudioVideoStream2(); |
| 1276 | |
| 1277 | // Remove BUNDLE from the answer. |
| 1278 | std::unique_ptr<SessionDescriptionInterface> answer( |
| 1279 | CreateRemoteAnswer(session_->local_description())); |
| 1280 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 1281 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1282 | JsepSessionDescription* modified_answer = |
| 1283 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 1284 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 1285 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 1286 | |
| 1287 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1288 | session_->video_rtp_transport_channel()); |
| 1289 | } |
| 1290 | |
| 1291 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer. |
| 1292 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) { |
| 1293 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 1294 | SendAudioVideoStream1(); |
| 1295 | |
| 1296 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1297 | options.use_rtp_mux = true; |
| 1298 | |
| 1299 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1300 | SetLocalDescriptionWithoutError(offer); |
| 1301 | |
| 1302 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1303 | session_->video_rtp_transport_channel()); |
| 1304 | |
| 1305 | SendAudioVideoStream2(); |
| 1306 | SessionDescriptionInterface* answer = |
| 1307 | CreateRemoteAnswer(session_->local_description()); |
| 1308 | SetRemoteDescriptionWithoutError(answer); |
| 1309 | |
| 1310 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1311 | session_->video_rtp_transport_channel()); |
| 1312 | } |
| 1313 | |
| 1314 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no |
| 1315 | // audio content in the answer. |
| 1316 | TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) { |
| 1317 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 1318 | SendAudioVideoStream1(); |
| 1319 | |
| 1320 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1321 | options.use_rtp_mux = true; |
| 1322 | |
| 1323 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1324 | SetLocalDescriptionWithoutError(offer); |
| 1325 | |
| 1326 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1327 | session_->video_rtp_transport_channel()); |
| 1328 | |
| 1329 | SendVideoOnlyStream2(); |
| 1330 | local_send_audio_ = false; |
| 1331 | remote_recv_audio_ = false; |
| 1332 | cricket::MediaSessionOptions recv_options; |
| 1333 | GetOptionsForRemoteAnswer(&recv_options); |
| 1334 | SessionDescriptionInterface* answer = |
| 1335 | CreateRemoteAnswer(session_->local_description(), recv_options); |
| 1336 | SetRemoteDescriptionWithoutError(answer); |
| 1337 | |
| 1338 | EXPECT_TRUE(nullptr == session_->voice_channel()); |
| 1339 | EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel()); |
| 1340 | |
| 1341 | session_->Close(); |
| 1342 | EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel()); |
| 1343 | EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel()); |
| 1344 | EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel()); |
| 1345 | EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel()); |
| 1346 | } |
| 1347 | |
| 1348 | // kBundlePolicyMaxBundle policy but no BUNDLE in the answer. |
| 1349 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) { |
| 1350 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 1351 | SendAudioVideoStream1(); |
| 1352 | |
| 1353 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1354 | options.use_rtp_mux = true; |
| 1355 | |
| 1356 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1357 | SetLocalDescriptionWithoutError(offer); |
| 1358 | |
| 1359 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1360 | session_->video_rtp_transport_channel()); |
| 1361 | |
| 1362 | SendAudioVideoStream2(); |
| 1363 | |
| 1364 | // Remove BUNDLE from the answer. |
| 1365 | std::unique_ptr<SessionDescriptionInterface> answer( |
| 1366 | CreateRemoteAnswer(session_->local_description())); |
| 1367 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 1368 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1369 | JsepSessionDescription* modified_answer = |
| 1370 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 1371 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 1372 | SetRemoteDescriptionWithoutError(modified_answer); |
| 1373 | |
| 1374 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1375 | session_->video_rtp_transport_channel()); |
| 1376 | } |
| 1377 | |
| 1378 | // kBundlePolicyMaxBundle policy with BUNDLE in the remote offer. |
| 1379 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) { |
| 1380 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 1381 | SendAudioVideoStream1(); |
| 1382 | |
| 1383 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 1384 | SetRemoteDescriptionWithoutError(offer); |
| 1385 | |
| 1386 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1387 | session_->video_rtp_transport_channel()); |
| 1388 | |
| 1389 | SendAudioVideoStream2(); |
| 1390 | SessionDescriptionInterface* answer = CreateAnswer(); |
| 1391 | SetLocalDescriptionWithoutError(answer); |
| 1392 | |
| 1393 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1394 | session_->video_rtp_transport_channel()); |
| 1395 | } |
| 1396 | |
| 1397 | // kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer. |
| 1398 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) { |
| 1399 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 1400 | SendAudioVideoStream1(); |
| 1401 | |
| 1402 | // Remove BUNDLE from the offer. |
| 1403 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
| 1404 | cricket::SessionDescription* offer_copy = offer->description()->Copy(); |
| 1405 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1406 | JsepSessionDescription* modified_offer = |
| 1407 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 1408 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 1409 | |
| 1410 | // Expect an error when applying the remote description |
| 1411 | SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, |
| 1412 | kCreateChannelFailed, modified_offer); |
| 1413 | } |
| 1414 | |
| 1415 | // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. |
| 1416 | TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { |
| 1417 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
| 1418 | SendAudioVideoStream1(); |
| 1419 | |
| 1420 | PeerConnectionInterface::RTCOfferAnswerOptions rtc_options; |
| 1421 | rtc_options.use_rtp_mux = true; |
| 1422 | |
| 1423 | SessionDescriptionInterface* offer = CreateOffer(rtc_options); |
| 1424 | SetLocalDescriptionWithoutError(offer); |
| 1425 | |
| 1426 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1427 | session_->video_rtp_transport_channel()); |
| 1428 | |
| 1429 | SendAudioVideoStream2(); |
| 1430 | SessionDescriptionInterface* answer = |
| 1431 | CreateRemoteAnswer(session_->local_description()); |
| 1432 | SetRemoteDescriptionWithoutError(answer); |
| 1433 | |
| 1434 | // This should lead to an audio-only call but isn't implemented |
| 1435 | // correctly yet. |
| 1436 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1437 | session_->video_rtp_transport_channel()); |
| 1438 | } |
| 1439 | |
| 1440 | // kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer. |
| 1441 | TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) { |
| 1442 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
| 1443 | SendAudioVideoStream1(); |
| 1444 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1445 | options.use_rtp_mux = true; |
| 1446 | |
| 1447 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1448 | SetLocalDescriptionWithoutError(offer); |
| 1449 | |
| 1450 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1451 | session_->video_rtp_transport_channel()); |
| 1452 | |
| 1453 | SendAudioVideoStream2(); |
| 1454 | |
| 1455 | // Remove BUNDLE from the answer. |
| 1456 | std::unique_ptr<SessionDescriptionInterface> answer( |
| 1457 | CreateRemoteAnswer(session_->local_description())); |
| 1458 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 1459 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1460 | JsepSessionDescription* modified_answer = |
| 1461 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 1462 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 1463 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 1464 | |
| 1465 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1466 | session_->video_rtp_transport_channel()); |
| 1467 | } |
| 1468 | |
| 1469 | // kBundlePolicyMaxbundle and then we call SetRemoteDescription first. |
| 1470 | TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) { |
| 1471 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
| 1472 | SendAudioVideoStream1(); |
| 1473 | |
| 1474 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1475 | options.use_rtp_mux = true; |
| 1476 | |
| 1477 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1478 | SetRemoteDescriptionWithoutError(offer); |
| 1479 | |
| 1480 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 1481 | session_->video_rtp_transport_channel()); |
| 1482 | } |
| 1483 | |
| 1484 | // Adding a new channel to a BUNDLE which is already connected should directly |
| 1485 | // assign the bundle transport to the channel, without first setting a |
| 1486 | // disconnected non-bundle transport and then replacing it. The application |
| 1487 | // should not receive any changes in the ICE state. |
| 1488 | TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) { |
| 1489 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1490 | // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain |
| 1491 | // connected. Disabling either of these two means that we need to wait for the |
| 1492 | // answer to find out if more transports are needed. |
| 1493 | configuration_.bundle_policy = |
| 1494 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 1495 | options_.disable_encryption = true; |
| 1496 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
| 1497 | |
| 1498 | // Negotiate an audio channel with MAX_BUNDLE enabled. |
| 1499 | SendAudioOnlyStream2(); |
| 1500 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1501 | SetLocalDescriptionWithoutError(offer); |
| 1502 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 1503 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| 1504 | std::string sdp; |
| 1505 | offer->ToString(&sdp); |
| 1506 | SessionDescriptionInterface* answer = webrtc::CreateSessionDescription( |
| 1507 | JsepSessionDescription::kAnswer, sdp, nullptr); |
| 1508 | ASSERT_TRUE(answer != NULL); |
| 1509 | SetRemoteDescriptionWithoutError(answer); |
| 1510 | |
| 1511 | // Wait for the ICE state to stabilize. |
| 1512 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 1513 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 1514 | observer_.ice_connection_state_history_.clear(); |
| 1515 | |
| 1516 | // Now add a video channel which should be using the same bundle transport. |
| 1517 | SendAudioVideoStream2(); |
| 1518 | offer = CreateOffer(); |
| 1519 | offer->ToString(&sdp); |
| 1520 | SetLocalDescriptionWithoutError(offer); |
| 1521 | answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, |
| 1522 | sdp, nullptr); |
| 1523 | ASSERT_TRUE(answer != NULL); |
| 1524 | SetRemoteDescriptionWithoutError(answer); |
| 1525 | |
| 1526 | // Wait for ICE state to stabilize |
| 1527 | rtc::Thread::Current()->ProcessMessages(0); |
| 1528 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 1529 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 1530 | |
| 1531 | // No ICE state changes are expected to happen. |
| 1532 | EXPECT_EQ(0, observer_.ice_connection_state_history_.size()); |
| 1533 | } |
| 1534 | |
| 1535 | TEST_F(WebRtcSessionTest, TestRequireRtcpMux) { |
| 1536 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
| 1537 | SendAudioVideoStream1(); |
| 1538 | |
| 1539 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1540 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1541 | SetLocalDescriptionWithoutError(offer); |
| 1542 | |
| 1543 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 1544 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
| 1545 | |
| 1546 | SendAudioVideoStream2(); |
| 1547 | SessionDescriptionInterface* answer = |
| 1548 | CreateRemoteAnswer(session_->local_description()); |
| 1549 | SetRemoteDescriptionWithoutError(answer); |
| 1550 | |
| 1551 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 1552 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
| 1553 | } |
| 1554 | |
| 1555 | TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) { |
| 1556 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
| 1557 | SendAudioVideoStream1(); |
| 1558 | |
| 1559 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1560 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1561 | SetLocalDescriptionWithoutError(offer); |
| 1562 | |
| 1563 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL); |
| 1564 | EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL); |
| 1565 | |
| 1566 | SendAudioVideoStream2(); |
| 1567 | SessionDescriptionInterface* answer = |
| 1568 | CreateRemoteAnswer(session_->local_description()); |
| 1569 | SetRemoteDescriptionWithoutError(answer); |
| 1570 | |
| 1571 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 1572 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
| 1573 | } |
| 1574 | |
| 1575 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 1576 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 1577 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
| 1578 | Init(); |
| 1579 | SendAudioVideoStream1(); |
| 1580 | |
| 1581 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1582 | options.use_rtp_mux = true; |
| 1583 | |
| 1584 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1585 | std::string offer_str; |
| 1586 | offer->ToString(&offer_str); |
| 1587 | // Disable rtcp-mux |
| 1588 | const std::string rtcp_mux = "rtcp-mux"; |
| 1589 | const std::string xrtcp_mux = "xrtcp-mux"; |
| 1590 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
| 1591 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 1592 | &offer_str); |
| 1593 | SessionDescriptionInterface* local_offer = CreateSessionDescription( |
| 1594 | SessionDescriptionInterface::kOffer, offer_str, nullptr); |
| 1595 | ASSERT_TRUE(local_offer); |
| 1596 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
| 1597 | |
| 1598 | SessionDescriptionInterface* remote_offer = CreateSessionDescription( |
| 1599 | SessionDescriptionInterface::kOffer, offer_str, nullptr); |
| 1600 | ASSERT_TRUE(remote_offer); |
| 1601 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
| 1602 | |
| 1603 | // Trying unmodified SDP. |
| 1604 | SetLocalDescriptionWithoutError(offer); |
| 1605 | } |
| 1606 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1607 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1608 | configuration_.enable_rtp_data_channel = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1609 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1610 | SetLocalDescriptionWithDataChannel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1611 | ASSERT_TRUE(data_engine_); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1612 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1615 | TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1616 | configuration_.enable_rtp_data_channel = true; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1617 | options_.disable_sctp_data_channels = false; |
| 1618 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1619 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | |
| 1621 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1622 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
| 1623 | } |
| 1624 | |
| 1625 | // Test that sctp_content_name/sctp_transport_name (used for stats) are correct |
| 1626 | // before and after BUNDLE is negotiated. |
| 1627 | TEST_P(WebRtcSessionTest, SctpContentAndTransportName) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1628 | SetFactoryDtlsSrtp(); |
| 1629 | InitWithDtls(GetParam()); |
| 1630 | |
| 1631 | // Initially these fields should be empty. |
| 1632 | EXPECT_FALSE(session_->sctp_content_name()); |
| 1633 | EXPECT_FALSE(session_->sctp_transport_name()); |
| 1634 | |
| 1635 | // Create offer with audio/video/data. |
| 1636 | // Default bundle policy is "balanced", so data should be using its own |
| 1637 | // transport. |
| 1638 | SendAudioVideoStream1(); |
| 1639 | CreateDataChannel(); |
| 1640 | InitiateCall(); |
| 1641 | ASSERT_TRUE(session_->sctp_content_name()); |
| 1642 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 1643 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 1644 | EXPECT_EQ("data", *session_->sctp_transport_name()); |
| 1645 | |
| 1646 | // Create answer that finishes BUNDLE negotiation, which means everything |
| 1647 | // should be bundled on the first transport (audio). |
| 1648 | cricket::MediaSessionOptions answer_options; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1649 | answer_options.bundle_enabled = true; |
| 1650 | answer_options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1651 | GetOptionsForAnswer(&answer_options); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1652 | SetRemoteDescriptionWithoutError(CreateRemoteAnswer( |
| 1653 | session_->local_description(), answer_options, cricket::SEC_DISABLED)); |
| 1654 | ASSERT_TRUE(session_->sctp_content_name()); |
| 1655 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 1656 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 1657 | EXPECT_EQ("audio", *session_->sctp_transport_name()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1660 | TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1661 | InitWithDtls(GetParam()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 1662 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1663 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 1664 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1665 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 1666 | } |
| 1667 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1668 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1669 | SetFactoryDtlsSrtp(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1670 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1671 | |
| 1672 | // Create remote offer with SCTP. |
| 1673 | cricket::MediaSessionOptions options; |
| 1674 | options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1675 | GetOptionsForRemoteOffer(&options); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1676 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1677 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1678 | SetRemoteDescriptionWithoutError(offer); |
| 1679 | |
| 1680 | // Verifies the answer contains SCTP. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1681 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1682 | EXPECT_TRUE(answer != NULL); |
| 1683 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 1684 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1687 | // Test that if DTLS is disabled, we don't end up with an SctpTransport |
| 1688 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1689 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1690 | configuration_.enable_dtls_srtp = rtc::Optional<bool>(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1691 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1692 | |
| 1693 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1694 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 1695 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1698 | // Test that if DTLS is enabled, we end up with an SctpTransport created |
| 1699 | // (and not an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1700 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1701 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1702 | |
| 1703 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1704 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 1705 | EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1706 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1707 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1708 | // Test that if SCTP is disabled, we don't end up with an SctpTransport |
| 1709 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1710 | TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1711 | options_.disable_sctp_data_channels = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1712 | InitWithDtls(GetParam()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1713 | |
| 1714 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1715 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 1716 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1719 | TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1720 | const int new_send_port = 9998; |
| 1721 | const int new_recv_port = 7775; |
| 1722 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1723 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1724 | SetFactoryDtlsSrtp(); |
| 1725 | |
| 1726 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 1727 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 1728 | // let the session description get parsed. That'll get the proper codecs |
| 1729 | // into the stream. |
| 1730 | cricket::MediaSessionOptions options; |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 1731 | SessionDescriptionInterface* offer = |
| 1732 | CreateRemoteOfferWithSctpPort("stream1", new_send_port, options); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1733 | |
| 1734 | // SetRemoteDescription will take the ownership of the offer. |
| 1735 | SetRemoteDescriptionWithoutError(offer); |
| 1736 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1737 | SessionDescriptionInterface* answer = |
| 1738 | ChangeSDPSctpPort(new_recv_port, CreateAnswer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1739 | ASSERT_TRUE(answer != NULL); |
| 1740 | |
| 1741 | // Now set the local description, which'll take ownership of the answer. |
| 1742 | SetLocalDescriptionWithoutError(answer); |
| 1743 | |
| 1744 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 1745 | // and pass it all the way down. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1746 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1747 | CreateDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1748 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
| 1749 | EXPECT_EQ( |
| 1750 | new_recv_port, |
| 1751 | fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port()); |
| 1752 | EXPECT_EQ( |
| 1753 | new_send_port, |
| 1754 | fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1757 | // Verifies that when a session's SctpTransport receives an OPEN message, |
| 1758 | // WebRtcSession signals the SctpTransport creation request with the expected |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1759 | // config. |
| 1760 | TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1761 | InitWithDtls(GetParam()); |
| 1762 | |
| 1763 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1764 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 1765 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1766 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1767 | // Make the fake SCTP transport pretend it received an OPEN message. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1768 | webrtc::DataChannelInit config; |
| 1769 | config.id = 1; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 1770 | rtc::CopyOnWriteBuffer payload; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1771 | webrtc::WriteDataChannelOpenMessage("a", config, &payload); |
| 1772 | cricket::ReceiveDataParams params; |
| 1773 | params.ssrc = config.id; |
| 1774 | params.type = cricket::DMT_CONTROL; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1775 | fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived( |
| 1776 | params, payload); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1777 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1778 | EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1779 | EXPECT_EQ(config.id, last_data_channel_config_.id); |
| 1780 | EXPECT_FALSE(last_data_channel_config_.negotiated); |
| 1781 | EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker, |
| 1782 | last_data_channel_config_.open_handshake_role); |
| 1783 | } |
| 1784 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1785 | #ifdef HAVE_QUIC |
| 1786 | TEST_P(WebRtcSessionTest, TestNegotiateQuic) { |
| 1787 | configuration_.enable_quic = true; |
| 1788 | InitWithDtls(GetParam()); |
| 1789 | EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC); |
| 1790 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1791 | ASSERT_TRUE(offer); |
| 1792 | ASSERT_TRUE(offer->description()); |
| 1793 | SetLocalDescriptionWithoutError(offer); |
| 1794 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1795 | GetOptionsForAnswer(&options); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1796 | SessionDescriptionInterface* answer = |
| 1797 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1798 | ASSERT_TRUE(answer); |
| 1799 | ASSERT_TRUE(answer->description()); |
| 1800 | SetRemoteDescriptionWithoutError(answer); |
| 1801 | } |
| 1802 | #endif // HAVE_QUIC |
| 1803 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1804 | // This verifies that the voice channel after bundle has both options from video |
| 1805 | // and voice channels. |
| 1806 | TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { |
| 1807 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1808 | SendAudioVideoStream1(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1809 | |
| 1810 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1811 | options.use_rtp_mux = true; |
| 1812 | |
| 1813 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 1814 | SetLocalDescriptionWithoutError(offer); |
| 1815 | |
| 1816 | session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 1817 | rtc::Socket::Option::OPT_SNDBUF, 4000); |
| 1818 | |
| 1819 | session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 1820 | rtc::Socket::Option::OPT_RCVBUF, 8000); |
| 1821 | |
| 1822 | int option_val; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1823 | EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1824 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 1825 | EXPECT_EQ(4000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1826 | EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1827 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 1828 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1829 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1830 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 1831 | EXPECT_EQ(8000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1832 | EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1833 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 1834 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1835 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 1836 | session_->video_rtp_transport_channel()); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1837 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1838 | SendAudioVideoStream2(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1839 | SessionDescriptionInterface* answer = |
| 1840 | CreateRemoteAnswer(session_->local_description()); |
| 1841 | SetRemoteDescriptionWithoutError(answer); |
| 1842 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1843 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1844 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 1845 | EXPECT_EQ(4000, option_val); |
| 1846 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1847 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 1848 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 1849 | EXPECT_EQ(8000, option_val); |
| 1850 | } |
| 1851 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1852 | TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
| 1853 | TestPacketOptions(); |
| 1854 | } |
| 1855 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1856 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 1857 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 1858 | // called more than once without returning to IceGatheringGathering. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1859 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1860 | INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 1861 | WebRtcSessionTest, |
| 1862 | testing::Values(ALREADY_GENERATED, |
| 1863 | DTLS_IDENTITY_STORE)); |