OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include <string> | 28 #include <string> |
29 | 29 |
| 30 #include "talk/app/webrtc/audiotrack.h" |
30 #include "talk/app/webrtc/fakeportallocatorfactory.h" | 31 #include "talk/app/webrtc/fakeportallocatorfactory.h" |
31 #include "talk/app/webrtc/jsepsessiondescription.h" | 32 #include "talk/app/webrtc/jsepsessiondescription.h" |
| 33 #include "talk/app/webrtc/mediastream.h" |
32 #include "talk/app/webrtc/mediastreaminterface.h" | 34 #include "talk/app/webrtc/mediastreaminterface.h" |
| 35 #include "talk/app/webrtc/peerconnection.h" |
33 #include "talk/app/webrtc/peerconnectioninterface.h" | 36 #include "talk/app/webrtc/peerconnectioninterface.h" |
| 37 #include "talk/app/webrtc/rtpreceiverinterface.h" |
| 38 #include "talk/app/webrtc/rtpsenderinterface.h" |
| 39 #include "talk/app/webrtc/streamcollection.h" |
34 #include "talk/app/webrtc/test/fakeconstraints.h" | 40 #include "talk/app/webrtc/test/fakeconstraints.h" |
35 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | 41 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
36 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" | 42 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
37 #include "talk/app/webrtc/test/testsdpstrings.h" | 43 #include "talk/app/webrtc/test/testsdpstrings.h" |
38 #include "talk/app/webrtc/videosource.h" | 44 #include "talk/app/webrtc/videosource.h" |
| 45 #include "talk/app/webrtc/videotrack.h" |
39 #include "talk/media/base/fakevideocapturer.h" | 46 #include "talk/media/base/fakevideocapturer.h" |
40 #include "talk/media/sctp/sctpdataengine.h" | 47 #include "talk/media/sctp/sctpdataengine.h" |
41 #include "talk/session/media/mediasession.h" | 48 #include "talk/session/media/mediasession.h" |
42 #include "webrtc/base/gunit.h" | 49 #include "webrtc/base/gunit.h" |
43 #include "webrtc/base/scoped_ptr.h" | 50 #include "webrtc/base/scoped_ptr.h" |
44 #include "webrtc/base/ssladapter.h" | 51 #include "webrtc/base/ssladapter.h" |
45 #include "webrtc/base/sslstreamadapter.h" | 52 #include "webrtc/base/sslstreamadapter.h" |
46 #include "webrtc/base/stringutils.h" | 53 #include "webrtc/base/stringutils.h" |
47 #include "webrtc/base/thread.h" | 54 #include "webrtc/base/thread.h" |
48 | 55 |
49 static const char kStreamLabel1[] = "local_stream_1"; | 56 static const char kStreamLabel1[] = "local_stream_1"; |
50 static const char kStreamLabel2[] = "local_stream_2"; | 57 static const char kStreamLabel2[] = "local_stream_2"; |
51 static const char kStreamLabel3[] = "local_stream_3"; | 58 static const char kStreamLabel3[] = "local_stream_3"; |
52 static const int kDefaultStunPort = 3478; | 59 static const int kDefaultStunPort = 3478; |
53 static const char kStunAddressOnly[] = "stun:address"; | 60 static const char kStunAddressOnly[] = "stun:address"; |
54 static const char kStunInvalidPort[] = "stun:address:-1"; | 61 static const char kStunInvalidPort[] = "stun:address:-1"; |
55 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; | 62 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
56 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; | 63 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
57 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; | 64 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; |
58 static const char kTurnUsername[] = "user"; | 65 static const char kTurnUsername[] = "user"; |
59 static const char kTurnPassword[] = "password"; | 66 static const char kTurnPassword[] = "password"; |
60 static const char kTurnHostname[] = "turn.example.org"; | 67 static const char kTurnHostname[] = "turn.example.org"; |
61 static const uint32 kTimeout = 10000U; | 68 static const uint32 kTimeout = 10000U; |
62 | 69 |
| 70 static const char kStreams[][8] = {"stream1", "stream2"}; |
| 71 static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"}; |
| 72 static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"}; |
| 73 |
| 74 // Reference SDP with a MediaStream with label "stream1" and audio track with |
| 75 // id "audio_1" and a video track with id "video_1; |
| 76 static const char kSdpStringWithStream1[] = |
| 77 "v=0\r\n" |
| 78 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 79 "s=-\r\n" |
| 80 "t=0 0\r\n" |
| 81 "a=ice-ufrag:e5785931\r\n" |
| 82 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 83 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 84 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 85 "m=audio 1 RTP/AVPF 103\r\n" |
| 86 "a=mid:audio\r\n" |
| 87 "a=rtpmap:103 ISAC/16000\r\n" |
| 88 "a=ssrc:1 cname:stream1\r\n" |
| 89 "a=ssrc:1 mslabel:stream1\r\n" |
| 90 "a=ssrc:1 label:audiotrack0\r\n" |
| 91 "m=video 1 RTP/AVPF 120\r\n" |
| 92 "a=mid:video\r\n" |
| 93 "a=rtpmap:120 VP8/90000\r\n" |
| 94 "a=ssrc:2 cname:stream1\r\n" |
| 95 "a=ssrc:2 mslabel:stream1\r\n" |
| 96 "a=ssrc:2 label:videotrack0\r\n"; |
| 97 |
| 98 // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each |
| 99 // MediaStreams have one audio track and one video track. |
| 100 // This uses MSID. |
| 101 static const char kSdpStringWithStream1And2[] = |
| 102 "v=0\r\n" |
| 103 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 104 "s=-\r\n" |
| 105 "t=0 0\r\n" |
| 106 "a=ice-ufrag:e5785931\r\n" |
| 107 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 108 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 109 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 110 "a=msid-semantic: WMS stream1 stream2\r\n" |
| 111 "m=audio 1 RTP/AVPF 103\r\n" |
| 112 "a=mid:audio\r\n" |
| 113 "a=rtpmap:103 ISAC/16000\r\n" |
| 114 "a=ssrc:1 cname:stream1\r\n" |
| 115 "a=ssrc:1 msid:stream1 audiotrack0\r\n" |
| 116 "a=ssrc:3 cname:stream2\r\n" |
| 117 "a=ssrc:3 msid:stream2 audiotrack1\r\n" |
| 118 "m=video 1 RTP/AVPF 120\r\n" |
| 119 "a=mid:video\r\n" |
| 120 "a=rtpmap:120 VP8/0\r\n" |
| 121 "a=ssrc:2 cname:stream1\r\n" |
| 122 "a=ssrc:2 msid:stream1 videotrack0\r\n" |
| 123 "a=ssrc:4 cname:stream2\r\n" |
| 124 "a=ssrc:4 msid:stream2 videotrack1\r\n"; |
| 125 |
| 126 // Reference SDP without MediaStreams. Msid is not supported. |
| 127 static const char kSdpStringWithoutStreams[] = |
| 128 "v=0\r\n" |
| 129 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 130 "s=-\r\n" |
| 131 "t=0 0\r\n" |
| 132 "a=ice-ufrag:e5785931\r\n" |
| 133 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 134 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 135 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 136 "m=audio 1 RTP/AVPF 103\r\n" |
| 137 "a=mid:audio\r\n" |
| 138 "a=rtpmap:103 ISAC/16000\r\n" |
| 139 "m=video 1 RTP/AVPF 120\r\n" |
| 140 "a=mid:video\r\n" |
| 141 "a=rtpmap:120 VP8/90000\r\n"; |
| 142 |
| 143 // Reference SDP without MediaStreams. Msid is supported. |
| 144 static const char kSdpStringWithMsidWithoutStreams[] = |
| 145 "v=0\r\n" |
| 146 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 147 "s=-\r\n" |
| 148 "t=0 0\r\n" |
| 149 "a=ice-ufrag:e5785931\r\n" |
| 150 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 151 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 152 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 153 "a=msid-semantic: WMS\r\n" |
| 154 "m=audio 1 RTP/AVPF 103\r\n" |
| 155 "a=mid:audio\r\n" |
| 156 "a=rtpmap:103 ISAC/16000\r\n" |
| 157 "m=video 1 RTP/AVPF 120\r\n" |
| 158 "a=mid:video\r\n" |
| 159 "a=rtpmap:120 VP8/90000\r\n"; |
| 160 |
| 161 // Reference SDP without MediaStreams and audio only. |
| 162 static const char kSdpStringWithoutStreamsAudioOnly[] = |
| 163 "v=0\r\n" |
| 164 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 165 "s=-\r\n" |
| 166 "t=0 0\r\n" |
| 167 "a=ice-ufrag:e5785931\r\n" |
| 168 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 169 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 170 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 171 "m=audio 1 RTP/AVPF 103\r\n" |
| 172 "a=mid:audio\r\n" |
| 173 "a=rtpmap:103 ISAC/16000\r\n"; |
| 174 |
| 175 // Reference SENDONLY SDP without MediaStreams. Msid is not supported. |
| 176 static const char kSdpStringSendOnlyWithoutStreams[] = |
| 177 "v=0\r\n" |
| 178 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 179 "s=-\r\n" |
| 180 "t=0 0\r\n" |
| 181 "a=ice-ufrag:e5785931\r\n" |
| 182 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 183 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 184 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 185 "m=audio 1 RTP/AVPF 103\r\n" |
| 186 "a=mid:audio\r\n" |
| 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" |
| 191 "a=sendonly\r\n" |
| 192 "a=rtpmap:120 VP8/90000\r\n"; |
| 193 |
| 194 static const char kSdpStringInit[] = |
| 195 "v=0\r\n" |
| 196 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 197 "s=-\r\n" |
| 198 "t=0 0\r\n" |
| 199 "a=ice-ufrag:e5785931\r\n" |
| 200 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 201 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 202 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 203 "a=msid-semantic: WMS\r\n"; |
| 204 |
| 205 static const char kSdpStringAudio[] = |
| 206 "m=audio 1 RTP/AVPF 103\r\n" |
| 207 "a=mid:audio\r\n" |
| 208 "a=rtpmap:103 ISAC/16000\r\n"; |
| 209 |
| 210 static const char kSdpStringVideo[] = |
| 211 "m=video 1 RTP/AVPF 120\r\n" |
| 212 "a=mid:video\r\n" |
| 213 "a=rtpmap:120 VP8/90000\r\n"; |
| 214 |
| 215 static const char kSdpStringMs1Audio0[] = |
| 216 "a=ssrc:1 cname:stream1\r\n" |
| 217 "a=ssrc:1 msid:stream1 audiotrack0\r\n"; |
| 218 |
| 219 static const char kSdpStringMs1Video0[] = |
| 220 "a=ssrc:2 cname:stream1\r\n" |
| 221 "a=ssrc:2 msid:stream1 videotrack0\r\n"; |
| 222 |
| 223 static const char kSdpStringMs1Audio1[] = |
| 224 "a=ssrc:3 cname:stream1\r\n" |
| 225 "a=ssrc:3 msid:stream1 audiotrack1\r\n"; |
| 226 |
| 227 static const char kSdpStringMs1Video1[] = |
| 228 "a=ssrc:4 cname:stream1\r\n" |
| 229 "a=ssrc:4 msid:stream1 videotrack1\r\n"; |
| 230 |
63 #define MAYBE_SKIP_TEST(feature) \ | 231 #define MAYBE_SKIP_TEST(feature) \ |
64 if (!(feature())) { \ | 232 if (!(feature())) { \ |
65 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 233 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
66 return; \ | 234 return; \ |
67 } | 235 } |
68 | 236 |
69 using rtc::scoped_ptr; | 237 using rtc::scoped_ptr; |
70 using rtc::scoped_refptr; | 238 using rtc::scoped_refptr; |
71 using webrtc::AudioSourceInterface; | 239 using webrtc::AudioSourceInterface; |
| 240 using webrtc::AudioTrack; |
72 using webrtc::AudioTrackInterface; | 241 using webrtc::AudioTrackInterface; |
73 using webrtc::DataBuffer; | 242 using webrtc::DataBuffer; |
74 using webrtc::DataChannelInterface; | 243 using webrtc::DataChannelInterface; |
75 using webrtc::FakeConstraints; | 244 using webrtc::FakeConstraints; |
76 using webrtc::FakePortAllocatorFactory; | 245 using webrtc::FakePortAllocatorFactory; |
77 using webrtc::IceCandidateInterface; | 246 using webrtc::IceCandidateInterface; |
| 247 using webrtc::MediaStream; |
78 using webrtc::MediaStreamInterface; | 248 using webrtc::MediaStreamInterface; |
79 using webrtc::MediaStreamTrackInterface; | 249 using webrtc::MediaStreamTrackInterface; |
80 using webrtc::MockCreateSessionDescriptionObserver; | 250 using webrtc::MockCreateSessionDescriptionObserver; |
81 using webrtc::MockDataChannelObserver; | 251 using webrtc::MockDataChannelObserver; |
82 using webrtc::MockSetSessionDescriptionObserver; | 252 using webrtc::MockSetSessionDescriptionObserver; |
83 using webrtc::MockStatsObserver; | 253 using webrtc::MockStatsObserver; |
84 using webrtc::PeerConnectionInterface; | 254 using webrtc::PeerConnectionInterface; |
85 using webrtc::PeerConnectionObserver; | 255 using webrtc::PeerConnectionObserver; |
86 using webrtc::PortAllocatorFactoryInterface; | 256 using webrtc::PortAllocatorFactoryInterface; |
| 257 using webrtc::RtpReceiverInterface; |
| 258 using webrtc::RtpSenderInterface; |
87 using webrtc::SdpParseError; | 259 using webrtc::SdpParseError; |
88 using webrtc::SessionDescriptionInterface; | 260 using webrtc::SessionDescriptionInterface; |
| 261 using webrtc::StreamCollection; |
| 262 using webrtc::StreamCollectionInterface; |
89 using webrtc::VideoSourceInterface; | 263 using webrtc::VideoSourceInterface; |
| 264 using webrtc::VideoTrack; |
90 using webrtc::VideoTrackInterface; | 265 using webrtc::VideoTrackInterface; |
91 | 266 |
| 267 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 268 |
92 namespace { | 269 namespace { |
93 | 270 |
94 // Gets the first ssrc of given content type from the ContentInfo. | 271 // Gets the first ssrc of given content type from the ContentInfo. |
95 bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { | 272 bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { |
96 if (!content_info || !ssrc) { | 273 if (!content_info || !ssrc) { |
97 return false; | 274 return false; |
98 } | 275 } |
99 const cricket::MediaContentDescription* media_desc = | 276 const cricket::MediaContentDescription* media_desc = |
100 static_cast<const cricket::MediaContentDescription*>( | 277 static_cast<const cricket::MediaContentDescription*>( |
101 content_info->description); | 278 content_info->description); |
102 if (!media_desc || media_desc->streams().empty()) { | 279 if (!media_desc || media_desc->streams().empty()) { |
103 return false; | 280 return false; |
104 } | 281 } |
105 *ssrc = media_desc->streams().begin()->first_ssrc(); | 282 *ssrc = media_desc->streams().begin()->first_ssrc(); |
106 return true; | 283 return true; |
107 } | 284 } |
108 | 285 |
109 void SetSsrcToZero(std::string* sdp) { | 286 void SetSsrcToZero(std::string* sdp) { |
110 const char kSdpSsrcAtribute[] = "a=ssrc:"; | 287 const char kSdpSsrcAtribute[] = "a=ssrc:"; |
111 const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; | 288 const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; |
112 size_t ssrc_pos = 0; | 289 size_t ssrc_pos = 0; |
113 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != | 290 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != |
114 std::string::npos) { | 291 std::string::npos) { |
115 size_t end_ssrc = sdp->find(" ", ssrc_pos); | 292 size_t end_ssrc = sdp->find(" ", ssrc_pos); |
116 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); | 293 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); |
117 ssrc_pos = end_ssrc; | 294 ssrc_pos = end_ssrc; |
118 } | 295 } |
119 } | 296 } |
120 | 297 |
| 298 // Check if |streams| contains the specified track. |
| 299 bool ContainsTrack(const std::vector<cricket::StreamParams>& streams, |
| 300 const std::string& stream_label, |
| 301 const std::string& track_id) { |
| 302 for (const cricket::StreamParams& params : streams) { |
| 303 if (params.sync_label == stream_label && params.id == track_id) { |
| 304 return true; |
| 305 } |
| 306 } |
| 307 return false; |
| 308 } |
| 309 |
| 310 // Check if |senders| contains the specified sender, by id. |
| 311 bool ContainsSender( |
| 312 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 313 const std::string& id) { |
| 314 for (const auto& sender : senders) { |
| 315 if (sender->id() == id) { |
| 316 return true; |
| 317 } |
| 318 } |
| 319 return false; |
| 320 } |
| 321 |
| 322 // Create a collection of streams. |
| 323 // CreateStreamCollection(1) creates a collection that |
| 324 // correspond to kSdpStringWithStream1. |
| 325 // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. |
| 326 rtc::scoped_refptr<StreamCollection> CreateStreamCollection( |
| 327 int number_of_streams) { |
| 328 rtc::scoped_refptr<StreamCollection> local_collection( |
| 329 StreamCollection::Create()); |
| 330 |
| 331 for (int i = 0; i < number_of_streams; ++i) { |
| 332 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 333 webrtc::MediaStream::Create(kStreams[i])); |
| 334 |
| 335 // Add a local audio track. |
| 336 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 337 webrtc::AudioTrack::Create(kAudioTracks[i], nullptr)); |
| 338 stream->AddTrack(audio_track); |
| 339 |
| 340 // Add a local video track. |
| 341 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 342 webrtc::VideoTrack::Create(kVideoTracks[i], nullptr)); |
| 343 stream->AddTrack(video_track); |
| 344 |
| 345 local_collection->AddStream(stream); |
| 346 } |
| 347 return local_collection; |
| 348 } |
| 349 |
| 350 // Check equality of StreamCollections. |
| 351 bool CompareStreamCollections(StreamCollectionInterface* s1, |
| 352 StreamCollectionInterface* s2) { |
| 353 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { |
| 354 return false; |
| 355 } |
| 356 |
| 357 for (size_t i = 0; i != s1->count(); ++i) { |
| 358 if (s1->at(i)->label() != s2->at(i)->label()) { |
| 359 return false; |
| 360 } |
| 361 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks(); |
| 362 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks(); |
| 363 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks(); |
| 364 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks(); |
| 365 |
| 366 if (audio_tracks1.size() != audio_tracks2.size()) { |
| 367 return false; |
| 368 } |
| 369 for (size_t j = 0; j != audio_tracks1.size(); ++j) { |
| 370 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) { |
| 371 return false; |
| 372 } |
| 373 } |
| 374 if (video_tracks1.size() != video_tracks2.size()) { |
| 375 return false; |
| 376 } |
| 377 for (size_t j = 0; j != video_tracks1.size(); ++j) { |
| 378 if (video_tracks1[j]->id() != video_tracks2[j]->id()) { |
| 379 return false; |
| 380 } |
| 381 } |
| 382 } |
| 383 return true; |
| 384 } |
| 385 |
121 class MockPeerConnectionObserver : public PeerConnectionObserver { | 386 class MockPeerConnectionObserver : public PeerConnectionObserver { |
122 public: | 387 public: |
123 MockPeerConnectionObserver() | 388 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {} |
124 : renegotiation_needed_(false), | |
125 ice_complete_(false) { | |
126 } | |
127 ~MockPeerConnectionObserver() { | 389 ~MockPeerConnectionObserver() { |
128 } | 390 } |
129 void SetPeerConnectionInterface(PeerConnectionInterface* pc) { | 391 void SetPeerConnectionInterface(PeerConnectionInterface* pc) { |
130 pc_ = pc; | 392 pc_ = pc; |
131 if (pc) { | 393 if (pc) { |
132 state_ = pc_->signaling_state(); | 394 state_ = pc_->signaling_state(); |
133 } | 395 } |
134 } | 396 } |
135 virtual void OnSignalingChange( | 397 virtual void OnSignalingChange( |
136 PeerConnectionInterface::SignalingState new_state) { | 398 PeerConnectionInterface::SignalingState new_state) { |
(...skipping 13 matching lines...) Expand all Loading... |
150 EXPECT_EQ(pc_->signaling_state(), state_); | 412 EXPECT_EQ(pc_->signaling_state(), state_); |
151 break; | 413 break; |
152 case kIceState: | 414 case kIceState: |
153 ADD_FAILURE(); | 415 ADD_FAILURE(); |
154 break; | 416 break; |
155 default: | 417 default: |
156 ADD_FAILURE(); | 418 ADD_FAILURE(); |
157 break; | 419 break; |
158 } | 420 } |
159 } | 421 } |
| 422 |
| 423 MediaStreamInterface* RemoteStream(const std::string& label) { |
| 424 return remote_streams_->find(label); |
| 425 } |
| 426 StreamCollectionInterface* remote_streams() const { return remote_streams_; } |
160 virtual void OnAddStream(MediaStreamInterface* stream) { | 427 virtual void OnAddStream(MediaStreamInterface* stream) { |
161 last_added_stream_ = stream; | 428 last_added_stream_ = stream; |
| 429 remote_streams_->AddStream(stream); |
162 } | 430 } |
163 virtual void OnRemoveStream(MediaStreamInterface* stream) { | 431 virtual void OnRemoveStream(MediaStreamInterface* stream) { |
164 last_removed_stream_ = stream; | 432 last_removed_stream_ = stream; |
| 433 remote_streams_->RemoveStream(stream); |
165 } | 434 } |
166 virtual void OnRenegotiationNeeded() { | 435 virtual void OnRenegotiationNeeded() { |
167 renegotiation_needed_ = true; | 436 renegotiation_needed_ = true; |
168 } | 437 } |
169 virtual void OnDataChannel(DataChannelInterface* data_channel) { | 438 virtual void OnDataChannel(DataChannelInterface* data_channel) { |
170 last_datachannel_ = data_channel; | 439 last_datachannel_ = data_channel; |
171 } | 440 } |
172 | 441 |
173 virtual void OnIceConnectionChange( | 442 virtual void OnIceConnectionChange( |
174 PeerConnectionInterface::IceConnectionState new_state) { | 443 PeerConnectionInterface::IceConnectionState new_state) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 std::string GetLastRemovedStreamLabel() { | 478 std::string GetLastRemovedStreamLabel() { |
210 if (last_removed_stream_.get()) | 479 if (last_removed_stream_.get()) |
211 return last_removed_stream_->label(); | 480 return last_removed_stream_->label(); |
212 return ""; | 481 return ""; |
213 } | 482 } |
214 | 483 |
215 scoped_refptr<PeerConnectionInterface> pc_; | 484 scoped_refptr<PeerConnectionInterface> pc_; |
216 PeerConnectionInterface::SignalingState state_; | 485 PeerConnectionInterface::SignalingState state_; |
217 scoped_ptr<IceCandidateInterface> last_candidate_; | 486 scoped_ptr<IceCandidateInterface> last_candidate_; |
218 scoped_refptr<DataChannelInterface> last_datachannel_; | 487 scoped_refptr<DataChannelInterface> last_datachannel_; |
219 bool renegotiation_needed_; | 488 rtc::scoped_refptr<StreamCollection> remote_streams_; |
220 bool ice_complete_; | 489 bool renegotiation_needed_ = false; |
| 490 bool ice_complete_ = false; |
221 | 491 |
222 private: | 492 private: |
223 scoped_refptr<MediaStreamInterface> last_added_stream_; | 493 scoped_refptr<MediaStreamInterface> last_added_stream_; |
224 scoped_refptr<MediaStreamInterface> last_removed_stream_; | 494 scoped_refptr<MediaStreamInterface> last_removed_stream_; |
225 }; | 495 }; |
226 | 496 |
227 } // namespace | 497 } // namespace |
| 498 |
228 class PeerConnectionInterfaceTest : public testing::Test { | 499 class PeerConnectionInterfaceTest : public testing::Test { |
229 protected: | 500 protected: |
230 virtual void SetUp() { | 501 virtual void SetUp() { |
231 pc_factory_ = webrtc::CreatePeerConnectionFactory( | 502 pc_factory_ = webrtc::CreatePeerConnectionFactory( |
232 rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL, | 503 rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL, |
233 NULL); | 504 NULL); |
234 ASSERT_TRUE(pc_factory_.get() != NULL); | 505 ASSERT_TRUE(pc_factory_.get() != NULL); |
235 } | 506 } |
236 | 507 |
237 void CreatePeerConnection() { | 508 void CreatePeerConnection() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 port_allocator_factory_->turn_configs()[0].password); | 582 port_allocator_factory_->turn_configs()[0].password); |
312 EXPECT_EQ(kTurnHostname, | 583 EXPECT_EQ(kTurnHostname, |
313 port_allocator_factory_->turn_configs()[0].server.hostname()); | 584 port_allocator_factory_->turn_configs()[0].server.hostname()); |
314 } | 585 } |
315 | 586 |
316 void ReleasePeerConnection() { | 587 void ReleasePeerConnection() { |
317 pc_ = NULL; | 588 pc_ = NULL; |
318 observer_.SetPeerConnectionInterface(NULL); | 589 observer_.SetPeerConnectionInterface(NULL); |
319 } | 590 } |
320 | 591 |
321 void AddStream(const std::string& label) { | 592 void AddVideoStream(const std::string& label) { |
322 // Create a local stream. | 593 // Create a local stream. |
323 scoped_refptr<MediaStreamInterface> stream( | 594 scoped_refptr<MediaStreamInterface> stream( |
324 pc_factory_->CreateLocalMediaStream(label)); | 595 pc_factory_->CreateLocalMediaStream(label)); |
325 scoped_refptr<VideoSourceInterface> video_source( | 596 scoped_refptr<VideoSourceInterface> video_source( |
326 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL)); | 597 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL)); |
327 scoped_refptr<VideoTrackInterface> video_track( | 598 scoped_refptr<VideoTrackInterface> video_track( |
328 pc_factory_->CreateVideoTrack(label + "v0", video_source)); | 599 pc_factory_->CreateVideoTrack(label + "v0", video_source)); |
329 stream->AddTrack(video_track.get()); | 600 stream->AddTrack(video_track.get()); |
330 EXPECT_TRUE(pc_->AddStream(stream)); | 601 EXPECT_TRUE(pc_->AddStream(stream)); |
331 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | 602 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 ASSERT_TRUE(DoCreateOffer(offer.use())); | 715 ASSERT_TRUE(DoCreateOffer(offer.use())); |
445 std::string sdp; | 716 std::string sdp; |
446 EXPECT_TRUE(offer->ToString(&sdp)); | 717 EXPECT_TRUE(offer->ToString(&sdp)); |
447 SessionDescriptionInterface* remote_offer = | 718 SessionDescriptionInterface* remote_offer = |
448 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | 719 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
449 sdp, NULL); | 720 sdp, NULL); |
450 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | 721 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); |
451 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); | 722 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
452 } | 723 } |
453 | 724 |
| 725 void CreateAndSetRemoteOffer(const std::string& sdp) { |
| 726 SessionDescriptionInterface* remote_offer = |
| 727 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
| 728 sdp, nullptr); |
| 729 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); |
| 730 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 731 } |
| 732 |
454 void CreateAnswerAsLocalDescription() { | 733 void CreateAnswerAsLocalDescription() { |
455 scoped_ptr<SessionDescriptionInterface> answer; | 734 scoped_ptr<SessionDescriptionInterface> answer; |
456 ASSERT_TRUE(DoCreateAnswer(answer.use())); | 735 ASSERT_TRUE(DoCreateAnswer(answer.use())); |
457 | 736 |
458 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an | 737 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
459 // audio codec change, even if the parameter has nothing to do with | 738 // audio codec change, even if the parameter has nothing to do with |
460 // receiving. Not all parameters are serialized to SDP. | 739 // receiving. Not all parameters are serialized to SDP. |
461 // Since CreatePrAnswerAsLocalDescription serialize/deserialize | 740 // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
462 // the SessionDescription, it is necessary to do that here to in order to | 741 // the SessionDescription, it is necessary to do that here to in order to |
463 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. | 742 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 webrtc::CreateSessionDescription( | 786 webrtc::CreateSessionDescription( |
508 SessionDescriptionInterface::kOffer, | 787 SessionDescriptionInterface::kOffer, |
509 sdp, NULL); | 788 sdp, NULL); |
510 | 789 |
511 EXPECT_TRUE(DoSetLocalDescription(new_offer)); | 790 EXPECT_TRUE(DoSetLocalDescription(new_offer)); |
512 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); | 791 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); |
513 // Wait for the ice_complete message, so that SDP will have candidates. | 792 // Wait for the ice_complete message, so that SDP will have candidates. |
514 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); | 793 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); |
515 } | 794 } |
516 | 795 |
517 void CreateAnswerAsRemoteDescription(const std::string& offer) { | 796 void CreateAnswerAsRemoteDescription(const std::string& sdp) { |
518 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( | 797 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( |
519 SessionDescriptionInterface::kAnswer); | 798 SessionDescriptionInterface::kAnswer); |
520 EXPECT_TRUE(answer->Initialize(offer, NULL)); | 799 EXPECT_TRUE(answer->Initialize(sdp, NULL)); |
521 EXPECT_TRUE(DoSetRemoteDescription(answer)); | 800 EXPECT_TRUE(DoSetRemoteDescription(answer)); |
522 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | 801 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
523 } | 802 } |
524 | 803 |
525 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& offer) { | 804 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) { |
526 webrtc::JsepSessionDescription* pr_answer = | 805 webrtc::JsepSessionDescription* pr_answer = |
527 new webrtc::JsepSessionDescription( | 806 new webrtc::JsepSessionDescription( |
528 SessionDescriptionInterface::kPrAnswer); | 807 SessionDescriptionInterface::kPrAnswer); |
529 EXPECT_TRUE(pr_answer->Initialize(offer, NULL)); | 808 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL)); |
530 EXPECT_TRUE(DoSetRemoteDescription(pr_answer)); | 809 EXPECT_TRUE(DoSetRemoteDescription(pr_answer)); |
531 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); | 810 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); |
532 webrtc::JsepSessionDescription* answer = | 811 webrtc::JsepSessionDescription* answer = |
533 new webrtc::JsepSessionDescription( | 812 new webrtc::JsepSessionDescription( |
534 SessionDescriptionInterface::kAnswer); | 813 SessionDescriptionInterface::kAnswer); |
535 EXPECT_TRUE(answer->Initialize(offer, NULL)); | 814 EXPECT_TRUE(answer->Initialize(sdp, NULL)); |
536 EXPECT_TRUE(DoSetRemoteDescription(answer)); | 815 EXPECT_TRUE(DoSetRemoteDescription(answer)); |
537 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | 816 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
538 } | 817 } |
539 | 818 |
540 // Help function used for waiting until a the last signaled remote stream has | 819 // Help function used for waiting until a the last signaled remote stream has |
541 // the same label as |stream_label|. In a few of the tests in this file we | 820 // the same label as |stream_label|. In a few of the tests in this file we |
542 // answer with the same session description as we offer and thus we can | 821 // answer with the same session description as we offer and thus we can |
543 // check if OnAddStream have been called with the same stream as we offer to | 822 // check if OnAddStream have been called with the same stream as we offer to |
544 // send. | 823 // send. |
545 void WaitAndVerifyOnAddStream(const std::string& stream_label) { | 824 void WaitAndVerifyOnAddStream(const std::string& stream_label) { |
546 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout); | 825 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout); |
547 } | 826 } |
548 | 827 |
549 // Creates an offer and applies it as a local session description. | 828 // Creates an offer and applies it as a local session description. |
550 // Creates an answer with the same SDP an the offer but removes all lines | 829 // Creates an answer with the same SDP an the offer but removes all lines |
551 // that start with a:ssrc" | 830 // that start with a:ssrc" |
552 void CreateOfferReceiveAnswerWithoutSsrc() { | 831 void CreateOfferReceiveAnswerWithoutSsrc() { |
553 CreateOfferAsLocalDescription(); | 832 CreateOfferAsLocalDescription(); |
554 std::string sdp; | 833 std::string sdp; |
555 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | 834 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
556 SetSsrcToZero(&sdp); | 835 SetSsrcToZero(&sdp); |
557 CreateAnswerAsRemoteDescription(sdp); | 836 CreateAnswerAsRemoteDescription(sdp); |
558 } | 837 } |
559 | 838 |
| 839 // This function creates a MediaStream with label kStreams[0] and |
| 840 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the |
| 841 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface |
| 842 // is returned in |desc| and the MediaStream is stored in |
| 843 // |reference_collection_| |
| 844 void CreateSessionDescriptionAndReference( |
| 845 size_t number_of_audio_tracks, |
| 846 size_t number_of_video_tracks, |
| 847 SessionDescriptionInterface** desc) { |
| 848 ASSERT_TRUE(desc != nullptr); |
| 849 ASSERT_LE(number_of_audio_tracks, 2u); |
| 850 ASSERT_LE(number_of_video_tracks, 2u); |
| 851 |
| 852 reference_collection_ = StreamCollection::Create(); |
| 853 std::string sdp_ms1 = std::string(kSdpStringInit); |
| 854 |
| 855 std::string mediastream_label = kStreams[0]; |
| 856 |
| 857 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 858 webrtc::MediaStream::Create(mediastream_label)); |
| 859 reference_collection_->AddStream(stream); |
| 860 |
| 861 if (number_of_audio_tracks > 0) { |
| 862 sdp_ms1 += std::string(kSdpStringAudio); |
| 863 sdp_ms1 += std::string(kSdpStringMs1Audio0); |
| 864 AddAudioTrack(kAudioTracks[0], stream); |
| 865 } |
| 866 if (number_of_audio_tracks > 1) { |
| 867 sdp_ms1 += kSdpStringMs1Audio1; |
| 868 AddAudioTrack(kAudioTracks[1], stream); |
| 869 } |
| 870 |
| 871 if (number_of_video_tracks > 0) { |
| 872 sdp_ms1 += std::string(kSdpStringVideo); |
| 873 sdp_ms1 += std::string(kSdpStringMs1Video0); |
| 874 AddVideoTrack(kVideoTracks[0], stream); |
| 875 } |
| 876 if (number_of_video_tracks > 1) { |
| 877 sdp_ms1 += kSdpStringMs1Video1; |
| 878 AddVideoTrack(kVideoTracks[1], stream); |
| 879 } |
| 880 |
| 881 *desc = webrtc::CreateSessionDescription( |
| 882 SessionDescriptionInterface::kOffer, sdp_ms1, nullptr); |
| 883 } |
| 884 |
| 885 void AddAudioTrack(const std::string& track_id, |
| 886 MediaStreamInterface* stream) { |
| 887 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 888 webrtc::AudioTrack::Create(track_id, nullptr)); |
| 889 ASSERT_TRUE(stream->AddTrack(audio_track)); |
| 890 } |
| 891 |
| 892 void AddVideoTrack(const std::string& track_id, |
| 893 MediaStreamInterface* stream) { |
| 894 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 895 webrtc::VideoTrack::Create(track_id, nullptr)); |
| 896 ASSERT_TRUE(stream->AddTrack(video_track)); |
| 897 } |
| 898 |
560 scoped_refptr<FakePortAllocatorFactory> port_allocator_factory_; | 899 scoped_refptr<FakePortAllocatorFactory> port_allocator_factory_; |
561 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 900 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
562 scoped_refptr<PeerConnectionInterface> pc_; | 901 scoped_refptr<PeerConnectionInterface> pc_; |
563 MockPeerConnectionObserver observer_; | 902 MockPeerConnectionObserver observer_; |
| 903 rtc::scoped_refptr<StreamCollection> reference_collection_; |
564 }; | 904 }; |
565 | 905 |
566 TEST_F(PeerConnectionInterfaceTest, | 906 TEST_F(PeerConnectionInterfaceTest, |
567 CreatePeerConnectionWithDifferentConfigurations) { | 907 CreatePeerConnectionWithDifferentConfigurations) { |
568 CreatePeerConnectionWithDifferentConfigurations(); | 908 CreatePeerConnectionWithDifferentConfigurations(); |
569 } | 909 } |
570 | 910 |
571 TEST_F(PeerConnectionInterfaceTest, AddStreams) { | 911 TEST_F(PeerConnectionInterfaceTest, AddStreams) { |
572 CreatePeerConnection(); | 912 CreatePeerConnection(); |
573 AddStream(kStreamLabel1); | 913 AddVideoStream(kStreamLabel1); |
574 AddVoiceStream(kStreamLabel2); | 914 AddVoiceStream(kStreamLabel2); |
575 ASSERT_EQ(2u, pc_->local_streams()->count()); | 915 ASSERT_EQ(2u, pc_->local_streams()->count()); |
576 | 916 |
577 // Test we can add multiple local streams to one peerconnection. | 917 // Test we can add multiple local streams to one peerconnection. |
578 scoped_refptr<MediaStreamInterface> stream( | 918 scoped_refptr<MediaStreamInterface> stream( |
579 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); | 919 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); |
580 scoped_refptr<AudioTrackInterface> audio_track( | 920 scoped_refptr<AudioTrackInterface> audio_track( |
581 pc_factory_->CreateAudioTrack( | 921 pc_factory_->CreateAudioTrack( |
582 kStreamLabel3, static_cast<AudioSourceInterface*>(NULL))); | 922 kStreamLabel3, static_cast<AudioSourceInterface*>(NULL))); |
583 stream->AddTrack(audio_track.get()); | 923 stream->AddTrack(audio_track.get()); |
584 EXPECT_TRUE(pc_->AddStream(stream)); | 924 EXPECT_TRUE(pc_->AddStream(stream)); |
585 EXPECT_EQ(3u, pc_->local_streams()->count()); | 925 EXPECT_EQ(3u, pc_->local_streams()->count()); |
586 | 926 |
587 // Remove the third stream. | 927 // Remove the third stream. |
588 pc_->RemoveStream(pc_->local_streams()->at(2)); | 928 pc_->RemoveStream(pc_->local_streams()->at(2)); |
589 EXPECT_EQ(2u, pc_->local_streams()->count()); | 929 EXPECT_EQ(2u, pc_->local_streams()->count()); |
590 | 930 |
591 // Remove the second stream. | 931 // Remove the second stream. |
592 pc_->RemoveStream(pc_->local_streams()->at(1)); | 932 pc_->RemoveStream(pc_->local_streams()->at(1)); |
593 EXPECT_EQ(1u, pc_->local_streams()->count()); | 933 EXPECT_EQ(1u, pc_->local_streams()->count()); |
594 | 934 |
595 // Remove the first stream. | 935 // Remove the first stream. |
596 pc_->RemoveStream(pc_->local_streams()->at(0)); | 936 pc_->RemoveStream(pc_->local_streams()->at(0)); |
597 EXPECT_EQ(0u, pc_->local_streams()->count()); | 937 EXPECT_EQ(0u, pc_->local_streams()->count()); |
598 } | 938 } |
599 | 939 |
| 940 // Test that the created offer includes streams we added. |
| 941 TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) { |
| 942 CreatePeerConnection(); |
| 943 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track"); |
| 944 scoped_ptr<SessionDescriptionInterface> offer; |
| 945 ASSERT_TRUE(DoCreateOffer(offer.accept())); |
| 946 |
| 947 const cricket::ContentInfo* audio_content = |
| 948 cricket::GetFirstAudioContent(offer->description()); |
| 949 const cricket::AudioContentDescription* audio_desc = |
| 950 static_cast<const cricket::AudioContentDescription*>( |
| 951 audio_content->description); |
| 952 EXPECT_TRUE( |
| 953 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); |
| 954 |
| 955 const cricket::ContentInfo* video_content = |
| 956 cricket::GetFirstVideoContent(offer->description()); |
| 957 const cricket::VideoContentDescription* video_desc = |
| 958 static_cast<const cricket::VideoContentDescription*>( |
| 959 video_content->description); |
| 960 EXPECT_TRUE( |
| 961 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); |
| 962 |
| 963 // Add another stream and ensure the offer includes both the old and new |
| 964 // streams. |
| 965 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2"); |
| 966 ASSERT_TRUE(DoCreateOffer(offer.accept())); |
| 967 |
| 968 audio_content = cricket::GetFirstAudioContent(offer->description()); |
| 969 audio_desc = static_cast<const cricket::AudioContentDescription*>( |
| 970 audio_content->description); |
| 971 EXPECT_TRUE( |
| 972 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); |
| 973 EXPECT_TRUE( |
| 974 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2")); |
| 975 |
| 976 video_content = cricket::GetFirstVideoContent(offer->description()); |
| 977 video_desc = static_cast<const cricket::VideoContentDescription*>( |
| 978 video_content->description); |
| 979 EXPECT_TRUE( |
| 980 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); |
| 981 EXPECT_TRUE( |
| 982 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2")); |
| 983 } |
| 984 |
600 TEST_F(PeerConnectionInterfaceTest, RemoveStream) { | 985 TEST_F(PeerConnectionInterfaceTest, RemoveStream) { |
601 CreatePeerConnection(); | 986 CreatePeerConnection(); |
602 AddStream(kStreamLabel1); | 987 AddVideoStream(kStreamLabel1); |
603 ASSERT_EQ(1u, pc_->local_streams()->count()); | 988 ASSERT_EQ(1u, pc_->local_streams()->count()); |
604 pc_->RemoveStream(pc_->local_streams()->at(0)); | 989 pc_->RemoveStream(pc_->local_streams()->at(0)); |
605 EXPECT_EQ(0u, pc_->local_streams()->count()); | 990 EXPECT_EQ(0u, pc_->local_streams()->count()); |
606 } | 991 } |
607 | 992 |
608 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { | 993 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { |
609 InitiateCall(); | 994 InitiateCall(); |
610 WaitAndVerifyOnAddStream(kStreamLabel1); | 995 WaitAndVerifyOnAddStream(kStreamLabel1); |
611 VerifyRemoteRtpHeaderExtensions(); | 996 VerifyRemoteRtpHeaderExtensions(); |
612 } | 997 } |
613 | 998 |
614 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { | 999 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { |
615 CreatePeerConnection(); | 1000 CreatePeerConnection(); |
616 AddStream(kStreamLabel1); | 1001 AddVideoStream(kStreamLabel1); |
617 CreateOfferAsLocalDescription(); | 1002 CreateOfferAsLocalDescription(); |
618 std::string offer; | 1003 std::string offer; |
619 EXPECT_TRUE(pc_->local_description()->ToString(&offer)); | 1004 EXPECT_TRUE(pc_->local_description()->ToString(&offer)); |
620 CreatePrAnswerAndAnswerAsRemoteDescription(offer); | 1005 CreatePrAnswerAndAnswerAsRemoteDescription(offer); |
621 WaitAndVerifyOnAddStream(kStreamLabel1); | 1006 WaitAndVerifyOnAddStream(kStreamLabel1); |
622 } | 1007 } |
623 | 1008 |
624 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { | 1009 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { |
625 CreatePeerConnection(); | 1010 CreatePeerConnection(); |
626 AddStream(kStreamLabel1); | 1011 AddVideoStream(kStreamLabel1); |
627 | 1012 |
628 CreateOfferAsRemoteDescription(); | 1013 CreateOfferAsRemoteDescription(); |
629 CreateAnswerAsLocalDescription(); | 1014 CreateAnswerAsLocalDescription(); |
630 | 1015 |
631 WaitAndVerifyOnAddStream(kStreamLabel1); | 1016 WaitAndVerifyOnAddStream(kStreamLabel1); |
632 } | 1017 } |
633 | 1018 |
634 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { | 1019 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { |
635 CreatePeerConnection(); | 1020 CreatePeerConnection(); |
636 AddStream(kStreamLabel1); | 1021 AddVideoStream(kStreamLabel1); |
637 | 1022 |
638 CreateOfferAsRemoteDescription(); | 1023 CreateOfferAsRemoteDescription(); |
639 CreatePrAnswerAsLocalDescription(); | 1024 CreatePrAnswerAsLocalDescription(); |
640 CreateAnswerAsLocalDescription(); | 1025 CreateAnswerAsLocalDescription(); |
641 | 1026 |
642 WaitAndVerifyOnAddStream(kStreamLabel1); | 1027 WaitAndVerifyOnAddStream(kStreamLabel1); |
643 } | 1028 } |
644 | 1029 |
645 TEST_F(PeerConnectionInterfaceTest, Renegotiate) { | 1030 TEST_F(PeerConnectionInterfaceTest, Renegotiate) { |
646 InitiateCall(); | 1031 InitiateCall(); |
647 ASSERT_EQ(1u, pc_->remote_streams()->count()); | 1032 ASSERT_EQ(1u, pc_->remote_streams()->count()); |
648 pc_->RemoveStream(pc_->local_streams()->at(0)); | 1033 pc_->RemoveStream(pc_->local_streams()->at(0)); |
649 CreateOfferReceiveAnswer(); | 1034 CreateOfferReceiveAnswer(); |
650 EXPECT_EQ(0u, pc_->remote_streams()->count()); | 1035 EXPECT_EQ(0u, pc_->remote_streams()->count()); |
651 AddStream(kStreamLabel1); | 1036 AddVideoStream(kStreamLabel1); |
652 CreateOfferReceiveAnswer(); | 1037 CreateOfferReceiveAnswer(); |
653 } | 1038 } |
654 | 1039 |
655 // Tests that after negotiating an audio only call, the respondent can perform a | 1040 // Tests that after negotiating an audio only call, the respondent can perform a |
656 // renegotiation that removes the audio stream. | 1041 // renegotiation that removes the audio stream. |
657 TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) { | 1042 TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) { |
658 CreatePeerConnection(); | 1043 CreatePeerConnection(); |
659 AddVoiceStream(kStreamLabel1); | 1044 AddVoiceStream(kStreamLabel1); |
660 CreateOfferAsRemoteDescription(); | 1045 CreateOfferAsRemoteDescription(); |
661 CreateAnswerAsLocalDescription(); | 1046 CreateAnswerAsLocalDescription(); |
662 | 1047 |
663 ASSERT_EQ(1u, pc_->remote_streams()->count()); | 1048 ASSERT_EQ(1u, pc_->remote_streams()->count()); |
664 pc_->RemoveStream(pc_->local_streams()->at(0)); | 1049 pc_->RemoveStream(pc_->local_streams()->at(0)); |
665 CreateOfferReceiveAnswer(); | 1050 CreateOfferReceiveAnswer(); |
666 EXPECT_EQ(0u, pc_->remote_streams()->count()); | 1051 EXPECT_EQ(0u, pc_->remote_streams()->count()); |
667 } | 1052 } |
668 | 1053 |
669 // Test that candidates are generated and that we can parse our own candidates. | 1054 // Test that candidates are generated and that we can parse our own candidates. |
670 TEST_F(PeerConnectionInterfaceTest, IceCandidates) { | 1055 TEST_F(PeerConnectionInterfaceTest, IceCandidates) { |
671 CreatePeerConnection(); | 1056 CreatePeerConnection(); |
672 | 1057 |
673 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get())); | 1058 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get())); |
674 // SetRemoteDescription takes ownership of offer. | 1059 // SetRemoteDescription takes ownership of offer. |
675 SessionDescriptionInterface* offer = NULL; | 1060 SessionDescriptionInterface* offer = NULL; |
676 AddStream(kStreamLabel1); | 1061 AddVideoStream(kStreamLabel1); |
677 EXPECT_TRUE(DoCreateOffer(&offer)); | 1062 EXPECT_TRUE(DoCreateOffer(&offer)); |
678 EXPECT_TRUE(DoSetRemoteDescription(offer)); | 1063 EXPECT_TRUE(DoSetRemoteDescription(offer)); |
679 | 1064 |
680 // SetLocalDescription takes ownership of answer. | 1065 // SetLocalDescription takes ownership of answer. |
681 SessionDescriptionInterface* answer = NULL; | 1066 SessionDescriptionInterface* answer = NULL; |
682 EXPECT_TRUE(DoCreateAnswer(&answer)); | 1067 EXPECT_TRUE(DoCreateAnswer(&answer)); |
683 EXPECT_TRUE(DoSetLocalDescription(answer)); | 1068 EXPECT_TRUE(DoSetLocalDescription(answer)); |
684 | 1069 |
685 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout); | 1070 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout); |
686 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); | 1071 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); |
687 | 1072 |
688 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get())); | 1073 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get())); |
689 } | 1074 } |
690 | 1075 |
691 // Test that the CreateOffer and CreatAnswer will fail if the track labels are | 1076 // Test that CreateOffer and CreateAnswer will fail if the track labels are |
692 // not unique. | 1077 // not unique. |
693 TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) { | 1078 TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) { |
694 CreatePeerConnection(); | 1079 CreatePeerConnection(); |
695 // Create a regular offer for the CreateAnswer test later. | 1080 // Create a regular offer for the CreateAnswer test later. |
696 SessionDescriptionInterface* offer = NULL; | 1081 SessionDescriptionInterface* offer = NULL; |
697 EXPECT_TRUE(DoCreateOffer(&offer)); | 1082 EXPECT_TRUE(DoCreateOffer(&offer)); |
698 EXPECT_TRUE(offer != NULL); | 1083 EXPECT_TRUE(offer != NULL); |
699 delete offer; | 1084 delete offer; |
700 offer = NULL; | 1085 offer = NULL; |
701 | 1086 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 CreatePeerConnection(&constraints); | 1316 CreatePeerConnection(&constraints); |
932 | 1317 |
933 std::string label = "test"; | 1318 std::string label = "test"; |
934 webrtc::DataChannelInit config; | 1319 webrtc::DataChannelInit config; |
935 config.reliable = true; | 1320 config.reliable = true; |
936 scoped_refptr<DataChannelInterface> channel = | 1321 scoped_refptr<DataChannelInterface> channel = |
937 pc_->CreateDataChannel(label, &config); | 1322 pc_->CreateDataChannel(label, &config); |
938 EXPECT_TRUE(channel == NULL); | 1323 EXPECT_TRUE(channel == NULL); |
939 } | 1324 } |
940 | 1325 |
| 1326 // Verifies that duplicated label is not allowed for RTP data channel. |
| 1327 TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) { |
| 1328 FakeConstraints constraints; |
| 1329 constraints.SetAllowRtpDataChannels(); |
| 1330 CreatePeerConnection(&constraints); |
| 1331 |
| 1332 std::string label = "test"; |
| 1333 scoped_refptr<DataChannelInterface> channel = |
| 1334 pc_->CreateDataChannel(label, nullptr); |
| 1335 EXPECT_NE(channel, nullptr); |
| 1336 |
| 1337 scoped_refptr<DataChannelInterface> dup_channel = |
| 1338 pc_->CreateDataChannel(label, nullptr); |
| 1339 EXPECT_EQ(dup_channel, nullptr); |
| 1340 } |
| 1341 |
941 // This tests that a SCTP data channel is returned using different | 1342 // This tests that a SCTP data channel is returned using different |
942 // DataChannelInit configurations. | 1343 // DataChannelInit configurations. |
943 TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) { | 1344 TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) { |
944 FakeConstraints constraints; | 1345 FakeConstraints constraints; |
945 constraints.SetAllowDtlsSctpDataChannels(); | 1346 constraints.SetAllowDtlsSctpDataChannels(); |
946 CreatePeerConnection(&constraints); | 1347 CreatePeerConnection(&constraints); |
947 | 1348 |
948 webrtc::DataChannelInit config; | 1349 webrtc::DataChannelInit config; |
949 | 1350 |
950 scoped_refptr<DataChannelInterface> channel = | 1351 scoped_refptr<DataChannelInterface> channel = |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 config.id = cricket::kMaxSctpSid; | 1416 config.id = cricket::kMaxSctpSid; |
1016 channel = pc_->CreateDataChannel("max", &config); | 1417 channel = pc_->CreateDataChannel("max", &config); |
1017 EXPECT_TRUE(channel != NULL); | 1418 EXPECT_TRUE(channel != NULL); |
1018 EXPECT_EQ(config.id, channel->id()); | 1419 EXPECT_EQ(config.id, channel->id()); |
1019 | 1420 |
1020 config.id = cricket::kMaxSctpSid + 1; | 1421 config.id = cricket::kMaxSctpSid + 1; |
1021 channel = pc_->CreateDataChannel("x", &config); | 1422 channel = pc_->CreateDataChannel("x", &config); |
1022 EXPECT_TRUE(channel == NULL); | 1423 EXPECT_TRUE(channel == NULL); |
1023 } | 1424 } |
1024 | 1425 |
| 1426 // Verifies that duplicated label is allowed for SCTP data channel. |
| 1427 TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { |
| 1428 FakeConstraints constraints; |
| 1429 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1430 true); |
| 1431 CreatePeerConnection(&constraints); |
| 1432 |
| 1433 std::string label = "test"; |
| 1434 scoped_refptr<DataChannelInterface> channel = |
| 1435 pc_->CreateDataChannel(label, nullptr); |
| 1436 EXPECT_NE(channel, nullptr); |
| 1437 |
| 1438 scoped_refptr<DataChannelInterface> dup_channel = |
| 1439 pc_->CreateDataChannel(label, nullptr); |
| 1440 EXPECT_NE(dup_channel, nullptr); |
| 1441 } |
| 1442 |
1025 // This test verifies that OnRenegotiationNeeded is fired for every new RTP | 1443 // This test verifies that OnRenegotiationNeeded is fired for every new RTP |
1026 // DataChannel. | 1444 // DataChannel. |
1027 TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { | 1445 TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { |
1028 FakeConstraints constraints; | 1446 FakeConstraints constraints; |
1029 constraints.SetAllowRtpDataChannels(); | 1447 constraints.SetAllowRtpDataChannels(); |
1030 CreatePeerConnection(&constraints); | 1448 CreatePeerConnection(&constraints); |
1031 | 1449 |
1032 scoped_refptr<DataChannelInterface> dc1 = | 1450 scoped_refptr<DataChannelInterface> dc1 = |
1033 pc_->CreateDataChannel("test1", NULL); | 1451 pc_->CreateDataChannel("test1", NULL); |
1034 EXPECT_TRUE(observer_.renegotiation_needed_); | 1452 EXPECT_TRUE(observer_.renegotiation_needed_); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 sdp, NULL); | 1636 sdp, NULL); |
1219 EXPECT_FALSE(DoSetLocalDescription(local_offer)); | 1637 EXPECT_FALSE(DoSetLocalDescription(local_offer)); |
1220 } | 1638 } |
1221 | 1639 |
1222 // Test that GetStats can still be called after PeerConnection::Close. | 1640 // Test that GetStats can still be called after PeerConnection::Close. |
1223 TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) { | 1641 TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) { |
1224 InitiateCall(); | 1642 InitiateCall(); |
1225 pc_->Close(); | 1643 pc_->Close(); |
1226 DoGetStats(NULL); | 1644 DoGetStats(NULL); |
1227 } | 1645 } |
| 1646 |
| 1647 // NOTE: The series of tests below come from what used to be |
| 1648 // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that |
| 1649 // setting a remote or local description has the expected effects. |
| 1650 |
| 1651 // This test verifies that the remote MediaStreams corresponding to a received |
| 1652 // SDP string is created. In this test the two separate MediaStreams are |
| 1653 // signaled. |
| 1654 TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) { |
| 1655 FakeConstraints constraints; |
| 1656 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1657 true); |
| 1658 CreatePeerConnection(&constraints); |
| 1659 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1660 |
| 1661 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1)); |
| 1662 EXPECT_TRUE( |
| 1663 CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 1664 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1665 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); |
| 1666 |
| 1667 // Create a session description based on another SDP with another |
| 1668 // MediaStream. |
| 1669 CreateAndSetRemoteOffer(kSdpStringWithStream1And2); |
| 1670 |
| 1671 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2)); |
| 1672 EXPECT_TRUE( |
| 1673 CompareStreamCollections(observer_.remote_streams(), reference2.get())); |
| 1674 } |
| 1675 |
| 1676 // This test verifies that when remote tracks are added/removed from SDP, the |
| 1677 // created remote streams are updated appropriately. |
| 1678 TEST_F(PeerConnectionInterfaceTest, |
| 1679 AddRemoveTrackFromExistingRemoteMediaStream) { |
| 1680 FakeConstraints constraints; |
| 1681 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1682 true); |
| 1683 CreatePeerConnection(&constraints); |
| 1684 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1; |
| 1685 CreateSessionDescriptionAndReference(1, 1, desc_ms1.accept()); |
| 1686 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release())); |
| 1687 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 1688 reference_collection_)); |
| 1689 |
| 1690 // Add extra audio and video tracks to the same MediaStream. |
| 1691 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks; |
| 1692 CreateSessionDescriptionAndReference(2, 2, desc_ms1_two_tracks.accept()); |
| 1693 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release())); |
| 1694 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 1695 reference_collection_)); |
| 1696 |
| 1697 // Remove the extra audio and video tracks. |
| 1698 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2; |
| 1699 CreateSessionDescriptionAndReference(1, 1, desc_ms2.accept()); |
| 1700 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release())); |
| 1701 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 1702 reference_collection_)); |
| 1703 } |
| 1704 |
| 1705 // This tests that remote tracks are ended if a local session description is set |
| 1706 // that rejects the media content type. |
| 1707 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) { |
| 1708 FakeConstraints constraints; |
| 1709 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1710 true); |
| 1711 CreatePeerConnection(&constraints); |
| 1712 // First create and set a remote offer, then reject its video content in our |
| 1713 // answer. |
| 1714 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1715 ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 1716 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1717 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 1718 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 1719 |
| 1720 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video = |
| 1721 remote_stream->GetVideoTracks()[0]; |
| 1722 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state()); |
| 1723 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio = |
| 1724 remote_stream->GetAudioTracks()[0]; |
| 1725 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
| 1726 |
| 1727 rtc::scoped_ptr<SessionDescriptionInterface> local_answer; |
| 1728 EXPECT_TRUE(DoCreateAnswer(local_answer.accept())); |
| 1729 cricket::ContentInfo* video_info = |
| 1730 local_answer->description()->GetContentByName("video"); |
| 1731 video_info->rejected = true; |
| 1732 EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); |
| 1733 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 1734 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
| 1735 |
| 1736 // Now create an offer where we reject both video and audio. |
| 1737 rtc::scoped_ptr<SessionDescriptionInterface> local_offer; |
| 1738 EXPECT_TRUE(DoCreateOffer(local_offer.accept())); |
| 1739 video_info = local_offer->description()->GetContentByName("video"); |
| 1740 ASSERT_TRUE(video_info != nullptr); |
| 1741 video_info->rejected = true; |
| 1742 cricket::ContentInfo* audio_info = |
| 1743 local_offer->description()->GetContentByName("audio"); |
| 1744 ASSERT_TRUE(audio_info != nullptr); |
| 1745 audio_info->rejected = true; |
| 1746 EXPECT_TRUE(DoSetLocalDescription(local_offer.release())); |
| 1747 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 1748 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_audio->state()); |
| 1749 } |
| 1750 |
| 1751 // This tests that we won't crash if the remote track has been removed outside |
| 1752 // of PeerConnection and then PeerConnection tries to reject the track. |
| 1753 TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) { |
| 1754 FakeConstraints constraints; |
| 1755 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1756 true); |
| 1757 CreatePeerConnection(&constraints); |
| 1758 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1759 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1760 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 1761 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 1762 |
| 1763 rtc::scoped_ptr<SessionDescriptionInterface> local_answer( |
| 1764 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, |
| 1765 kSdpStringWithStream1, nullptr)); |
| 1766 cricket::ContentInfo* video_info = |
| 1767 local_answer->description()->GetContentByName("video"); |
| 1768 video_info->rejected = true; |
| 1769 cricket::ContentInfo* audio_info = |
| 1770 local_answer->description()->GetContentByName("audio"); |
| 1771 audio_info->rejected = true; |
| 1772 EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); |
| 1773 |
| 1774 // No crash is a pass. |
| 1775 } |
| 1776 |
| 1777 // This tests that a default MediaStream is created if a remote session |
| 1778 // description doesn't contain any streams and no MSID support. |
| 1779 // It also tests that the default stream is updated if a video m-line is added |
| 1780 // in a subsequent session description. |
| 1781 TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) { |
| 1782 FakeConstraints constraints; |
| 1783 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1784 true); |
| 1785 CreatePeerConnection(&constraints); |
| 1786 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 1787 |
| 1788 ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 1789 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1790 |
| 1791 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 1792 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); |
| 1793 EXPECT_EQ("default", remote_stream->label()); |
| 1794 |
| 1795 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 1796 ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 1797 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 1798 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); |
| 1799 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 1800 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); |
| 1801 } |
| 1802 |
| 1803 // This tests that a default MediaStream is created if a remote session |
| 1804 // description doesn't contain any streams and media direction is send only. |
| 1805 TEST_F(PeerConnectionInterfaceTest, |
| 1806 SendOnlySdpWithoutMsidCreatesDefaultStream) { |
| 1807 FakeConstraints constraints; |
| 1808 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1809 true); |
| 1810 CreatePeerConnection(&constraints); |
| 1811 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); |
| 1812 |
| 1813 ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 1814 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1815 |
| 1816 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 1817 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 1818 EXPECT_EQ("default", remote_stream->label()); |
| 1819 } |
| 1820 |
| 1821 // This tests that it won't crash when PeerConnection tries to remove |
| 1822 // a remote track that as already been removed from the MediaStream. |
| 1823 TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) { |
| 1824 FakeConstraints constraints; |
| 1825 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1826 true); |
| 1827 CreatePeerConnection(&constraints); |
| 1828 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1829 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1830 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 1831 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 1832 |
| 1833 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 1834 |
| 1835 // No crash is a pass. |
| 1836 } |
| 1837 |
| 1838 // This tests that a default MediaStream is created if the remote session |
| 1839 // description doesn't contain any streams and don't contain an indication if |
| 1840 // MSID is supported. |
| 1841 TEST_F(PeerConnectionInterfaceTest, |
| 1842 SdpWithoutMsidAndStreamsCreatesDefaultStream) { |
| 1843 FakeConstraints constraints; |
| 1844 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1845 true); |
| 1846 CreatePeerConnection(&constraints); |
| 1847 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 1848 |
| 1849 ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 1850 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1851 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 1852 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 1853 } |
| 1854 |
| 1855 // This tests that a default MediaStream is not created if the remote session |
| 1856 // description doesn't contain any streams but does support MSID. |
| 1857 TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) { |
| 1858 FakeConstraints constraints; |
| 1859 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1860 true); |
| 1861 CreatePeerConnection(&constraints); |
| 1862 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); |
| 1863 EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 1864 } |
| 1865 |
| 1866 // This tests that a default MediaStream is not created if a remote session |
| 1867 // description is updated to not have any MediaStreams. |
| 1868 TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) { |
| 1869 FakeConstraints constraints; |
| 1870 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1871 true); |
| 1872 CreatePeerConnection(&constraints); |
| 1873 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1874 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1)); |
| 1875 EXPECT_TRUE( |
| 1876 CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 1877 |
| 1878 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 1879 EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 1880 } |
| 1881 |
| 1882 // This tests that an RtpSender is created when the local description is set |
| 1883 // after adding a local stream. |
| 1884 // TODO(deadbeef): This test and the one below it need to be updated when |
| 1885 // an RtpSender's lifetime isn't determined by when a local description is set. |
| 1886 TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) { |
| 1887 FakeConstraints constraints; |
| 1888 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1889 true); |
| 1890 CreatePeerConnection(&constraints); |
| 1891 // Create an offer just to ensure we have an identity before we manually |
| 1892 // call SetLocalDescription. |
| 1893 rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
| 1894 ASSERT_TRUE(DoCreateOffer(throwaway.accept())); |
| 1895 |
| 1896 rtc::scoped_ptr<SessionDescriptionInterface> desc_1; |
| 1897 CreateSessionDescriptionAndReference(2, 2, desc_1.accept()); |
| 1898 |
| 1899 pc_->AddStream(reference_collection_->at(0)); |
| 1900 EXPECT_TRUE(DoSetLocalDescription(desc_1.release())); |
| 1901 auto senders = pc_->GetSenders(); |
| 1902 EXPECT_EQ(4u, senders.size()); |
| 1903 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 1904 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 1905 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 1906 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 1907 |
| 1908 // Remove an audio and video track. |
| 1909 rtc::scoped_ptr<SessionDescriptionInterface> desc_2; |
| 1910 CreateSessionDescriptionAndReference(1, 1, desc_2.accept()); |
| 1911 EXPECT_TRUE(DoSetLocalDescription(desc_2.release())); |
| 1912 senders = pc_->GetSenders(); |
| 1913 EXPECT_EQ(2u, senders.size()); |
| 1914 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 1915 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 1916 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); |
| 1917 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); |
| 1918 } |
| 1919 |
| 1920 // This tests that an RtpSender is created when the local description is set |
| 1921 // before adding a local stream. |
| 1922 TEST_F(PeerConnectionInterfaceTest, |
| 1923 AddLocalStreamAfterLocalDescriptionChanged) { |
| 1924 FakeConstraints constraints; |
| 1925 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1926 true); |
| 1927 CreatePeerConnection(&constraints); |
| 1928 // Create an offer just to ensure we have an identity before we manually |
| 1929 // call SetLocalDescription. |
| 1930 rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
| 1931 ASSERT_TRUE(DoCreateOffer(throwaway.accept())); |
| 1932 |
| 1933 rtc::scoped_ptr<SessionDescriptionInterface> desc_1; |
| 1934 CreateSessionDescriptionAndReference(2, 2, desc_1.accept()); |
| 1935 |
| 1936 EXPECT_TRUE(DoSetLocalDescription(desc_1.release())); |
| 1937 auto senders = pc_->GetSenders(); |
| 1938 EXPECT_EQ(0u, senders.size()); |
| 1939 |
| 1940 pc_->AddStream(reference_collection_->at(0)); |
| 1941 senders = pc_->GetSenders(); |
| 1942 EXPECT_EQ(4u, senders.size()); |
| 1943 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 1944 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 1945 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 1946 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 1947 } |
| 1948 |
| 1949 // This tests that the expected behavior occurs if the SSRC on a local track is |
| 1950 // changed when SetLocalDescription is called. |
| 1951 TEST_F(PeerConnectionInterfaceTest, |
| 1952 ChangeSsrcOnTrackInLocalSessionDescription) { |
| 1953 FakeConstraints constraints; |
| 1954 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1955 true); |
| 1956 CreatePeerConnection(&constraints); |
| 1957 // Create an offer just to ensure we have an identity before we manually |
| 1958 // call SetLocalDescription. |
| 1959 rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
| 1960 ASSERT_TRUE(DoCreateOffer(throwaway.accept())); |
| 1961 |
| 1962 rtc::scoped_ptr<SessionDescriptionInterface> desc; |
| 1963 CreateSessionDescriptionAndReference(1, 1, desc.accept()); |
| 1964 std::string sdp; |
| 1965 desc->ToString(&sdp); |
| 1966 |
| 1967 pc_->AddStream(reference_collection_->at(0)); |
| 1968 EXPECT_TRUE(DoSetLocalDescription(desc.release())); |
| 1969 auto senders = pc_->GetSenders(); |
| 1970 EXPECT_EQ(2u, senders.size()); |
| 1971 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 1972 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 1973 |
| 1974 // Change the ssrc of the audio and video track. |
| 1975 std::string ssrc_org = "a=ssrc:1"; |
| 1976 std::string ssrc_to = "a=ssrc:97"; |
| 1977 rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(), |
| 1978 ssrc_to.length(), &sdp); |
| 1979 ssrc_org = "a=ssrc:2"; |
| 1980 ssrc_to = "a=ssrc:98"; |
| 1981 rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(), |
| 1982 ssrc_to.length(), &sdp); |
| 1983 rtc::scoped_ptr<SessionDescriptionInterface> updated_desc( |
| 1984 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp, |
| 1985 nullptr)); |
| 1986 |
| 1987 EXPECT_TRUE(DoSetLocalDescription(updated_desc.release())); |
| 1988 senders = pc_->GetSenders(); |
| 1989 EXPECT_EQ(2u, senders.size()); |
| 1990 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 1991 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 1992 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC |
| 1993 // changed. |
| 1994 } |
| 1995 |
| 1996 // This tests that the expected behavior occurs if a new session description is |
| 1997 // set with the same tracks, but on a different MediaStream. |
| 1998 TEST_F(PeerConnectionInterfaceTest, SignalSameTracksInSeparateMediaStream) { |
| 1999 FakeConstraints constraints; |
| 2000 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2001 true); |
| 2002 CreatePeerConnection(&constraints); |
| 2003 // Create an offer just to ensure we have an identity before we manually |
| 2004 // call SetLocalDescription. |
| 2005 rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
| 2006 ASSERT_TRUE(DoCreateOffer(throwaway.accept())); |
| 2007 |
| 2008 rtc::scoped_ptr<SessionDescriptionInterface> desc; |
| 2009 CreateSessionDescriptionAndReference(1, 1, desc.accept()); |
| 2010 std::string sdp; |
| 2011 desc->ToString(&sdp); |
| 2012 |
| 2013 pc_->AddStream(reference_collection_->at(0)); |
| 2014 EXPECT_TRUE(DoSetLocalDescription(desc.release())); |
| 2015 auto senders = pc_->GetSenders(); |
| 2016 EXPECT_EQ(2u, senders.size()); |
| 2017 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2018 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2019 |
| 2020 // Add a new MediaStream but with the same tracks as in the first stream. |
| 2021 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( |
| 2022 webrtc::MediaStream::Create(kStreams[1])); |
| 2023 stream_1->AddTrack(reference_collection_->at(0)->GetVideoTracks()[0]); |
| 2024 stream_1->AddTrack(reference_collection_->at(0)->GetAudioTracks()[0]); |
| 2025 pc_->AddStream(stream_1); |
| 2026 |
| 2027 // Replace msid in the original SDP. |
| 2028 rtc::replace_substrs(kStreams[0], strlen(kStreams[0]), kStreams[1], |
| 2029 strlen(kStreams[1]), &sdp); |
| 2030 |
| 2031 rtc::scoped_ptr<SessionDescriptionInterface> updated_desc( |
| 2032 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp, |
| 2033 nullptr)); |
| 2034 |
| 2035 EXPECT_TRUE(DoSetLocalDescription(updated_desc.release())); |
| 2036 senders = pc_->GetSenders(); |
| 2037 EXPECT_EQ(2u, senders.size()); |
| 2038 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2039 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2040 } |
| 2041 |
| 2042 // The following tests verify that session options are created correctly. |
| 2043 |
| 2044 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) { |
| 2045 RTCOfferAnswerOptions rtc_options; |
| 2046 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; |
| 2047 |
| 2048 cricket::MediaSessionOptions options; |
| 2049 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2050 |
| 2051 rtc_options.offer_to_receive_audio = |
| 2052 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 2053 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2054 } |
| 2055 |
| 2056 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) { |
| 2057 RTCOfferAnswerOptions rtc_options; |
| 2058 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; |
| 2059 |
| 2060 cricket::MediaSessionOptions options; |
| 2061 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2062 |
| 2063 rtc_options.offer_to_receive_video = |
| 2064 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 2065 EXPECT_FALSE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2066 } |
| 2067 |
| 2068 // Test that a MediaSessionOptions is created for an offer if |
| 2069 // OfferToReceiveAudio and OfferToReceiveVideo options are set but no |
| 2070 // MediaStreams are sent. |
| 2071 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) { |
| 2072 RTCOfferAnswerOptions rtc_options; |
| 2073 rtc_options.offer_to_receive_audio = 1; |
| 2074 rtc_options.offer_to_receive_video = 1; |
| 2075 |
| 2076 cricket::MediaSessionOptions options; |
| 2077 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2078 EXPECT_TRUE(options.has_audio()); |
| 2079 EXPECT_TRUE(options.has_video()); |
| 2080 EXPECT_TRUE(options.bundle_enabled); |
| 2081 } |
| 2082 |
| 2083 // Test that a correct MediaSessionOptions is created for an offer if |
| 2084 // OfferToReceiveAudio is set but no MediaStreams are sent. |
| 2085 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) { |
| 2086 RTCOfferAnswerOptions rtc_options; |
| 2087 rtc_options.offer_to_receive_audio = 1; |
| 2088 |
| 2089 cricket::MediaSessionOptions options; |
| 2090 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2091 EXPECT_TRUE(options.has_audio()); |
| 2092 EXPECT_FALSE(options.has_video()); |
| 2093 EXPECT_TRUE(options.bundle_enabled); |
| 2094 } |
| 2095 |
| 2096 // Test that a correct MediaSessionOptions is created for an offer if |
| 2097 // the default OfferOptons is used or MediaStreams are sent. |
| 2098 TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) { |
| 2099 RTCOfferAnswerOptions rtc_options; |
| 2100 |
| 2101 cricket::MediaSessionOptions options; |
| 2102 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2103 EXPECT_FALSE(options.has_audio()); |
| 2104 EXPECT_FALSE(options.has_video()); |
| 2105 EXPECT_FALSE(options.bundle_enabled); |
| 2106 EXPECT_TRUE(options.vad_enabled); |
| 2107 EXPECT_FALSE(options.transport_options.ice_restart); |
| 2108 } |
| 2109 |
| 2110 // Test that a correct MediaSessionOptions is created for an offer if |
| 2111 // OfferToReceiveVideo is set but no MediaStreams are sent. |
| 2112 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) { |
| 2113 RTCOfferAnswerOptions rtc_options; |
| 2114 rtc_options.offer_to_receive_audio = 0; |
| 2115 rtc_options.offer_to_receive_video = 1; |
| 2116 |
| 2117 cricket::MediaSessionOptions options; |
| 2118 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2119 EXPECT_FALSE(options.has_audio()); |
| 2120 EXPECT_TRUE(options.has_video()); |
| 2121 EXPECT_TRUE(options.bundle_enabled); |
| 2122 } |
| 2123 |
| 2124 // Test that a correct MediaSessionOptions is created for an offer if |
| 2125 // UseRtpMux is set to false. |
| 2126 TEST(CreateSessionOptionsTest, |
| 2127 GetMediaSessionOptionsForOfferWithBundleDisabled) { |
| 2128 RTCOfferAnswerOptions rtc_options; |
| 2129 rtc_options.offer_to_receive_audio = 1; |
| 2130 rtc_options.offer_to_receive_video = 1; |
| 2131 rtc_options.use_rtp_mux = false; |
| 2132 |
| 2133 cricket::MediaSessionOptions options; |
| 2134 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2135 EXPECT_TRUE(options.has_audio()); |
| 2136 EXPECT_TRUE(options.has_video()); |
| 2137 EXPECT_FALSE(options.bundle_enabled); |
| 2138 } |
| 2139 |
| 2140 // Test that a correct MediaSessionOptions is created to restart ice if |
| 2141 // IceRestart is set. It also tests that subsequent MediaSessionOptions don't |
| 2142 // have |transport_options.ice_restart| set. |
| 2143 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) { |
| 2144 RTCOfferAnswerOptions rtc_options; |
| 2145 rtc_options.ice_restart = true; |
| 2146 |
| 2147 cricket::MediaSessionOptions options; |
| 2148 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2149 EXPECT_TRUE(options.transport_options.ice_restart); |
| 2150 |
| 2151 rtc_options = RTCOfferAnswerOptions(); |
| 2152 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_options, &options)); |
| 2153 EXPECT_FALSE(options.transport_options.ice_restart); |
| 2154 } |
| 2155 |
| 2156 // Test that the MediaConstraints in an answer don't affect if audio and video |
| 2157 // is offered in an offer but that if kOfferToReceiveAudio or |
| 2158 // kOfferToReceiveVideo constraints are true in an offer, the media type will be |
| 2159 // included in subsequent answers. |
| 2160 TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) { |
| 2161 FakeConstraints answer_c; |
| 2162 answer_c.SetMandatoryReceiveAudio(true); |
| 2163 answer_c.SetMandatoryReceiveVideo(true); |
| 2164 |
| 2165 cricket::MediaSessionOptions answer_options; |
| 2166 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options)); |
| 2167 EXPECT_TRUE(answer_options.has_audio()); |
| 2168 EXPECT_TRUE(answer_options.has_video()); |
| 2169 |
| 2170 RTCOfferAnswerOptions rtc_offer_optoins; |
| 2171 |
| 2172 cricket::MediaSessionOptions offer_options; |
| 2173 EXPECT_TRUE(ConvertRtcOptionsForOffer(rtc_offer_optoins, &offer_options)); |
| 2174 EXPECT_FALSE(offer_options.has_audio()); |
| 2175 EXPECT_FALSE(offer_options.has_video()); |
| 2176 |
| 2177 RTCOfferAnswerOptions updated_rtc_offer_optoins; |
| 2178 updated_rtc_offer_optoins.offer_to_receive_audio = 1; |
| 2179 updated_rtc_offer_optoins.offer_to_receive_video = 1; |
| 2180 |
| 2181 cricket::MediaSessionOptions updated_offer_options; |
| 2182 EXPECT_TRUE(ConvertRtcOptionsForOffer(updated_rtc_offer_optoins, |
| 2183 &updated_offer_options)); |
| 2184 EXPECT_TRUE(updated_offer_options.has_audio()); |
| 2185 EXPECT_TRUE(updated_offer_options.has_video()); |
| 2186 |
| 2187 // Since an offer has been created with both audio and video, subsequent |
| 2188 // offers and answers should contain both audio and video. |
| 2189 // Answers will only contain the media types that exist in the offer |
| 2190 // regardless of the value of |updated_answer_options.has_audio| and |
| 2191 // |updated_answer_options.has_video|. |
| 2192 FakeConstraints updated_answer_c; |
| 2193 answer_c.SetMandatoryReceiveAudio(false); |
| 2194 answer_c.SetMandatoryReceiveVideo(false); |
| 2195 |
| 2196 cricket::MediaSessionOptions updated_answer_options; |
| 2197 EXPECT_TRUE( |
| 2198 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
| 2199 EXPECT_TRUE(updated_answer_options.has_audio()); |
| 2200 EXPECT_TRUE(updated_answer_options.has_video()); |
| 2201 |
| 2202 RTCOfferAnswerOptions default_rtc_options; |
| 2203 EXPECT_TRUE( |
| 2204 ConvertRtcOptionsForOffer(default_rtc_options, &updated_offer_options)); |
| 2205 // By default, |has_audio| or |has_video| are false if there is no media |
| 2206 // track. |
| 2207 EXPECT_FALSE(updated_offer_options.has_audio()); |
| 2208 EXPECT_FALSE(updated_offer_options.has_video()); |
| 2209 } |
OLD | NEW |