| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <utility> | |
| 14 | |
| 15 #include "webrtc/api/audiotrack.h" | |
| 16 #include "webrtc/api/jsepsessiondescription.h" | |
| 17 #include "webrtc/api/mediastream.h" | |
| 18 #include "webrtc/api/mediastreaminterface.h" | |
| 19 #include "webrtc/api/peerconnection.h" | |
| 20 #include "webrtc/api/peerconnectioninterface.h" | |
| 21 #include "webrtc/api/rtpreceiverinterface.h" | |
| 22 #include "webrtc/api/rtpsenderinterface.h" | |
| 23 #include "webrtc/api/streamcollection.h" | |
| 24 #include "webrtc/api/test/fakeconstraints.h" | |
| 25 #include "webrtc/api/test/fakertccertificategenerator.h" | |
| 26 #include "webrtc/api/test/fakevideotracksource.h" | |
| 27 #include "webrtc/api/test/mockpeerconnectionobservers.h" | |
| 28 #include "webrtc/api/test/testsdpstrings.h" | |
| 29 #include "webrtc/api/videocapturertracksource.h" | |
| 30 #include "webrtc/api/videotrack.h" | |
| 31 #include "webrtc/base/gunit.h" | |
| 32 #include "webrtc/base/ssladapter.h" | |
| 33 #include "webrtc/base/sslstreamadapter.h" | |
| 34 #include "webrtc/base/stringutils.h" | |
| 35 #include "webrtc/base/thread.h" | |
| 36 #include "webrtc/media/base/fakevideocapturer.h" | |
| 37 #include "webrtc/media/sctp/sctpdataengine.h" | |
| 38 #include "webrtc/p2p/base/fakeportallocator.h" | |
| 39 #include "webrtc/p2p/base/faketransportcontroller.h" | |
| 40 #include "webrtc/pc/mediasession.h" | |
| 41 #include "webrtc/test/gmock.h" | |
| 42 | |
| 43 #ifdef WEBRTC_ANDROID | |
| 44 #include "webrtc/api/test/androidtestinitializer.h" | |
| 45 #endif | |
| 46 | |
| 47 static const char kStreamLabel1[] = "local_stream_1"; | |
| 48 static const char kStreamLabel2[] = "local_stream_2"; | |
| 49 static const char kStreamLabel3[] = "local_stream_3"; | |
| 50 static const int kDefaultStunPort = 3478; | |
| 51 static const char kStunAddressOnly[] = "stun:address"; | |
| 52 static const char kStunInvalidPort[] = "stun:address:-1"; | |
| 53 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; | |
| 54 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; | |
| 55 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; | |
| 56 static const char kTurnUsername[] = "user"; | |
| 57 static const char kTurnPassword[] = "password"; | |
| 58 static const char kTurnHostname[] = "turn.example.org"; | |
| 59 static const uint32_t kTimeout = 10000U; | |
| 60 | |
| 61 static const char kStreams[][8] = {"stream1", "stream2"}; | |
| 62 static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"}; | |
| 63 static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"}; | |
| 64 | |
| 65 static const char kRecvonly[] = "recvonly"; | |
| 66 static const char kSendrecv[] = "sendrecv"; | |
| 67 | |
| 68 // Reference SDP with a MediaStream with label "stream1" and audio track with | |
| 69 // id "audio_1" and a video track with id "video_1; | |
| 70 static const char kSdpStringWithStream1[] = | |
| 71 "v=0\r\n" | |
| 72 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 73 "s=-\r\n" | |
| 74 "t=0 0\r\n" | |
| 75 "a=ice-ufrag:e5785931\r\n" | |
| 76 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 77 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 78 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 79 "m=audio 1 RTP/AVPF 103\r\n" | |
| 80 "a=mid:audio\r\n" | |
| 81 "a=sendrecv\r\n" | |
| 82 "a=rtcp-mux\r\n" | |
| 83 "a=rtpmap:103 ISAC/16000\r\n" | |
| 84 "a=ssrc:1 cname:stream1\r\n" | |
| 85 "a=ssrc:1 mslabel:stream1\r\n" | |
| 86 "a=ssrc:1 label:audiotrack0\r\n" | |
| 87 "m=video 1 RTP/AVPF 120\r\n" | |
| 88 "a=mid:video\r\n" | |
| 89 "a=sendrecv\r\n" | |
| 90 "a=rtcp-mux\r\n" | |
| 91 "a=rtpmap:120 VP8/90000\r\n" | |
| 92 "a=ssrc:2 cname:stream1\r\n" | |
| 93 "a=ssrc:2 mslabel:stream1\r\n" | |
| 94 "a=ssrc:2 label:videotrack0\r\n"; | |
| 95 | |
| 96 // Reference SDP with a MediaStream with label "stream1" and audio track with | |
| 97 // id "audio_1"; | |
| 98 static const char kSdpStringWithStream1AudioTrackOnly[] = | |
| 99 "v=0\r\n" | |
| 100 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 101 "s=-\r\n" | |
| 102 "t=0 0\r\n" | |
| 103 "a=ice-ufrag:e5785931\r\n" | |
| 104 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 105 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 106 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 107 "m=audio 1 RTP/AVPF 103\r\n" | |
| 108 "a=mid:audio\r\n" | |
| 109 "a=sendrecv\r\n" | |
| 110 "a=rtpmap:103 ISAC/16000\r\n" | |
| 111 "a=ssrc:1 cname:stream1\r\n" | |
| 112 "a=ssrc:1 mslabel:stream1\r\n" | |
| 113 "a=ssrc:1 label:audiotrack0\r\n" | |
| 114 "a=rtcp-mux\r\n"; | |
| 115 | |
| 116 // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each | |
| 117 // MediaStreams have one audio track and one video track. | |
| 118 // This uses MSID. | |
| 119 static const char kSdpStringWithStream1And2[] = | |
| 120 "v=0\r\n" | |
| 121 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 122 "s=-\r\n" | |
| 123 "t=0 0\r\n" | |
| 124 "a=ice-ufrag:e5785931\r\n" | |
| 125 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 126 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 127 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 128 "a=msid-semantic: WMS stream1 stream2\r\n" | |
| 129 "m=audio 1 RTP/AVPF 103\r\n" | |
| 130 "a=mid:audio\r\n" | |
| 131 "a=sendrecv\r\n" | |
| 132 "a=rtcp-mux\r\n" | |
| 133 "a=rtpmap:103 ISAC/16000\r\n" | |
| 134 "a=ssrc:1 cname:stream1\r\n" | |
| 135 "a=ssrc:1 msid:stream1 audiotrack0\r\n" | |
| 136 "a=ssrc:3 cname:stream2\r\n" | |
| 137 "a=ssrc:3 msid:stream2 audiotrack1\r\n" | |
| 138 "m=video 1 RTP/AVPF 120\r\n" | |
| 139 "a=mid:video\r\n" | |
| 140 "a=sendrecv\r\n" | |
| 141 "a=rtcp-mux\r\n" | |
| 142 "a=rtpmap:120 VP8/0\r\n" | |
| 143 "a=ssrc:2 cname:stream1\r\n" | |
| 144 "a=ssrc:2 msid:stream1 videotrack0\r\n" | |
| 145 "a=ssrc:4 cname:stream2\r\n" | |
| 146 "a=ssrc:4 msid:stream2 videotrack1\r\n"; | |
| 147 | |
| 148 // Reference SDP without MediaStreams. Msid is not supported. | |
| 149 static const char kSdpStringWithoutStreams[] = | |
| 150 "v=0\r\n" | |
| 151 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 152 "s=-\r\n" | |
| 153 "t=0 0\r\n" | |
| 154 "a=ice-ufrag:e5785931\r\n" | |
| 155 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 156 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 157 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 158 "m=audio 1 RTP/AVPF 103\r\n" | |
| 159 "a=mid:audio\r\n" | |
| 160 "a=sendrecv\r\n" | |
| 161 "a=rtcp-mux\r\n" | |
| 162 "a=rtpmap:103 ISAC/16000\r\n" | |
| 163 "m=video 1 RTP/AVPF 120\r\n" | |
| 164 "a=mid:video\r\n" | |
| 165 "a=sendrecv\r\n" | |
| 166 "a=rtcp-mux\r\n" | |
| 167 "a=rtpmap:120 VP8/90000\r\n"; | |
| 168 | |
| 169 // Reference SDP without MediaStreams. Msid is supported. | |
| 170 static const char kSdpStringWithMsidWithoutStreams[] = | |
| 171 "v=0\r\n" | |
| 172 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 173 "s=-\r\n" | |
| 174 "t=0 0\r\n" | |
| 175 "a=ice-ufrag:e5785931\r\n" | |
| 176 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 177 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 178 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 179 "a=msid-semantic: WMS\r\n" | |
| 180 "m=audio 1 RTP/AVPF 103\r\n" | |
| 181 "a=mid:audio\r\n" | |
| 182 "a=sendrecv\r\n" | |
| 183 "a=rtcp-mux\r\n" | |
| 184 "a=rtpmap:103 ISAC/16000\r\n" | |
| 185 "m=video 1 RTP/AVPF 120\r\n" | |
| 186 "a=mid:video\r\n" | |
| 187 "a=sendrecv\r\n" | |
| 188 "a=rtcp-mux\r\n" | |
| 189 "a=rtpmap:120 VP8/90000\r\n"; | |
| 190 | |
| 191 // Reference SDP without MediaStreams and audio only. | |
| 192 static const char kSdpStringWithoutStreamsAudioOnly[] = | |
| 193 "v=0\r\n" | |
| 194 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 195 "s=-\r\n" | |
| 196 "t=0 0\r\n" | |
| 197 "a=ice-ufrag:e5785931\r\n" | |
| 198 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 199 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 200 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 201 "m=audio 1 RTP/AVPF 103\r\n" | |
| 202 "a=mid:audio\r\n" | |
| 203 "a=sendrecv\r\n" | |
| 204 "a=rtcp-mux\r\n" | |
| 205 "a=rtpmap:103 ISAC/16000\r\n"; | |
| 206 | |
| 207 // Reference SENDONLY SDP without MediaStreams. Msid is not supported. | |
| 208 static const char kSdpStringSendOnlyWithoutStreams[] = | |
| 209 "v=0\r\n" | |
| 210 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 211 "s=-\r\n" | |
| 212 "t=0 0\r\n" | |
| 213 "a=ice-ufrag:e5785931\r\n" | |
| 214 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 215 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 216 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 217 "m=audio 1 RTP/AVPF 103\r\n" | |
| 218 "a=mid:audio\r\n" | |
| 219 "a=sendrecv\r\n" | |
| 220 "a=sendonly\r\n" | |
| 221 "a=rtcp-mux\r\n" | |
| 222 "a=rtpmap:103 ISAC/16000\r\n" | |
| 223 "m=video 1 RTP/AVPF 120\r\n" | |
| 224 "a=mid:video\r\n" | |
| 225 "a=sendrecv\r\n" | |
| 226 "a=sendonly\r\n" | |
| 227 "a=rtcp-mux\r\n" | |
| 228 "a=rtpmap:120 VP8/90000\r\n"; | |
| 229 | |
| 230 static const char kSdpStringInit[] = | |
| 231 "v=0\r\n" | |
| 232 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 233 "s=-\r\n" | |
| 234 "t=0 0\r\n" | |
| 235 "a=ice-ufrag:e5785931\r\n" | |
| 236 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 237 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 238 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 239 "a=msid-semantic: WMS\r\n"; | |
| 240 | |
| 241 static const char kSdpStringAudio[] = | |
| 242 "m=audio 1 RTP/AVPF 103\r\n" | |
| 243 "a=mid:audio\r\n" | |
| 244 "a=sendrecv\r\n" | |
| 245 "a=rtcp-mux\r\n" | |
| 246 "a=rtpmap:103 ISAC/16000\r\n"; | |
| 247 | |
| 248 static const char kSdpStringVideo[] = | |
| 249 "m=video 1 RTP/AVPF 120\r\n" | |
| 250 "a=mid:video\r\n" | |
| 251 "a=sendrecv\r\n" | |
| 252 "a=rtcp-mux\r\n" | |
| 253 "a=rtpmap:120 VP8/90000\r\n"; | |
| 254 | |
| 255 static const char kSdpStringMs1Audio0[] = | |
| 256 "a=ssrc:1 cname:stream1\r\n" | |
| 257 "a=ssrc:1 msid:stream1 audiotrack0\r\n"; | |
| 258 | |
| 259 static const char kSdpStringMs1Video0[] = | |
| 260 "a=ssrc:2 cname:stream1\r\n" | |
| 261 "a=ssrc:2 msid:stream1 videotrack0\r\n"; | |
| 262 | |
| 263 static const char kSdpStringMs1Audio1[] = | |
| 264 "a=ssrc:3 cname:stream1\r\n" | |
| 265 "a=ssrc:3 msid:stream1 audiotrack1\r\n"; | |
| 266 | |
| 267 static const char kSdpStringMs1Video1[] = | |
| 268 "a=ssrc:4 cname:stream1\r\n" | |
| 269 "a=ssrc:4 msid:stream1 videotrack1\r\n"; | |
| 270 | |
| 271 #define MAYBE_SKIP_TEST(feature) \ | |
| 272 if (!(feature())) { \ | |
| 273 LOG(LS_INFO) << "Feature disabled... skipping"; \ | |
| 274 return; \ | |
| 275 } | |
| 276 | |
| 277 using ::testing::Exactly; | |
| 278 using cricket::StreamParams; | |
| 279 using webrtc::AudioSourceInterface; | |
| 280 using webrtc::AudioTrack; | |
| 281 using webrtc::AudioTrackInterface; | |
| 282 using webrtc::DataBuffer; | |
| 283 using webrtc::DataChannelInterface; | |
| 284 using webrtc::FakeConstraints; | |
| 285 using webrtc::IceCandidateInterface; | |
| 286 using webrtc::JsepSessionDescription; | |
| 287 using webrtc::MediaConstraintsInterface; | |
| 288 using webrtc::MediaStream; | |
| 289 using webrtc::MediaStreamInterface; | |
| 290 using webrtc::MediaStreamTrackInterface; | |
| 291 using webrtc::MockCreateSessionDescriptionObserver; | |
| 292 using webrtc::MockDataChannelObserver; | |
| 293 using webrtc::MockSetSessionDescriptionObserver; | |
| 294 using webrtc::MockStatsObserver; | |
| 295 using webrtc::NotifierInterface; | |
| 296 using webrtc::ObserverInterface; | |
| 297 using webrtc::PeerConnectionInterface; | |
| 298 using webrtc::PeerConnectionObserver; | |
| 299 using webrtc::RtpReceiverInterface; | |
| 300 using webrtc::RtpSenderInterface; | |
| 301 using webrtc::SdpParseError; | |
| 302 using webrtc::SessionDescriptionInterface; | |
| 303 using webrtc::StreamCollection; | |
| 304 using webrtc::StreamCollectionInterface; | |
| 305 using webrtc::VideoTrackSourceInterface; | |
| 306 using webrtc::VideoTrack; | |
| 307 using webrtc::VideoTrackInterface; | |
| 308 | |
| 309 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | |
| 310 | |
| 311 namespace { | |
| 312 | |
| 313 // Gets the first ssrc of given content type from the ContentInfo. | |
| 314 bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { | |
| 315 if (!content_info || !ssrc) { | |
| 316 return false; | |
| 317 } | |
| 318 const cricket::MediaContentDescription* media_desc = | |
| 319 static_cast<const cricket::MediaContentDescription*>( | |
| 320 content_info->description); | |
| 321 if (!media_desc || media_desc->streams().empty()) { | |
| 322 return false; | |
| 323 } | |
| 324 *ssrc = media_desc->streams().begin()->first_ssrc(); | |
| 325 return true; | |
| 326 } | |
| 327 | |
| 328 void SetSsrcToZero(std::string* sdp) { | |
| 329 const char kSdpSsrcAtribute[] = "a=ssrc:"; | |
| 330 const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; | |
| 331 size_t ssrc_pos = 0; | |
| 332 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != | |
| 333 std::string::npos) { | |
| 334 size_t end_ssrc = sdp->find(" ", ssrc_pos); | |
| 335 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); | |
| 336 ssrc_pos = end_ssrc; | |
| 337 } | |
| 338 } | |
| 339 | |
| 340 // Check if |streams| contains the specified track. | |
| 341 bool ContainsTrack(const std::vector<cricket::StreamParams>& streams, | |
| 342 const std::string& stream_label, | |
| 343 const std::string& track_id) { | |
| 344 for (const cricket::StreamParams& params : streams) { | |
| 345 if (params.sync_label == stream_label && params.id == track_id) { | |
| 346 return true; | |
| 347 } | |
| 348 } | |
| 349 return false; | |
| 350 } | |
| 351 | |
| 352 // Check if |senders| contains the specified sender, by id. | |
| 353 bool ContainsSender( | |
| 354 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | |
| 355 const std::string& id) { | |
| 356 for (const auto& sender : senders) { | |
| 357 if (sender->id() == id) { | |
| 358 return true; | |
| 359 } | |
| 360 } | |
| 361 return false; | |
| 362 } | |
| 363 | |
| 364 // Check if |senders| contains the specified sender, by id and stream id. | |
| 365 bool ContainsSender( | |
| 366 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | |
| 367 const std::string& id, | |
| 368 const std::string& stream_id) { | |
| 369 for (const auto& sender : senders) { | |
| 370 if (sender->id() == id && sender->stream_ids()[0] == stream_id) { | |
| 371 return true; | |
| 372 } | |
| 373 } | |
| 374 return false; | |
| 375 } | |
| 376 | |
| 377 // Create a collection of streams. | |
| 378 // CreateStreamCollection(1) creates a collection that | |
| 379 // correspond to kSdpStringWithStream1. | |
| 380 // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. | |
| 381 rtc::scoped_refptr<StreamCollection> CreateStreamCollection( | |
| 382 int number_of_streams, | |
| 383 int tracks_per_stream) { | |
| 384 rtc::scoped_refptr<StreamCollection> local_collection( | |
| 385 StreamCollection::Create()); | |
| 386 | |
| 387 for (int i = 0; i < number_of_streams; ++i) { | |
| 388 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( | |
| 389 webrtc::MediaStream::Create(kStreams[i])); | |
| 390 | |
| 391 for (int j = 0; j < tracks_per_stream; ++j) { | |
| 392 // Add a local audio track. | |
| 393 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | |
| 394 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j], | |
| 395 nullptr)); | |
| 396 stream->AddTrack(audio_track); | |
| 397 | |
| 398 // Add a local video track. | |
| 399 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | |
| 400 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j], | |
| 401 webrtc::FakeVideoTrackSource::Create())); | |
| 402 stream->AddTrack(video_track); | |
| 403 } | |
| 404 | |
| 405 local_collection->AddStream(stream); | |
| 406 } | |
| 407 return local_collection; | |
| 408 } | |
| 409 | |
| 410 // Check equality of StreamCollections. | |
| 411 bool CompareStreamCollections(StreamCollectionInterface* s1, | |
| 412 StreamCollectionInterface* s2) { | |
| 413 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { | |
| 414 return false; | |
| 415 } | |
| 416 | |
| 417 for (size_t i = 0; i != s1->count(); ++i) { | |
| 418 if (s1->at(i)->label() != s2->at(i)->label()) { | |
| 419 return false; | |
| 420 } | |
| 421 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks(); | |
| 422 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks(); | |
| 423 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks(); | |
| 424 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks(); | |
| 425 | |
| 426 if (audio_tracks1.size() != audio_tracks2.size()) { | |
| 427 return false; | |
| 428 } | |
| 429 for (size_t j = 0; j != audio_tracks1.size(); ++j) { | |
| 430 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) { | |
| 431 return false; | |
| 432 } | |
| 433 } | |
| 434 if (video_tracks1.size() != video_tracks2.size()) { | |
| 435 return false; | |
| 436 } | |
| 437 for (size_t j = 0; j != video_tracks1.size(); ++j) { | |
| 438 if (video_tracks1[j]->id() != video_tracks2[j]->id()) { | |
| 439 return false; | |
| 440 } | |
| 441 } | |
| 442 } | |
| 443 return true; | |
| 444 } | |
| 445 | |
| 446 // Helper class to test Observer. | |
| 447 class MockTrackObserver : public ObserverInterface { | |
| 448 public: | |
| 449 explicit MockTrackObserver(NotifierInterface* notifier) | |
| 450 : notifier_(notifier) { | |
| 451 notifier_->RegisterObserver(this); | |
| 452 } | |
| 453 | |
| 454 ~MockTrackObserver() { Unregister(); } | |
| 455 | |
| 456 void Unregister() { | |
| 457 if (notifier_) { | |
| 458 notifier_->UnregisterObserver(this); | |
| 459 notifier_ = nullptr; | |
| 460 } | |
| 461 } | |
| 462 | |
| 463 MOCK_METHOD0(OnChanged, void()); | |
| 464 | |
| 465 private: | |
| 466 NotifierInterface* notifier_; | |
| 467 }; | |
| 468 | |
| 469 class MockPeerConnectionObserver : public PeerConnectionObserver { | |
| 470 public: | |
| 471 // We need these using declarations because there are two versions of each of | |
| 472 // the below methods and we only override one of them. | |
| 473 // TODO(deadbeef): Remove once there's only one version of the methods. | |
| 474 using PeerConnectionObserver::OnAddStream; | |
| 475 using PeerConnectionObserver::OnRemoveStream; | |
| 476 using PeerConnectionObserver::OnDataChannel; | |
| 477 | |
| 478 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {} | |
| 479 virtual ~MockPeerConnectionObserver() { | |
| 480 } | |
| 481 void SetPeerConnectionInterface(PeerConnectionInterface* pc) { | |
| 482 pc_ = pc; | |
| 483 if (pc) { | |
| 484 state_ = pc_->signaling_state(); | |
| 485 } | |
| 486 } | |
| 487 void OnSignalingChange( | |
| 488 PeerConnectionInterface::SignalingState new_state) override { | |
| 489 EXPECT_EQ(pc_->signaling_state(), new_state); | |
| 490 state_ = new_state; | |
| 491 } | |
| 492 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange. | |
| 493 virtual void OnStateChange(StateType state_changed) { | |
| 494 if (pc_.get() == NULL) | |
| 495 return; | |
| 496 switch (state_changed) { | |
| 497 case kSignalingState: | |
| 498 // OnSignalingChange and OnStateChange(kSignalingState) should always | |
| 499 // be called approximately simultaneously. To ease testing, we require | |
| 500 // that they always be called in that order. This check verifies | |
| 501 // that OnSignalingChange has just been called. | |
| 502 EXPECT_EQ(pc_->signaling_state(), state_); | |
| 503 break; | |
| 504 case kIceState: | |
| 505 ADD_FAILURE(); | |
| 506 break; | |
| 507 default: | |
| 508 ADD_FAILURE(); | |
| 509 break; | |
| 510 } | |
| 511 } | |
| 512 | |
| 513 MediaStreamInterface* RemoteStream(const std::string& label) { | |
| 514 return remote_streams_->find(label); | |
| 515 } | |
| 516 StreamCollectionInterface* remote_streams() const { return remote_streams_; } | |
| 517 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override { | |
| 518 last_added_stream_ = stream; | |
| 519 remote_streams_->AddStream(stream); | |
| 520 } | |
| 521 void OnRemoveStream( | |
| 522 rtc::scoped_refptr<MediaStreamInterface> stream) override { | |
| 523 last_removed_stream_ = stream; | |
| 524 remote_streams_->RemoveStream(stream); | |
| 525 } | |
| 526 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } | |
| 527 void OnDataChannel( | |
| 528 rtc::scoped_refptr<DataChannelInterface> data_channel) override { | |
| 529 last_datachannel_ = data_channel; | |
| 530 } | |
| 531 | |
| 532 void OnIceConnectionChange( | |
| 533 PeerConnectionInterface::IceConnectionState new_state) override { | |
| 534 EXPECT_EQ(pc_->ice_connection_state(), new_state); | |
| 535 callback_triggered_ = true; | |
| 536 } | |
| 537 void OnIceGatheringChange( | |
| 538 PeerConnectionInterface::IceGatheringState new_state) override { | |
| 539 EXPECT_EQ(pc_->ice_gathering_state(), new_state); | |
| 540 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; | |
| 541 callback_triggered_ = true; | |
| 542 } | |
| 543 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { | |
| 544 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, | |
| 545 pc_->ice_gathering_state()); | |
| 546 | |
| 547 std::string sdp; | |
| 548 EXPECT_TRUE(candidate->ToString(&sdp)); | |
| 549 EXPECT_LT(0u, sdp.size()); | |
| 550 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), | |
| 551 candidate->sdp_mline_index(), sdp, NULL)); | |
| 552 EXPECT_TRUE(last_candidate_.get() != NULL); | |
| 553 callback_triggered_ = true; | |
| 554 } | |
| 555 | |
| 556 void OnIceCandidatesRemoved( | |
| 557 const std::vector<cricket::Candidate>& candidates) override { | |
| 558 callback_triggered_ = true; | |
| 559 } | |
| 560 | |
| 561 void OnIceConnectionReceivingChange(bool receiving) override { | |
| 562 callback_triggered_ = true; | |
| 563 } | |
| 564 | |
| 565 void OnAddTrack( | |
| 566 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, | |
| 567 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& | |
| 568 streams) override { | |
| 569 EXPECT_TRUE(receiver != nullptr); | |
| 570 num_added_tracks_++; | |
| 571 last_added_track_label_ = receiver->id(); | |
| 572 } | |
| 573 | |
| 574 // Returns the label of the last added stream. | |
| 575 // Empty string if no stream have been added. | |
| 576 std::string GetLastAddedStreamLabel() { | |
| 577 if (last_added_stream_.get()) | |
| 578 return last_added_stream_->label(); | |
| 579 return ""; | |
| 580 } | |
| 581 std::string GetLastRemovedStreamLabel() { | |
| 582 if (last_removed_stream_.get()) | |
| 583 return last_removed_stream_->label(); | |
| 584 return ""; | |
| 585 } | |
| 586 | |
| 587 rtc::scoped_refptr<PeerConnectionInterface> pc_; | |
| 588 PeerConnectionInterface::SignalingState state_; | |
| 589 std::unique_ptr<IceCandidateInterface> last_candidate_; | |
| 590 rtc::scoped_refptr<DataChannelInterface> last_datachannel_; | |
| 591 rtc::scoped_refptr<StreamCollection> remote_streams_; | |
| 592 bool renegotiation_needed_ = false; | |
| 593 bool ice_complete_ = false; | |
| 594 bool callback_triggered_ = false; | |
| 595 int num_added_tracks_ = 0; | |
| 596 std::string last_added_track_label_; | |
| 597 | |
| 598 private: | |
| 599 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_; | |
| 600 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_; | |
| 601 }; | |
| 602 | |
| 603 } // namespace | |
| 604 | |
| 605 // The PeerConnectionMediaConfig tests below verify that configuration | |
| 606 // and constraints are propagated into the MediaConfig passed to | |
| 607 // CreateMediaController. These settings are intended for MediaChannel | |
| 608 // constructors, but that is not exercised by these unittest. | |
| 609 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { | |
| 610 public: | |
| 611 webrtc::MediaControllerInterface* CreateMediaController( | |
| 612 const cricket::MediaConfig& config, | |
| 613 webrtc::RtcEventLog* event_log) const override { | |
| 614 create_media_controller_called_ = true; | |
| 615 create_media_controller_config_ = config; | |
| 616 | |
| 617 webrtc::MediaControllerInterface* mc = | |
| 618 PeerConnectionFactory::CreateMediaController(config, event_log); | |
| 619 EXPECT_TRUE(mc != nullptr); | |
| 620 return mc; | |
| 621 } | |
| 622 | |
| 623 cricket::TransportController* CreateTransportController( | |
| 624 cricket::PortAllocator* port_allocator, | |
| 625 bool redetermine_role_on_ice_restart) override { | |
| 626 transport_controller = new cricket::TransportController( | |
| 627 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator, | |
| 628 redetermine_role_on_ice_restart); | |
| 629 return transport_controller; | |
| 630 } | |
| 631 | |
| 632 cricket::TransportController* transport_controller; | |
| 633 // Mutable, so they can be modified in the above const-declared method. | |
| 634 mutable bool create_media_controller_called_ = false; | |
| 635 mutable cricket::MediaConfig create_media_controller_config_; | |
| 636 }; | |
| 637 | |
| 638 class PeerConnectionInterfaceTest : public testing::Test { | |
| 639 protected: | |
| 640 PeerConnectionInterfaceTest() { | |
| 641 #ifdef WEBRTC_ANDROID | |
| 642 webrtc::InitializeAndroidObjects(); | |
| 643 #endif | |
| 644 } | |
| 645 | |
| 646 virtual void SetUp() { | |
| 647 pc_factory_ = webrtc::CreatePeerConnectionFactory( | |
| 648 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), | |
| 649 nullptr, nullptr, nullptr); | |
| 650 ASSERT_TRUE(pc_factory_); | |
| 651 pc_factory_for_test_ = | |
| 652 new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | |
| 653 pc_factory_for_test_->Initialize(); | |
| 654 } | |
| 655 | |
| 656 void CreatePeerConnection() { | |
| 657 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); | |
| 658 } | |
| 659 | |
| 660 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | |
| 661 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), | |
| 662 constraints); | |
| 663 } | |
| 664 | |
| 665 void CreatePeerConnectionWithIceTransportsType( | |
| 666 PeerConnectionInterface::IceTransportsType type) { | |
| 667 PeerConnectionInterface::RTCConfiguration config; | |
| 668 config.type = type; | |
| 669 return CreatePeerConnection(config, nullptr); | |
| 670 } | |
| 671 | |
| 672 void CreatePeerConnectionWithIceServer(const std::string& uri, | |
| 673 const std::string& password) { | |
| 674 PeerConnectionInterface::RTCConfiguration config; | |
| 675 PeerConnectionInterface::IceServer server; | |
| 676 server.uri = uri; | |
| 677 server.password = password; | |
| 678 config.servers.push_back(server); | |
| 679 CreatePeerConnection(config, nullptr); | |
| 680 } | |
| 681 | |
| 682 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config, | |
| 683 webrtc::MediaConstraintsInterface* constraints) { | |
| 684 std::unique_ptr<cricket::FakePortAllocator> port_allocator( | |
| 685 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | |
| 686 port_allocator_ = port_allocator.get(); | |
| 687 | |
| 688 // DTLS does not work in a loopback call, so is disabled for most of the | |
| 689 // tests in this file. We only create a FakeIdentityService if the test | |
| 690 // explicitly sets the constraint. | |
| 691 FakeConstraints default_constraints; | |
| 692 if (!constraints) { | |
| 693 constraints = &default_constraints; | |
| 694 | |
| 695 default_constraints.AddMandatory( | |
| 696 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); | |
| 697 } | |
| 698 | |
| 699 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator; | |
| 700 bool dtls; | |
| 701 if (FindConstraint(constraints, | |
| 702 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 703 &dtls, | |
| 704 nullptr) && dtls) { | |
| 705 cert_generator.reset(new FakeRTCCertificateGenerator()); | |
| 706 } | |
| 707 pc_ = pc_factory_->CreatePeerConnection( | |
| 708 config, constraints, std::move(port_allocator), | |
| 709 std::move(cert_generator), &observer_); | |
| 710 ASSERT_TRUE(pc_.get() != NULL); | |
| 711 observer_.SetPeerConnectionInterface(pc_.get()); | |
| 712 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 713 } | |
| 714 | |
| 715 void CreatePeerConnectionExpectFail(const std::string& uri) { | |
| 716 PeerConnectionInterface::RTCConfiguration config; | |
| 717 PeerConnectionInterface::IceServer server; | |
| 718 server.uri = uri; | |
| 719 config.servers.push_back(server); | |
| 720 | |
| 721 rtc::scoped_refptr<PeerConnectionInterface> pc; | |
| 722 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, | |
| 723 &observer_); | |
| 724 EXPECT_EQ(nullptr, pc); | |
| 725 } | |
| 726 | |
| 727 void CreatePeerConnectionWithDifferentConfigurations() { | |
| 728 CreatePeerConnectionWithIceServer(kStunAddressOnly, ""); | |
| 729 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | |
| 730 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); | |
| 731 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); | |
| 732 EXPECT_EQ(kDefaultStunPort, | |
| 733 port_allocator_->stun_servers().begin()->port()); | |
| 734 | |
| 735 CreatePeerConnectionExpectFail(kStunInvalidPort); | |
| 736 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); | |
| 737 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); | |
| 738 | |
| 739 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword); | |
| 740 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); | |
| 741 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); | |
| 742 EXPECT_EQ(kTurnUsername, | |
| 743 port_allocator_->turn_servers()[0].credentials.username); | |
| 744 EXPECT_EQ(kTurnPassword, | |
| 745 port_allocator_->turn_servers()[0].credentials.password); | |
| 746 EXPECT_EQ(kTurnHostname, | |
| 747 port_allocator_->turn_servers()[0].ports[0].address.hostname()); | |
| 748 } | |
| 749 | |
| 750 void ReleasePeerConnection() { | |
| 751 pc_ = NULL; | |
| 752 observer_.SetPeerConnectionInterface(NULL); | |
| 753 } | |
| 754 | |
| 755 void AddVideoStream(const std::string& label) { | |
| 756 // Create a local stream. | |
| 757 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 758 pc_factory_->CreateLocalMediaStream(label)); | |
| 759 rtc::scoped_refptr<VideoTrackSourceInterface> video_source( | |
| 760 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL)); | |
| 761 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 762 pc_factory_->CreateVideoTrack(label + "v0", video_source)); | |
| 763 stream->AddTrack(video_track.get()); | |
| 764 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 765 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | |
| 766 observer_.renegotiation_needed_ = false; | |
| 767 } | |
| 768 | |
| 769 void AddVoiceStream(const std::string& label) { | |
| 770 // Create a local stream. | |
| 771 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 772 pc_factory_->CreateLocalMediaStream(label)); | |
| 773 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 774 pc_factory_->CreateAudioTrack(label + "a0", NULL)); | |
| 775 stream->AddTrack(audio_track.get()); | |
| 776 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 777 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | |
| 778 observer_.renegotiation_needed_ = false; | |
| 779 } | |
| 780 | |
| 781 void AddAudioVideoStream(const std::string& stream_label, | |
| 782 const std::string& audio_track_label, | |
| 783 const std::string& video_track_label) { | |
| 784 // Create a local stream. | |
| 785 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 786 pc_factory_->CreateLocalMediaStream(stream_label)); | |
| 787 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 788 pc_factory_->CreateAudioTrack( | |
| 789 audio_track_label, static_cast<AudioSourceInterface*>(NULL))); | |
| 790 stream->AddTrack(audio_track.get()); | |
| 791 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 792 pc_factory_->CreateVideoTrack( | |
| 793 video_track_label, | |
| 794 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 795 stream->AddTrack(video_track.get()); | |
| 796 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 797 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | |
| 798 observer_.renegotiation_needed_ = false; | |
| 799 } | |
| 800 | |
| 801 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, | |
| 802 bool offer, | |
| 803 MediaConstraintsInterface* constraints) { | |
| 804 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> | |
| 805 observer(new rtc::RefCountedObject< | |
| 806 MockCreateSessionDescriptionObserver>()); | |
| 807 if (offer) { | |
| 808 pc_->CreateOffer(observer, constraints); | |
| 809 } else { | |
| 810 pc_->CreateAnswer(observer, constraints); | |
| 811 } | |
| 812 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | |
| 813 desc->reset(observer->release_desc()); | |
| 814 return observer->result(); | |
| 815 } | |
| 816 | |
| 817 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc, | |
| 818 MediaConstraintsInterface* constraints) { | |
| 819 return DoCreateOfferAnswer(desc, true, constraints); | |
| 820 } | |
| 821 | |
| 822 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, | |
| 823 MediaConstraintsInterface* constraints) { | |
| 824 return DoCreateOfferAnswer(desc, false, constraints); | |
| 825 } | |
| 826 | |
| 827 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { | |
| 828 rtc::scoped_refptr<MockSetSessionDescriptionObserver> | |
| 829 observer(new rtc::RefCountedObject< | |
| 830 MockSetSessionDescriptionObserver>()); | |
| 831 if (local) { | |
| 832 pc_->SetLocalDescription(observer, desc); | |
| 833 } else { | |
| 834 pc_->SetRemoteDescription(observer, desc); | |
| 835 } | |
| 836 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) { | |
| 837 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | |
| 838 } | |
| 839 return observer->result(); | |
| 840 } | |
| 841 | |
| 842 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { | |
| 843 return DoSetSessionDescription(desc, true); | |
| 844 } | |
| 845 | |
| 846 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { | |
| 847 return DoSetSessionDescription(desc, false); | |
| 848 } | |
| 849 | |
| 850 // Calls PeerConnection::GetStats and check the return value. | |
| 851 // It does not verify the values in the StatReports since a RTCP packet might | |
| 852 // be required. | |
| 853 bool DoGetStats(MediaStreamTrackInterface* track) { | |
| 854 rtc::scoped_refptr<MockStatsObserver> observer( | |
| 855 new rtc::RefCountedObject<MockStatsObserver>()); | |
| 856 if (!pc_->GetStats( | |
| 857 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)) | |
| 858 return false; | |
| 859 EXPECT_TRUE_WAIT(observer->called(), kTimeout); | |
| 860 return observer->called(); | |
| 861 } | |
| 862 | |
| 863 void InitiateCall() { | |
| 864 CreatePeerConnection(); | |
| 865 // Create a local stream with audio&video tracks. | |
| 866 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 867 CreateOfferReceiveAnswer(); | |
| 868 } | |
| 869 | |
| 870 // Verify that RTP Header extensions has been negotiated for audio and video. | |
| 871 void VerifyRemoteRtpHeaderExtensions() { | |
| 872 const cricket::MediaContentDescription* desc = | |
| 873 cricket::GetFirstAudioContentDescription( | |
| 874 pc_->remote_description()->description()); | |
| 875 ASSERT_TRUE(desc != NULL); | |
| 876 EXPECT_GT(desc->rtp_header_extensions().size(), 0u); | |
| 877 | |
| 878 desc = cricket::GetFirstVideoContentDescription( | |
| 879 pc_->remote_description()->description()); | |
| 880 ASSERT_TRUE(desc != NULL); | |
| 881 EXPECT_GT(desc->rtp_header_extensions().size(), 0u); | |
| 882 } | |
| 883 | |
| 884 void CreateOfferAsRemoteDescription() { | |
| 885 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 886 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 887 std::string sdp; | |
| 888 EXPECT_TRUE(offer->ToString(&sdp)); | |
| 889 SessionDescriptionInterface* remote_offer = | |
| 890 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 891 sdp, NULL); | |
| 892 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
| 893 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); | |
| 894 } | |
| 895 | |
| 896 void CreateAndSetRemoteOffer(const std::string& sdp) { | |
| 897 SessionDescriptionInterface* remote_offer = | |
| 898 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 899 sdp, nullptr); | |
| 900 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
| 901 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); | |
| 902 } | |
| 903 | |
| 904 void CreateAnswerAsLocalDescription() { | |
| 905 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 906 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 907 | |
| 908 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an | |
| 909 // audio codec change, even if the parameter has nothing to do with | |
| 910 // receiving. Not all parameters are serialized to SDP. | |
| 911 // Since CreatePrAnswerAsLocalDescription serialize/deserialize | |
| 912 // the SessionDescription, it is necessary to do that here to in order to | |
| 913 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. | |
| 914 // https://code.google.com/p/webrtc/issues/detail?id=1356 | |
| 915 std::string sdp; | |
| 916 EXPECT_TRUE(answer->ToString(&sdp)); | |
| 917 SessionDescriptionInterface* new_answer = | |
| 918 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, | |
| 919 sdp, NULL); | |
| 920 EXPECT_TRUE(DoSetLocalDescription(new_answer)); | |
| 921 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 922 } | |
| 923 | |
| 924 void CreatePrAnswerAsLocalDescription() { | |
| 925 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 926 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 927 | |
| 928 std::string sdp; | |
| 929 EXPECT_TRUE(answer->ToString(&sdp)); | |
| 930 SessionDescriptionInterface* pr_answer = | |
| 931 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer, | |
| 932 sdp, NULL); | |
| 933 EXPECT_TRUE(DoSetLocalDescription(pr_answer)); | |
| 934 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_); | |
| 935 } | |
| 936 | |
| 937 void CreateOfferReceiveAnswer() { | |
| 938 CreateOfferAsLocalDescription(); | |
| 939 std::string sdp; | |
| 940 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 941 CreateAnswerAsRemoteDescription(sdp); | |
| 942 } | |
| 943 | |
| 944 void CreateOfferAsLocalDescription() { | |
| 945 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 946 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 947 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an | |
| 948 // audio codec change, even if the parameter has nothing to do with | |
| 949 // receiving. Not all parameters are serialized to SDP. | |
| 950 // Since CreatePrAnswerAsLocalDescription serialize/deserialize | |
| 951 // the SessionDescription, it is necessary to do that here to in order to | |
| 952 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. | |
| 953 // https://code.google.com/p/webrtc/issues/detail?id=1356 | |
| 954 std::string sdp; | |
| 955 EXPECT_TRUE(offer->ToString(&sdp)); | |
| 956 SessionDescriptionInterface* new_offer = | |
| 957 webrtc::CreateSessionDescription( | |
| 958 SessionDescriptionInterface::kOffer, | |
| 959 sdp, NULL); | |
| 960 | |
| 961 EXPECT_TRUE(DoSetLocalDescription(new_offer)); | |
| 962 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); | |
| 963 // Wait for the ice_complete message, so that SDP will have candidates. | |
| 964 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); | |
| 965 } | |
| 966 | |
| 967 void CreateAnswerAsRemoteDescription(const std::string& sdp) { | |
| 968 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( | |
| 969 SessionDescriptionInterface::kAnswer); | |
| 970 EXPECT_TRUE(answer->Initialize(sdp, NULL)); | |
| 971 EXPECT_TRUE(DoSetRemoteDescription(answer)); | |
| 972 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 973 } | |
| 974 | |
| 975 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) { | |
| 976 webrtc::JsepSessionDescription* pr_answer = | |
| 977 new webrtc::JsepSessionDescription( | |
| 978 SessionDescriptionInterface::kPrAnswer); | |
| 979 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL)); | |
| 980 EXPECT_TRUE(DoSetRemoteDescription(pr_answer)); | |
| 981 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); | |
| 982 webrtc::JsepSessionDescription* answer = | |
| 983 new webrtc::JsepSessionDescription( | |
| 984 SessionDescriptionInterface::kAnswer); | |
| 985 EXPECT_TRUE(answer->Initialize(sdp, NULL)); | |
| 986 EXPECT_TRUE(DoSetRemoteDescription(answer)); | |
| 987 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 988 } | |
| 989 | |
| 990 // Help function used for waiting until a the last signaled remote stream has | |
| 991 // the same label as |stream_label|. In a few of the tests in this file we | |
| 992 // answer with the same session description as we offer and thus we can | |
| 993 // check if OnAddStream have been called with the same stream as we offer to | |
| 994 // send. | |
| 995 void WaitAndVerifyOnAddStream(const std::string& stream_label) { | |
| 996 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout); | |
| 997 } | |
| 998 | |
| 999 // Creates an offer and applies it as a local session description. | |
| 1000 // Creates an answer with the same SDP an the offer but removes all lines | |
| 1001 // that start with a:ssrc" | |
| 1002 void CreateOfferReceiveAnswerWithoutSsrc() { | |
| 1003 CreateOfferAsLocalDescription(); | |
| 1004 std::string sdp; | |
| 1005 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 1006 SetSsrcToZero(&sdp); | |
| 1007 CreateAnswerAsRemoteDescription(sdp); | |
| 1008 } | |
| 1009 | |
| 1010 // This function creates a MediaStream with label kStreams[0] and | |
| 1011 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the | |
| 1012 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface | |
| 1013 // is returned and the MediaStream is stored in | |
| 1014 // |reference_collection_| | |
| 1015 std::unique_ptr<SessionDescriptionInterface> | |
| 1016 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks, | |
| 1017 size_t number_of_video_tracks) { | |
| 1018 EXPECT_LE(number_of_audio_tracks, 2u); | |
| 1019 EXPECT_LE(number_of_video_tracks, 2u); | |
| 1020 | |
| 1021 reference_collection_ = StreamCollection::Create(); | |
| 1022 std::string sdp_ms1 = std::string(kSdpStringInit); | |
| 1023 | |
| 1024 std::string mediastream_label = kStreams[0]; | |
| 1025 | |
| 1026 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( | |
| 1027 webrtc::MediaStream::Create(mediastream_label)); | |
| 1028 reference_collection_->AddStream(stream); | |
| 1029 | |
| 1030 if (number_of_audio_tracks > 0) { | |
| 1031 sdp_ms1 += std::string(kSdpStringAudio); | |
| 1032 sdp_ms1 += std::string(kSdpStringMs1Audio0); | |
| 1033 AddAudioTrack(kAudioTracks[0], stream); | |
| 1034 } | |
| 1035 if (number_of_audio_tracks > 1) { | |
| 1036 sdp_ms1 += kSdpStringMs1Audio1; | |
| 1037 AddAudioTrack(kAudioTracks[1], stream); | |
| 1038 } | |
| 1039 | |
| 1040 if (number_of_video_tracks > 0) { | |
| 1041 sdp_ms1 += std::string(kSdpStringVideo); | |
| 1042 sdp_ms1 += std::string(kSdpStringMs1Video0); | |
| 1043 AddVideoTrack(kVideoTracks[0], stream); | |
| 1044 } | |
| 1045 if (number_of_video_tracks > 1) { | |
| 1046 sdp_ms1 += kSdpStringMs1Video1; | |
| 1047 AddVideoTrack(kVideoTracks[1], stream); | |
| 1048 } | |
| 1049 | |
| 1050 return std::unique_ptr<SessionDescriptionInterface>( | |
| 1051 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 1052 sdp_ms1, nullptr)); | |
| 1053 } | |
| 1054 | |
| 1055 void AddAudioTrack(const std::string& track_id, | |
| 1056 MediaStreamInterface* stream) { | |
| 1057 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | |
| 1058 webrtc::AudioTrack::Create(track_id, nullptr)); | |
| 1059 ASSERT_TRUE(stream->AddTrack(audio_track)); | |
| 1060 } | |
| 1061 | |
| 1062 void AddVideoTrack(const std::string& track_id, | |
| 1063 MediaStreamInterface* stream) { | |
| 1064 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | |
| 1065 webrtc::VideoTrack::Create(track_id, | |
| 1066 webrtc::FakeVideoTrackSource::Create())); | |
| 1067 ASSERT_TRUE(stream->AddTrack(video_track)); | |
| 1068 } | |
| 1069 | |
| 1070 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() { | |
| 1071 CreatePeerConnection(); | |
| 1072 AddVoiceStream(kStreamLabel1); | |
| 1073 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1074 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1075 return offer; | |
| 1076 } | |
| 1077 | |
| 1078 std::unique_ptr<SessionDescriptionInterface> | |
| 1079 CreateAnswerWithOneAudioStream() { | |
| 1080 std::unique_ptr<SessionDescriptionInterface> offer = | |
| 1081 CreateOfferWithOneAudioStream(); | |
| 1082 EXPECT_TRUE(DoSetRemoteDescription(offer.release())); | |
| 1083 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1084 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 1085 return answer; | |
| 1086 } | |
| 1087 | |
| 1088 const std::string& GetFirstAudioStreamCname( | |
| 1089 const SessionDescriptionInterface* desc) { | |
| 1090 const cricket::ContentInfo* audio_content = | |
| 1091 cricket::GetFirstAudioContent(desc->description()); | |
| 1092 const cricket::AudioContentDescription* audio_desc = | |
| 1093 static_cast<const cricket::AudioContentDescription*>( | |
| 1094 audio_content->description); | |
| 1095 return audio_desc->streams()[0].cname; | |
| 1096 } | |
| 1097 | |
| 1098 cricket::FakePortAllocator* port_allocator_ = nullptr; | |
| 1099 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | |
| 1100 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; | |
| 1101 rtc::scoped_refptr<PeerConnectionInterface> pc_; | |
| 1102 MockPeerConnectionObserver observer_; | |
| 1103 rtc::scoped_refptr<StreamCollection> reference_collection_; | |
| 1104 }; | |
| 1105 | |
| 1106 // Test that no callbacks on the PeerConnectionObserver are called after the | |
| 1107 // PeerConnection is closed. | |
| 1108 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { | |
| 1109 rtc::scoped_refptr<PeerConnectionInterface> pc( | |
| 1110 pc_factory_for_test_->CreatePeerConnection( | |
| 1111 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, | |
| 1112 nullptr, &observer_)); | |
| 1113 observer_.SetPeerConnectionInterface(pc.get()); | |
| 1114 pc->Close(); | |
| 1115 | |
| 1116 // No callbacks is expected to be called. | |
| 1117 observer_.callback_triggered_ = false; | |
| 1118 std::vector<cricket::Candidate> candidates; | |
| 1119 pc_factory_for_test_->transport_controller->SignalGatheringState( | |
| 1120 cricket::IceGatheringState{}); | |
| 1121 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( | |
| 1122 "", candidates); | |
| 1123 pc_factory_for_test_->transport_controller->SignalConnectionState( | |
| 1124 cricket::IceConnectionState{}); | |
| 1125 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( | |
| 1126 candidates); | |
| 1127 pc_factory_for_test_->transport_controller->SignalReceiving(false); | |
| 1128 EXPECT_FALSE(observer_.callback_triggered_); | |
| 1129 } | |
| 1130 | |
| 1131 // Generate different CNAMEs when PeerConnections are created. | |
| 1132 // The CNAMEs are expected to be generated randomly. It is possible | |
| 1133 // that the test fails, though the possibility is very low. | |
| 1134 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { | |
| 1135 std::unique_ptr<SessionDescriptionInterface> offer1 = | |
| 1136 CreateOfferWithOneAudioStream(); | |
| 1137 std::unique_ptr<SessionDescriptionInterface> offer2 = | |
| 1138 CreateOfferWithOneAudioStream(); | |
| 1139 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), | |
| 1140 GetFirstAudioStreamCname(offer2.get())); | |
| 1141 } | |
| 1142 | |
| 1143 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) { | |
| 1144 std::unique_ptr<SessionDescriptionInterface> answer1 = | |
| 1145 CreateAnswerWithOneAudioStream(); | |
| 1146 std::unique_ptr<SessionDescriptionInterface> answer2 = | |
| 1147 CreateAnswerWithOneAudioStream(); | |
| 1148 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), | |
| 1149 GetFirstAudioStreamCname(answer2.get())); | |
| 1150 } | |
| 1151 | |
| 1152 TEST_F(PeerConnectionInterfaceTest, | |
| 1153 CreatePeerConnectionWithDifferentConfigurations) { | |
| 1154 CreatePeerConnectionWithDifferentConfigurations(); | |
| 1155 } | |
| 1156 | |
| 1157 TEST_F(PeerConnectionInterfaceTest, | |
| 1158 CreatePeerConnectionWithDifferentIceTransportsTypes) { | |
| 1159 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone); | |
| 1160 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter()); | |
| 1161 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay); | |
| 1162 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); | |
| 1163 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost); | |
| 1164 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST, | |
| 1165 port_allocator_->candidate_filter()); | |
| 1166 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll); | |
| 1167 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter()); | |
| 1168 } | |
| 1169 | |
| 1170 // Test that when a PeerConnection is created with a nonzero candidate pool | |
| 1171 // size, the pooled PortAllocatorSession is created with all the attributes | |
| 1172 // in the RTCConfiguration. | |
| 1173 TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { | |
| 1174 PeerConnectionInterface::RTCConfiguration config; | |
| 1175 PeerConnectionInterface::IceServer server; | |
| 1176 server.uri = kStunAddressOnly; | |
| 1177 config.servers.push_back(server); | |
| 1178 config.type = PeerConnectionInterface::kRelay; | |
| 1179 config.disable_ipv6 = true; | |
| 1180 config.tcp_candidate_policy = | |
| 1181 PeerConnectionInterface::kTcpCandidatePolicyDisabled; | |
| 1182 config.candidate_network_policy = | |
| 1183 PeerConnectionInterface::kCandidateNetworkPolicyLowCost; | |
| 1184 config.ice_candidate_pool_size = 1; | |
| 1185 CreatePeerConnection(config, nullptr); | |
| 1186 | |
| 1187 const cricket::FakePortAllocatorSession* session = | |
| 1188 static_cast<const cricket::FakePortAllocatorSession*>( | |
| 1189 port_allocator_->GetPooledSession()); | |
| 1190 ASSERT_NE(nullptr, session); | |
| 1191 EXPECT_EQ(1UL, session->stun_servers().size()); | |
| 1192 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); | |
| 1193 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); | |
| 1194 EXPECT_LT(0U, | |
| 1195 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); | |
| 1196 } | |
| 1197 | |
| 1198 // Test that the PeerConnection initializes the port allocator passed into it, | |
| 1199 // and on the correct thread. | |
| 1200 TEST_F(PeerConnectionInterfaceTest, | |
| 1201 CreatePeerConnectionInitializesPortAllocator) { | |
| 1202 rtc::Thread network_thread; | |
| 1203 network_thread.Start(); | |
| 1204 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory( | |
| 1205 webrtc::CreatePeerConnectionFactory( | |
| 1206 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(), | |
| 1207 nullptr, nullptr, nullptr)); | |
| 1208 std::unique_ptr<cricket::FakePortAllocator> port_allocator( | |
| 1209 new cricket::FakePortAllocator(&network_thread, nullptr)); | |
| 1210 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get(); | |
| 1211 PeerConnectionInterface::RTCConfiguration config; | |
| 1212 rtc::scoped_refptr<PeerConnectionInterface> pc( | |
| 1213 pc_factory->CreatePeerConnection( | |
| 1214 config, nullptr, std::move(port_allocator), nullptr, &observer_)); | |
| 1215 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread, | |
| 1216 // so all we have to do here is check that it's initialized. | |
| 1217 EXPECT_TRUE(raw_port_allocator->initialized()); | |
| 1218 } | |
| 1219 | |
| 1220 // Check that GetConfiguration returns the configuration the PeerConnection was | |
| 1221 // constructed with, before SetConfiguration is called. | |
| 1222 TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) { | |
| 1223 PeerConnectionInterface::RTCConfiguration config; | |
| 1224 config.type = PeerConnectionInterface::kRelay; | |
| 1225 CreatePeerConnection(config, nullptr); | |
| 1226 | |
| 1227 PeerConnectionInterface::RTCConfiguration returned_config = | |
| 1228 pc_->GetConfiguration(); | |
| 1229 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); | |
| 1230 } | |
| 1231 | |
| 1232 // Check that GetConfiguration returns the last configuration passed into | |
| 1233 // SetConfiguration. | |
| 1234 TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) { | |
| 1235 CreatePeerConnection(); | |
| 1236 | |
| 1237 PeerConnectionInterface::RTCConfiguration config; | |
| 1238 config.type = PeerConnectionInterface::kRelay; | |
| 1239 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 1240 | |
| 1241 PeerConnectionInterface::RTCConfiguration returned_config = | |
| 1242 pc_->GetConfiguration(); | |
| 1243 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); | |
| 1244 } | |
| 1245 | |
| 1246 TEST_F(PeerConnectionInterfaceTest, AddStreams) { | |
| 1247 CreatePeerConnection(); | |
| 1248 AddVideoStream(kStreamLabel1); | |
| 1249 AddVoiceStream(kStreamLabel2); | |
| 1250 ASSERT_EQ(2u, pc_->local_streams()->count()); | |
| 1251 | |
| 1252 // Test we can add multiple local streams to one peerconnection. | |
| 1253 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 1254 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); | |
| 1255 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 1256 pc_factory_->CreateAudioTrack(kStreamLabel3, | |
| 1257 static_cast<AudioSourceInterface*>(NULL))); | |
| 1258 stream->AddTrack(audio_track.get()); | |
| 1259 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 1260 EXPECT_EQ(3u, pc_->local_streams()->count()); | |
| 1261 | |
| 1262 // Remove the third stream. | |
| 1263 pc_->RemoveStream(pc_->local_streams()->at(2)); | |
| 1264 EXPECT_EQ(2u, pc_->local_streams()->count()); | |
| 1265 | |
| 1266 // Remove the second stream. | |
| 1267 pc_->RemoveStream(pc_->local_streams()->at(1)); | |
| 1268 EXPECT_EQ(1u, pc_->local_streams()->count()); | |
| 1269 | |
| 1270 // Remove the first stream. | |
| 1271 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1272 EXPECT_EQ(0u, pc_->local_streams()->count()); | |
| 1273 } | |
| 1274 | |
| 1275 // Test that the created offer includes streams we added. | |
| 1276 TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) { | |
| 1277 CreatePeerConnection(); | |
| 1278 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track"); | |
| 1279 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1280 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1281 | |
| 1282 const cricket::ContentInfo* audio_content = | |
| 1283 cricket::GetFirstAudioContent(offer->description()); | |
| 1284 const cricket::AudioContentDescription* audio_desc = | |
| 1285 static_cast<const cricket::AudioContentDescription*>( | |
| 1286 audio_content->description); | |
| 1287 EXPECT_TRUE( | |
| 1288 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1289 | |
| 1290 const cricket::ContentInfo* video_content = | |
| 1291 cricket::GetFirstVideoContent(offer->description()); | |
| 1292 const cricket::VideoContentDescription* video_desc = | |
| 1293 static_cast<const cricket::VideoContentDescription*>( | |
| 1294 video_content->description); | |
| 1295 EXPECT_TRUE( | |
| 1296 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1297 | |
| 1298 // Add another stream and ensure the offer includes both the old and new | |
| 1299 // streams. | |
| 1300 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2"); | |
| 1301 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1302 | |
| 1303 audio_content = cricket::GetFirstAudioContent(offer->description()); | |
| 1304 audio_desc = static_cast<const cricket::AudioContentDescription*>( | |
| 1305 audio_content->description); | |
| 1306 EXPECT_TRUE( | |
| 1307 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1308 EXPECT_TRUE( | |
| 1309 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2")); | |
| 1310 | |
| 1311 video_content = cricket::GetFirstVideoContent(offer->description()); | |
| 1312 video_desc = static_cast<const cricket::VideoContentDescription*>( | |
| 1313 video_content->description); | |
| 1314 EXPECT_TRUE( | |
| 1315 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1316 EXPECT_TRUE( | |
| 1317 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2")); | |
| 1318 } | |
| 1319 | |
| 1320 TEST_F(PeerConnectionInterfaceTest, RemoveStream) { | |
| 1321 CreatePeerConnection(); | |
| 1322 AddVideoStream(kStreamLabel1); | |
| 1323 ASSERT_EQ(1u, pc_->local_streams()->count()); | |
| 1324 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1325 EXPECT_EQ(0u, pc_->local_streams()->count()); | |
| 1326 } | |
| 1327 | |
| 1328 // Test for AddTrack and RemoveTrack methods. | |
| 1329 // Tests that the created offer includes tracks we added, | |
| 1330 // and that the RtpSenders are created correctly. | |
| 1331 // Also tests that RemoveTrack removes the tracks from subsequent offers. | |
| 1332 TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) { | |
| 1333 CreatePeerConnection(); | |
| 1334 // Create a dummy stream, so tracks share a stream label. | |
| 1335 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 1336 pc_factory_->CreateLocalMediaStream(kStreamLabel1)); | |
| 1337 std::vector<MediaStreamInterface*> stream_list; | |
| 1338 stream_list.push_back(stream.get()); | |
| 1339 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 1340 pc_factory_->CreateAudioTrack("audio_track", nullptr)); | |
| 1341 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 1342 pc_factory_->CreateVideoTrack( | |
| 1343 "video_track", | |
| 1344 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 1345 auto audio_sender = pc_->AddTrack(audio_track, stream_list); | |
| 1346 auto video_sender = pc_->AddTrack(video_track, stream_list); | |
| 1347 EXPECT_EQ(1UL, audio_sender->stream_ids().size()); | |
| 1348 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]); | |
| 1349 EXPECT_EQ("audio_track", audio_sender->id()); | |
| 1350 EXPECT_EQ(audio_track, audio_sender->track()); | |
| 1351 EXPECT_EQ(1UL, video_sender->stream_ids().size()); | |
| 1352 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]); | |
| 1353 EXPECT_EQ("video_track", video_sender->id()); | |
| 1354 EXPECT_EQ(video_track, video_sender->track()); | |
| 1355 | |
| 1356 // Now create an offer and check for the senders. | |
| 1357 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1358 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1359 | |
| 1360 const cricket::ContentInfo* audio_content = | |
| 1361 cricket::GetFirstAudioContent(offer->description()); | |
| 1362 const cricket::AudioContentDescription* audio_desc = | |
| 1363 static_cast<const cricket::AudioContentDescription*>( | |
| 1364 audio_content->description); | |
| 1365 EXPECT_TRUE( | |
| 1366 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1367 | |
| 1368 const cricket::ContentInfo* video_content = | |
| 1369 cricket::GetFirstVideoContent(offer->description()); | |
| 1370 const cricket::VideoContentDescription* video_desc = | |
| 1371 static_cast<const cricket::VideoContentDescription*>( | |
| 1372 video_content->description); | |
| 1373 EXPECT_TRUE( | |
| 1374 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1375 | |
| 1376 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 1377 | |
| 1378 // Now try removing the tracks. | |
| 1379 EXPECT_TRUE(pc_->RemoveTrack(audio_sender)); | |
| 1380 EXPECT_TRUE(pc_->RemoveTrack(video_sender)); | |
| 1381 | |
| 1382 // Create a new offer and ensure it doesn't contain the removed senders. | |
| 1383 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1384 | |
| 1385 audio_content = cricket::GetFirstAudioContent(offer->description()); | |
| 1386 audio_desc = static_cast<const cricket::AudioContentDescription*>( | |
| 1387 audio_content->description); | |
| 1388 EXPECT_FALSE( | |
| 1389 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1390 | |
| 1391 video_content = cricket::GetFirstVideoContent(offer->description()); | |
| 1392 video_desc = static_cast<const cricket::VideoContentDescription*>( | |
| 1393 video_content->description); | |
| 1394 EXPECT_FALSE( | |
| 1395 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1396 | |
| 1397 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 1398 | |
| 1399 // Calling RemoveTrack on a sender no longer attached to a PeerConnection | |
| 1400 // should return false. | |
| 1401 EXPECT_FALSE(pc_->RemoveTrack(audio_sender)); | |
| 1402 EXPECT_FALSE(pc_->RemoveTrack(video_sender)); | |
| 1403 } | |
| 1404 | |
| 1405 // Test creating senders without a stream specified, | |
| 1406 // expecting a random stream ID to be generated. | |
| 1407 TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) { | |
| 1408 CreatePeerConnection(); | |
| 1409 // Create a dummy stream, so tracks share a stream label. | |
| 1410 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 1411 pc_factory_->CreateAudioTrack("audio_track", nullptr)); | |
| 1412 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 1413 pc_factory_->CreateVideoTrack( | |
| 1414 "video_track", | |
| 1415 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 1416 auto audio_sender = | |
| 1417 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>()); | |
| 1418 auto video_sender = | |
| 1419 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>()); | |
| 1420 EXPECT_EQ("audio_track", audio_sender->id()); | |
| 1421 EXPECT_EQ(audio_track, audio_sender->track()); | |
| 1422 EXPECT_EQ("video_track", video_sender->id()); | |
| 1423 EXPECT_EQ(video_track, video_sender->track()); | |
| 1424 // If the ID is truly a random GUID, it should be infinitely unlikely they | |
| 1425 // will be the same. | |
| 1426 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids()); | |
| 1427 } | |
| 1428 | |
| 1429 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { | |
| 1430 InitiateCall(); | |
| 1431 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1432 VerifyRemoteRtpHeaderExtensions(); | |
| 1433 } | |
| 1434 | |
| 1435 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { | |
| 1436 CreatePeerConnection(); | |
| 1437 AddVideoStream(kStreamLabel1); | |
| 1438 CreateOfferAsLocalDescription(); | |
| 1439 std::string offer; | |
| 1440 EXPECT_TRUE(pc_->local_description()->ToString(&offer)); | |
| 1441 CreatePrAnswerAndAnswerAsRemoteDescription(offer); | |
| 1442 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1443 } | |
| 1444 | |
| 1445 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { | |
| 1446 CreatePeerConnection(); | |
| 1447 AddVideoStream(kStreamLabel1); | |
| 1448 | |
| 1449 CreateOfferAsRemoteDescription(); | |
| 1450 CreateAnswerAsLocalDescription(); | |
| 1451 | |
| 1452 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1453 } | |
| 1454 | |
| 1455 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { | |
| 1456 CreatePeerConnection(); | |
| 1457 AddVideoStream(kStreamLabel1); | |
| 1458 | |
| 1459 CreateOfferAsRemoteDescription(); | |
| 1460 CreatePrAnswerAsLocalDescription(); | |
| 1461 CreateAnswerAsLocalDescription(); | |
| 1462 | |
| 1463 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1464 } | |
| 1465 | |
| 1466 TEST_F(PeerConnectionInterfaceTest, Renegotiate) { | |
| 1467 InitiateCall(); | |
| 1468 ASSERT_EQ(1u, pc_->remote_streams()->count()); | |
| 1469 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1470 CreateOfferReceiveAnswer(); | |
| 1471 EXPECT_EQ(0u, pc_->remote_streams()->count()); | |
| 1472 AddVideoStream(kStreamLabel1); | |
| 1473 CreateOfferReceiveAnswer(); | |
| 1474 } | |
| 1475 | |
| 1476 // Tests that after negotiating an audio only call, the respondent can perform a | |
| 1477 // renegotiation that removes the audio stream. | |
| 1478 TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) { | |
| 1479 CreatePeerConnection(); | |
| 1480 AddVoiceStream(kStreamLabel1); | |
| 1481 CreateOfferAsRemoteDescription(); | |
| 1482 CreateAnswerAsLocalDescription(); | |
| 1483 | |
| 1484 ASSERT_EQ(1u, pc_->remote_streams()->count()); | |
| 1485 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1486 CreateOfferReceiveAnswer(); | |
| 1487 EXPECT_EQ(0u, pc_->remote_streams()->count()); | |
| 1488 } | |
| 1489 | |
| 1490 // Test that candidates are generated and that we can parse our own candidates. | |
| 1491 TEST_F(PeerConnectionInterfaceTest, IceCandidates) { | |
| 1492 CreatePeerConnection(); | |
| 1493 | |
| 1494 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get())); | |
| 1495 // SetRemoteDescription takes ownership of offer. | |
| 1496 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1497 AddVideoStream(kStreamLabel1); | |
| 1498 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1499 EXPECT_TRUE(DoSetRemoteDescription(offer.release())); | |
| 1500 | |
| 1501 // SetLocalDescription takes ownership of answer. | |
| 1502 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1503 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 1504 EXPECT_TRUE(DoSetLocalDescription(answer.release())); | |
| 1505 | |
| 1506 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout); | |
| 1507 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); | |
| 1508 | |
| 1509 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get())); | |
| 1510 } | |
| 1511 | |
| 1512 // Test that CreateOffer and CreateAnswer will fail if the track labels are | |
| 1513 // not unique. | |
| 1514 TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) { | |
| 1515 CreatePeerConnection(); | |
| 1516 // Create a regular offer for the CreateAnswer test later. | |
| 1517 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1518 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1519 EXPECT_TRUE(offer); | |
| 1520 offer.reset(); | |
| 1521 | |
| 1522 // Create a local stream with audio&video tracks having same label. | |
| 1523 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label"); | |
| 1524 | |
| 1525 // Test CreateOffer | |
| 1526 EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); | |
| 1527 | |
| 1528 // Test CreateAnswer | |
| 1529 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1530 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); | |
| 1531 } | |
| 1532 | |
| 1533 // Test that we will get different SSRCs for each tracks in the offer and answer | |
| 1534 // we created. | |
| 1535 TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) { | |
| 1536 CreatePeerConnection(); | |
| 1537 // Create a local stream with audio&video tracks having different labels. | |
| 1538 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 1539 | |
| 1540 // Test CreateOffer | |
| 1541 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1542 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1543 int audio_ssrc = 0; | |
| 1544 int video_ssrc = 0; | |
| 1545 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()), | |
| 1546 &audio_ssrc)); | |
| 1547 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()), | |
| 1548 &video_ssrc)); | |
| 1549 EXPECT_NE(audio_ssrc, video_ssrc); | |
| 1550 | |
| 1551 // Test CreateAnswer | |
| 1552 EXPECT_TRUE(DoSetRemoteDescription(offer.release())); | |
| 1553 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1554 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 1555 audio_ssrc = 0; | |
| 1556 video_ssrc = 0; | |
| 1557 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()), | |
| 1558 &audio_ssrc)); | |
| 1559 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()), | |
| 1560 &video_ssrc)); | |
| 1561 EXPECT_NE(audio_ssrc, video_ssrc); | |
| 1562 } | |
| 1563 | |
| 1564 // Test that it's possible to call AddTrack on a MediaStream after adding | |
| 1565 // the stream to a PeerConnection. | |
| 1566 // TODO(deadbeef): Remove this test once this behavior is no longer supported. | |
| 1567 TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) { | |
| 1568 CreatePeerConnection(); | |
| 1569 // Create audio stream and add to PeerConnection. | |
| 1570 AddVoiceStream(kStreamLabel1); | |
| 1571 MediaStreamInterface* stream = pc_->local_streams()->at(0); | |
| 1572 | |
| 1573 // Add video track to the audio-only stream. | |
| 1574 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 1575 pc_factory_->CreateVideoTrack( | |
| 1576 "video_label", | |
| 1577 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 1578 stream->AddTrack(video_track.get()); | |
| 1579 | |
| 1580 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1581 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1582 | |
| 1583 const cricket::MediaContentDescription* video_desc = | |
| 1584 cricket::GetFirstVideoContentDescription(offer->description()); | |
| 1585 EXPECT_TRUE(video_desc != nullptr); | |
| 1586 } | |
| 1587 | |
| 1588 // Test that it's possible to call RemoveTrack on a MediaStream after adding | |
| 1589 // the stream to a PeerConnection. | |
| 1590 // TODO(deadbeef): Remove this test once this behavior is no longer supported. | |
| 1591 TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) { | |
| 1592 CreatePeerConnection(); | |
| 1593 // Create audio/video stream and add to PeerConnection. | |
| 1594 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 1595 MediaStreamInterface* stream = pc_->local_streams()->at(0); | |
| 1596 | |
| 1597 // Remove the video track. | |
| 1598 stream->RemoveTrack(stream->GetVideoTracks()[0]); | |
| 1599 | |
| 1600 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1601 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1602 | |
| 1603 const cricket::MediaContentDescription* video_desc = | |
| 1604 cricket::GetFirstVideoContentDescription(offer->description()); | |
| 1605 EXPECT_TRUE(video_desc == nullptr); | |
| 1606 } | |
| 1607 | |
| 1608 // Test creating a sender with a stream ID, and ensure the ID is populated | |
| 1609 // in the offer. | |
| 1610 TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) { | |
| 1611 CreatePeerConnection(); | |
| 1612 pc_->CreateSender("video", kStreamLabel1); | |
| 1613 | |
| 1614 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1615 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1616 | |
| 1617 const cricket::MediaContentDescription* video_desc = | |
| 1618 cricket::GetFirstVideoContentDescription(offer->description()); | |
| 1619 ASSERT_TRUE(video_desc != nullptr); | |
| 1620 ASSERT_EQ(1u, video_desc->streams().size()); | |
| 1621 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label); | |
| 1622 } | |
| 1623 | |
| 1624 // Test that we can specify a certain track that we want statistics about. | |
| 1625 TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) { | |
| 1626 InitiateCall(); | |
| 1627 ASSERT_LT(0u, pc_->remote_streams()->count()); | |
| 1628 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size()); | |
| 1629 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = | |
| 1630 pc_->remote_streams()->at(0)->GetAudioTracks()[0]; | |
| 1631 EXPECT_TRUE(DoGetStats(remote_audio)); | |
| 1632 | |
| 1633 // Remove the stream. Since we are sending to our selves the local | |
| 1634 // and the remote stream is the same. | |
| 1635 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1636 // Do a re-negotiation. | |
| 1637 CreateOfferReceiveAnswer(); | |
| 1638 | |
| 1639 ASSERT_EQ(0u, pc_->remote_streams()->count()); | |
| 1640 | |
| 1641 // Test that we still can get statistics for the old track. Even if it is not | |
| 1642 // sent any longer. | |
| 1643 EXPECT_TRUE(DoGetStats(remote_audio)); | |
| 1644 } | |
| 1645 | |
| 1646 // Test that we can get stats on a video track. | |
| 1647 TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) { | |
| 1648 InitiateCall(); | |
| 1649 ASSERT_LT(0u, pc_->remote_streams()->count()); | |
| 1650 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size()); | |
| 1651 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video = | |
| 1652 pc_->remote_streams()->at(0)->GetVideoTracks()[0]; | |
| 1653 EXPECT_TRUE(DoGetStats(remote_video)); | |
| 1654 } | |
| 1655 | |
| 1656 // Test that we don't get statistics for an invalid track. | |
| 1657 TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) { | |
| 1658 InitiateCall(); | |
| 1659 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track( | |
| 1660 pc_factory_->CreateAudioTrack("unknown track", NULL)); | |
| 1661 EXPECT_FALSE(DoGetStats(unknown_audio_track)); | |
| 1662 } | |
| 1663 | |
| 1664 // This test setup two RTP data channels in loop back. | |
| 1665 TEST_F(PeerConnectionInterfaceTest, TestDataChannel) { | |
| 1666 FakeConstraints constraints; | |
| 1667 constraints.SetAllowRtpDataChannels(); | |
| 1668 CreatePeerConnection(&constraints); | |
| 1669 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1670 pc_->CreateDataChannel("test1", NULL); | |
| 1671 rtc::scoped_refptr<DataChannelInterface> data2 = | |
| 1672 pc_->CreateDataChannel("test2", NULL); | |
| 1673 ASSERT_TRUE(data1 != NULL); | |
| 1674 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1675 new MockDataChannelObserver(data1)); | |
| 1676 std::unique_ptr<MockDataChannelObserver> observer2( | |
| 1677 new MockDataChannelObserver(data2)); | |
| 1678 | |
| 1679 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); | |
| 1680 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); | |
| 1681 std::string data_to_send1 = "testing testing"; | |
| 1682 std::string data_to_send2 = "testing something else"; | |
| 1683 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1))); | |
| 1684 | |
| 1685 CreateOfferReceiveAnswer(); | |
| 1686 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1687 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); | |
| 1688 | |
| 1689 EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); | |
| 1690 EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); | |
| 1691 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1))); | |
| 1692 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); | |
| 1693 | |
| 1694 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout); | |
| 1695 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); | |
| 1696 | |
| 1697 data1->Close(); | |
| 1698 EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); | |
| 1699 CreateOfferReceiveAnswer(); | |
| 1700 EXPECT_FALSE(observer1->IsOpen()); | |
| 1701 EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); | |
| 1702 EXPECT_TRUE(observer2->IsOpen()); | |
| 1703 | |
| 1704 data_to_send2 = "testing something else again"; | |
| 1705 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); | |
| 1706 | |
| 1707 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); | |
| 1708 } | |
| 1709 | |
| 1710 // This test verifies that sendnig binary data over RTP data channels should | |
| 1711 // fail. | |
| 1712 TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) { | |
| 1713 FakeConstraints constraints; | |
| 1714 constraints.SetAllowRtpDataChannels(); | |
| 1715 CreatePeerConnection(&constraints); | |
| 1716 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1717 pc_->CreateDataChannel("test1", NULL); | |
| 1718 rtc::scoped_refptr<DataChannelInterface> data2 = | |
| 1719 pc_->CreateDataChannel("test2", NULL); | |
| 1720 ASSERT_TRUE(data1 != NULL); | |
| 1721 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1722 new MockDataChannelObserver(data1)); | |
| 1723 std::unique_ptr<MockDataChannelObserver> observer2( | |
| 1724 new MockDataChannelObserver(data2)); | |
| 1725 | |
| 1726 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); | |
| 1727 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); | |
| 1728 | |
| 1729 CreateOfferReceiveAnswer(); | |
| 1730 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1731 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); | |
| 1732 | |
| 1733 EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); | |
| 1734 EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); | |
| 1735 | |
| 1736 rtc::CopyOnWriteBuffer buffer("test", 4); | |
| 1737 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true))); | |
| 1738 } | |
| 1739 | |
| 1740 // This test setup a RTP data channels in loop back and test that a channel is | |
| 1741 // opened even if the remote end answer with a zero SSRC. | |
| 1742 TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) { | |
| 1743 FakeConstraints constraints; | |
| 1744 constraints.SetAllowRtpDataChannels(); | |
| 1745 CreatePeerConnection(&constraints); | |
| 1746 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1747 pc_->CreateDataChannel("test1", NULL); | |
| 1748 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1749 new MockDataChannelObserver(data1)); | |
| 1750 | |
| 1751 CreateOfferReceiveAnswerWithoutSsrc(); | |
| 1752 | |
| 1753 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1754 | |
| 1755 data1->Close(); | |
| 1756 EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); | |
| 1757 CreateOfferReceiveAnswerWithoutSsrc(); | |
| 1758 EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); | |
| 1759 EXPECT_FALSE(observer1->IsOpen()); | |
| 1760 } | |
| 1761 | |
| 1762 // This test that if a data channel is added in an answer a receive only channel | |
| 1763 // channel is created. | |
| 1764 TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) { | |
| 1765 FakeConstraints constraints; | |
| 1766 constraints.SetAllowRtpDataChannels(); | |
| 1767 CreatePeerConnection(&constraints); | |
| 1768 | |
| 1769 std::string offer_label = "offer_channel"; | |
| 1770 rtc::scoped_refptr<DataChannelInterface> offer_channel = | |
| 1771 pc_->CreateDataChannel(offer_label, NULL); | |
| 1772 | |
| 1773 CreateOfferAsLocalDescription(); | |
| 1774 | |
| 1775 // Replace the data channel label in the offer and apply it as an answer. | |
| 1776 std::string receive_label = "answer_channel"; | |
| 1777 std::string sdp; | |
| 1778 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 1779 rtc::replace_substrs(offer_label.c_str(), offer_label.length(), | |
| 1780 receive_label.c_str(), receive_label.length(), | |
| 1781 &sdp); | |
| 1782 CreateAnswerAsRemoteDescription(sdp); | |
| 1783 | |
| 1784 // Verify that a new incoming data channel has been created and that | |
| 1785 // it is open but can't we written to. | |
| 1786 ASSERT_TRUE(observer_.last_datachannel_ != NULL); | |
| 1787 DataChannelInterface* received_channel = observer_.last_datachannel_; | |
| 1788 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state()); | |
| 1789 EXPECT_EQ(receive_label, received_channel->label()); | |
| 1790 EXPECT_FALSE(received_channel->Send(DataBuffer("something"))); | |
| 1791 | |
| 1792 // Verify that the channel we initially offered has been rejected. | |
| 1793 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); | |
| 1794 | |
| 1795 // Do another offer / answer exchange and verify that the data channel is | |
| 1796 // opened. | |
| 1797 CreateOfferReceiveAnswer(); | |
| 1798 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(), | |
| 1799 kTimeout); | |
| 1800 } | |
| 1801 | |
| 1802 // This test that no data channel is returned if a reliable channel is | |
| 1803 // requested. | |
| 1804 // TODO(perkj): Remove this test once reliable channels are implemented. | |
| 1805 TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) { | |
| 1806 FakeConstraints constraints; | |
| 1807 constraints.SetAllowRtpDataChannels(); | |
| 1808 CreatePeerConnection(&constraints); | |
| 1809 | |
| 1810 std::string label = "test"; | |
| 1811 webrtc::DataChannelInit config; | |
| 1812 config.reliable = true; | |
| 1813 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1814 pc_->CreateDataChannel(label, &config); | |
| 1815 EXPECT_TRUE(channel == NULL); | |
| 1816 } | |
| 1817 | |
| 1818 // Verifies that duplicated label is not allowed for RTP data channel. | |
| 1819 TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) { | |
| 1820 FakeConstraints constraints; | |
| 1821 constraints.SetAllowRtpDataChannels(); | |
| 1822 CreatePeerConnection(&constraints); | |
| 1823 | |
| 1824 std::string label = "test"; | |
| 1825 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1826 pc_->CreateDataChannel(label, nullptr); | |
| 1827 EXPECT_NE(channel, nullptr); | |
| 1828 | |
| 1829 rtc::scoped_refptr<DataChannelInterface> dup_channel = | |
| 1830 pc_->CreateDataChannel(label, nullptr); | |
| 1831 EXPECT_EQ(dup_channel, nullptr); | |
| 1832 } | |
| 1833 | |
| 1834 // This tests that a SCTP data channel is returned using different | |
| 1835 // DataChannelInit configurations. | |
| 1836 TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) { | |
| 1837 FakeConstraints constraints; | |
| 1838 constraints.SetAllowDtlsSctpDataChannels(); | |
| 1839 CreatePeerConnection(&constraints); | |
| 1840 | |
| 1841 webrtc::DataChannelInit config; | |
| 1842 | |
| 1843 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1844 pc_->CreateDataChannel("1", &config); | |
| 1845 EXPECT_TRUE(channel != NULL); | |
| 1846 EXPECT_TRUE(channel->reliable()); | |
| 1847 EXPECT_TRUE(observer_.renegotiation_needed_); | |
| 1848 observer_.renegotiation_needed_ = false; | |
| 1849 | |
| 1850 config.ordered = false; | |
| 1851 channel = pc_->CreateDataChannel("2", &config); | |
| 1852 EXPECT_TRUE(channel != NULL); | |
| 1853 EXPECT_TRUE(channel->reliable()); | |
| 1854 EXPECT_FALSE(observer_.renegotiation_needed_); | |
| 1855 | |
| 1856 config.ordered = true; | |
| 1857 config.maxRetransmits = 0; | |
| 1858 channel = pc_->CreateDataChannel("3", &config); | |
| 1859 EXPECT_TRUE(channel != NULL); | |
| 1860 EXPECT_FALSE(channel->reliable()); | |
| 1861 EXPECT_FALSE(observer_.renegotiation_needed_); | |
| 1862 | |
| 1863 config.maxRetransmits = -1; | |
| 1864 config.maxRetransmitTime = 0; | |
| 1865 channel = pc_->CreateDataChannel("4", &config); | |
| 1866 EXPECT_TRUE(channel != NULL); | |
| 1867 EXPECT_FALSE(channel->reliable()); | |
| 1868 EXPECT_FALSE(observer_.renegotiation_needed_); | |
| 1869 } | |
| 1870 | |
| 1871 // This tests that no data channel is returned if both maxRetransmits and | |
| 1872 // maxRetransmitTime are set for SCTP data channels. | |
| 1873 TEST_F(PeerConnectionInterfaceTest, | |
| 1874 CreateSctpDataChannelShouldFailForInvalidConfig) { | |
| 1875 FakeConstraints constraints; | |
| 1876 constraints.SetAllowDtlsSctpDataChannels(); | |
| 1877 CreatePeerConnection(&constraints); | |
| 1878 | |
| 1879 std::string label = "test"; | |
| 1880 webrtc::DataChannelInit config; | |
| 1881 config.maxRetransmits = 0; | |
| 1882 config.maxRetransmitTime = 0; | |
| 1883 | |
| 1884 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1885 pc_->CreateDataChannel(label, &config); | |
| 1886 EXPECT_TRUE(channel == NULL); | |
| 1887 } | |
| 1888 | |
| 1889 // The test verifies that creating a SCTP data channel with an id already in use | |
| 1890 // or out of range should fail. | |
| 1891 TEST_F(PeerConnectionInterfaceTest, | |
| 1892 CreateSctpDataChannelWithInvalidIdShouldFail) { | |
| 1893 FakeConstraints constraints; | |
| 1894 constraints.SetAllowDtlsSctpDataChannels(); | |
| 1895 CreatePeerConnection(&constraints); | |
| 1896 | |
| 1897 webrtc::DataChannelInit config; | |
| 1898 rtc::scoped_refptr<DataChannelInterface> channel; | |
| 1899 | |
| 1900 config.id = 1; | |
| 1901 channel = pc_->CreateDataChannel("1", &config); | |
| 1902 EXPECT_TRUE(channel != NULL); | |
| 1903 EXPECT_EQ(1, channel->id()); | |
| 1904 | |
| 1905 channel = pc_->CreateDataChannel("x", &config); | |
| 1906 EXPECT_TRUE(channel == NULL); | |
| 1907 | |
| 1908 config.id = cricket::kMaxSctpSid; | |
| 1909 channel = pc_->CreateDataChannel("max", &config); | |
| 1910 EXPECT_TRUE(channel != NULL); | |
| 1911 EXPECT_EQ(config.id, channel->id()); | |
| 1912 | |
| 1913 config.id = cricket::kMaxSctpSid + 1; | |
| 1914 channel = pc_->CreateDataChannel("x", &config); | |
| 1915 EXPECT_TRUE(channel == NULL); | |
| 1916 } | |
| 1917 | |
| 1918 // Verifies that duplicated label is allowed for SCTP data channel. | |
| 1919 TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { | |
| 1920 FakeConstraints constraints; | |
| 1921 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 1922 true); | |
| 1923 CreatePeerConnection(&constraints); | |
| 1924 | |
| 1925 std::string label = "test"; | |
| 1926 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1927 pc_->CreateDataChannel(label, nullptr); | |
| 1928 EXPECT_NE(channel, nullptr); | |
| 1929 | |
| 1930 rtc::scoped_refptr<DataChannelInterface> dup_channel = | |
| 1931 pc_->CreateDataChannel(label, nullptr); | |
| 1932 EXPECT_NE(dup_channel, nullptr); | |
| 1933 } | |
| 1934 | |
| 1935 // This test verifies that OnRenegotiationNeeded is fired for every new RTP | |
| 1936 // DataChannel. | |
| 1937 TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { | |
| 1938 FakeConstraints constraints; | |
| 1939 constraints.SetAllowRtpDataChannels(); | |
| 1940 CreatePeerConnection(&constraints); | |
| 1941 | |
| 1942 rtc::scoped_refptr<DataChannelInterface> dc1 = | |
| 1943 pc_->CreateDataChannel("test1", NULL); | |
| 1944 EXPECT_TRUE(observer_.renegotiation_needed_); | |
| 1945 observer_.renegotiation_needed_ = false; | |
| 1946 | |
| 1947 rtc::scoped_refptr<DataChannelInterface> dc2 = | |
| 1948 pc_->CreateDataChannel("test2", NULL); | |
| 1949 EXPECT_TRUE(observer_.renegotiation_needed_); | |
| 1950 } | |
| 1951 | |
| 1952 // This test that a data channel closes when a PeerConnection is deleted/closed. | |
| 1953 TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) { | |
| 1954 FakeConstraints constraints; | |
| 1955 constraints.SetAllowRtpDataChannels(); | |
| 1956 CreatePeerConnection(&constraints); | |
| 1957 | |
| 1958 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1959 pc_->CreateDataChannel("test1", NULL); | |
| 1960 rtc::scoped_refptr<DataChannelInterface> data2 = | |
| 1961 pc_->CreateDataChannel("test2", NULL); | |
| 1962 ASSERT_TRUE(data1 != NULL); | |
| 1963 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1964 new MockDataChannelObserver(data1)); | |
| 1965 std::unique_ptr<MockDataChannelObserver> observer2( | |
| 1966 new MockDataChannelObserver(data2)); | |
| 1967 | |
| 1968 CreateOfferReceiveAnswer(); | |
| 1969 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1970 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); | |
| 1971 | |
| 1972 ReleasePeerConnection(); | |
| 1973 EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); | |
| 1974 EXPECT_EQ(DataChannelInterface::kClosed, data2->state()); | |
| 1975 } | |
| 1976 | |
| 1977 // This test that data channels can be rejected in an answer. | |
| 1978 TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) { | |
| 1979 FakeConstraints constraints; | |
| 1980 constraints.SetAllowRtpDataChannels(); | |
| 1981 CreatePeerConnection(&constraints); | |
| 1982 | |
| 1983 rtc::scoped_refptr<DataChannelInterface> offer_channel( | |
| 1984 pc_->CreateDataChannel("offer_channel", NULL)); | |
| 1985 | |
| 1986 CreateOfferAsLocalDescription(); | |
| 1987 | |
| 1988 // Create an answer where the m-line for data channels are rejected. | |
| 1989 std::string sdp; | |
| 1990 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 1991 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( | |
| 1992 SessionDescriptionInterface::kAnswer); | |
| 1993 EXPECT_TRUE(answer->Initialize(sdp, NULL)); | |
| 1994 cricket::ContentInfo* data_info = | |
| 1995 answer->description()->GetContentByName("data"); | |
| 1996 data_info->rejected = true; | |
| 1997 | |
| 1998 DoSetRemoteDescription(answer); | |
| 1999 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); | |
| 2000 } | |
| 2001 | |
| 2002 // Test that we can create a session description from an SDP string from | |
| 2003 // FireFox, use it as a remote session description, generate an answer and use | |
| 2004 // the answer as a local description. | |
| 2005 TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) { | |
| 2006 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 2007 FakeConstraints constraints; | |
| 2008 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2009 true); | |
| 2010 CreatePeerConnection(&constraints); | |
| 2011 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2012 SessionDescriptionInterface* desc = | |
| 2013 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2014 webrtc::kFireFoxSdpOffer, nullptr); | |
| 2015 EXPECT_TRUE(DoSetSessionDescription(desc, false)); | |
| 2016 CreateAnswerAsLocalDescription(); | |
| 2017 ASSERT_TRUE(pc_->local_description() != NULL); | |
| 2018 ASSERT_TRUE(pc_->remote_description() != NULL); | |
| 2019 | |
| 2020 const cricket::ContentInfo* content = | |
| 2021 cricket::GetFirstAudioContent(pc_->local_description()->description()); | |
| 2022 ASSERT_TRUE(content != NULL); | |
| 2023 EXPECT_FALSE(content->rejected); | |
| 2024 | |
| 2025 content = | |
| 2026 cricket::GetFirstVideoContent(pc_->local_description()->description()); | |
| 2027 ASSERT_TRUE(content != NULL); | |
| 2028 EXPECT_FALSE(content->rejected); | |
| 2029 #ifdef HAVE_SCTP | |
| 2030 content = | |
| 2031 cricket::GetFirstDataContent(pc_->local_description()->description()); | |
| 2032 ASSERT_TRUE(content != NULL); | |
| 2033 EXPECT_TRUE(content->rejected); | |
| 2034 #endif | |
| 2035 } | |
| 2036 | |
| 2037 // Test that we can create an audio only offer and receive an answer with a | |
| 2038 // limited set of audio codecs and receive an updated offer with more audio | |
| 2039 // codecs, where the added codecs are not supported. | |
| 2040 TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) { | |
| 2041 CreatePeerConnection(); | |
| 2042 AddVoiceStream("audio_label"); | |
| 2043 CreateOfferAsLocalDescription(); | |
| 2044 | |
| 2045 SessionDescriptionInterface* answer = | |
| 2046 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, | |
| 2047 webrtc::kAudioSdp, nullptr); | |
| 2048 EXPECT_TRUE(DoSetSessionDescription(answer, false)); | |
| 2049 | |
| 2050 SessionDescriptionInterface* updated_offer = | |
| 2051 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2052 webrtc::kAudioSdpWithUnsupportedCodecs, | |
| 2053 nullptr); | |
| 2054 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false)); | |
| 2055 CreateAnswerAsLocalDescription(); | |
| 2056 } | |
| 2057 | |
| 2058 // Test that if we're receiving (but not sending) a track, subsequent offers | |
| 2059 // will have m-lines with a=recvonly. | |
| 2060 TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) { | |
| 2061 FakeConstraints constraints; | |
| 2062 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2063 true); | |
| 2064 CreatePeerConnection(&constraints); | |
| 2065 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2066 CreateAnswerAsLocalDescription(); | |
| 2067 | |
| 2068 // At this point we should be receiving stream 1, but not sending anything. | |
| 2069 // A new offer should be recvonly. | |
| 2070 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2071 DoCreateOffer(&offer, nullptr); | |
| 2072 | |
| 2073 const cricket::ContentInfo* video_content = | |
| 2074 cricket::GetFirstVideoContent(offer->description()); | |
| 2075 const cricket::VideoContentDescription* video_desc = | |
| 2076 static_cast<const cricket::VideoContentDescription*>( | |
| 2077 video_content->description); | |
| 2078 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction()); | |
| 2079 | |
| 2080 const cricket::ContentInfo* audio_content = | |
| 2081 cricket::GetFirstAudioContent(offer->description()); | |
| 2082 const cricket::AudioContentDescription* audio_desc = | |
| 2083 static_cast<const cricket::AudioContentDescription*>( | |
| 2084 audio_content->description); | |
| 2085 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction()); | |
| 2086 } | |
| 2087 | |
| 2088 // Test that if we're receiving (but not sending) a track, and the | |
| 2089 // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to | |
| 2090 // false, the generated m-lines will be a=inactive. | |
| 2091 TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) { | |
| 2092 FakeConstraints constraints; | |
| 2093 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2094 true); | |
| 2095 CreatePeerConnection(&constraints); | |
| 2096 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2097 CreateAnswerAsLocalDescription(); | |
| 2098 | |
| 2099 // At this point we should be receiving stream 1, but not sending anything. | |
| 2100 // A new offer would be recvonly, but we'll set the "no receive" constraints | |
| 2101 // to make it inactive. | |
| 2102 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2103 FakeConstraints offer_constraints; | |
| 2104 offer_constraints.AddMandatory( | |
| 2105 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false); | |
| 2106 offer_constraints.AddMandatory( | |
| 2107 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false); | |
| 2108 DoCreateOffer(&offer, &offer_constraints); | |
| 2109 | |
| 2110 const cricket::ContentInfo* video_content = | |
| 2111 cricket::GetFirstVideoContent(offer->description()); | |
| 2112 const cricket::VideoContentDescription* video_desc = | |
| 2113 static_cast<const cricket::VideoContentDescription*>( | |
| 2114 video_content->description); | |
| 2115 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction()); | |
| 2116 | |
| 2117 const cricket::ContentInfo* audio_content = | |
| 2118 cricket::GetFirstAudioContent(offer->description()); | |
| 2119 const cricket::AudioContentDescription* audio_desc = | |
| 2120 static_cast<const cricket::AudioContentDescription*>( | |
| 2121 audio_content->description); | |
| 2122 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction()); | |
| 2123 } | |
| 2124 | |
| 2125 // Test that we can use SetConfiguration to change the ICE servers of the | |
| 2126 // PortAllocator. | |
| 2127 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { | |
| 2128 CreatePeerConnection(); | |
| 2129 | |
| 2130 PeerConnectionInterface::RTCConfiguration config; | |
| 2131 PeerConnectionInterface::IceServer server; | |
| 2132 server.uri = "stun:test_hostname"; | |
| 2133 config.servers.push_back(server); | |
| 2134 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2135 | |
| 2136 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | |
| 2137 EXPECT_EQ("test_hostname", | |
| 2138 port_allocator_->stun_servers().begin()->hostname()); | |
| 2139 } | |
| 2140 | |
| 2141 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { | |
| 2142 CreatePeerConnection(); | |
| 2143 PeerConnectionInterface::RTCConfiguration config; | |
| 2144 config.type = PeerConnectionInterface::kRelay; | |
| 2145 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2146 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); | |
| 2147 } | |
| 2148 | |
| 2149 // Test that when SetConfiguration changes both the pool size and other | |
| 2150 // attributes, the pooled session is created with the updated attributes. | |
| 2151 TEST_F(PeerConnectionInterfaceTest, | |
| 2152 SetConfigurationCreatesPooledSessionCorrectly) { | |
| 2153 CreatePeerConnection(); | |
| 2154 PeerConnectionInterface::RTCConfiguration config; | |
| 2155 config.ice_candidate_pool_size = 1; | |
| 2156 PeerConnectionInterface::IceServer server; | |
| 2157 server.uri = kStunAddressOnly; | |
| 2158 config.servers.push_back(server); | |
| 2159 config.type = PeerConnectionInterface::kRelay; | |
| 2160 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2161 | |
| 2162 const cricket::FakePortAllocatorSession* session = | |
| 2163 static_cast<const cricket::FakePortAllocatorSession*>( | |
| 2164 port_allocator_->GetPooledSession()); | |
| 2165 ASSERT_NE(nullptr, session); | |
| 2166 EXPECT_EQ(1UL, session->stun_servers().size()); | |
| 2167 } | |
| 2168 | |
| 2169 // Test that PeerConnection::Close changes the states to closed and all remote | |
| 2170 // tracks change state to ended. | |
| 2171 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { | |
| 2172 // Initialize a PeerConnection and negotiate local and remote session | |
| 2173 // description. | |
| 2174 InitiateCall(); | |
| 2175 ASSERT_EQ(1u, pc_->local_streams()->count()); | |
| 2176 ASSERT_EQ(1u, pc_->remote_streams()->count()); | |
| 2177 | |
| 2178 pc_->Close(); | |
| 2179 | |
| 2180 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state()); | |
| 2181 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed, | |
| 2182 pc_->ice_connection_state()); | |
| 2183 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, | |
| 2184 pc_->ice_gathering_state()); | |
| 2185 | |
| 2186 EXPECT_EQ(1u, pc_->local_streams()->count()); | |
| 2187 EXPECT_EQ(1u, pc_->remote_streams()->count()); | |
| 2188 | |
| 2189 rtc::scoped_refptr<MediaStreamInterface> remote_stream = | |
| 2190 pc_->remote_streams()->at(0); | |
| 2191 // Track state may be updated asynchronously. | |
| 2192 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, | |
| 2193 remote_stream->GetAudioTracks()[0]->state(), kTimeout); | |
| 2194 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, | |
| 2195 remote_stream->GetVideoTracks()[0]->state(), kTimeout); | |
| 2196 } | |
| 2197 | |
| 2198 // Test that PeerConnection methods fails gracefully after | |
| 2199 // PeerConnection::Close has been called. | |
| 2200 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) { | |
| 2201 CreatePeerConnection(); | |
| 2202 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2203 CreateOfferAsRemoteDescription(); | |
| 2204 CreateAnswerAsLocalDescription(); | |
| 2205 | |
| 2206 ASSERT_EQ(1u, pc_->local_streams()->count()); | |
| 2207 rtc::scoped_refptr<MediaStreamInterface> local_stream = | |
| 2208 pc_->local_streams()->at(0); | |
| 2209 | |
| 2210 pc_->Close(); | |
| 2211 | |
| 2212 pc_->RemoveStream(local_stream); | |
| 2213 EXPECT_FALSE(pc_->AddStream(local_stream)); | |
| 2214 | |
| 2215 ASSERT_FALSE(local_stream->GetAudioTracks().empty()); | |
| 2216 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender( | |
| 2217 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0])); | |
| 2218 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed. | |
| 2219 | |
| 2220 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL); | |
| 2221 | |
| 2222 EXPECT_TRUE(pc_->local_description() != NULL); | |
| 2223 EXPECT_TRUE(pc_->remote_description() != NULL); | |
| 2224 | |
| 2225 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2226 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2227 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 2228 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 2229 | |
| 2230 std::string sdp; | |
| 2231 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp)); | |
| 2232 SessionDescriptionInterface* remote_offer = | |
| 2233 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2234 sdp, NULL); | |
| 2235 EXPECT_FALSE(DoSetRemoteDescription(remote_offer)); | |
| 2236 | |
| 2237 ASSERT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 2238 SessionDescriptionInterface* local_offer = | |
| 2239 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2240 sdp, NULL); | |
| 2241 EXPECT_FALSE(DoSetLocalDescription(local_offer)); | |
| 2242 } | |
| 2243 | |
| 2244 // Test that GetStats can still be called after PeerConnection::Close. | |
| 2245 TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) { | |
| 2246 InitiateCall(); | |
| 2247 pc_->Close(); | |
| 2248 DoGetStats(NULL); | |
| 2249 } | |
| 2250 | |
| 2251 // NOTE: The series of tests below come from what used to be | |
| 2252 // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that | |
| 2253 // setting a remote or local description has the expected effects. | |
| 2254 | |
| 2255 // This test verifies that the remote MediaStreams corresponding to a received | |
| 2256 // SDP string is created. In this test the two separate MediaStreams are | |
| 2257 // signaled. | |
| 2258 TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) { | |
| 2259 FakeConstraints constraints; | |
| 2260 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2261 true); | |
| 2262 CreatePeerConnection(&constraints); | |
| 2263 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2264 | |
| 2265 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); | |
| 2266 EXPECT_TRUE( | |
| 2267 CompareStreamCollections(observer_.remote_streams(), reference.get())); | |
| 2268 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2269 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); | |
| 2270 | |
| 2271 // Create a session description based on another SDP with another | |
| 2272 // MediaStream. | |
| 2273 CreateAndSetRemoteOffer(kSdpStringWithStream1And2); | |
| 2274 | |
| 2275 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1)); | |
| 2276 EXPECT_TRUE( | |
| 2277 CompareStreamCollections(observer_.remote_streams(), reference2.get())); | |
| 2278 } | |
| 2279 | |
| 2280 // This test verifies that when remote tracks are added/removed from SDP, the | |
| 2281 // created remote streams are updated appropriately. | |
| 2282 TEST_F(PeerConnectionInterfaceTest, | |
| 2283 AddRemoveTrackFromExistingRemoteMediaStream) { | |
| 2284 FakeConstraints constraints; | |
| 2285 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2286 true); | |
| 2287 CreatePeerConnection(&constraints); | |
| 2288 std::unique_ptr<SessionDescriptionInterface> desc_ms1 = | |
| 2289 CreateSessionDescriptionAndReference(1, 1); | |
| 2290 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release())); | |
| 2291 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), | |
| 2292 reference_collection_)); | |
| 2293 | |
| 2294 // Add extra audio and video tracks to the same MediaStream. | |
| 2295 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = | |
| 2296 CreateSessionDescriptionAndReference(2, 2); | |
| 2297 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release())); | |
| 2298 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), | |
| 2299 reference_collection_)); | |
| 2300 rtc::scoped_refptr<AudioTrackInterface> audio_track2 = | |
| 2301 observer_.remote_streams()->at(0)->GetAudioTracks()[1]; | |
| 2302 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state()); | |
| 2303 rtc::scoped_refptr<VideoTrackInterface> video_track2 = | |
| 2304 observer_.remote_streams()->at(0)->GetVideoTracks()[1]; | |
| 2305 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state()); | |
| 2306 | |
| 2307 // Remove the extra audio and video tracks. | |
| 2308 std::unique_ptr<SessionDescriptionInterface> desc_ms2 = | |
| 2309 CreateSessionDescriptionAndReference(1, 1); | |
| 2310 MockTrackObserver audio_track_observer(audio_track2); | |
| 2311 MockTrackObserver video_track_observer(video_track2); | |
| 2312 | |
| 2313 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1)); | |
| 2314 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1)); | |
| 2315 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release())); | |
| 2316 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), | |
| 2317 reference_collection_)); | |
| 2318 // Track state may be updated asynchronously. | |
| 2319 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2320 audio_track2->state(), kTimeout); | |
| 2321 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2322 video_track2->state(), kTimeout); | |
| 2323 } | |
| 2324 | |
| 2325 // This tests that remote tracks are ended if a local session description is set | |
| 2326 // that rejects the media content type. | |
| 2327 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) { | |
| 2328 FakeConstraints constraints; | |
| 2329 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2330 true); | |
| 2331 CreatePeerConnection(&constraints); | |
| 2332 // First create and set a remote offer, then reject its video content in our | |
| 2333 // answer. | |
| 2334 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2335 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2336 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2337 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2338 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2339 | |
| 2340 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video = | |
| 2341 remote_stream->GetVideoTracks()[0]; | |
| 2342 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state()); | |
| 2343 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio = | |
| 2344 remote_stream->GetAudioTracks()[0]; | |
| 2345 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); | |
| 2346 | |
| 2347 std::unique_ptr<SessionDescriptionInterface> local_answer; | |
| 2348 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr)); | |
| 2349 cricket::ContentInfo* video_info = | |
| 2350 local_answer->description()->GetContentByName("video"); | |
| 2351 video_info->rejected = true; | |
| 2352 EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); | |
| 2353 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); | |
| 2354 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); | |
| 2355 | |
| 2356 // Now create an offer where we reject both video and audio. | |
| 2357 std::unique_ptr<SessionDescriptionInterface> local_offer; | |
| 2358 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr)); | |
| 2359 video_info = local_offer->description()->GetContentByName("video"); | |
| 2360 ASSERT_TRUE(video_info != nullptr); | |
| 2361 video_info->rejected = true; | |
| 2362 cricket::ContentInfo* audio_info = | |
| 2363 local_offer->description()->GetContentByName("audio"); | |
| 2364 ASSERT_TRUE(audio_info != nullptr); | |
| 2365 audio_info->rejected = true; | |
| 2366 EXPECT_TRUE(DoSetLocalDescription(local_offer.release())); | |
| 2367 // Track state may be updated asynchronously. | |
| 2368 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2369 remote_audio->state(), kTimeout); | |
| 2370 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2371 remote_video->state(), kTimeout); | |
| 2372 } | |
| 2373 | |
| 2374 // This tests that we won't crash if the remote track has been removed outside | |
| 2375 // of PeerConnection and then PeerConnection tries to reject the track. | |
| 2376 TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) { | |
| 2377 FakeConstraints constraints; | |
| 2378 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2379 true); | |
| 2380 CreatePeerConnection(&constraints); | |
| 2381 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2382 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2383 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); | |
| 2384 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); | |
| 2385 | |
| 2386 std::unique_ptr<SessionDescriptionInterface> local_answer( | |
| 2387 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, | |
| 2388 kSdpStringWithStream1, nullptr)); | |
| 2389 cricket::ContentInfo* video_info = | |
| 2390 local_answer->description()->GetContentByName("video"); | |
| 2391 video_info->rejected = true; | |
| 2392 cricket::ContentInfo* audio_info = | |
| 2393 local_answer->description()->GetContentByName("audio"); | |
| 2394 audio_info->rejected = true; | |
| 2395 EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); | |
| 2396 | |
| 2397 // No crash is a pass. | |
| 2398 } | |
| 2399 | |
| 2400 // This tests that if a recvonly remote description is set, no remote streams | |
| 2401 // will be created, even if the description contains SSRCs/MSIDs. | |
| 2402 // See: https://code.google.com/p/webrtc/issues/detail?id=5054 | |
| 2403 TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) { | |
| 2404 FakeConstraints constraints; | |
| 2405 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2406 true); | |
| 2407 CreatePeerConnection(&constraints); | |
| 2408 | |
| 2409 std::string recvonly_offer = kSdpStringWithStream1; | |
| 2410 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly, | |
| 2411 strlen(kRecvonly), &recvonly_offer); | |
| 2412 CreateAndSetRemoteOffer(recvonly_offer); | |
| 2413 | |
| 2414 EXPECT_EQ(0u, observer_.remote_streams()->count()); | |
| 2415 } | |
| 2416 | |
| 2417 // This tests that a default MediaStream is created if a remote session | |
| 2418 // description doesn't contain any streams and no MSID support. | |
| 2419 // It also tests that the default stream is updated if a video m-line is added | |
| 2420 // in a subsequent session description. | |
| 2421 TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) { | |
| 2422 FakeConstraints constraints; | |
| 2423 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2424 true); | |
| 2425 CreatePeerConnection(&constraints); | |
| 2426 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); | |
| 2427 | |
| 2428 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2429 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2430 | |
| 2431 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2432 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); | |
| 2433 EXPECT_EQ("default", remote_stream->label()); | |
| 2434 | |
| 2435 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2436 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2437 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2438 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); | |
| 2439 EXPECT_EQ(MediaStreamTrackInterface::kLive, | |
| 2440 remote_stream->GetAudioTracks()[0]->state()); | |
| 2441 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2442 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); | |
| 2443 EXPECT_EQ(MediaStreamTrackInterface::kLive, | |
| 2444 remote_stream->GetVideoTracks()[0]->state()); | |
| 2445 } | |
| 2446 | |
| 2447 // This tests that a default MediaStream is created if a remote session | |
| 2448 // description doesn't contain any streams and media direction is send only. | |
| 2449 TEST_F(PeerConnectionInterfaceTest, | |
| 2450 SendOnlySdpWithoutMsidCreatesDefaultStream) { | |
| 2451 FakeConstraints constraints; | |
| 2452 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2453 true); | |
| 2454 CreatePeerConnection(&constraints); | |
| 2455 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); | |
| 2456 | |
| 2457 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2458 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2459 | |
| 2460 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2461 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2462 EXPECT_EQ("default", remote_stream->label()); | |
| 2463 } | |
| 2464 | |
| 2465 // This tests that it won't crash when PeerConnection tries to remove | |
| 2466 // a remote track that as already been removed from the MediaStream. | |
| 2467 TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) { | |
| 2468 FakeConstraints constraints; | |
| 2469 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2470 true); | |
| 2471 CreatePeerConnection(&constraints); | |
| 2472 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2473 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2474 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); | |
| 2475 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); | |
| 2476 | |
| 2477 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2478 | |
| 2479 // No crash is a pass. | |
| 2480 } | |
| 2481 | |
| 2482 // This tests that a default MediaStream is created if the remote session | |
| 2483 // description doesn't contain any streams and don't contain an indication if | |
| 2484 // MSID is supported. | |
| 2485 TEST_F(PeerConnectionInterfaceTest, | |
| 2486 SdpWithoutMsidAndStreamsCreatesDefaultStream) { | |
| 2487 FakeConstraints constraints; | |
| 2488 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2489 true); | |
| 2490 CreatePeerConnection(&constraints); | |
| 2491 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2492 | |
| 2493 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2494 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2495 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2496 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2497 } | |
| 2498 | |
| 2499 // This tests that a default MediaStream is not created if the remote session | |
| 2500 // description doesn't contain any streams but does support MSID. | |
| 2501 TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) { | |
| 2502 FakeConstraints constraints; | |
| 2503 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2504 true); | |
| 2505 CreatePeerConnection(&constraints); | |
| 2506 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); | |
| 2507 EXPECT_EQ(0u, observer_.remote_streams()->count()); | |
| 2508 } | |
| 2509 | |
| 2510 // This tests that when setting a new description, the old default tracks are | |
| 2511 // not destroyed and recreated. | |
| 2512 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250 | |
| 2513 TEST_F(PeerConnectionInterfaceTest, | |
| 2514 DefaultTracksNotDestroyedAndRecreated) { | |
| 2515 FakeConstraints constraints; | |
| 2516 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2517 true); | |
| 2518 CreatePeerConnection(&constraints); | |
| 2519 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); | |
| 2520 | |
| 2521 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2522 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2523 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2524 | |
| 2525 // Set the track to "disabled", then set a new description and ensure the | |
| 2526 // track is still disabled, which ensures it hasn't been recreated. | |
| 2527 remote_stream->GetAudioTracks()[0]->set_enabled(false); | |
| 2528 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); | |
| 2529 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2530 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled()); | |
| 2531 } | |
| 2532 | |
| 2533 // This tests that a default MediaStream is not created if a remote session | |
| 2534 // description is updated to not have any MediaStreams. | |
| 2535 TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) { | |
| 2536 FakeConstraints constraints; | |
| 2537 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2538 true); | |
| 2539 CreatePeerConnection(&constraints); | |
| 2540 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2541 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); | |
| 2542 EXPECT_TRUE( | |
| 2543 CompareStreamCollections(observer_.remote_streams(), reference.get())); | |
| 2544 | |
| 2545 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2546 EXPECT_EQ(0u, observer_.remote_streams()->count()); | |
| 2547 } | |
| 2548 | |
| 2549 // This tests that an RtpSender is created when the local description is set | |
| 2550 // after adding a local stream. | |
| 2551 // TODO(deadbeef): This test and the one below it need to be updated when | |
| 2552 // an RtpSender's lifetime isn't determined by when a local description is set. | |
| 2553 TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) { | |
| 2554 FakeConstraints constraints; | |
| 2555 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2556 true); | |
| 2557 CreatePeerConnection(&constraints); | |
| 2558 | |
| 2559 // Create an offer with 1 stream with 2 tracks of each type. | |
| 2560 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2561 CreateStreamCollection(1, 2); | |
| 2562 pc_->AddStream(stream_collection->at(0)); | |
| 2563 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2564 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2565 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2566 | |
| 2567 auto senders = pc_->GetSenders(); | |
| 2568 EXPECT_EQ(4u, senders.size()); | |
| 2569 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2570 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2571 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); | |
| 2572 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); | |
| 2573 | |
| 2574 // Remove an audio and video track. | |
| 2575 pc_->RemoveStream(stream_collection->at(0)); | |
| 2576 stream_collection = CreateStreamCollection(1, 1); | |
| 2577 pc_->AddStream(stream_collection->at(0)); | |
| 2578 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2579 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2580 | |
| 2581 senders = pc_->GetSenders(); | |
| 2582 EXPECT_EQ(2u, senders.size()); | |
| 2583 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2584 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2585 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); | |
| 2586 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); | |
| 2587 } | |
| 2588 | |
| 2589 // This tests that an RtpSender is created when the local description is set | |
| 2590 // before adding a local stream. | |
| 2591 TEST_F(PeerConnectionInterfaceTest, | |
| 2592 AddLocalStreamAfterLocalDescriptionChanged) { | |
| 2593 FakeConstraints constraints; | |
| 2594 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2595 true); | |
| 2596 CreatePeerConnection(&constraints); | |
| 2597 | |
| 2598 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2599 CreateStreamCollection(1, 2); | |
| 2600 // Add a stream to create the offer, but remove it afterwards. | |
| 2601 pc_->AddStream(stream_collection->at(0)); | |
| 2602 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2603 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2604 pc_->RemoveStream(stream_collection->at(0)); | |
| 2605 | |
| 2606 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2607 auto senders = pc_->GetSenders(); | |
| 2608 EXPECT_EQ(0u, senders.size()); | |
| 2609 | |
| 2610 pc_->AddStream(stream_collection->at(0)); | |
| 2611 senders = pc_->GetSenders(); | |
| 2612 EXPECT_EQ(4u, senders.size()); | |
| 2613 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2614 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2615 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); | |
| 2616 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); | |
| 2617 } | |
| 2618 | |
| 2619 // This tests that the expected behavior occurs if the SSRC on a local track is | |
| 2620 // changed when SetLocalDescription is called. | |
| 2621 TEST_F(PeerConnectionInterfaceTest, | |
| 2622 ChangeSsrcOnTrackInLocalSessionDescription) { | |
| 2623 FakeConstraints constraints; | |
| 2624 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2625 true); | |
| 2626 CreatePeerConnection(&constraints); | |
| 2627 | |
| 2628 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2629 CreateStreamCollection(2, 1); | |
| 2630 pc_->AddStream(stream_collection->at(0)); | |
| 2631 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2632 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2633 // Grab a copy of the offer before it gets passed into the PC. | |
| 2634 std::unique_ptr<JsepSessionDescription> modified_offer( | |
| 2635 new JsepSessionDescription(JsepSessionDescription::kOffer)); | |
| 2636 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(), | |
| 2637 offer->session_version()); | |
| 2638 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2639 | |
| 2640 auto senders = pc_->GetSenders(); | |
| 2641 EXPECT_EQ(2u, senders.size()); | |
| 2642 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2643 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2644 | |
| 2645 // Change the ssrc of the audio and video track. | |
| 2646 cricket::MediaContentDescription* desc = | |
| 2647 cricket::GetFirstAudioContentDescription(modified_offer->description()); | |
| 2648 ASSERT_TRUE(desc != NULL); | |
| 2649 for (StreamParams& stream : desc->mutable_streams()) { | |
| 2650 for (unsigned int& ssrc : stream.ssrcs) { | |
| 2651 ++ssrc; | |
| 2652 } | |
| 2653 } | |
| 2654 | |
| 2655 desc = | |
| 2656 cricket::GetFirstVideoContentDescription(modified_offer->description()); | |
| 2657 ASSERT_TRUE(desc != NULL); | |
| 2658 for (StreamParams& stream : desc->mutable_streams()) { | |
| 2659 for (unsigned int& ssrc : stream.ssrcs) { | |
| 2660 ++ssrc; | |
| 2661 } | |
| 2662 } | |
| 2663 | |
| 2664 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release())); | |
| 2665 senders = pc_->GetSenders(); | |
| 2666 EXPECT_EQ(2u, senders.size()); | |
| 2667 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2668 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2669 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC | |
| 2670 // changed. | |
| 2671 } | |
| 2672 | |
| 2673 // This tests that the expected behavior occurs if a new session description is | |
| 2674 // set with the same tracks, but on a different MediaStream. | |
| 2675 TEST_F(PeerConnectionInterfaceTest, | |
| 2676 SignalSameTracksInSeparateMediaStream) { | |
| 2677 FakeConstraints constraints; | |
| 2678 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2679 true); | |
| 2680 CreatePeerConnection(&constraints); | |
| 2681 | |
| 2682 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2683 CreateStreamCollection(2, 1); | |
| 2684 pc_->AddStream(stream_collection->at(0)); | |
| 2685 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2686 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2687 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2688 | |
| 2689 auto senders = pc_->GetSenders(); | |
| 2690 EXPECT_EQ(2u, senders.size()); | |
| 2691 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0])); | |
| 2692 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0])); | |
| 2693 | |
| 2694 // Add a new MediaStream but with the same tracks as in the first stream. | |
| 2695 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( | |
| 2696 webrtc::MediaStream::Create(kStreams[1])); | |
| 2697 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]); | |
| 2698 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]); | |
| 2699 pc_->AddStream(stream_1); | |
| 2700 | |
| 2701 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2702 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2703 | |
| 2704 auto new_senders = pc_->GetSenders(); | |
| 2705 // Should be the same senders as before, but with updated stream id. | |
| 2706 // Note that this behavior is subject to change in the future. | |
| 2707 // We may decide the PC should ignore existing tracks in AddStream. | |
| 2708 EXPECT_EQ(senders, new_senders); | |
| 2709 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); | |
| 2710 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); | |
| 2711 } | |
| 2712 | |
| 2713 // This tests that PeerConnectionObserver::OnAddTrack is correctly called. | |
| 2714 TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) { | |
| 2715 FakeConstraints constraints; | |
| 2716 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2717 true); | |
| 2718 CreatePeerConnection(&constraints); | |
| 2719 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly); | |
| 2720 EXPECT_EQ(observer_.num_added_tracks_, 1); | |
| 2721 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]); | |
| 2722 | |
| 2723 // Create and set the updated remote SDP. | |
| 2724 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2725 EXPECT_EQ(observer_.num_added_tracks_, 2); | |
| 2726 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]); | |
| 2727 } | |
| 2728 | |
| 2729 class PeerConnectionMediaConfigTest : public testing::Test { | |
| 2730 protected: | |
| 2731 void SetUp() override { | |
| 2732 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | |
| 2733 pcf_->Initialize(); | |
| 2734 } | |
| 2735 const cricket::MediaConfig& TestCreatePeerConnection( | |
| 2736 const PeerConnectionInterface::RTCConfiguration& config, | |
| 2737 const MediaConstraintsInterface *constraints) { | |
| 2738 pcf_->create_media_controller_called_ = false; | |
| 2739 | |
| 2740 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection( | |
| 2741 config, constraints, nullptr, nullptr, &observer_)); | |
| 2742 EXPECT_TRUE(pc.get()); | |
| 2743 EXPECT_TRUE(pcf_->create_media_controller_called_); | |
| 2744 return pcf_->create_media_controller_config_; | |
| 2745 } | |
| 2746 | |
| 2747 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; | |
| 2748 MockPeerConnectionObserver observer_; | |
| 2749 }; | |
| 2750 | |
| 2751 // This test verifies the default behaviour with no constraints and a | |
| 2752 // default RTCConfiguration. | |
| 2753 TEST_F(PeerConnectionMediaConfigTest, TestDefaults) { | |
| 2754 PeerConnectionInterface::RTCConfiguration config; | |
| 2755 FakeConstraints constraints; | |
| 2756 | |
| 2757 const cricket::MediaConfig& media_config = | |
| 2758 TestCreatePeerConnection(config, &constraints); | |
| 2759 | |
| 2760 EXPECT_FALSE(media_config.enable_dscp); | |
| 2761 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection); | |
| 2762 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing); | |
| 2763 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate); | |
| 2764 } | |
| 2765 | |
| 2766 // This test verifies the DSCP constraint is recognized and passed to | |
| 2767 // the CreateMediaController call. | |
| 2768 TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) { | |
| 2769 PeerConnectionInterface::RTCConfiguration config; | |
| 2770 FakeConstraints constraints; | |
| 2771 | |
| 2772 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true); | |
| 2773 const cricket::MediaConfig& media_config = | |
| 2774 TestCreatePeerConnection(config, &constraints); | |
| 2775 | |
| 2776 EXPECT_TRUE(media_config.enable_dscp); | |
| 2777 } | |
| 2778 | |
| 2779 // This test verifies the cpu overuse detection constraint is | |
| 2780 // recognized and passed to the CreateMediaController call. | |
| 2781 TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) { | |
| 2782 PeerConnectionInterface::RTCConfiguration config; | |
| 2783 FakeConstraints constraints; | |
| 2784 | |
| 2785 constraints.AddOptional( | |
| 2786 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false); | |
| 2787 const cricket::MediaConfig media_config = | |
| 2788 TestCreatePeerConnection(config, &constraints); | |
| 2789 | |
| 2790 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection); | |
| 2791 } | |
| 2792 | |
| 2793 // This test verifies that the disable_prerenderer_smoothing flag is | |
| 2794 // propagated from RTCConfiguration to the CreateMediaController call. | |
| 2795 TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) { | |
| 2796 PeerConnectionInterface::RTCConfiguration config; | |
| 2797 FakeConstraints constraints; | |
| 2798 | |
| 2799 config.set_prerenderer_smoothing(false); | |
| 2800 const cricket::MediaConfig& media_config = | |
| 2801 TestCreatePeerConnection(config, &constraints); | |
| 2802 | |
| 2803 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing); | |
| 2804 } | |
| 2805 | |
| 2806 // This test verifies the suspend below min bitrate constraint is | |
| 2807 // recognized and passed to the CreateMediaController call. | |
| 2808 TEST_F(PeerConnectionMediaConfigTest, | |
| 2809 TestSuspendBelowMinBitrateConstraintTrue) { | |
| 2810 PeerConnectionInterface::RTCConfiguration config; | |
| 2811 FakeConstraints constraints; | |
| 2812 | |
| 2813 constraints.AddOptional( | |
| 2814 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, | |
| 2815 true); | |
| 2816 const cricket::MediaConfig media_config = | |
| 2817 TestCreatePeerConnection(config, &constraints); | |
| 2818 | |
| 2819 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); | |
| 2820 } | |
| 2821 | |
| 2822 // The following tests verify that session options are created correctly. | |
| 2823 // TODO(deadbeef): Convert these tests to be more end-to-end. Instead of | |
| 2824 // "verify options are converted correctly", should be "pass options into | |
| 2825 // CreateOffer and verify the correct offer is produced." | |
| 2826 | |
| 2827 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) { | |
| 2828 RTCOfferAnswerOptions rtc_options; | |
| 2829 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; | |
| 2830 | |
| 2831 cricket::MediaSessionOptions options; | |
| 2832 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2833 | |
| 2834 rtc_options.offer_to_receive_audio = | |
| 2835 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
| 2836 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2837 } | |
| 2838 | |
| 2839 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) { | |
| 2840 RTCOfferAnswerOptions rtc_options; | |
| 2841 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; | |
| 2842 | |
| 2843 cricket::MediaSessionOptions options; | |
| 2844 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2845 | |
| 2846 rtc_options.offer_to_receive_video = | |
| 2847 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
| 2848 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2849 } | |
| 2850 | |
| 2851 // Test that a MediaSessionOptions is created for an offer if | |
| 2852 // OfferToReceiveAudio and OfferToReceiveVideo options are set. | |
| 2853 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) { | |
| 2854 RTCOfferAnswerOptions rtc_options; | |
| 2855 rtc_options.offer_to_receive_audio = 1; | |
| 2856 rtc_options.offer_to_receive_video = 1; | |
| 2857 | |
| 2858 cricket::MediaSessionOptions options; | |
| 2859 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2860 EXPECT_TRUE(options.has_audio()); | |
| 2861 EXPECT_TRUE(options.has_video()); | |
| 2862 EXPECT_TRUE(options.bundle_enabled); | |
| 2863 } | |
| 2864 | |
| 2865 // Test that a correct MediaSessionOptions is created for an offer if | |
| 2866 // OfferToReceiveAudio is set. | |
| 2867 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) { | |
| 2868 RTCOfferAnswerOptions rtc_options; | |
| 2869 rtc_options.offer_to_receive_audio = 1; | |
| 2870 | |
| 2871 cricket::MediaSessionOptions options; | |
| 2872 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2873 EXPECT_TRUE(options.has_audio()); | |
| 2874 EXPECT_FALSE(options.has_video()); | |
| 2875 EXPECT_TRUE(options.bundle_enabled); | |
| 2876 } | |
| 2877 | |
| 2878 // Test that a correct MediaSessionOptions is created for an offer if | |
| 2879 // the default OfferOptions are used. | |
| 2880 TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) { | |
| 2881 RTCOfferAnswerOptions rtc_options; | |
| 2882 | |
| 2883 cricket::MediaSessionOptions options; | |
| 2884 options.transport_options["audio"] = cricket::TransportOptions(); | |
| 2885 options.transport_options["video"] = cricket::TransportOptions(); | |
| 2886 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2887 EXPECT_TRUE(options.has_audio()); | |
| 2888 EXPECT_FALSE(options.has_video()); | |
| 2889 EXPECT_TRUE(options.bundle_enabled); | |
| 2890 EXPECT_TRUE(options.vad_enabled); | |
| 2891 EXPECT_FALSE(options.transport_options["audio"].ice_restart); | |
| 2892 EXPECT_FALSE(options.transport_options["video"].ice_restart); | |
| 2893 } | |
| 2894 | |
| 2895 // Test that a correct MediaSessionOptions is created for an offer if | |
| 2896 // OfferToReceiveVideo is set. | |
| 2897 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) { | |
| 2898 RTCOfferAnswerOptions rtc_options; | |
| 2899 rtc_options.offer_to_receive_audio = 0; | |
| 2900 rtc_options.offer_to_receive_video = 1; | |
| 2901 | |
| 2902 cricket::MediaSessionOptions options; | |
| 2903 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2904 EXPECT_FALSE(options.has_audio()); | |
| 2905 EXPECT_TRUE(options.has_video()); | |
| 2906 EXPECT_TRUE(options.bundle_enabled); | |
| 2907 } | |
| 2908 | |
| 2909 // Test that a correct MediaSessionOptions is created for an offer if | |
| 2910 // UseRtpMux is set to false. | |
| 2911 TEST(CreateSessionOptionsTest, | |
| 2912 GetMediaSessionOptionsForOfferWithBundleDisabled) { | |
| 2913 RTCOfferAnswerOptions rtc_options; | |
| 2914 rtc_options.offer_to_receive_audio = 1; | |
| 2915 rtc_options.offer_to_receive_video = 1; | |
| 2916 rtc_options.use_rtp_mux = false; | |
| 2917 | |
| 2918 cricket::MediaSessionOptions options; | |
| 2919 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2920 EXPECT_TRUE(options.has_audio()); | |
| 2921 EXPECT_TRUE(options.has_video()); | |
| 2922 EXPECT_FALSE(options.bundle_enabled); | |
| 2923 } | |
| 2924 | |
| 2925 // Test that a correct MediaSessionOptions is created to restart ice if | |
| 2926 // IceRestart is set. It also tests that subsequent MediaSessionOptions don't | |
| 2927 // have |audio_transport_options.ice_restart| etc. set. | |
| 2928 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) { | |
| 2929 RTCOfferAnswerOptions rtc_options; | |
| 2930 rtc_options.ice_restart = true; | |
| 2931 | |
| 2932 cricket::MediaSessionOptions options; | |
| 2933 options.transport_options["audio"] = cricket::TransportOptions(); | |
| 2934 options.transport_options["video"] = cricket::TransportOptions(); | |
| 2935 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2936 EXPECT_TRUE(options.transport_options["audio"].ice_restart); | |
| 2937 EXPECT_TRUE(options.transport_options["video"].ice_restart); | |
| 2938 | |
| 2939 rtc_options = RTCOfferAnswerOptions(); | |
| 2940 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 2941 EXPECT_FALSE(options.transport_options["audio"].ice_restart); | |
| 2942 EXPECT_FALSE(options.transport_options["video"].ice_restart); | |
| 2943 } | |
| 2944 | |
| 2945 // Test that the MediaConstraints in an answer don't affect if audio and video | |
| 2946 // is offered in an offer but that if kOfferToReceiveAudio or | |
| 2947 // kOfferToReceiveVideo constraints are true in an offer, the media type will be | |
| 2948 // included in subsequent answers. | |
| 2949 TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) { | |
| 2950 FakeConstraints answer_c; | |
| 2951 answer_c.SetMandatoryReceiveAudio(true); | |
| 2952 answer_c.SetMandatoryReceiveVideo(true); | |
| 2953 | |
| 2954 cricket::MediaSessionOptions answer_options; | |
| 2955 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options)); | |
| 2956 EXPECT_TRUE(answer_options.has_audio()); | |
| 2957 EXPECT_TRUE(answer_options.has_video()); | |
| 2958 | |
| 2959 RTCOfferAnswerOptions rtc_offer_options; | |
| 2960 | |
| 2961 cricket::MediaSessionOptions offer_options; | |
| 2962 EXPECT_TRUE( | |
| 2963 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options)); | |
| 2964 EXPECT_TRUE(offer_options.has_audio()); | |
| 2965 EXPECT_TRUE(offer_options.has_video()); | |
| 2966 | |
| 2967 RTCOfferAnswerOptions updated_rtc_offer_options; | |
| 2968 updated_rtc_offer_options.offer_to_receive_audio = 1; | |
| 2969 updated_rtc_offer_options.offer_to_receive_video = 1; | |
| 2970 | |
| 2971 cricket::MediaSessionOptions updated_offer_options; | |
| 2972 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false, | |
| 2973 &updated_offer_options)); | |
| 2974 EXPECT_TRUE(updated_offer_options.has_audio()); | |
| 2975 EXPECT_TRUE(updated_offer_options.has_video()); | |
| 2976 | |
| 2977 // Since an offer has been created with both audio and video, subsequent | |
| 2978 // offers and answers should contain both audio and video. | |
| 2979 // Answers will only contain the media types that exist in the offer | |
| 2980 // regardless of the value of |updated_answer_options.has_audio| and | |
| 2981 // |updated_answer_options.has_video|. | |
| 2982 FakeConstraints updated_answer_c; | |
| 2983 answer_c.SetMandatoryReceiveAudio(false); | |
| 2984 answer_c.SetMandatoryReceiveVideo(false); | |
| 2985 | |
| 2986 cricket::MediaSessionOptions updated_answer_options; | |
| 2987 EXPECT_TRUE( | |
| 2988 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | |
| 2989 EXPECT_TRUE(updated_answer_options.has_audio()); | |
| 2990 EXPECT_TRUE(updated_answer_options.has_video()); | |
| 2991 } | |
| OLD | NEW |