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