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