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; |
| 86 | static const char kMediaContentName0[] = "audio"; |
| 87 | |
| 88 | // Media index of candidates belonging to the second media content. |
| 89 | static const int kMediaContentIndex1 = 1; |
| 90 | static const char kMediaContentName1[] = "video"; |
| 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 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 95 | static const char kSdpWithRtx[] = |
| 96 | "v=0\r\n" |
| 97 | "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n" |
| 98 | "s=-\r\n" |
| 99 | "t=0 0\r\n" |
| 100 | "a=msid-semantic: WMS stream1\r\n" |
| 101 | "m=video 9 RTP/SAVPF 0 96\r\n" |
| 102 | "c=IN IP4 0.0.0.0\r\n" |
| 103 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 104 | "a=ice-ufrag:CerjGp19G7wpXwl7\r\n" |
| 105 | "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n" |
| 106 | "a=mid:video\r\n" |
| 107 | "a=sendrecv\r\n" |
| 108 | "a=rtcp-mux\r\n" |
| 109 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 110 | "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n" |
| 111 | "a=rtpmap:0 fake_video_codec/90000\r\n" |
| 112 | "a=rtpmap:96 rtx/90000\r\n" |
| 113 | "a=fmtp:96 apt=0\r\n"; |
| 114 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 115 | static const char kStream1[] = "stream1"; |
| 116 | static const char kVideoTrack1[] = "video1"; |
| 117 | static const char kAudioTrack1[] = "audio1"; |
| 118 | |
| 119 | static const char kStream2[] = "stream2"; |
| 120 | static const char kVideoTrack2[] = "video2"; |
| 121 | static const char kAudioTrack2[] = "audio2"; |
| 122 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 123 | static constexpr bool kStopped = true; |
| 124 | static constexpr bool kActive = false; |
| 125 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 126 | enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; |
| 127 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | class MockIceObserver : public webrtc::IceObserver { |
| 129 | public: |
| 130 | MockIceObserver() |
| 131 | : oncandidatesready_(false), |
| 132 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 133 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 134 | } |
| 135 | |
Henrik Kjellander | 3fe372d | 2016-05-12 08:10:52 +0200 | [diff] [blame] | 136 | virtual ~MockIceObserver() = default; |
| 137 | |
zstein | 6dfd53a | 2017-03-06 13:49:03 -0800 | [diff] [blame] | 138 | void OnIceConnectionStateChange( |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 139 | PeerConnectionInterface::IceConnectionState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | ice_connection_state_ = new_state; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 141 | ice_connection_state_history_.push_back(new_state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 143 | void OnIceGatheringChange( |
| 144 | PeerConnectionInterface::IceGatheringState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | // We can never transition back to "new". |
| 146 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 147 | ice_gathering_state_ = new_state; |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 148 | oncandidatesready_ = |
| 149 | new_state == PeerConnectionInterface::kIceGatheringComplete; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // Found a new candidate. |
jbauch | 81bf7b0 | 2017-03-25 08:31:12 -0700 | [diff] [blame] | 153 | void OnIceCandidate( |
| 154 | std::unique_ptr<webrtc::IceCandidateInterface> candidate) override { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 155 | switch (candidate->sdp_mline_index()) { |
| 156 | case kMediaContentIndex0: |
| 157 | mline_0_candidates_.push_back(candidate->candidate()); |
| 158 | break; |
| 159 | case kMediaContentIndex1: |
| 160 | mline_1_candidates_.push_back(candidate->candidate()); |
| 161 | break; |
| 162 | default: |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 163 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 165 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | // The ICE gathering state should always be Gathering when a candidate is |
| 167 | // received (or possibly Completed in the case of the final candidate). |
| 168 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 169 | } |
| 170 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 171 | // Some local candidates are removed. |
| 172 | void OnIceCandidatesRemoved( |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 173 | const std::vector<cricket::Candidate>& candidates) override { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 174 | num_candidates_removed_ += candidates.size(); |
| 175 | } |
| 176 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | bool oncandidatesready_; |
| 178 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 179 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 180 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 181 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 182 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 183 | ice_connection_state_history_; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 184 | size_t num_candidates_removed_ = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 187 | // Used for tests in this file to verify that WebRtcSession responds to signals |
| 188 | // from the SctpTransport correctly, and calls Start with the correct |
| 189 | // local/remote ports. |
| 190 | class FakeSctpTransport : public cricket::SctpTransportInternal { |
| 191 | public: |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 192 | void SetTransportChannel(rtc::PacketTransportInternal* channel) override {} |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 193 | bool Start(int local_port, int remote_port) override { |
| 194 | local_port_ = local_port; |
| 195 | remote_port_ = remote_port; |
| 196 | return true; |
| 197 | } |
| 198 | bool OpenStream(int sid) override { return true; } |
| 199 | bool ResetStream(int sid) override { return true; } |
| 200 | bool SendData(const cricket::SendDataParams& params, |
| 201 | const rtc::CopyOnWriteBuffer& payload, |
| 202 | cricket::SendDataResult* result = nullptr) override { |
| 203 | return true; |
| 204 | } |
| 205 | bool ReadyToSendData() override { return true; } |
| 206 | void set_debug_name_for_testing(const char* debug_name) override {} |
| 207 | |
| 208 | int local_port() const { return local_port_; } |
| 209 | int remote_port() const { return remote_port_; } |
| 210 | |
| 211 | private: |
| 212 | int local_port_ = -1; |
| 213 | int remote_port_ = -1; |
| 214 | }; |
| 215 | |
| 216 | class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory { |
| 217 | public: |
| 218 | std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport( |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 219 | rtc::PacketTransportInternal*) override { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 220 | last_fake_sctp_transport_ = new FakeSctpTransport(); |
| 221 | return std::unique_ptr<cricket::SctpTransportInternal>( |
| 222 | last_fake_sctp_transport_); |
| 223 | } |
| 224 | |
| 225 | FakeSctpTransport* last_fake_sctp_transport() { |
| 226 | return last_fake_sctp_transport_; |
| 227 | } |
| 228 | |
| 229 | private: |
| 230 | FakeSctpTransport* last_fake_sctp_transport_ = nullptr; |
| 231 | }; |
| 232 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 234 | public: |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 235 | WebRtcSessionForTest( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 236 | webrtc::Call* fake_call, |
| 237 | cricket::ChannelManager* channel_manager, |
| 238 | const cricket::MediaConfig& media_config, |
| 239 | webrtc::RtcEventLog* event_log, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 240 | rtc::Thread* network_thread, |
| 241 | rtc::Thread* worker_thread, |
| 242 | rtc::Thread* signaling_thread, |
| 243 | cricket::PortAllocator* port_allocator, |
| 244 | webrtc::IceObserver* ice_observer, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 245 | std::unique_ptr<cricket::TransportController> transport_controller, |
| 246 | std::unique_ptr<FakeSctpTransportFactory> sctp_factory) |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 247 | : WebRtcSession(fake_call, channel_manager, media_config, event_log, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 248 | network_thread, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 249 | worker_thread, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 250 | signaling_thread, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 251 | port_allocator, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 252 | std::move(transport_controller), |
| 253 | std::move(sctp_factory)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 254 | RegisterIceObserver(ice_observer); |
| 255 | } |
| 256 | virtual ~WebRtcSessionForTest() {} |
| 257 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 258 | // Note that these methods are only safe to use if the signaling thread |
| 259 | // is the same as the worker thread |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 260 | rtc::PacketTransportInternal* voice_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 261 | return rtp_transport_channel(voice_channel()); |
| 262 | } |
| 263 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 264 | rtc::PacketTransportInternal* voice_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 265 | return rtcp_transport_channel(voice_channel()); |
| 266 | } |
| 267 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 268 | rtc::PacketTransportInternal* video_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 269 | return rtp_transport_channel(video_channel()); |
| 270 | } |
| 271 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 272 | rtc::PacketTransportInternal* video_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 273 | return rtcp_transport_channel(video_channel()); |
| 274 | } |
| 275 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 276 | private: |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 277 | rtc::PacketTransportInternal* rtp_transport_channel( |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 278 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 279 | if (!ch) { |
| 280 | return nullptr; |
| 281 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 282 | return ch->rtp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 283 | } |
| 284 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 285 | rtc::PacketTransportInternal* rtcp_transport_channel( |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 286 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 287 | if (!ch) { |
| 288 | return nullptr; |
| 289 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 290 | return ch->rtcp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 291 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 294 | class WebRtcSessionCreateSDPObserverForTest |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 295 | : public rtc::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 296 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 297 | enum State { |
| 298 | kInit, |
| 299 | kFailed, |
| 300 | kSucceeded, |
| 301 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 302 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 303 | |
| 304 | // CreateSessionDescriptionObserver implementation. |
| 305 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 306 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 307 | state_ = kSucceeded; |
| 308 | } |
| 309 | virtual void OnFailure(const std::string& error) { |
| 310 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 311 | } |
| 312 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 313 | SessionDescriptionInterface* description() { return description_.get(); } |
| 314 | |
| 315 | SessionDescriptionInterface* ReleaseDescription() { |
| 316 | return description_.release(); |
| 317 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 318 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 319 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 321 | protected: |
| 322 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 323 | |
| 324 | private: |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 325 | std::unique_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 326 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 329 | class WebRtcSessionTest |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 330 | : public testing::TestWithParam<RTCCertificateGenerationMethod>, |
| 331 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 332 | protected: |
| 333 | // TODO Investigate why ChannelManager crashes, if it's created |
| 334 | // after stun_server. |
| 335 | WebRtcSessionTest() |
deadbeef | 98e186c | 2017-05-16 18:00:06 -0700 | [diff] [blame] | 336 | : vss_(new rtc::VirtualSocketServer()), |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 337 | fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 338 | thread_(fss_.get()), |
| 339 | media_engine_(new cricket::FakeMediaEngine()), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 340 | data_engine_(new cricket::FakeDataEngine()), |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 341 | channel_manager_(new cricket::ChannelManager( |
| 342 | std::unique_ptr<cricket::MediaEngineInterface>(media_engine_), |
| 343 | std::unique_ptr<cricket::DataEngineInterface>(data_engine_), |
| 344 | rtc::Thread::Current())), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 345 | fake_call_(webrtc::Call::Config(&event_log_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 346 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 347 | desc_factory_( |
| 348 | new cricket::MediaSessionDescriptionFactory(channel_manager_.get(), |
| 349 | tdesc_factory_.get())), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 350 | stun_socket_addr_( |
| 351 | rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)), |
| 352 | stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 353 | stun_socket_addr_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 354 | metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 355 | cricket::ServerAddresses stun_servers; |
| 356 | stun_servers.insert(stun_socket_addr_); |
| 357 | allocator_.reset(new cricket::BasicPortAllocator( |
| 358 | &network_manager_, |
| 359 | stun_servers, |
| 360 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 361 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 362 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 363 | EXPECT_TRUE(channel_manager_->Init()); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 364 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void AddInterface(const SocketAddress& addr) { |
| 368 | network_manager_.AddInterface(addr); |
| 369 | } |
| 370 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 371 | // If |cert_generator| != null or |rtc_configuration| contains |certificates| |
| 372 | // then DTLS will be enabled unless explicitly disabled by |rtc_configuration| |
| 373 | // options. When DTLS is enabled a certificate will be used if provided, |
| 374 | // otherwise one will be generated using the |cert_generator|. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 375 | void Init( |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 376 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 377 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy, |
| 378 | const rtc::CryptoOptions& crypto_options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 379 | ASSERT_TRUE(session_.get() == NULL); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 380 | fake_sctp_transport_factory_ = new FakeSctpTransportFactory(); |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 381 | session_.reset(new WebRtcSessionForTest(&fake_call_, |
| 382 | channel_manager_.get(), cricket::MediaConfig(), &event_log_, |
| 383 | rtc::Thread::Current(), rtc::Thread::Current(), |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 384 | rtc::Thread::Current(), allocator_.get(), &observer_, |
| 385 | std::unique_ptr<cricket::TransportController>( |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 386 | new cricket::TransportController( |
| 387 | rtc::Thread::Current(), rtc::Thread::Current(), |
| 388 | allocator_.get(), |
| 389 | /*redetermine_role_on_ice_restart=*/true, crypto_options)), |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 390 | std::unique_ptr<FakeSctpTransportFactory>( |
| 391 | fake_sctp_transport_factory_))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 392 | session_->SignalDataChannelOpenMessage.connect( |
| 393 | this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 394 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 395 | configuration_.rtcp_mux_policy = rtcp_mux_policy; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 396 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 397 | observer_.ice_connection_state_); |
| 398 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 399 | observer_.ice_gathering_state_); |
| 400 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 401 | EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 402 | configuration_)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 403 | session_->set_metrics_observer(metrics_observer_); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 404 | crypto_options_ = crypto_options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | } |
| 406 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 407 | void OnDataChannelOpenMessage(const std::string& label, |
| 408 | const InternalDataChannelInit& config) { |
| 409 | last_data_channel_label_ = label; |
| 410 | last_data_channel_config_ = config; |
| 411 | } |
| 412 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 413 | void Init() { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 414 | Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 415 | rtc::CryptoOptions()); |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 416 | } |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 417 | |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 418 | void InitWithBundlePolicy( |
| 419 | PeerConnectionInterface::BundlePolicy bundle_policy) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 420 | configuration_.bundle_policy = bundle_policy; |
| 421 | Init(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void InitWithRtcpMuxPolicy( |
| 425 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 426 | PeerConnectionInterface::RTCConfiguration configuration; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 427 | Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions()); |
| 428 | } |
| 429 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 430 | // Successfully init with DTLS; with a certificate generated and supplied or |
| 431 | // with a store that generates it for us. |
| 432 | void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 433 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 434 | if (cert_gen_method == ALREADY_GENERATED) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 435 | configuration_.certificates.push_back( |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 436 | FakeRTCCertificateGenerator::GenerateCertificate()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 437 | } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 438 | cert_generator.reset(new FakeRTCCertificateGenerator()); |
| 439 | cert_generator->set_should_fail(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 440 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 441 | RTC_CHECK(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 442 | } |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 443 | Init(std::move(cert_generator), |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 444 | PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 445 | rtc::CryptoOptions()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 446 | } |
| 447 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 448 | // The following convenience functions can be applied for both local side and |
| 449 | // remote side. The flags can be overwritten for different use cases. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 450 | void SendAudioVideoStream1() { |
| 451 | send_stream_1_ = true; |
| 452 | send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 453 | local_send_audio_ = true; |
| 454 | local_send_video_ = true; |
| 455 | remote_send_audio_ = true; |
| 456 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void SendAudioVideoStream2() { |
| 460 | send_stream_1_ = false; |
| 461 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 462 | local_send_audio_ = true; |
| 463 | local_send_video_ = true; |
| 464 | remote_send_audio_ = true; |
| 465 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void SendAudioVideoStream1And2() { |
| 469 | send_stream_1_ = true; |
| 470 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 471 | local_send_audio_ = true; |
| 472 | local_send_video_ = true; |
| 473 | remote_send_audio_ = true; |
| 474 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void SendNothing() { |
| 478 | send_stream_1_ = false; |
| 479 | send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 480 | local_send_audio_ = false; |
| 481 | local_send_video_ = false; |
| 482 | remote_send_audio_ = false; |
| 483 | remote_send_video_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void SendAudioOnlyStream2() { |
| 487 | send_stream_1_ = false; |
| 488 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 489 | local_send_audio_ = true; |
| 490 | local_send_video_ = false; |
| 491 | remote_send_audio_ = true; |
| 492 | remote_send_video_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void SendVideoOnlyStream2() { |
| 496 | send_stream_1_ = false; |
| 497 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 498 | local_send_audio_ = false; |
| 499 | local_send_video_ = true; |
| 500 | remote_send_audio_ = false; |
| 501 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 502 | } |
| 503 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 504 | // Helper function used to add a specific media section to the |
| 505 | // |session_options|. |
| 506 | void AddMediaSection(cricket::MediaType type, |
| 507 | const std::string& mid, |
| 508 | cricket::MediaContentDirection direction, |
| 509 | bool stopped, |
| 510 | cricket::MediaSessionOptions* opts) { |
| 511 | opts->media_description_options.push_back(cricket::MediaDescriptionOptions( |
| 512 | type, mid, |
| 513 | cricket::RtpTransceiverDirection::FromMediaContentDirection(direction), |
| 514 | stopped)); |
| 515 | } |
| 516 | |
| 517 | // Add the media sections to the options from |offered_media_sections_| when |
| 518 | // creating an answer or a new offer. |
| 519 | // This duplicates a lot of logic from PeerConnection but this can be fixed |
| 520 | // when PeerConnection and WebRtcSession are merged. |
| 521 | void AddExistingMediaSectionsAndSendersToOptions( |
| 522 | cricket::MediaSessionOptions* session_options, |
| 523 | bool send_audio, |
| 524 | bool recv_audio, |
| 525 | bool send_video, |
| 526 | bool recv_video) { |
| 527 | int num_sim_layer = 1; |
| 528 | for (auto media_description_options : offered_media_sections_) { |
| 529 | if (media_description_options.type == cricket::MEDIA_TYPE_AUDIO) { |
| 530 | bool stopped = !send_audio && !recv_audio; |
| 531 | auto media_desc_options = cricket::MediaDescriptionOptions( |
| 532 | cricket::MEDIA_TYPE_AUDIO, media_description_options.mid, |
| 533 | cricket::RtpTransceiverDirection(send_audio, recv_audio), stopped); |
| 534 | if (send_stream_1_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 535 | media_desc_options.AddAudioSender(kAudioTrack1, {kStream1}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 536 | } |
| 537 | if (send_stream_2_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 538 | media_desc_options.AddAudioSender(kAudioTrack2, {kStream2}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 539 | } |
| 540 | session_options->media_description_options.push_back( |
| 541 | media_desc_options); |
| 542 | } else if (media_description_options.type == cricket::MEDIA_TYPE_VIDEO) { |
| 543 | bool stopped = !send_video && !recv_video; |
| 544 | auto media_desc_options = cricket::MediaDescriptionOptions( |
| 545 | cricket::MEDIA_TYPE_VIDEO, media_description_options.mid, |
| 546 | cricket::RtpTransceiverDirection(send_video, recv_video), stopped); |
| 547 | if (send_stream_1_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 548 | media_desc_options.AddVideoSender(kVideoTrack1, {kStream1}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 549 | num_sim_layer); |
| 550 | } |
| 551 | if (send_stream_2_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 552 | media_desc_options.AddVideoSender(kVideoTrack2, {kStream2}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 553 | num_sim_layer); |
| 554 | } |
| 555 | session_options->media_description_options.push_back( |
| 556 | media_desc_options); |
| 557 | } else if (media_description_options.type == cricket::MEDIA_TYPE_DATA) { |
| 558 | session_options->media_description_options.push_back( |
| 559 | cricket::MediaDescriptionOptions( |
| 560 | cricket::MEDIA_TYPE_DATA, media_description_options.mid, |
| 561 | // Direction for data sections is meaningless, but legacy |
| 562 | // endpoints might expect sendrecv. |
| 563 | cricket::RtpTransceiverDirection(true, true), false)); |
| 564 | } else { |
| 565 | RTC_NOTREACHED(); |
| 566 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 567 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | // Add the existing media sections first and then add new media sections if |
| 571 | // needed. |
| 572 | void AddMediaSectionsAndSendersToOptions( |
| 573 | cricket::MediaSessionOptions* session_options, |
| 574 | bool send_audio, |
| 575 | bool recv_audio, |
| 576 | bool send_video, |
| 577 | bool recv_video) { |
| 578 | AddExistingMediaSectionsAndSendersToOptions( |
| 579 | session_options, send_audio, recv_audio, send_video, recv_video); |
| 580 | |
| 581 | if (!session_options->has_audio() && (send_audio || recv_audio)) { |
| 582 | cricket::MediaDescriptionOptions media_desc_options = |
| 583 | cricket::MediaDescriptionOptions( |
| 584 | cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 585 | cricket::RtpTransceiverDirection(send_audio, recv_audio), |
| 586 | kActive); |
| 587 | if (send_stream_1_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 588 | media_desc_options.AddAudioSender(kAudioTrack1, {kStream1}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 589 | } |
| 590 | if (send_stream_2_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 591 | media_desc_options.AddAudioSender(kAudioTrack2, {kStream2}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 592 | } |
| 593 | session_options->media_description_options.push_back(media_desc_options); |
| 594 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 595 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 596 | |
| 597 | if (!session_options->has_video() && (send_video || recv_video)) { |
| 598 | cricket::MediaDescriptionOptions media_desc_options = |
| 599 | cricket::MediaDescriptionOptions( |
| 600 | cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 601 | cricket::RtpTransceiverDirection(send_video, recv_video), |
| 602 | kActive); |
| 603 | int num_sim_layer = 1; |
| 604 | if (send_stream_1_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 605 | media_desc_options.AddVideoSender(kVideoTrack1, {kStream1}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 606 | num_sim_layer); |
| 607 | } |
| 608 | if (send_stream_2_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 609 | media_desc_options.AddVideoSender(kVideoTrack2, {kStream2}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 610 | num_sim_layer); |
| 611 | } |
| 612 | session_options->media_description_options.push_back(media_desc_options); |
| 613 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 614 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 615 | |
| 616 | if (!session_options->has_data() && |
| 617 | (data_channel_ || |
| 618 | session_options->data_channel_type != cricket::DCT_NONE)) { |
| 619 | cricket::MediaDescriptionOptions media_desc_options = |
| 620 | cricket::MediaDescriptionOptions( |
| 621 | cricket::MEDIA_TYPE_DATA, cricket::CN_DATA, |
| 622 | cricket::RtpTransceiverDirection(true, true), kActive); |
| 623 | if (session_options->data_channel_type == cricket::DCT_RTP) { |
| 624 | media_desc_options.AddRtpDataChannel(data_channel_->label(), |
| 625 | data_channel_->label()); |
| 626 | } |
| 627 | session_options->media_description_options.push_back(media_desc_options); |
| 628 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | void GetOptionsForOffer( |
| 633 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 634 | cricket::MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 635 | ExtractSharedMediaSessionOptions(rtc_options, session_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 636 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 637 | // |recv_X| is true by default if |offer_to_receive_X| is undefined. |
| 638 | bool recv_audio = rtc_options.offer_to_receive_audio != 0; |
| 639 | bool recv_video = rtc_options.offer_to_receive_video != 0; |
| 640 | |
| 641 | AddMediaSectionsAndSendersToOptions(session_options, local_send_audio_, |
| 642 | recv_audio, local_send_video_, |
| 643 | recv_video); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 644 | session_options->bundle_enabled = |
| 645 | session_options->bundle_enabled && |
| 646 | (session_options->has_audio() || session_options->has_video() || |
| 647 | session_options->has_data()); |
| 648 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 649 | session_options->crypto_options = crypto_options_; |
| 650 | } |
| 651 | |
| 652 | void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 653 | AddExistingMediaSectionsAndSendersToOptions( |
| 654 | session_options, local_send_audio_, local_recv_audio_, |
| 655 | local_send_video_, local_recv_video_); |
| 656 | |
| 657 | session_options->bundle_enabled = |
| 658 | session_options->bundle_enabled && |
| 659 | (session_options->has_audio() || session_options->has_video() || |
| 660 | session_options->has_data()); |
| 661 | |
| 662 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 663 | session_options->data_channel_type = session_->data_channel_type(); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 664 | } |
| 665 | |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 666 | session_options->crypto_options = crypto_options_; |
| 667 | } |
| 668 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 669 | void GetOptionsForRemoteAnswer( |
| 670 | cricket::MediaSessionOptions* session_options) { |
| 671 | bool recv_audio = local_send_audio_ || remote_recv_audio_; |
| 672 | bool recv_video = local_send_video_ || remote_recv_video_; |
| 673 | bool send_audio = false; |
| 674 | bool send_video = false; |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 675 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 676 | AddExistingMediaSectionsAndSendersToOptions( |
| 677 | session_options, send_audio, recv_audio, send_video, recv_video); |
| 678 | |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 679 | session_options->bundle_enabled = |
| 680 | session_options->bundle_enabled && |
| 681 | (session_options->has_audio() || session_options->has_video() || |
| 682 | session_options->has_data()); |
| 683 | |
| 684 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 685 | session_options->data_channel_type = session_->data_channel_type(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 686 | } |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 687 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 688 | session_options->crypto_options = crypto_options_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 689 | } |
| 690 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 691 | void GetOptionsForAudioOnlyRemoteOffer( |
| 692 | cricket::MediaSessionOptions* session_options) { |
| 693 | remote_recv_audio_ = true; |
| 694 | remote_recv_video_ = false; |
| 695 | GetOptionsForRemoteOffer(session_options); |
| 696 | } |
| 697 | |
| 698 | void GetOptionsForRemoteOffer(cricket::MediaSessionOptions* session_options) { |
| 699 | AddMediaSectionsAndSendersToOptions(session_options, remote_send_audio_, |
| 700 | remote_recv_audio_, remote_send_video_, |
| 701 | remote_recv_video_); |
| 702 | session_options->bundle_enabled = |
| 703 | (session_options->has_audio() || session_options->has_video() || |
| 704 | session_options->has_data()); |
| 705 | |
| 706 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 707 | session_options->data_channel_type = session_->data_channel_type(); |
| 708 | } |
| 709 | |
| 710 | session_options->crypto_options = crypto_options_; |
| 711 | } |
| 712 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 713 | // Creates a local offer and applies it. Starts ICE. |
| 714 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 715 | // to decide which streams to create. |
| 716 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 717 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 718 | SetLocalDescriptionWithoutError(offer); |
| 719 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 720 | observer_.ice_gathering_state_, |
| 721 | kIceCandidatesTimeout); |
| 722 | } |
| 723 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 724 | SessionDescriptionInterface* CreateOffer() { |
| 725 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 726 | options.offer_to_receive_audio = |
| 727 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 728 | return CreateOffer(options); |
| 729 | } |
| 730 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 731 | SessionDescriptionInterface* CreateOffer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 732 | const PeerConnectionInterface::RTCOfferAnswerOptions options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 733 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 734 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 735 | cricket::MediaSessionOptions session_options; |
| 736 | GetOptionsForOffer(options, &session_options); |
| 737 | session_->CreateOffer(observer, options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 738 | EXPECT_TRUE_WAIT( |
| 739 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 740 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 741 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | SessionDescriptionInterface* CreateAnswer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 745 | const cricket::MediaSessionOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 746 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 747 | = new WebRtcSessionCreateSDPObserverForTest(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 748 | cricket::MediaSessionOptions session_options = options; |
| 749 | GetOptionsForAnswer(&session_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 750 | session_->CreateAnswer(observer, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 751 | EXPECT_TRUE_WAIT( |
| 752 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 753 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 754 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 755 | } |
| 756 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 757 | SessionDescriptionInterface* CreateAnswer() { |
| 758 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 759 | options.bundle_enabled = true; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 760 | return CreateAnswer(options); |
| 761 | } |
| 762 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | // Set the internal fake description factories to do DTLS-SRTP. |
| 764 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 765 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 766 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 767 | rtc::ToString(rtc::CreateRandomId()); |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 768 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 769 | tdesc_factory_->set_certificate( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 770 | rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 771 | rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 772 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 773 | } |
| 774 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 775 | // Compares ufrag/password only for the specified |media_type|. |
| 776 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 777 | const cricket::SessionDescription* desc2, |
| 778 | cricket::MediaType media_type) { |
| 779 | if (desc1->contents().size() != desc2->contents().size()) { |
| 780 | return false; |
| 781 | } |
| 782 | |
| 783 | const cricket::ContentInfo* cinfo = |
| 784 | cricket::GetFirstMediaContent(desc1->contents(), media_type); |
| 785 | const cricket::TransportDescription* transport_desc1 = |
| 786 | desc1->GetTransportDescriptionByName(cinfo->name); |
| 787 | const cricket::TransportDescription* transport_desc2 = |
| 788 | desc2->GetTransportDescriptionByName(cinfo->name); |
| 789 | if (!transport_desc1 || !transport_desc2) { |
| 790 | return false; |
| 791 | } |
| 792 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 793 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 794 | return false; |
| 795 | } |
| 796 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 797 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 798 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 799 | // Sets ufrag/pwd for specified |media_type|. |
| 800 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 801 | cricket::MediaType media_type, |
| 802 | const std::string& ufrag, |
| 803 | const std::string& pwd) { |
| 804 | cricket::SessionDescription* desc = current_desc->description(); |
| 805 | const cricket::ContentInfo* cinfo = |
| 806 | cricket::GetFirstMediaContent(desc->contents(), media_type); |
| 807 | TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name); |
| 808 | cricket::TransportDescription* transport_desc = |
| 809 | &transport_info->description; |
| 810 | transport_desc->ice_ufrag = ufrag; |
| 811 | transport_desc->ice_pwd = pwd; |
| 812 | } |
| 813 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 814 | // Creates a remote offer and and applies it as a remote description, |
| 815 | // creates a local answer and applies is as a local description. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 816 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | // to decide which local and remote streams to create. |
| 818 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 819 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 820 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 821 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 822 | SetLocalDescriptionWithoutError(answer); |
| 823 | } |
| 824 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 825 | ASSERT_TRUE(session_->SetLocalDescription(desc, nullptr)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 826 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 827 | } |
| 828 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 829 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 830 | SetLocalDescriptionWithoutError(desc); |
| 831 | EXPECT_EQ(expected_state, session_->state()); |
| 832 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 833 | void SetLocalDescriptionExpectError(const std::string& action, |
| 834 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 835 | SessionDescriptionInterface* desc) { |
| 836 | std::string error; |
| 837 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 838 | std::string sdp_type = "local "; |
| 839 | sdp_type.append(action); |
| 840 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 841 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 842 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 843 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 844 | SessionDescriptionInterface* desc) { |
| 845 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 846 | expected_error, desc); |
| 847 | } |
| 848 | void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, |
| 849 | SessionDescriptionInterface* desc) { |
| 850 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 851 | expected_error, desc); |
| 852 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 853 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 854 | ASSERT_TRUE(session_->SetRemoteDescription(desc, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 855 | } |
| 856 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 857 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 858 | SetRemoteDescriptionWithoutError(desc); |
| 859 | EXPECT_EQ(expected_state, session_->state()); |
| 860 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 861 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 862 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 863 | SessionDescriptionInterface* desc) { |
| 864 | std::string error; |
| 865 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 866 | std::string sdp_type = "remote "; |
| 867 | sdp_type.append(action); |
| 868 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 869 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 870 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 871 | void SetRemoteDescriptionOfferExpectError( |
| 872 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 873 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 874 | expected_error, desc); |
| 875 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 876 | void SetRemoteDescriptionAnswerExpectError( |
| 877 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 878 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 879 | expected_error, desc); |
| 880 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 881 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 883 | cricket::MediaSessionOptions options, |
| 884 | cricket::SecurePolicy secure_policy, |
| 885 | const std::string& session_version, |
| 886 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 887 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | const cricket::SessionDescription* cricket_desc = NULL; |
| 889 | if (current_desc) { |
| 890 | cricket_desc = current_desc->description(); |
| 891 | session_id = current_desc->session_id(); |
| 892 | } |
| 893 | |
| 894 | desc_factory_->set_secure(secure_policy); |
| 895 | JsepSessionDescription* offer( |
| 896 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 897 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 898 | session_id, session_version)) { |
| 899 | delete offer; |
| 900 | offer = NULL; |
| 901 | } |
| 902 | return offer; |
| 903 | } |
| 904 | JsepSessionDescription* CreateRemoteOffer( |
| 905 | cricket::MediaSessionOptions options) { |
| 906 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 907 | kSessionVersion, NULL); |
| 908 | } |
| 909 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 910 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 911 | return CreateRemoteOfferWithVersion( |
| 912 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 913 | } |
| 914 | JsepSessionDescription* CreateRemoteOffer( |
| 915 | cricket::MediaSessionOptions options, |
| 916 | const SessionDescriptionInterface* current_desc) { |
| 917 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 918 | kSessionVersion, current_desc); |
| 919 | } |
| 920 | |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 921 | SessionDescriptionInterface* CreateRemoteOfferWithSctpPort( |
| 922 | const char* sctp_stream_name, |
| 923 | int new_port, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 924 | cricket::MediaSessionOptions options) { |
| 925 | options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 926 | GetOptionsForRemoteOffer(&options); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 927 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 928 | } |
| 929 | |
| 930 | // Takes ownership of offer_basis (and deletes it). |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 931 | SessionDescriptionInterface* ChangeSDPSctpPort( |
| 932 | int new_port, |
| 933 | webrtc::SessionDescriptionInterface* offer_basis) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 934 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 935 | // SessionDescription from the mutated string. |
| 936 | const char* default_port_str = "5000"; |
| 937 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 938 | 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] | 939 | std::string offer_str; |
| 940 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 941 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 942 | new_port_str, strlen(new_port_str), |
| 943 | &offer_str); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 944 | SessionDescriptionInterface* offer = |
| 945 | CreateSessionDescription(offer_basis->type(), offer_str, nullptr); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 946 | delete offer_basis; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 947 | return offer; |
| 948 | } |
| 949 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 950 | // Create a remote offer. Call SendAudioVideoStreamX() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 951 | // before this function to decide which streams to create. |
| 952 | JsepSessionDescription* CreateRemoteOffer() { |
| 953 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 954 | GetOptionsForRemoteOffer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 955 | return CreateRemoteOffer(options, session_->remote_description()); |
| 956 | } |
| 957 | |
| 958 | JsepSessionDescription* CreateRemoteAnswer( |
| 959 | const SessionDescriptionInterface* offer, |
| 960 | cricket::MediaSessionOptions options, |
| 961 | cricket::SecurePolicy policy) { |
| 962 | desc_factory_->set_secure(policy); |
| 963 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 964 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 965 | JsepSessionDescription* answer( |
| 966 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 967 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 968 | options, NULL), |
| 969 | session_id, kSessionVersion)) { |
| 970 | delete answer; |
| 971 | answer = NULL; |
| 972 | } |
| 973 | return answer; |
| 974 | } |
| 975 | |
| 976 | JsepSessionDescription* CreateRemoteAnswer( |
| 977 | const SessionDescriptionInterface* offer, |
| 978 | cricket::MediaSessionOptions options) { |
| 979 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 980 | } |
| 981 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 982 | // Creates an answer session description. |
| 983 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 984 | // to decide which streams to create. |
| 985 | JsepSessionDescription* CreateRemoteAnswer( |
| 986 | const SessionDescriptionInterface* offer) { |
| 987 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 988 | GetOptionsForAnswer(&options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 989 | options.bundle_enabled = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 990 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 991 | } |
| 992 | |
| 993 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 994 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 995 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 996 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 997 | |
| 998 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 999 | options.use_rtp_mux = bundle; |
| 1000 | |
| 1001 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1002 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1003 | // and answer. |
| 1004 | SetLocalDescriptionWithoutError(offer); |
| 1005 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1006 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1007 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1008 | std::string sdp; |
| 1009 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 1010 | |
| 1011 | size_t expected_candidate_num = 2; |
| 1012 | if (!rtcp_mux) { |
| 1013 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 1014 | // for rtp and rtcp. |
| 1015 | expected_candidate_num = 4; |
| 1016 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1017 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 1018 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1019 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1020 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 1021 | &sdp); |
| 1022 | } |
| 1023 | |
| 1024 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 1025 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1026 | |
| 1027 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1028 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1029 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1030 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1031 | if (bundle) { |
| 1032 | EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
| 1033 | } else { |
| 1034 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1035 | } |
| 1036 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1037 | |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 1038 | bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc, |
| 1039 | const std::string& codec_name) { |
| 1040 | for (const auto& content : desc->description()->contents()) { |
| 1041 | if (static_cast<cricket::MediaContentDescription*>(content.description) |
| 1042 | ->type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1043 | const auto* mdesc = |
| 1044 | static_cast<cricket::VideoContentDescription*>(content.description); |
| 1045 | for (const auto& codec : mdesc->codecs()) { |
| 1046 | if (codec.name == codec_name) { |
| 1047 | return true; |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | return false; |
| 1053 | } |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1054 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1055 | // The method sets up a call from the session to itself, in a loopback |
| 1056 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1057 | // disconnection, and then a permanent disconnection. |
| 1058 | // 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] | 1059 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 1060 | // While running the call, this method also checks if the session goes through |
| 1061 | // the correct sequence of ICE states when a connection is established, |
| 1062 | // broken, and re-established. |
| 1063 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1064 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 1065 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1066 | // The Gathering state should go: New -> Gathering -> Completed. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1067 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1068 | void SetupLoopbackCall() { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1069 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1070 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1071 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1072 | |
| 1073 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 1074 | observer_.ice_gathering_state_); |
| 1075 | SetLocalDescriptionWithoutError(offer); |
| 1076 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 1077 | observer_.ice_connection_state_); |
| 1078 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1079 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1080 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1081 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1082 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1083 | |
| 1084 | std::string sdp; |
| 1085 | offer->ToString(&sdp); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1086 | SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( |
| 1087 | JsepSessionDescription::kAnswer, sdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1088 | ASSERT_TRUE(desc != NULL); |
| 1089 | SetRemoteDescriptionWithoutError(desc); |
| 1090 | |
| 1091 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1092 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1093 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1094 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 1095 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1096 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 1097 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1098 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1099 | void TestPacketOptions() { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 1100 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1101 | |
| 1102 | SetupLoopbackCall(); |
| 1103 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 1104 | // Wait for channel to be ready for sending. |
| 1105 | EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1106 | uint8_t test_packet[15] = {0}; |
| 1107 | rtc::PacketOptions options; |
| 1108 | options.packet_id = 10; |
| 1109 | media_engine_->GetVideoChannel(0) |
| 1110 | ->SendRtp(test_packet, sizeof(test_packet), options); |
| 1111 | |
| 1112 | const int kPacketTimeout = 2000; |
deadbeef | 14461d4 | 2016-06-15 11:06:57 -0700 | [diff] [blame] | 1113 | EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(), |
| 1114 | kPacketTimeout); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1115 | EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1); |
| 1116 | } |
| 1117 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1118 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 1119 | void AddCNCodecs() { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1120 | const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1); |
| 1121 | const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1122 | |
| 1123 | // Add kCNCodec for dtmf test. |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 1124 | std::vector<cricket::AudioCodec> codecs = |
| 1125 | media_engine_->audio_send_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1126 | codecs.push_back(kCNCodec1); |
| 1127 | codecs.push_back(kCNCodec2); |
| 1128 | media_engine_->SetAudioCodecs(codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1129 | desc_factory_->set_audio_codecs(codecs, codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 1133 | const cricket::ContentDescription* description = content->description; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1134 | RTC_CHECK(description != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1135 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1136 | static_cast<const cricket::AudioContentDescription*>(description); |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1137 | RTC_CHECK(audio_content_desc != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1138 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 1139 | if (audio_content_desc->codecs()[i].name == "CN") |
| 1140 | return false; |
| 1141 | } |
| 1142 | return true; |
| 1143 | } |
| 1144 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1145 | void CreateDataChannel() { |
deadbeef | fc648b6 | 2015-10-13 16:42:33 -0700 | [diff] [blame] | 1146 | webrtc::InternalDataChannelInit dci; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1147 | RTC_CHECK(session_.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1148 | dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP; |
| 1149 | data_channel_ = DataChannel::Create( |
| 1150 | session_.get(), session_->data_channel_type(), "datachannel", dci); |
| 1151 | } |
| 1152 | |
| 1153 | void SetLocalDescriptionWithDataChannel() { |
| 1154 | CreateDataChannel(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1155 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1156 | SetLocalDescriptionWithoutError(offer); |
| 1157 | } |
| 1158 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1159 | webrtc::RtcEventLogNullImpl event_log_; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 1160 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 1161 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
| 1162 | rtc::AutoSocketServerThread thread_; |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 1163 | // |media_engine_| and |data_engine_| are actually owned by |
| 1164 | // |channel_manager_|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1165 | cricket::FakeMediaEngine* media_engine_; |
| 1166 | cricket::FakeDataEngine* data_engine_; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1167 | // Actually owned by session_. |
| 1168 | FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1169 | std::unique_ptr<cricket::ChannelManager> channel_manager_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1170 | cricket::FakeCall fake_call_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1171 | std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
| 1172 | std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1173 | rtc::SocketAddress stun_socket_addr_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1174 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1175 | rtc::FakeNetworkManager network_manager_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1176 | std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1177 | PeerConnectionFactoryInterface::Options options_; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1178 | PeerConnectionInterface::RTCConfiguration configuration_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1179 | std::unique_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1180 | MockIceObserver observer_; |
| 1181 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1182 | cricket::FakeVoiceMediaChannel* voice_channel_; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1183 | rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1184 | // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1185 | bool send_stream_1_ = false; |
| 1186 | bool send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1187 | bool local_send_audio_ = false; |
| 1188 | bool local_send_video_ = false; |
| 1189 | bool local_recv_audio_ = true; |
| 1190 | bool local_recv_video_ = true; |
| 1191 | bool remote_send_audio_ = false; |
| 1192 | bool remote_send_video_ = false; |
| 1193 | bool remote_recv_audio_ = true; |
| 1194 | bool remote_recv_video_ = true; |
| 1195 | std::vector<cricket::MediaDescriptionOptions> offered_media_sections_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1196 | rtc::scoped_refptr<DataChannel> data_channel_; |
| 1197 | // Last values received from data channel creation signal. |
| 1198 | std::string last_data_channel_label_; |
| 1199 | InternalDataChannelInit last_data_channel_config_; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1200 | rtc::CryptoOptions crypto_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1201 | }; |
| 1202 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1203 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1204 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1205 | } |
| 1206 | |
| 1207 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1208 | // with rtcp-mux and/or bundle. |
| 1209 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1210 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1211 | } |
| 1212 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1213 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1214 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1215 | } |
| 1216 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1217 | TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1218 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1219 | SessionDescriptionInterface* offer = NULL; |
| 1220 | // Since |offer| is NULL, there's no way to tell if it's an offer or answer. |
| 1221 | std::string unknown_action; |
| 1222 | SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1223 | SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1224 | } |
| 1225 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1226 | // Test creating offers and receive answers and make sure the |
| 1227 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1228 | TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1229 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1230 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1231 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1232 | const std::string session_id_orig = offer->session_id(); |
| 1233 | const std::string session_version_orig = offer->session_version(); |
| 1234 | SetLocalDescriptionWithoutError(offer); |
| 1235 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1236 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1237 | SessionDescriptionInterface* answer = |
| 1238 | CreateRemoteAnswer(session_->local_description()); |
| 1239 | SetRemoteDescriptionWithoutError(answer); |
| 1240 | |
| 1241 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1242 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1243 | |
| 1244 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1245 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1246 | |
| 1247 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1248 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1249 | |
| 1250 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1251 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1252 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1253 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1254 | |
| 1255 | // Create new offer without send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1256 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1257 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1258 | |
| 1259 | // Verify the session id is the same and the session version is |
| 1260 | // increased. |
| 1261 | EXPECT_EQ(session_id_orig, offer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1262 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1263 | rtc::FromString<uint64_t>(offer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1264 | |
| 1265 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1266 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1267 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1268 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1269 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1270 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1271 | SetRemoteDescriptionWithoutError(answer); |
| 1272 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1273 | // Make sure the receive streams have not changed. |
| 1274 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1275 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1276 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1277 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1278 | } |
| 1279 | |
| 1280 | // Test receiving offers and creating answers and make sure the |
| 1281 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1282 | TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1283 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1284 | SendAudioVideoStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1285 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1286 | SetRemoteDescriptionWithoutError(offer); |
| 1287 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1288 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1289 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1290 | SetLocalDescriptionWithoutError(answer); |
| 1291 | |
| 1292 | const std::string session_id_orig = answer->session_id(); |
| 1293 | const std::string session_version_orig = answer->session_version(); |
| 1294 | |
| 1295 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1296 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1297 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1298 | ASSERT_TRUE(video_channel_); |
| 1299 | ASSERT_TRUE(voice_channel_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1300 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1301 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1302 | |
| 1303 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1304 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1305 | |
| 1306 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1307 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1308 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1309 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1310 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1311 | SendAudioVideoStream1And2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1312 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1313 | SetRemoteDescriptionWithoutError(offer); |
| 1314 | |
| 1315 | // Answer by turning off all send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1316 | SendNothing(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1317 | answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1318 | |
| 1319 | // Verify the session id is the same and the session version is |
| 1320 | // increased. |
| 1321 | EXPECT_EQ(session_id_orig, answer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1322 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1323 | rtc::FromString<uint64_t>(answer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1324 | SetLocalDescriptionWithoutError(answer); |
| 1325 | |
| 1326 | ASSERT_EQ(2u, video_channel_->recv_streams().size()); |
| 1327 | EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id); |
| 1328 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id); |
| 1329 | ASSERT_EQ(2u, voice_channel_->recv_streams().size()); |
| 1330 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id); |
| 1331 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id); |
| 1332 | |
| 1333 | // Make sure we have no send streams. |
| 1334 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1335 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1336 | } |
| 1337 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1338 | TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1339 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1340 | media_engine_->set_fail_create_channel(true); |
| 1341 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1342 | SessionDescriptionInterface* offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1343 | ASSERT_TRUE(offer != NULL); |
| 1344 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1345 | // the offer. |
| 1346 | SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1347 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1348 | ASSERT_TRUE(offer != NULL); |
| 1349 | SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer); |
| 1350 | } |
| 1351 | |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1352 | // Test that we can create and set an answer correctly when different |
| 1353 | // SSL roles have been negotiated for different transports. |
| 1354 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525 |
| 1355 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) { |
| 1356 | SendAudioVideoStream1(); |
| 1357 | InitWithDtls(GetParam()); |
| 1358 | SetFactoryDtlsSrtp(); |
| 1359 | |
| 1360 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1361 | SetLocalDescriptionWithoutError(offer); |
| 1362 | |
| 1363 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1364 | GetOptionsForAnswer(&options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1365 | |
| 1366 | // First, negotiate different SSL roles. |
| 1367 | SessionDescriptionInterface* answer = |
| 1368 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1369 | TransportInfo* audio_transport_info = |
| 1370 | answer->description()->GetTransportInfoByName("audio"); |
| 1371 | audio_transport_info->description.connection_role = |
| 1372 | cricket::CONNECTIONROLE_ACTIVE; |
| 1373 | TransportInfo* video_transport_info = |
| 1374 | answer->description()->GetTransportInfoByName("video"); |
| 1375 | video_transport_info->description.connection_role = |
| 1376 | cricket::CONNECTIONROLE_PASSIVE; |
| 1377 | SetRemoteDescriptionWithoutError(answer); |
| 1378 | |
| 1379 | // Now create an offer in the reverse direction, and ensure the initial |
| 1380 | // offerer responds with an answer with correct SSL roles. |
| 1381 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1382 | kSessionVersion, |
| 1383 | session_->remote_description()); |
| 1384 | SetRemoteDescriptionWithoutError(offer); |
| 1385 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1386 | cricket::MediaSessionOptions answer_options; |
| 1387 | answer_options.bundle_enabled = true; |
| 1388 | answer = CreateAnswer(answer_options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1389 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1390 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1391 | audio_transport_info->description.connection_role); |
| 1392 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1393 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 1394 | video_transport_info->description.connection_role); |
| 1395 | SetLocalDescriptionWithoutError(answer); |
| 1396 | |
| 1397 | // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of |
| 1398 | // audio is transferred over to video in the answer that completes the BUNDLE |
| 1399 | // negotiation. |
| 1400 | options.bundle_enabled = true; |
| 1401 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1402 | kSessionVersion, |
| 1403 | session_->remote_description()); |
| 1404 | SetRemoteDescriptionWithoutError(offer); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1405 | answer = CreateAnswer(answer_options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1406 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1407 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1408 | audio_transport_info->description.connection_role); |
| 1409 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1410 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1411 | video_transport_info->description.connection_role); |
| 1412 | SetLocalDescriptionWithoutError(answer); |
| 1413 | } |
| 1414 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1415 | TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1416 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1417 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1418 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1419 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1420 | SetLocalDescriptionWithoutError(offer); |
| 1421 | |
| 1422 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1423 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1424 | SetLocalDescriptionWithoutError(offer2); |
| 1425 | } |
| 1426 | |
| 1427 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1428 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1429 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1430 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1431 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1432 | SetRemoteDescriptionWithoutError(offer); |
| 1433 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1434 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1435 | SetRemoteDescriptionWithoutError(offer2); |
| 1436 | } |
| 1437 | |
| 1438 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1439 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1440 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1441 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1442 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1443 | offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1444 | SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER", |
| 1445 | offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1449 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1450 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1451 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1452 | SetRemoteDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1453 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1454 | SetLocalDescriptionOfferExpectError( |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1455 | "Called in wrong state: STATE_RECEIVEDOFFER", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1459 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1460 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1461 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1462 | SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1463 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1464 | JsepSessionDescription* pranswer = |
| 1465 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1466 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1467 | SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1468 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1469 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1470 | JsepSessionDescription* pranswer2 = |
| 1471 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1472 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1473 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1474 | SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1475 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1476 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1477 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1478 | SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1482 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1483 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1484 | SessionDescriptionInterface* offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1485 | SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1486 | |
| 1487 | JsepSessionDescription* pranswer = |
| 1488 | CreateRemoteAnswer(session_->local_description()); |
| 1489 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1490 | |
| 1491 | SetRemoteDescriptionExpectState(pranswer, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1492 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1493 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1494 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1495 | JsepSessionDescription* pranswer2 = |
| 1496 | CreateRemoteAnswer(session_->local_description()); |
| 1497 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1498 | |
| 1499 | SetRemoteDescriptionExpectState(pranswer2, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1500 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1501 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1502 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1503 | SessionDescriptionInterface* answer = |
| 1504 | CreateRemoteAnswer(session_->local_description()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1505 | SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1509 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1510 | SendNothing(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1511 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1512 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1513 | SessionDescriptionInterface* answer = |
| 1514 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1515 | SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT", |
| 1516 | answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1520 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1521 | SendNothing(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1522 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1523 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1524 | SessionDescriptionInterface* answer = |
| 1525 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1526 | SetRemoteDescriptionAnswerExpectError( |
| 1527 | "Called in wrong state: STATE_INIT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1530 | // Verifies TransportProxy and media channels are created with content names |
| 1531 | // present in the SessionDescription. |
| 1532 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1533 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1534 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1535 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1536 | |
| 1537 | // CreateOffer creates session description with the content names "audio" and |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1538 | // "video". Goal is to modify these content names and verify transport |
| 1539 | // channels |
| 1540 | // in the WebRtcSession, as channels are created with the content names |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1541 | // present in SDP. |
| 1542 | std::string sdp; |
| 1543 | EXPECT_TRUE(offer->ToString(&sdp)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1544 | |
| 1545 | SessionDescriptionInterface* modified_offer = |
| 1546 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 1547 | |
| 1548 | SetRemoteDescriptionWithoutError(modified_offer); |
| 1549 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1550 | cricket::MediaSessionOptions answer_options; |
| 1551 | answer_options.bundle_enabled = false; |
| 1552 | SessionDescriptionInterface* answer = CreateAnswer(answer_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1553 | SetLocalDescriptionWithoutError(answer); |
| 1554 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 1555 | rtc::PacketTransportInternal* voice_transport_channel = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1556 | session_->voice_rtp_transport_channel(); |
| 1557 | EXPECT_TRUE(voice_transport_channel != NULL); |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 1558 | EXPECT_EQ(voice_transport_channel->debug_name(), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1559 | "audio " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 1560 | rtc::PacketTransportInternal* video_transport_channel = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1561 | session_->video_rtp_transport_channel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1562 | ASSERT_TRUE(video_transport_channel != NULL); |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 1563 | EXPECT_EQ(video_transport_channel->debug_name(), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1564 | "video " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1565 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 1566 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 1567 | } |
| 1568 | |
| 1569 | // Test that an offer contains the correct media content descriptions based on |
| 1570 | // the send streams when no constraints have been set. |
| 1571 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1572 | Init(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1573 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1574 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1575 | ASSERT_TRUE(offer != NULL); |
| 1576 | const cricket::ContentInfo* content = |
| 1577 | cricket::GetFirstAudioContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1578 | ASSERT_TRUE(content != NULL); |
| 1579 | EXPECT_EQ( |
| 1580 | cricket::MD_RECVONLY, |
| 1581 | static_cast<const cricket::AudioContentDescription*>(content->description) |
| 1582 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1583 | content = cricket::GetFirstVideoContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1584 | ASSERT_TRUE(content != NULL); |
| 1585 | EXPECT_EQ( |
| 1586 | cricket::MD_RECVONLY, |
| 1587 | static_cast<const cricket::VideoContentDescription*>(content->description) |
| 1588 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | // Test that an offer contains the correct media content descriptions based on |
| 1592 | // the send streams when no constraints have been set. |
| 1593 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1594 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1595 | // Test Audio only offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1596 | SendAudioOnlyStream2(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1597 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1598 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1599 | const cricket::ContentInfo* content = |
| 1600 | cricket::GetFirstAudioContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1601 | ASSERT_TRUE(content != NULL); |
| 1602 | EXPECT_EQ( |
| 1603 | cricket::MD_SENDRECV, |
| 1604 | static_cast<const cricket::AudioContentDescription*>(content->description) |
| 1605 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1606 | content = cricket::GetFirstVideoContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1607 | ASSERT_TRUE(content != NULL); |
| 1608 | EXPECT_EQ( |
| 1609 | cricket::MD_RECVONLY, |
| 1610 | static_cast<const cricket::VideoContentDescription*>(content->description) |
| 1611 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1612 | |
| 1613 | // Test Audio / Video offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1614 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1615 | offer.reset(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1616 | content = cricket::GetFirstAudioContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1617 | ASSERT_TRUE(content != NULL); |
| 1618 | EXPECT_EQ( |
| 1619 | cricket::MD_SENDRECV, |
| 1620 | static_cast<const cricket::AudioContentDescription*>(content->description) |
| 1621 | ->direction()); |
| 1622 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | content = cricket::GetFirstVideoContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1624 | ASSERT_TRUE(content != NULL); |
| 1625 | EXPECT_EQ( |
| 1626 | cricket::MD_SENDRECV, |
| 1627 | static_cast<const cricket::VideoContentDescription*>(content->description) |
| 1628 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | // Test that an offer contains no media content descriptions if |
| 1632 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 1633 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1634 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1635 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1636 | options.offer_to_receive_audio = 0; |
| 1637 | options.offer_to_receive_video = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1638 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1639 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1640 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1641 | ASSERT_TRUE(offer != NULL); |
| 1642 | const cricket::ContentInfo* content = |
| 1643 | cricket::GetFirstAudioContent(offer->description()); |
| 1644 | EXPECT_TRUE(content == NULL); |
| 1645 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1646 | EXPECT_TRUE(content == NULL); |
| 1647 | } |
| 1648 | |
| 1649 | // Test that an offer contains only audio media content descriptions if |
| 1650 | // kOfferToReceiveAudio constraints are set to true. |
| 1651 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1652 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1653 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1654 | options.offer_to_receive_audio = |
| 1655 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1656 | options.offer_to_receive_video = 0; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1657 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1658 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1659 | |
| 1660 | const cricket::ContentInfo* content = |
| 1661 | cricket::GetFirstAudioContent(offer->description()); |
| 1662 | EXPECT_TRUE(content != NULL); |
| 1663 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1664 | EXPECT_TRUE(content == NULL); |
| 1665 | } |
| 1666 | |
| 1667 | // Test that an offer contains audio and video media content descriptions if |
| 1668 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 1669 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1670 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1671 | // Test Audio / Video offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1672 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1673 | options.offer_to_receive_audio = |
| 1674 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 1675 | options.offer_to_receive_video = |
| 1676 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 1677 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1678 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1679 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1680 | const cricket::ContentInfo* content = |
| 1681 | cricket::GetFirstAudioContent(offer->description()); |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 1682 | EXPECT_TRUE(content != NULL); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1683 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1684 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1685 | EXPECT_TRUE(content != NULL); |
| 1686 | |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1687 | // Sets constraints to false and verifies that audio/video contents are |
| 1688 | // removed. |
| 1689 | options.offer_to_receive_audio = 0; |
| 1690 | options.offer_to_receive_video = 0; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1691 | // Remove the media sections added in previous offer. |
| 1692 | offered_media_sections_.clear(); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1693 | offer.reset(CreateOffer(options)); |
| 1694 | |
| 1695 | content = cricket::GetFirstAudioContent(offer->description()); |
| 1696 | EXPECT_TRUE(content == NULL); |
| 1697 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1698 | EXPECT_TRUE(content == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | // Test that an answer can not be created if the last remote description is not |
| 1702 | // an offer. |
| 1703 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1704 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1705 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1706 | SetLocalDescriptionWithoutError(offer); |
| 1707 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 1708 | SetRemoteDescriptionWithoutError(answer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1709 | EXPECT_TRUE(CreateAnswer() == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | // Test that an answer contains the correct media content descriptions when no |
| 1713 | // constraints have been set. |
| 1714 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1715 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1716 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1717 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1718 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1719 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1720 | const cricket::ContentInfo* content = |
| 1721 | cricket::GetFirstAudioContent(answer->description()); |
| 1722 | ASSERT_TRUE(content != NULL); |
| 1723 | EXPECT_FALSE(content->rejected); |
| 1724 | |
| 1725 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1726 | ASSERT_TRUE(content != NULL); |
| 1727 | EXPECT_FALSE(content->rejected); |
| 1728 | } |
| 1729 | |
| 1730 | // Test that an answer contains the correct media content descriptions when no |
| 1731 | // constraints have been set and the offer only contain audio. |
| 1732 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1733 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1734 | // Create a remote offer with audio only. |
| 1735 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1736 | GetOptionsForAudioOnlyRemoteOffer(&options); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1737 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1738 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1739 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 1740 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 1741 | |
| 1742 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1743 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1744 | const cricket::ContentInfo* content = |
| 1745 | cricket::GetFirstAudioContent(answer->description()); |
| 1746 | ASSERT_TRUE(content != NULL); |
| 1747 | EXPECT_FALSE(content->rejected); |
| 1748 | |
| 1749 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 1750 | } |
| 1751 | |
| 1752 | // Test that an answer contains the correct media content descriptions when no |
| 1753 | // constraints have been set. |
| 1754 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1755 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1756 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1757 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1758 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1759 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1760 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1761 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1762 | const cricket::ContentInfo* content = |
| 1763 | cricket::GetFirstAudioContent(answer->description()); |
| 1764 | ASSERT_TRUE(content != NULL); |
| 1765 | EXPECT_FALSE(content->rejected); |
| 1766 | |
| 1767 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1768 | ASSERT_TRUE(content != NULL); |
| 1769 | EXPECT_FALSE(content->rejected); |
| 1770 | } |
| 1771 | |
| 1772 | // Test that an answer contains the correct media content descriptions when |
| 1773 | // constraints have been set but no stream is sent. |
| 1774 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1775 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1776 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1777 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1778 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1779 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1780 | cricket::MediaSessionOptions session_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1781 | remote_send_audio_ = false; |
| 1782 | remote_send_video_ = false; |
| 1783 | local_recv_audio_ = false; |
| 1784 | local_recv_video_ = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1785 | std::unique_ptr<SessionDescriptionInterface> answer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1786 | CreateAnswer(session_options)); |
| 1787 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1788 | const cricket::ContentInfo* content = |
| 1789 | cricket::GetFirstAudioContent(answer->description()); |
| 1790 | ASSERT_TRUE(content != NULL); |
| 1791 | EXPECT_TRUE(content->rejected); |
| 1792 | |
| 1793 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1794 | ASSERT_TRUE(content != NULL); |
| 1795 | EXPECT_TRUE(content->rejected); |
| 1796 | } |
| 1797 | |
| 1798 | // Test that an answer contains the correct media content descriptions when |
| 1799 | // constraints have been set and streams are sent. |
| 1800 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1801 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1802 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1803 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1804 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1805 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1806 | cricket::MediaSessionOptions options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1807 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1808 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1809 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1810 | |
| 1811 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1812 | const cricket::ContentInfo* content = |
| 1813 | cricket::GetFirstAudioContent(answer->description()); |
| 1814 | ASSERT_TRUE(content != NULL); |
| 1815 | EXPECT_FALSE(content->rejected); |
| 1816 | |
| 1817 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1818 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1819 | ASSERT_TRUE(content != NULL); |
| 1820 | EXPECT_FALSE(content->rejected); |
| 1821 | } |
| 1822 | |
| 1823 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 1824 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1825 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1826 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1827 | options.offer_to_receive_audio = |
| 1828 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 1829 | options.voice_activity_detection = false; |
| 1830 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1831 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1832 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1833 | const cricket::ContentInfo* content = |
| 1834 | cricket::GetFirstAudioContent(offer->description()); |
| 1835 | EXPECT_TRUE(content != NULL); |
| 1836 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1837 | } |
| 1838 | |
| 1839 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 1840 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1841 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1842 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1843 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1844 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1845 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1846 | cricket::MediaSessionOptions options; |
| 1847 | options.vad_enabled = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1848 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1849 | const cricket::ContentInfo* content = |
| 1850 | cricket::GetFirstAudioContent(answer->description()); |
| 1851 | ASSERT_TRUE(content != NULL); |
| 1852 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1853 | } |
| 1854 | |
| 1855 | // This test verifies the call setup when remote answer with audio only and |
| 1856 | // later updates with video. |
| 1857 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1858 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1859 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 1860 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 1861 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1862 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1863 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1864 | |
| 1865 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1866 | AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 1867 | cricket::MD_RECVONLY, kActive, &options); |
| 1868 | AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 1869 | cricket::MD_INACTIVE, kStopped, &options); |
| 1870 | local_recv_video_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1871 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 1872 | |
| 1873 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1874 | // and answer; |
| 1875 | SetLocalDescriptionWithoutError(offer); |
| 1876 | SetRemoteDescriptionWithoutError(answer); |
| 1877 | |
| 1878 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1879 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1880 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1881 | ASSERT_TRUE(video_channel_ == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1882 | |
| 1883 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 1884 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1885 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 1886 | |
| 1887 | // Let the remote end update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1888 | SendAudioVideoStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1889 | local_recv_video_ = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1890 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1891 | |
| 1892 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1893 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1894 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1895 | ASSERT_TRUE(video_channel_ != nullptr); |
| 1896 | ASSERT_TRUE(voice_channel_ != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1897 | |
| 1898 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1899 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1900 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 1901 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 1902 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1903 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1904 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1905 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1906 | |
| 1907 | // Change session back to audio only. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1908 | // The remote side doesn't send and recv video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1909 | SendAudioOnlyStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1910 | remote_recv_video_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1911 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 1912 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1913 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1914 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1915 | |
| 1916 | // The audio is expected to be rejected. |
| 1917 | EXPECT_TRUE(video_channel_ == nullptr); |
| 1918 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1919 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1920 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1921 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1922 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1923 | } |
| 1924 | |
| 1925 | // This test verifies the call setup when remote answer with video only and |
| 1926 | // later updates with audio. |
| 1927 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1928 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1929 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 1930 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1931 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1932 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1933 | |
| 1934 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1935 | AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 1936 | cricket::MD_INACTIVE, kStopped, &options); |
| 1937 | AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 1938 | cricket::MD_RECVONLY, kActive, &options); |
| 1939 | local_recv_audio_ = false; |
| 1940 | SessionDescriptionInterface* answer = |
| 1941 | CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1942 | |
| 1943 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1944 | // and answer. |
| 1945 | SetLocalDescriptionWithoutError(offer); |
| 1946 | SetRemoteDescriptionWithoutError(answer); |
| 1947 | |
| 1948 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1949 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1950 | |
| 1951 | ASSERT_TRUE(voice_channel_ == NULL); |
| 1952 | ASSERT_TRUE(video_channel_ != NULL); |
| 1953 | |
| 1954 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 1955 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1956 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 1957 | |
| 1958 | // Update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1959 | SendAudioVideoStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1960 | local_recv_audio_ = true; |
| 1961 | SessionDescriptionInterface* offer2 = CreateRemoteOffer(); |
| 1962 | SetRemoteDescriptionWithoutError(offer2); |
| 1963 | cricket::MediaSessionOptions answer_options; |
| 1964 | // Disable the bundling here. If the media is bundled on audio |
| 1965 | // transport, then we can't reject the audio because switching the bundled |
| 1966 | // transport is not currently supported. |
| 1967 | // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704) |
| 1968 | answer_options.bundle_enabled = false; |
| 1969 | SessionDescriptionInterface* answer2 = CreateAnswer(answer_options); |
| 1970 | SetLocalDescriptionWithoutError(answer2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1971 | |
| 1972 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 1973 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1974 | ASSERT_TRUE(voice_channel_ != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1975 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1976 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1977 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 1978 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 1979 | |
| 1980 | // Change session back to video only. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1981 | // The remote side doesn't send and recv audio. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1982 | SendVideoOnlyStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1983 | remote_recv_audio_ = false; |
| 1984 | SessionDescriptionInterface* offer3 = CreateRemoteOffer(); |
| 1985 | SetRemoteDescriptionWithoutError(offer3); |
| 1986 | SessionDescriptionInterface* answer3 = CreateAnswer(answer_options); |
| 1987 | SetLocalDescriptionWithoutError(answer3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1988 | |
| 1989 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1990 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1991 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1992 | // The video is expected to be rejected. |
| 1993 | EXPECT_TRUE(voice_channel_ == nullptr); |
| 1994 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1995 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1996 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 1997 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1998 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 1999 | } |
| 2000 | |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2001 | // Test that candidates sent to the "video" transport do not get pushed down to |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2002 | // the "audio" transport channel when bundling. |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2003 | TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { |
| 2004 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2005 | |
| 2006 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2007 | SendAudioVideoStream1(); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2008 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2009 | cricket::MediaSessionOptions offer_options; |
| 2010 | GetOptionsForRemoteOffer(&offer_options); |
| 2011 | offer_options.bundle_enabled = true; |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2012 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2013 | SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2014 | SetRemoteDescriptionWithoutError(offer); |
| 2015 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2016 | cricket::MediaSessionOptions answer_options; |
| 2017 | answer_options.bundle_enabled = true; |
| 2018 | SessionDescriptionInterface* answer = CreateAnswer(answer_options); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2019 | SetLocalDescriptionWithoutError(answer); |
| 2020 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2021 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2022 | session_->video_rtp_transport_channel()); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2023 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2024 | cricket::BaseChannel* voice_channel = session_->voice_channel(); |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 2025 | ASSERT_TRUE(voice_channel != NULL); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2026 | |
| 2027 | // Checks if one of the transport channels contains a connection using a given |
| 2028 | // port. |
eladalon | 1cc5fc3 | 2017-08-23 04:15:18 -0700 | [diff] [blame] | 2029 | auto connection_with_remote_port = [this](int port) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 2030 | std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s(); |
| 2031 | for (auto& kv : stats->transport_stats) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2032 | for (auto& chan_stat : kv.second.channel_stats) { |
| 2033 | for (auto& conn_info : chan_stat.connection_infos) { |
| 2034 | if (conn_info.remote_candidate.address().port() == port) { |
| 2035 | return true; |
| 2036 | } |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | } |
| 2040 | return false; |
| 2041 | }; |
| 2042 | |
| 2043 | EXPECT_FALSE(connection_with_remote_port(5000)); |
| 2044 | EXPECT_FALSE(connection_with_remote_port(5001)); |
| 2045 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2046 | |
| 2047 | // The way the *_WAIT checks work is they only wait if the condition fails, |
| 2048 | // which does not help in the case where state is not changing. This is |
| 2049 | // problematic in this test since we want to verify that adding a video |
| 2050 | // candidate does _not_ change state. So we interleave candidates and assume |
| 2051 | // that messages are executed in the order they were posted. |
| 2052 | |
| 2053 | // First audio candidate. |
| 2054 | cricket::Candidate candidate0; |
| 2055 | candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
| 2056 | candidate0.set_component(1); |
| 2057 | candidate0.set_protocol("udp"); |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 2058 | candidate0.set_type("local"); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2059 | JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0, |
| 2060 | candidate0); |
| 2061 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0)); |
| 2062 | |
| 2063 | // Video candidate. |
| 2064 | cricket::Candidate candidate1; |
| 2065 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2066 | candidate1.set_component(1); |
| 2067 | candidate1.set_protocol("udp"); |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 2068 | candidate1.set_type("local"); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2069 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2070 | candidate1); |
| 2071 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2072 | |
| 2073 | // Second audio candidate. |
| 2074 | cricket::Candidate candidate2; |
| 2075 | candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001)); |
| 2076 | candidate2.set_component(1); |
| 2077 | candidate2.set_protocol("udp"); |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 2078 | candidate2.set_type("local"); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2079 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2080 | candidate2); |
| 2081 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2082 | |
| 2083 | EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000); |
| 2084 | EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000); |
| 2085 | |
| 2086 | // No need here for a _WAIT check since we are checking that state hasn't |
| 2087 | // changed: if this is false we would be doing waits for nothing and if this |
| 2088 | // is true then there will be no messages processed anyways. |
| 2089 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2090 | } |
| 2091 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2092 | // kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2093 | TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) { |
| 2094 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2095 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2096 | |
| 2097 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2098 | options.use_rtp_mux = true; |
| 2099 | |
| 2100 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2101 | SetLocalDescriptionWithoutError(offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2102 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2103 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2104 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2105 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2106 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2107 | SessionDescriptionInterface* answer = |
| 2108 | CreateRemoteAnswer(session_->local_description()); |
| 2109 | SetRemoteDescriptionWithoutError(answer); |
| 2110 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2111 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2112 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2115 | // kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2116 | TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) { |
| 2117 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2118 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2119 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2120 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2121 | options.use_rtp_mux = true; |
| 2122 | |
| 2123 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2124 | SetLocalDescriptionWithoutError(offer); |
| 2125 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2126 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2127 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2128 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2129 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2130 | |
| 2131 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2132 | std::unique_ptr<SessionDescriptionInterface> answer( |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2133 | CreateRemoteAnswer(session_->local_description())); |
| 2134 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2135 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2136 | JsepSessionDescription* modified_answer = |
| 2137 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2138 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2139 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 2140 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2141 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2142 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer. |
| 2146 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) { |
| 2147 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2148 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2149 | |
| 2150 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2151 | options.use_rtp_mux = true; |
| 2152 | |
| 2153 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2154 | SetLocalDescriptionWithoutError(offer); |
| 2155 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2156 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2157 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2158 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2159 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2160 | SessionDescriptionInterface* answer = |
| 2161 | CreateRemoteAnswer(session_->local_description()); |
| 2162 | SetRemoteDescriptionWithoutError(answer); |
| 2163 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2164 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2165 | session_->video_rtp_transport_channel()); |
| 2166 | } |
| 2167 | |
| 2168 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no |
| 2169 | // audio content in the answer. |
| 2170 | TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) { |
| 2171 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2172 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2173 | |
| 2174 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2175 | options.use_rtp_mux = true; |
| 2176 | |
| 2177 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2178 | SetLocalDescriptionWithoutError(offer); |
| 2179 | |
| 2180 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2181 | session_->video_rtp_transport_channel()); |
| 2182 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2183 | SendVideoOnlyStream2(); |
| 2184 | local_send_audio_ = false; |
| 2185 | remote_recv_audio_ = false; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2186 | cricket::MediaSessionOptions recv_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2187 | GetOptionsForRemoteAnswer(&recv_options); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2188 | SessionDescriptionInterface* answer = |
| 2189 | CreateRemoteAnswer(session_->local_description(), recv_options); |
| 2190 | SetRemoteDescriptionWithoutError(answer); |
| 2191 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2192 | EXPECT_TRUE(nullptr == session_->voice_channel()); |
| 2193 | EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2194 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2195 | session_->Close(); |
| 2196 | EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel()); |
| 2197 | EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel()); |
| 2198 | EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel()); |
| 2199 | EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | // kBundlePolicyMaxBundle policy but no BUNDLE in the answer. |
| 2203 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) { |
| 2204 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2205 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2206 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2207 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2208 | options.use_rtp_mux = true; |
| 2209 | |
| 2210 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2211 | SetLocalDescriptionWithoutError(offer); |
| 2212 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2213 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2214 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2215 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2216 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2217 | |
| 2218 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2219 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2220 | CreateRemoteAnswer(session_->local_description())); |
| 2221 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2222 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2223 | JsepSessionDescription* modified_answer = |
| 2224 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2225 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2226 | SetRemoteDescriptionWithoutError(modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2227 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2228 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2229 | session_->video_rtp_transport_channel()); |
| 2230 | } |
| 2231 | |
| 2232 | // kBundlePolicyMaxBundle policy with BUNDLE in the remote offer. |
| 2233 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) { |
| 2234 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2235 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2236 | |
| 2237 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2238 | SetRemoteDescriptionWithoutError(offer); |
| 2239 | |
| 2240 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2241 | session_->video_rtp_transport_channel()); |
| 2242 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2243 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2244 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2245 | SetLocalDescriptionWithoutError(answer); |
| 2246 | |
| 2247 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2248 | session_->video_rtp_transport_channel()); |
| 2249 | } |
| 2250 | |
| 2251 | // kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer. |
| 2252 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) { |
| 2253 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2254 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2255 | |
| 2256 | // Remove BUNDLE from the offer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2257 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2258 | cricket::SessionDescription* offer_copy = offer->description()->Copy(); |
| 2259 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2260 | JsepSessionDescription* modified_offer = |
| 2261 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2262 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 2263 | |
| 2264 | // Expect an error when applying the remote description |
| 2265 | SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, |
| 2266 | kCreateChannelFailed, modified_offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2267 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2268 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2269 | // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2270 | TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { |
| 2271 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2272 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2273 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2274 | PeerConnectionInterface::RTCOfferAnswerOptions rtc_options; |
| 2275 | rtc_options.use_rtp_mux = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2276 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2277 | SessionDescriptionInterface* offer = CreateOffer(rtc_options); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2278 | SetLocalDescriptionWithoutError(offer); |
| 2279 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2280 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2281 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2282 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2283 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2284 | SessionDescriptionInterface* answer = |
| 2285 | CreateRemoteAnswer(session_->local_description()); |
| 2286 | SetRemoteDescriptionWithoutError(answer); |
| 2287 | |
| 2288 | // This should lead to an audio-only call but isn't implemented |
| 2289 | // correctly yet. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2290 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2291 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2294 | // kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2295 | TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) { |
| 2296 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2297 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2298 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2299 | options.use_rtp_mux = true; |
| 2300 | |
| 2301 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2302 | SetLocalDescriptionWithoutError(offer); |
| 2303 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2304 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2305 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2306 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2307 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2308 | |
| 2309 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2310 | std::unique_ptr<SessionDescriptionInterface> answer( |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2311 | CreateRemoteAnswer(session_->local_description())); |
| 2312 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2313 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2314 | JsepSessionDescription* modified_answer = |
| 2315 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2316 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2317 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 2318 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2319 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2320 | session_->video_rtp_transport_channel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2323 | // kBundlePolicyMaxbundle and then we call SetRemoteDescription first. |
| 2324 | TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) { |
| 2325 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2326 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2327 | |
| 2328 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2329 | options.use_rtp_mux = true; |
| 2330 | |
| 2331 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2332 | SetRemoteDescriptionWithoutError(offer); |
| 2333 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2334 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2335 | session_->video_rtp_transport_channel()); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2338 | // Adding a new channel to a BUNDLE which is already connected should directly |
| 2339 | // assign the bundle transport to the channel, without first setting a |
| 2340 | // disconnected non-bundle transport and then replacing it. The application |
| 2341 | // should not receive any changes in the ICE state. |
| 2342 | TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) { |
Steve Anton | ede9ca5 | 2017-10-16 13:04:27 -0700 | [diff] [blame] | 2343 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2344 | // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain |
| 2345 | // connected. Disabling either of these two means that we need to wait for the |
| 2346 | // answer to find out if more transports are needed. |
| 2347 | configuration_.bundle_policy = |
| 2348 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2349 | options_.disable_encryption = true; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 2350 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2351 | |
| 2352 | // Negotiate an audio channel with MAX_BUNDLE enabled. |
| 2353 | SendAudioOnlyStream2(); |
| 2354 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2355 | SetLocalDescriptionWithoutError(offer); |
| 2356 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 2357 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| 2358 | std::string sdp; |
| 2359 | offer->ToString(&sdp); |
| 2360 | SessionDescriptionInterface* answer = webrtc::CreateSessionDescription( |
| 2361 | JsepSessionDescription::kAnswer, sdp, nullptr); |
| 2362 | ASSERT_TRUE(answer != NULL); |
| 2363 | SetRemoteDescriptionWithoutError(answer); |
| 2364 | |
| 2365 | // Wait for the ICE state to stabilize. |
| 2366 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2367 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 2368 | observer_.ice_connection_state_history_.clear(); |
| 2369 | |
| 2370 | // Now add a video channel which should be using the same bundle transport. |
| 2371 | SendAudioVideoStream2(); |
| 2372 | offer = CreateOffer(); |
| 2373 | offer->ToString(&sdp); |
| 2374 | SetLocalDescriptionWithoutError(offer); |
| 2375 | answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, |
| 2376 | sdp, nullptr); |
| 2377 | ASSERT_TRUE(answer != NULL); |
| 2378 | SetRemoteDescriptionWithoutError(answer); |
| 2379 | |
| 2380 | // Wait for ICE state to stabilize |
| 2381 | rtc::Thread::Current()->ProcessMessages(0); |
| 2382 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2383 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 2384 | |
| 2385 | // No ICE state changes are expected to happen. |
| 2386 | EXPECT_EQ(0, observer_.ice_connection_state_history_.size()); |
| 2387 | } |
| 2388 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2389 | TEST_F(WebRtcSessionTest, TestRequireRtcpMux) { |
| 2390 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2391 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2392 | |
| 2393 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2394 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2395 | SetLocalDescriptionWithoutError(offer); |
| 2396 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2397 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 2398 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2399 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2400 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2401 | SessionDescriptionInterface* answer = |
| 2402 | CreateRemoteAnswer(session_->local_description()); |
| 2403 | SetRemoteDescriptionWithoutError(answer); |
| 2404 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2405 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 2406 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) { |
| 2410 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2411 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2412 | |
| 2413 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2414 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2415 | SetLocalDescriptionWithoutError(offer); |
| 2416 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2417 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL); |
| 2418 | EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2419 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2420 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2421 | SessionDescriptionInterface* answer = |
| 2422 | CreateRemoteAnswer(session_->local_description()); |
| 2423 | SetRemoteDescriptionWithoutError(answer); |
| 2424 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2425 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 2426 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2429 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 2430 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 2431 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2432 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2433 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2434 | |
| 2435 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2436 | options.use_rtp_mux = true; |
| 2437 | |
| 2438 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2439 | std::string offer_str; |
| 2440 | offer->ToString(&offer_str); |
| 2441 | // Disable rtcp-mux |
| 2442 | const std::string rtcp_mux = "rtcp-mux"; |
| 2443 | const std::string xrtcp_mux = "xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2444 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2445 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 2446 | &offer_str); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2447 | SessionDescriptionInterface* local_offer = CreateSessionDescription( |
| 2448 | SessionDescriptionInterface::kOffer, offer_str, nullptr); |
| 2449 | ASSERT_TRUE(local_offer); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2450 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2451 | |
| 2452 | SessionDescriptionInterface* remote_offer = CreateSessionDescription( |
| 2453 | SessionDescriptionInterface::kOffer, offer_str, nullptr); |
| 2454 | ASSERT_TRUE(remote_offer); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2455 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2456 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2457 | // Trying unmodified SDP. |
| 2458 | SetLocalDescriptionWithoutError(offer); |
| 2459 | } |
| 2460 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2461 | // This test verifies the |initial_offerer| flag when session initiates the |
| 2462 | // call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2463 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2464 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2465 | EXPECT_FALSE(session_->initial_offerer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2466 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2467 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2468 | SetLocalDescriptionWithoutError(offer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2469 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2470 | SetRemoteDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2471 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2474 | // This test verifies the |initial_offerer| flag when session receives the call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2475 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2476 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2477 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2478 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2479 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2480 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2481 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2482 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2483 | SetLocalDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2484 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2487 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 2488 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2489 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2490 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2491 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2492 | SetLocalDescriptionWithoutError(offer); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2493 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2494 | CreateRemoteAnswer(session_->local_description())); |
| 2495 | |
| 2496 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2497 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2498 | JsepSessionDescription* modified_answer = |
| 2499 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2500 | |
| 2501 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2502 | answer->session_id(), |
| 2503 | answer->session_version())); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2504 | SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer, |
| 2505 | modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2506 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2507 | // Different content names. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2508 | std::string sdp; |
| 2509 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2510 | const std::string kAudioMid = "a=mid:audio"; |
| 2511 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2512 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2513 | kAudioMidReplaceStr.c_str(), |
| 2514 | kAudioMidReplaceStr.length(), |
| 2515 | &sdp); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2516 | SessionDescriptionInterface* modified_answer1 = |
| 2517 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2518 | SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer, |
| 2519 | modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2520 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2521 | // Different media types. |
| 2522 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2523 | const std::string kAudioMline = "m=audio"; |
| 2524 | const std::string kAudioMlineReplaceStr = "m=video"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2525 | rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(), |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2526 | kAudioMlineReplaceStr.c_str(), |
| 2527 | kAudioMlineReplaceStr.length(), |
| 2528 | &sdp); |
| 2529 | SessionDescriptionInterface* modified_answer2 = |
| 2530 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2531 | SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer, |
| 2532 | modified_answer2); |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2533 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2534 | SetRemoteDescriptionWithoutError(answer.release()); |
| 2535 | } |
| 2536 | |
| 2537 | // Verifying remote offer and local answer have matching m-lines as per |
| 2538 | // RFC 3264. |
| 2539 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2540 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2541 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2542 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2543 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2544 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2545 | |
| 2546 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2547 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2548 | JsepSessionDescription* modified_answer = |
| 2549 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2550 | |
| 2551 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2552 | answer->session_id(), |
| 2553 | answer->session_version())); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2554 | SetLocalDescriptionAnswerExpectError(kMlineMismatchInAnswer, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2555 | SetLocalDescriptionWithoutError(answer); |
| 2556 | } |
| 2557 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2558 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2559 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2560 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2561 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2562 | const std::string session_id_orig = offer->session_id(); |
| 2563 | const std::string session_version_orig = offer->session_version(); |
| 2564 | SetLocalDescriptionWithoutError(offer); |
| 2565 | |
| 2566 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2567 | video_channel_->set_fail_set_send_codecs(true); |
| 2568 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2569 | SessionDescriptionInterface* answer = |
| 2570 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2571 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2572 | |
| 2573 | // Test that after a content error, setting any description will |
| 2574 | // result in an error. |
| 2575 | video_channel_->set_fail_set_send_codecs(false); |
| 2576 | answer = CreateRemoteAnswer(session_->local_description()); |
| 2577 | SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer); |
| 2578 | offer = CreateRemoteOffer(); |
| 2579 | SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2582 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2583 | configuration_.enable_rtp_data_channel = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2584 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2585 | SetLocalDescriptionWithDataChannel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2586 | ASSERT_TRUE(data_engine_); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2587 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2590 | TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2591 | configuration_.enable_rtp_data_channel = true; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2592 | options_.disable_sctp_data_channels = false; |
| 2593 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2594 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2595 | |
| 2596 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2597 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
| 2598 | } |
| 2599 | |
| 2600 | // Test that sctp_content_name/sctp_transport_name (used for stats) are correct |
| 2601 | // before and after BUNDLE is negotiated. |
| 2602 | TEST_P(WebRtcSessionTest, SctpContentAndTransportName) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2603 | SetFactoryDtlsSrtp(); |
| 2604 | InitWithDtls(GetParam()); |
| 2605 | |
| 2606 | // Initially these fields should be empty. |
| 2607 | EXPECT_FALSE(session_->sctp_content_name()); |
| 2608 | EXPECT_FALSE(session_->sctp_transport_name()); |
| 2609 | |
| 2610 | // Create offer with audio/video/data. |
| 2611 | // Default bundle policy is "balanced", so data should be using its own |
| 2612 | // transport. |
| 2613 | SendAudioVideoStream1(); |
| 2614 | CreateDataChannel(); |
| 2615 | InitiateCall(); |
| 2616 | ASSERT_TRUE(session_->sctp_content_name()); |
| 2617 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 2618 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 2619 | EXPECT_EQ("data", *session_->sctp_transport_name()); |
| 2620 | |
| 2621 | // Create answer that finishes BUNDLE negotiation, which means everything |
| 2622 | // should be bundled on the first transport (audio). |
| 2623 | cricket::MediaSessionOptions answer_options; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2624 | answer_options.bundle_enabled = true; |
| 2625 | answer_options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2626 | GetOptionsForAnswer(&answer_options); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2627 | SetRemoteDescriptionWithoutError(CreateRemoteAnswer( |
| 2628 | session_->local_description(), answer_options, cricket::SEC_DISABLED)); |
| 2629 | ASSERT_TRUE(session_->sctp_content_name()); |
| 2630 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 2631 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 2632 | EXPECT_EQ("audio", *session_->sctp_transport_name()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2635 | TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2636 | InitWithDtls(GetParam()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2637 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2638 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2639 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2640 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 2641 | } |
| 2642 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2643 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2644 | SetFactoryDtlsSrtp(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2645 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2646 | |
| 2647 | // Create remote offer with SCTP. |
| 2648 | cricket::MediaSessionOptions options; |
| 2649 | options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2650 | GetOptionsForRemoteOffer(&options); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2651 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 2652 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2653 | SetRemoteDescriptionWithoutError(offer); |
| 2654 | |
| 2655 | // Verifies the answer contains SCTP. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2656 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2657 | EXPECT_TRUE(answer != NULL); |
| 2658 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 2659 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2662 | // Test that if DTLS is disabled, we don't end up with an SctpTransport |
| 2663 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2664 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2665 | configuration_.enable_dtls_srtp = rtc::Optional<bool>(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2666 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2667 | |
| 2668 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2669 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2670 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2673 | // Test that if DTLS is enabled, we end up with an SctpTransport created |
| 2674 | // (and not an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2675 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2676 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2677 | |
| 2678 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2679 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2680 | EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2681 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2682 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2683 | // Test that if SCTP is disabled, we don't end up with an SctpTransport |
| 2684 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2685 | TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2686 | options_.disable_sctp_data_channels = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2687 | InitWithDtls(GetParam()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2688 | |
| 2689 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2690 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2691 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2694 | TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2695 | const int new_send_port = 9998; |
| 2696 | const int new_recv_port = 7775; |
| 2697 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2698 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2699 | SetFactoryDtlsSrtp(); |
| 2700 | |
| 2701 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 2702 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 2703 | // let the session description get parsed. That'll get the proper codecs |
| 2704 | // into the stream. |
| 2705 | cricket::MediaSessionOptions options; |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2706 | SessionDescriptionInterface* offer = |
| 2707 | CreateRemoteOfferWithSctpPort("stream1", new_send_port, options); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2708 | |
| 2709 | // SetRemoteDescription will take the ownership of the offer. |
| 2710 | SetRemoteDescriptionWithoutError(offer); |
| 2711 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2712 | SessionDescriptionInterface* answer = |
| 2713 | ChangeSDPSctpPort(new_recv_port, CreateAnswer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2714 | ASSERT_TRUE(answer != NULL); |
| 2715 | |
| 2716 | // Now set the local description, which'll take ownership of the answer. |
| 2717 | SetLocalDescriptionWithoutError(answer); |
| 2718 | |
| 2719 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 2720 | // and pass it all the way down. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2721 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2722 | CreateDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2723 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
| 2724 | EXPECT_EQ( |
| 2725 | new_recv_port, |
| 2726 | fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port()); |
| 2727 | EXPECT_EQ( |
| 2728 | new_send_port, |
| 2729 | fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2732 | // Verifies that when a session's SctpTransport receives an OPEN message, |
| 2733 | // WebRtcSession signals the SctpTransport creation request with the expected |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2734 | // config. |
| 2735 | TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2736 | InitWithDtls(GetParam()); |
| 2737 | |
| 2738 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2739 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2740 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2741 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2742 | // Make the fake SCTP transport pretend it received an OPEN message. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2743 | webrtc::DataChannelInit config; |
| 2744 | config.id = 1; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 2745 | rtc::CopyOnWriteBuffer payload; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2746 | webrtc::WriteDataChannelOpenMessage("a", config, &payload); |
| 2747 | cricket::ReceiveDataParams params; |
| 2748 | params.ssrc = config.id; |
| 2749 | params.type = cricket::DMT_CONTROL; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2750 | fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived( |
| 2751 | params, payload); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2752 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2753 | EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2754 | EXPECT_EQ(config.id, last_data_channel_config_.id); |
| 2755 | EXPECT_FALSE(last_data_channel_config_.negotiated); |
| 2756 | EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker, |
| 2757 | last_data_channel_config_.open_handshake_role); |
| 2758 | } |
| 2759 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2760 | TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2761 | configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2762 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2763 | SendAudioVideoStream1(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2764 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2765 | |
| 2766 | SetLocalDescriptionWithoutError(offer); |
| 2767 | |
| 2768 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2769 | |
| 2770 | ASSERT_TRUE(voice_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 2771 | const cricket::AudioOptions& audio_options = voice_channel_->options(); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 2772 | EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2775 | #ifdef HAVE_QUIC |
| 2776 | TEST_P(WebRtcSessionTest, TestNegotiateQuic) { |
| 2777 | configuration_.enable_quic = true; |
| 2778 | InitWithDtls(GetParam()); |
| 2779 | EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC); |
| 2780 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2781 | ASSERT_TRUE(offer); |
| 2782 | ASSERT_TRUE(offer->description()); |
| 2783 | SetLocalDescriptionWithoutError(offer); |
| 2784 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2785 | GetOptionsForAnswer(&options); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2786 | SessionDescriptionInterface* answer = |
| 2787 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 2788 | ASSERT_TRUE(answer); |
| 2789 | ASSERT_TRUE(answer->description()); |
| 2790 | SetRemoteDescriptionWithoutError(answer); |
| 2791 | } |
| 2792 | #endif // HAVE_QUIC |
| 2793 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2794 | // Tests that RTX codec is removed from the answer when it isn't supported |
| 2795 | // by local side. |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 2796 | TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) { |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2797 | Init(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2798 | // Send video only to match the |kSdpWithRtx|. |
| 2799 | SendVideoOnlyStream2(); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2800 | std::string offer_sdp(kSdpWithRtx); |
| 2801 | |
| 2802 | SessionDescriptionInterface* offer = |
| 2803 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL); |
| 2804 | EXPECT_TRUE(offer->ToString(&offer_sdp)); |
| 2805 | |
| 2806 | // Offer SDP contains the RTX codec. |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 2807 | EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx")); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2808 | SetRemoteDescriptionWithoutError(offer); |
| 2809 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2810 | // |offered_media_sections_| is used when creating answer. |
| 2811 | offered_media_sections_.push_back(cricket::MediaDescriptionOptions( |
| 2812 | cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 2813 | cricket::RtpTransceiverDirection(true, true), false)); |
| 2814 | // Don't create media section for audio in the answer. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2815 | SessionDescriptionInterface* answer = CreateAnswer(); |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 2816 | // Answer SDP does not contain the RTX codec. |
| 2817 | EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx")); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 2818 | SetLocalDescriptionWithoutError(answer); |
| 2819 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2820 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2821 | // This verifies that the voice channel after bundle has both options from video |
| 2822 | // and voice channels. |
| 2823 | TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { |
| 2824 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2825 | SendAudioVideoStream1(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2826 | |
| 2827 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2828 | options.use_rtp_mux = true; |
| 2829 | |
| 2830 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2831 | SetLocalDescriptionWithoutError(offer); |
| 2832 | |
| 2833 | session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 2834 | rtc::Socket::Option::OPT_SNDBUF, 4000); |
| 2835 | |
| 2836 | session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 2837 | rtc::Socket::Option::OPT_RCVBUF, 8000); |
| 2838 | |
| 2839 | int option_val; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2840 | EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2841 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 2842 | EXPECT_EQ(4000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2843 | EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2844 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 2845 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2846 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2847 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 2848 | EXPECT_EQ(8000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2849 | EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2850 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 2851 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2852 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2853 | session_->video_rtp_transport_channel()); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2854 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2855 | SendAudioVideoStream2(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2856 | SessionDescriptionInterface* answer = |
| 2857 | CreateRemoteAnswer(session_->local_description()); |
| 2858 | SetRemoteDescriptionWithoutError(answer); |
| 2859 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2860 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2861 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 2862 | EXPECT_EQ(4000, option_val); |
| 2863 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2864 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 2865 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 2866 | EXPECT_EQ(8000, option_val); |
| 2867 | } |
| 2868 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 2869 | // Test creating a session, request multiple offers, destroy the session |
| 2870 | // and make sure we got success/failure callbacks for all of the requests. |
| 2871 | // Background: crbug.com/507307 |
| 2872 | TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { |
| 2873 | Init(); |
| 2874 | |
| 2875 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100]; |
| 2876 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2877 | options.offer_to_receive_audio = |
| 2878 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2879 | cricket::MediaSessionOptions session_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2880 | GetOptionsForOffer(options, &session_options); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 2881 | for (auto& o : observers) { |
| 2882 | o = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2883 | session_->CreateOffer(o, options, session_options); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | session_.reset(); |
| 2887 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 2888 | for (auto& o : observers) { |
| 2889 | // We expect to have received a notification now even if the session was |
| 2890 | // terminated. The offer creation may or may not have succeeded, but we |
| 2891 | // must have received a notification which, so the only invalid state |
| 2892 | // is kInit. |
| 2893 | EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); |
| 2894 | } |
| 2895 | } |
| 2896 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2897 | TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
| 2898 | TestPacketOptions(); |
| 2899 | } |
| 2900 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2901 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 2902 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 2903 | // called more than once without returning to IceGatheringGathering. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2904 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2905 | INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 2906 | WebRtcSessionTest, |
| 2907 | testing::Values(ALREADY_GENERATED, |
| 2908 | DTLS_IDENTITY_STORE)); |