OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> // For std::pair, std::move. | 12 #include <utility> // For std::pair, std::move. |
13 | 13 |
14 #include "webrtc/api/ortc/ortcfactoryinterface.h" | 14 #include "webrtc/api/ortc/ortcfactoryinterface.h" |
15 #include "webrtc/base/criticalsection.h" | 15 #include "webrtc/base/criticalsection.h" |
16 #include "webrtc/base/fakenetwork.h" | 16 #include "webrtc/base/fakenetwork.h" |
17 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
18 #include "webrtc/base/physicalsocketserver.h" | 18 #include "webrtc/base/physicalsocketserver.h" |
19 #include "webrtc/base/virtualsocketserver.h" | 19 #include "webrtc/base/virtualsocketserver.h" |
20 #include "webrtc/ortc/testrtpparameters.h" | 20 #include "webrtc/ortc/testrtpparameters.h" |
21 #include "webrtc/p2p/base/udptransport.h" | 21 #include "webrtc/p2p/base/udptransport.h" |
22 #include "webrtc/pc/test/fakeaudiocapturemodule.h" | 22 #include "webrtc/pc/test/fakeaudiocapturemodule.h" |
23 #include "webrtc/pc/test/fakeperiodicvideocapturer.h" | 23 #include "webrtc/pc/test/fakeperiodicvideocapturer.h" |
24 #include "webrtc/pc/test/fakevideotrackrenderer.h" | 24 #include "webrtc/pc/test/fakevideotrackrenderer.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const int kDefaultTimeout = 10000; // 10 seconds. | 28 const int kDefaultTimeout = 10000; // 10 seconds. |
29 const int kReceivingTimeout = 1000; // 1 second. | |
Taylor Brandstetter
2017/03/01 19:18:08
nit: This isn't really a "timeout", since the test
Zhi Huang
2017/03/02 23:35:39
Yes, this would be better.
| |
29 // Default number of audio/video frames to wait for before considering a test a | 30 // Default number of audio/video frames to wait for before considering a test a |
30 // success. | 31 // success. |
31 const int kDefaultNumFrames = 3; | 32 const int kDefaultNumFrames = 3; |
32 const rtc::IPAddress kIPv4LocalHostAddress = | 33 const rtc::IPAddress kIPv4LocalHostAddress = |
33 rtc::IPAddress(0x7F000001); // 127.0.0.1 | 34 rtc::IPAddress(0x7F000001); // 127.0.0.1 |
34 | 35 |
36 static const char kTestKeyParams1[] = | |
37 "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; | |
38 static const char kTestKeyParams2[] = | |
39 "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR"; | |
40 static const cricket::CryptoParams kTestCryptoParams1(1, | |
41 "AES_CM_128_HMAC_SHA1_80", | |
42 kTestKeyParams1, | |
43 ""); | |
44 static const cricket::CryptoParams kTestCryptoParams2(1, | |
45 "AES_CM_128_HMAC_SHA1_80", | |
46 kTestKeyParams2, | |
47 ""); | |
35 } // namespace | 48 } // namespace |
36 | 49 |
37 namespace webrtc { | 50 namespace webrtc { |
38 | 51 |
39 // Used to test that things work end-to-end when using the default | 52 // Used to test that things work end-to-end when using the default |
40 // implementations of threads/etc. provided by OrtcFactory, with the exception | 53 // implementations of threads/etc. provided by OrtcFactory, with the exception |
41 // of using a virtual network. | 54 // of using a virtual network. |
42 // | 55 // |
43 // By default, the virtual network manager doesn't enumerate any networks, but | 56 // By default, the virtual network manager doesn't enumerate any networks, but |
44 // sockets can still be created in this state. | 57 // sockets can still be created in this state. |
(...skipping 19 matching lines...) Expand all Loading... | |
64 .MoveValue(); | 77 .MoveValue(); |
65 } | 78 } |
66 | 79 |
67 protected: | 80 protected: |
68 typedef std::pair<std::unique_ptr<UdpTransportInterface>, | 81 typedef std::pair<std::unique_ptr<UdpTransportInterface>, |
69 std::unique_ptr<UdpTransportInterface>> | 82 std::unique_ptr<UdpTransportInterface>> |
70 UdpTransportPair; | 83 UdpTransportPair; |
71 typedef std::pair<std::unique_ptr<RtpTransportInterface>, | 84 typedef std::pair<std::unique_ptr<RtpTransportInterface>, |
72 std::unique_ptr<RtpTransportInterface>> | 85 std::unique_ptr<RtpTransportInterface>> |
73 RtpTransportPair; | 86 RtpTransportPair; |
87 typedef std::pair<std::unique_ptr<SrtpTransportInterface>, | |
88 std::unique_ptr<SrtpTransportInterface>> | |
89 SrtpTransportPair; | |
74 typedef std::pair<std::unique_ptr<RtpTransportControllerInterface>, | 90 typedef std::pair<std::unique_ptr<RtpTransportControllerInterface>, |
75 std::unique_ptr<RtpTransportControllerInterface>> | 91 std::unique_ptr<RtpTransportControllerInterface>> |
76 RtpTransportControllerPair; | 92 RtpTransportControllerPair; |
77 | 93 |
78 // Helper function that creates one UDP transport each for |ortc_factory1_| | 94 // Helper function that creates one UDP transport each for |ortc_factory1_| |
79 // and |ortc_factory2_|, and connects them. | 95 // and |ortc_factory2_|, and connects them. |
80 UdpTransportPair CreateAndConnectUdpTransportPair() { | 96 UdpTransportPair CreateAndConnectUdpTransportPair() { |
81 auto transport1 = ortc_factory1_->CreateUdpTransport(AF_INET).MoveValue(); | 97 auto transport1 = ortc_factory1_->CreateUdpTransport(AF_INET).MoveValue(); |
82 auto transport2 = ortc_factory2_->CreateUdpTransport(AF_INET).MoveValue(); | 98 auto transport2 = ortc_factory2_->CreateUdpTransport(AF_INET).MoveValue(); |
83 transport1->SetRemoteAddress( | 99 transport1->SetRemoteAddress( |
(...skipping 24 matching lines...) Expand all Loading... | |
108 const RtpTransportControllerPair& transport_controllers) { | 124 const RtpTransportControllerPair& transport_controllers) { |
109 auto transport_result1 = ortc_factory1_->CreateRtpTransport( | 125 auto transport_result1 = ortc_factory1_->CreateRtpTransport( |
110 rtcp_parameters, rtp_udp_transports.first.get(), | 126 rtcp_parameters, rtp_udp_transports.first.get(), |
111 rtcp_udp_transports.first.get(), transport_controllers.first.get()); | 127 rtcp_udp_transports.first.get(), transport_controllers.first.get()); |
112 auto transport_result2 = ortc_factory2_->CreateRtpTransport( | 128 auto transport_result2 = ortc_factory2_->CreateRtpTransport( |
113 rtcp_parameters, rtp_udp_transports.second.get(), | 129 rtcp_parameters, rtp_udp_transports.second.get(), |
114 rtcp_udp_transports.second.get(), transport_controllers.second.get()); | 130 rtcp_udp_transports.second.get(), transport_controllers.second.get()); |
115 return {transport_result1.MoveValue(), transport_result2.MoveValue()}; | 131 return {transport_result1.MoveValue(), transport_result2.MoveValue()}; |
116 } | 132 } |
117 | 133 |
134 SrtpTransportPair CreateSrtpTransportPair( | |
135 const RtcpParameters& rtcp_parameters, | |
136 const UdpTransportPair& rtp_udp_transports, | |
137 const UdpTransportPair& rtcp_udp_transports, | |
138 const RtpTransportControllerPair& transport_controllers) { | |
139 auto transport_result1 = ortc_factory1_->CreateSrtpTransport( | |
140 rtcp_parameters, rtp_udp_transports.first.get(), | |
141 rtcp_udp_transports.first.get(), transport_controllers.first.get()); | |
142 auto transport_result2 = ortc_factory2_->CreateSrtpTransport( | |
143 rtcp_parameters, rtp_udp_transports.second.get(), | |
144 rtcp_udp_transports.second.get(), transport_controllers.second.get()); | |
145 return {transport_result1.MoveValue(), transport_result2.MoveValue()}; | |
146 } | |
147 | |
118 // For convenience when |rtcp_udp_transports| and |transport_controllers| | 148 // For convenience when |rtcp_udp_transports| and |transport_controllers| |
119 // aren't needed. | 149 // aren't needed. |
120 RtpTransportPair CreateRtpTransportPair( | 150 RtpTransportPair CreateRtpTransportPair( |
121 const RtcpParameters& rtcp_parameters, | 151 const RtcpParameters& rtcp_parameters, |
122 const UdpTransportPair& rtp_udp_transports) { | 152 const UdpTransportPair& rtp_udp_transports) { |
123 return CreateRtpTransportPair(rtcp_parameters, rtp_udp_transports, | 153 return CreateRtpTransportPair(rtcp_parameters, rtp_udp_transports, |
124 UdpTransportPair(), | 154 UdpTransportPair(), |
125 RtpTransportControllerPair()); | 155 RtpTransportControllerPair()); |
126 } | 156 } |
127 | 157 |
158 SrtpTransportPair CreateSrtpTransportPairAndSetKeys( | |
159 const RtcpParameters& rtcp_parameters, | |
160 const UdpTransportPair& rtp_udp_transports) { | |
161 SrtpTransportPair srtp_transports = CreateSrtpTransportPair( | |
162 rtcp_parameters, rtp_udp_transports, UdpTransportPair(), | |
163 RtpTransportControllerPair()); | |
164 auto transport1 = std::move(srtp_transports.first); | |
165 auto transport2 = std::move(srtp_transports.second); | |
166 EXPECT_TRUE(transport1->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
167 EXPECT_TRUE(transport1->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
168 EXPECT_TRUE(transport2->SetSrtpSendKey(kTestCryptoParams2).ok()); | |
169 EXPECT_TRUE(transport2->SetSrtpReceiveKey(kTestCryptoParams1).ok()); | |
170 return {std::move(transport1), std::move(transport2)}; | |
Taylor Brandstetter
2017/03/01 19:18:08
Is it possible to return "std::move(srtp_transport
Zhi Huang
2017/03/02 23:35:39
Done.
| |
171 } | |
172 | |
173 SrtpTransportPair CreateSrtpTransportPairAndSetMismatchingKeys( | |
174 const RtcpParameters& rtcp_parameters, | |
175 const UdpTransportPair& rtp_udp_transports) { | |
176 SrtpTransportPair srtp_transports = CreateSrtpTransportPair( | |
177 rtcp_parameters, rtp_udp_transports, UdpTransportPair(), | |
178 RtpTransportControllerPair()); | |
179 auto transport1 = std::move(srtp_transports.first); | |
180 auto transport2 = std::move(srtp_transports.second); | |
181 // Set mismatching keys. | |
182 EXPECT_TRUE(transport1->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
183 EXPECT_TRUE(transport1->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
184 EXPECT_TRUE(transport2->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
185 EXPECT_TRUE(transport2->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
186 return {std::move(transport1), std::move(transport2)}; | |
187 } | |
188 | |
128 // Ends up using fake audio capture module, which was passed into OrtcFactory | 189 // Ends up using fake audio capture module, which was passed into OrtcFactory |
129 // on creation. | 190 // on creation. |
130 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( | 191 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( |
131 const std::string& id, | 192 const std::string& id, |
132 OrtcFactoryInterface* ortc_factory) { | 193 OrtcFactoryInterface* ortc_factory) { |
133 // Disable echo cancellation to make test more efficient. | 194 // Disable echo cancellation to make test more efficient. |
134 cricket::AudioOptions options; | 195 cricket::AudioOptions options; |
135 options.echo_cancellation.emplace(true); | 196 options.echo_cancellation.emplace(true); |
136 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = | 197 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
137 ortc_factory->CreateAudioSource(options); | 198 ortc_factory->CreateAudioSource(options); |
138 return ortc_factory->CreateAudioTrack(id, source); | 199 return ortc_factory->CreateAudioTrack(id, source); |
139 } | 200 } |
140 | 201 |
141 // Stores created capturer in |fake_video_capturers_|. | 202 // Stores created capturer in |fake_video_capturers_|. |
142 rtc::scoped_refptr<webrtc::VideoTrackInterface> | 203 rtc::scoped_refptr<webrtc::VideoTrackInterface> |
143 CreateLocalVideoTrackAndFakeCapturer(const std::string& id, | 204 CreateLocalVideoTrackAndFakeCapturer(const std::string& id, |
144 OrtcFactoryInterface* ortc_factory) { | 205 OrtcFactoryInterface* ortc_factory) { |
145 cricket::FakeVideoCapturer* fake_capturer = | 206 cricket::FakeVideoCapturer* fake_capturer = |
146 new webrtc::FakePeriodicVideoCapturer(); | 207 new webrtc::FakePeriodicVideoCapturer(); |
147 fake_video_capturers_.push_back(fake_capturer); | 208 fake_video_capturers_.push_back(fake_capturer); |
148 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = | 209 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = |
149 ortc_factory->CreateVideoSource( | 210 ortc_factory->CreateVideoSource( |
150 std::unique_ptr<cricket::VideoCapturer>(fake_capturer)); | 211 std::unique_ptr<cricket::VideoCapturer>(fake_capturer)); |
151 return rtc::scoped_refptr<webrtc::VideoTrackInterface>( | 212 return rtc::scoped_refptr<webrtc::VideoTrackInterface>( |
152 ortc_factory->CreateVideoTrack(id, source)); | 213 ortc_factory->CreateVideoTrack(id, source)); |
153 } | 214 } |
154 | 215 |
216 // Helper function used to test two way RTP senders and receivers with basic | |
217 // configurations. | |
Taylor Brandstetter
2017/03/01 19:18:07
Could you add a comment saying: "If |expect_succes
Zhi Huang
2017/03/02 23:35:39
Done.
| |
218 void BasicsTwoWayRtpSendersAndReceiversTest(UdpTransportPair udp_transports, | |
Taylor Brandstetter
2017/03/01 19:18:07
nit: "Basic" instead of "Basics"
Taylor Brandstetter
2017/03/01 19:18:07
It doesn't look like the udp_transports parameter
Zhi Huang
2017/03/02 23:35:39
Oh, I'm so careless.
| |
219 RtpTransportPair srtp_transports, | |
220 bool expect_success) { | |
221 received_audio_frame1_ = 0; | |
222 received_audio_frame2_ = 0; | |
223 rendered_video_frame1_ = 0; | |
224 rendered_video_frame2_ = 0; | |
Taylor Brandstetter
2017/03/01 19:18:07
nit: "frames", plural?
Zhi Huang
2017/03/02 23:35:39
Done.
| |
225 // Create all the senders and receivers (four per endpoint). | |
226 auto audio_sender_result1 = ortc_factory1_->CreateRtpSender( | |
227 cricket::MEDIA_TYPE_AUDIO, srtp_transports.first.get()); | |
228 auto video_sender_result1 = ortc_factory1_->CreateRtpSender( | |
229 cricket::MEDIA_TYPE_VIDEO, srtp_transports.first.get()); | |
230 auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver( | |
231 cricket::MEDIA_TYPE_AUDIO, srtp_transports.first.get()); | |
232 auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver( | |
233 cricket::MEDIA_TYPE_VIDEO, srtp_transports.first.get()); | |
234 ASSERT_TRUE(audio_sender_result1.ok()); | |
235 ASSERT_TRUE(video_sender_result1.ok()); | |
236 ASSERT_TRUE(audio_receiver_result1.ok()); | |
237 ASSERT_TRUE(video_receiver_result1.ok()); | |
238 auto audio_sender1 = audio_sender_result1.MoveValue(); | |
239 auto video_sender1 = video_sender_result1.MoveValue(); | |
240 auto audio_receiver1 = audio_receiver_result1.MoveValue(); | |
241 auto video_receiver1 = video_receiver_result1.MoveValue(); | |
242 | |
243 auto audio_sender_result2 = ortc_factory2_->CreateRtpSender( | |
244 cricket::MEDIA_TYPE_AUDIO, srtp_transports.second.get()); | |
245 auto video_sender_result2 = ortc_factory2_->CreateRtpSender( | |
246 cricket::MEDIA_TYPE_VIDEO, srtp_transports.second.get()); | |
247 auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver( | |
248 cricket::MEDIA_TYPE_AUDIO, srtp_transports.second.get()); | |
249 auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver( | |
250 cricket::MEDIA_TYPE_VIDEO, srtp_transports.second.get()); | |
251 ASSERT_TRUE(audio_sender_result2.ok()); | |
252 ASSERT_TRUE(video_sender_result2.ok()); | |
253 ASSERT_TRUE(audio_receiver_result2.ok()); | |
254 ASSERT_TRUE(video_receiver_result2.ok()); | |
255 auto audio_sender2 = audio_sender_result2.MoveValue(); | |
256 auto video_sender2 = video_sender_result2.MoveValue(); | |
257 auto audio_receiver2 = audio_receiver_result2.MoveValue(); | |
258 auto video_receiver2 = video_receiver_result2.MoveValue(); | |
259 | |
260 // Add fake tracks. | |
261 RTCError error = audio_sender1->SetTrack( | |
262 CreateLocalAudioTrack("audio", ortc_factory1_.get())); | |
263 EXPECT_TRUE(error.ok()); | |
264 error = video_sender1->SetTrack( | |
265 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get())); | |
266 EXPECT_TRUE(error.ok()); | |
267 error = audio_sender2->SetTrack( | |
268 CreateLocalAudioTrack("audio", ortc_factory2_.get())); | |
269 EXPECT_TRUE(error.ok()); | |
270 error = video_sender2->SetTrack( | |
271 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get())); | |
272 EXPECT_TRUE(error.ok()); | |
273 | |
274 // "sent_X_parameters1" are the parameters that endpoint 1 sends with and | |
275 // endpoint 2 receives with. | |
276 RtpParameters sent_opus_parameters1 = | |
277 MakeMinimalOpusParametersWithSsrc(0xdeadbeef); | |
278 RtpParameters sent_vp8_parameters1 = | |
279 MakeMinimalVp8ParametersWithSsrc(0xbaadfeed); | |
280 RtpParameters sent_opus_parameters2 = | |
281 MakeMinimalOpusParametersWithSsrc(0x13333337); | |
282 RtpParameters sent_vp8_parameters2 = | |
283 MakeMinimalVp8ParametersWithSsrc(0x12345678); | |
284 | |
285 // Configure the senders' and receivers' parameters. | |
286 EXPECT_TRUE(audio_receiver1->Receive(sent_opus_parameters2).ok()); | |
287 EXPECT_TRUE(video_receiver1->Receive(sent_vp8_parameters2).ok()); | |
288 EXPECT_TRUE(audio_receiver2->Receive(sent_opus_parameters1).ok()); | |
289 EXPECT_TRUE(video_receiver2->Receive(sent_vp8_parameters1).ok()); | |
290 EXPECT_TRUE(audio_sender1->Send(sent_opus_parameters1).ok()); | |
291 EXPECT_TRUE(video_sender1->Send(sent_vp8_parameters1).ok()); | |
292 EXPECT_TRUE(audio_sender2->Send(sent_opus_parameters2).ok()); | |
293 EXPECT_TRUE(video_sender2->Send(sent_vp8_parameters2).ok()); | |
294 | |
295 FakeVideoTrackRenderer fake_video_renderer1( | |
296 static_cast<VideoTrackInterface*>(video_receiver1->GetTrack().get())); | |
297 FakeVideoTrackRenderer fake_video_renderer2( | |
298 static_cast<VideoTrackInterface*>(video_receiver2->GetTrack().get())); | |
299 | |
300 // If the test is expected to succeed, at least |kDefaultNumFrames| of | |
301 // frames should be rendered within |kDefaultTimeout|. | |
302 // If the test is expected to fail, no frames should be rendered after | |
303 // waiting for |kReceivingTimeout|. | |
304 if (expect_success) { | |
305 EXPECT_TRUE_WAIT( | |
306 fake_audio_capture_module1_->frames_received() > kDefaultNumFrames && | |
307 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames && | |
308 fake_audio_capture_module2_->frames_received() > | |
309 kDefaultNumFrames && | |
310 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames, | |
311 kDefaultTimeout); | |
312 } else { | |
313 WAIT(false, kReceivingTimeout); | |
314 rendered_video_frame1_ = fake_video_renderer1.num_rendered_frames(); | |
315 rendered_video_frame2_ = fake_video_renderer2.num_rendered_frames(); | |
316 received_audio_frame1_ = fake_audio_capture_module1_->frames_received(); | |
317 received_audio_frame2_ = fake_audio_capture_module2_->frames_received(); | |
318 } | |
319 } | |
320 | |
155 rtc::PhysicalSocketServer physical_socket_server_; | 321 rtc::PhysicalSocketServer physical_socket_server_; |
156 rtc::VirtualSocketServer virtual_socket_server_; | 322 rtc::VirtualSocketServer virtual_socket_server_; |
157 rtc::Thread network_thread_; | 323 rtc::Thread network_thread_; |
158 rtc::FakeNetworkManager fake_network_manager_; | 324 rtc::FakeNetworkManager fake_network_manager_; |
159 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module1_; | 325 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module1_; |
160 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module2_; | 326 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module2_; |
161 std::unique_ptr<OrtcFactoryInterface> ortc_factory1_; | 327 std::unique_ptr<OrtcFactoryInterface> ortc_factory1_; |
162 std::unique_ptr<OrtcFactoryInterface> ortc_factory2_; | 328 std::unique_ptr<OrtcFactoryInterface> ortc_factory2_; |
163 // Actually owned by video tracks. | 329 // Actually owned by video tracks. |
164 std::vector<cricket::FakeVideoCapturer*> fake_video_capturers_; | 330 std::vector<cricket::FakeVideoCapturer*> fake_video_capturers_; |
331 int received_audio_frame1_ = 0; | |
332 int received_audio_frame2_ = 0; | |
333 int rendered_video_frame1_ = 0; | |
334 int rendered_video_frame2_ = 0; | |
165 }; | 335 }; |
166 | 336 |
167 // Very basic end-to-end test with a single pair of audio RTP sender and | 337 // Very basic end-to-end test with a single pair of audio RTP sender and |
168 // receiver. | 338 // receiver. |
169 // | 339 // |
170 // Uses muxed RTCP, and minimal parameters with a hard-coded config that's | 340 // Uses muxed RTCP, and minimal parameters with a hard-coded config that's |
171 // known to work. | 341 // known to work. |
172 TEST_F(OrtcFactoryIntegrationTest, BasicOneWayAudioRtpSenderAndReceiver) { | 342 TEST_F(OrtcFactoryIntegrationTest, BasicOneWayAudioRtpSenderAndReceiver) { |
173 auto udp_transports = CreateAndConnectUdpTransportPair(); | 343 auto udp_transports = CreateAndConnectUdpTransportPair(); |
174 auto rtp_transports = | 344 auto rtp_transports = |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 // End-to-end test with two pairs of RTP senders and receivers, for audio and | 448 // End-to-end test with two pairs of RTP senders and receivers, for audio and |
279 // video. | 449 // video. |
280 // | 450 // |
281 // Uses muxed RTCP, and minimal parameters with hard-coded configs that are | 451 // Uses muxed RTCP, and minimal parameters with hard-coded configs that are |
282 // known to work. | 452 // known to work. |
283 TEST_F(OrtcFactoryIntegrationTest, | 453 TEST_F(OrtcFactoryIntegrationTest, |
284 BasicTwoWayAudioVideoRtpSendersAndReceivers) { | 454 BasicTwoWayAudioVideoRtpSendersAndReceivers) { |
285 auto udp_transports = CreateAndConnectUdpTransportPair(); | 455 auto udp_transports = CreateAndConnectUdpTransportPair(); |
286 auto rtp_transports = | 456 auto rtp_transports = |
287 CreateRtpTransportPair(MakeRtcpMuxParameters(), udp_transports); | 457 CreateRtpTransportPair(MakeRtcpMuxParameters(), udp_transports); |
288 | 458 BasicsTwoWayRtpSendersAndReceiversTest(std::move(udp_transports), |
289 // Create all the senders and receivers (four per endpoint). | 459 std::move(rtp_transports), |
290 auto audio_sender_result1 = ortc_factory1_->CreateRtpSender( | 460 true /*expect_success*/); |
Taylor Brandstetter
2017/03/01 19:18:08
nit: Our style (at least, from what I've learned f
Zhi Huang
2017/03/02 23:35:39
Done.
| |
291 cricket::MEDIA_TYPE_AUDIO, rtp_transports.first.get()); | |
292 auto video_sender_result1 = ortc_factory1_->CreateRtpSender( | |
293 cricket::MEDIA_TYPE_VIDEO, rtp_transports.first.get()); | |
294 auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver( | |
295 cricket::MEDIA_TYPE_AUDIO, rtp_transports.first.get()); | |
296 auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver( | |
297 cricket::MEDIA_TYPE_VIDEO, rtp_transports.first.get()); | |
298 ASSERT_TRUE(audio_sender_result1.ok()); | |
299 ASSERT_TRUE(video_sender_result1.ok()); | |
300 ASSERT_TRUE(audio_receiver_result1.ok()); | |
301 ASSERT_TRUE(video_receiver_result1.ok()); | |
302 auto audio_sender1 = audio_sender_result1.MoveValue(); | |
303 auto video_sender1 = video_sender_result1.MoveValue(); | |
304 auto audio_receiver1 = audio_receiver_result1.MoveValue(); | |
305 auto video_receiver1 = video_receiver_result1.MoveValue(); | |
306 | |
307 auto audio_sender_result2 = ortc_factory2_->CreateRtpSender( | |
308 cricket::MEDIA_TYPE_AUDIO, rtp_transports.second.get()); | |
309 auto video_sender_result2 = ortc_factory2_->CreateRtpSender( | |
310 cricket::MEDIA_TYPE_VIDEO, rtp_transports.second.get()); | |
311 auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver( | |
312 cricket::MEDIA_TYPE_AUDIO, rtp_transports.second.get()); | |
313 auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver( | |
314 cricket::MEDIA_TYPE_VIDEO, rtp_transports.second.get()); | |
315 ASSERT_TRUE(audio_sender_result2.ok()); | |
316 ASSERT_TRUE(video_sender_result2.ok()); | |
317 ASSERT_TRUE(audio_receiver_result2.ok()); | |
318 ASSERT_TRUE(video_receiver_result2.ok()); | |
319 auto audio_sender2 = audio_sender_result2.MoveValue(); | |
320 auto video_sender2 = video_sender_result2.MoveValue(); | |
321 auto audio_receiver2 = audio_receiver_result2.MoveValue(); | |
322 auto video_receiver2 = video_receiver_result2.MoveValue(); | |
323 | |
324 // Add fake tracks. | |
325 RTCError error = audio_sender1->SetTrack( | |
326 CreateLocalAudioTrack("audio", ortc_factory1_.get())); | |
327 EXPECT_TRUE(error.ok()); | |
328 error = video_sender1->SetTrack( | |
329 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get())); | |
330 EXPECT_TRUE(error.ok()); | |
331 error = audio_sender2->SetTrack( | |
332 CreateLocalAudioTrack("audio", ortc_factory2_.get())); | |
333 EXPECT_TRUE(error.ok()); | |
334 error = video_sender2->SetTrack( | |
335 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get())); | |
336 EXPECT_TRUE(error.ok()); | |
337 | |
338 // "sent_X_parameters1" are the parameters that endpoint 1 sends with and | |
339 // endpoint 2 receives with. | |
340 RtpParameters sent_opus_parameters1 = | |
341 MakeMinimalOpusParametersWithSsrc(0xdeadbeef); | |
342 RtpParameters sent_vp8_parameters1 = | |
343 MakeMinimalVp8ParametersWithSsrc(0xbaadfeed); | |
344 RtpParameters sent_opus_parameters2 = | |
345 MakeMinimalOpusParametersWithSsrc(0x13333337); | |
346 RtpParameters sent_vp8_parameters2 = | |
347 MakeMinimalVp8ParametersWithSsrc(0x12345678); | |
348 | |
349 // Configure the senders' and receivers' parameters. | |
350 EXPECT_TRUE(audio_receiver1->Receive(sent_opus_parameters2).ok()); | |
351 EXPECT_TRUE(video_receiver1->Receive(sent_vp8_parameters2).ok()); | |
352 EXPECT_TRUE(audio_receiver2->Receive(sent_opus_parameters1).ok()); | |
353 EXPECT_TRUE(video_receiver2->Receive(sent_vp8_parameters1).ok()); | |
354 EXPECT_TRUE(audio_sender1->Send(sent_opus_parameters1).ok()); | |
355 EXPECT_TRUE(video_sender1->Send(sent_vp8_parameters1).ok()); | |
356 EXPECT_TRUE(audio_sender2->Send(sent_opus_parameters2).ok()); | |
357 EXPECT_TRUE(video_sender2->Send(sent_vp8_parameters2).ok()); | |
358 | |
359 FakeVideoTrackRenderer fake_video_renderer1( | |
360 static_cast<VideoTrackInterface*>(video_receiver1->GetTrack().get())); | |
361 FakeVideoTrackRenderer fake_video_renderer2( | |
362 static_cast<VideoTrackInterface*>(video_receiver2->GetTrack().get())); | |
363 | |
364 // Senders and receivers are connected and configured; audio and video frames | |
365 // should be able to flow at this point. | |
366 EXPECT_TRUE_WAIT( | |
367 fake_audio_capture_module1_->frames_received() > kDefaultNumFrames && | |
368 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames && | |
369 fake_audio_capture_module2_->frames_received() > kDefaultNumFrames && | |
370 fake_video_renderer2.num_rendered_frames() > kDefaultNumFrames, | |
371 kDefaultTimeout); | |
372 } | 461 } |
373 | 462 |
374 // End-to-end test with two pairs of RTP senders and receivers, for audio and | 463 // End-to-end test with two pairs of RTP senders and receivers, for audio and |
375 // video. Unlike the test above, this attempts to make the parameters as | 464 // video. Unlike the test above, this attempts to make the parameters as |
376 // complex as possible. | 465 // complex as possible. |
377 // | 466 // |
378 // Uses non-muxed RTCP, with separate audio/video transports, and a full set of | 467 // Uses non-muxed RTCP, with separate audio/video transports, and a full set of |
379 // parameters, as would normally be used in a PeerConnection. | 468 // parameters, as would normally be used in a PeerConnection. |
380 // | 469 // |
381 // TODO(deadbeef): Update this test as more audio/video features become | 470 // TODO(deadbeef): Update this test as more audio/video features become |
382 // supported. | 471 // supported. |
383 TEST_F(OrtcFactoryIntegrationTest, FullTwoWayAudioVideoRtpSendersAndReceivers) { | 472 TEST_F(OrtcFactoryIntegrationTest, FullTwoWayAudioVideoRtpSendersAndReceivers) { |
Taylor Brandstetter
2017/03/01 19:18:08
Could we change this test to use SRTP?
It would a
Zhi Huang
2017/03/02 23:35:39
How about setting different keys in this test sinc
Taylor Brandstetter
2017/03/02 23:51:10
Sounds good.
| |
384 // We want four pairs of UDP transports for this test, for audio/video and | 473 // We want four pairs of UDP transports for this test, for audio/video and |
385 // RTP/RTCP. | 474 // RTP/RTCP. |
386 auto audio_rtp_udp_transports = CreateAndConnectUdpTransportPair(); | 475 auto audio_rtp_udp_transports = CreateAndConnectUdpTransportPair(); |
387 auto audio_rtcp_udp_transports = CreateAndConnectUdpTransportPair(); | 476 auto audio_rtcp_udp_transports = CreateAndConnectUdpTransportPair(); |
388 auto video_rtp_udp_transports = CreateAndConnectUdpTransportPair(); | 477 auto video_rtp_udp_transports = CreateAndConnectUdpTransportPair(); |
389 auto video_rtcp_udp_transports = CreateAndConnectUdpTransportPair(); | 478 auto video_rtcp_udp_transports = CreateAndConnectUdpTransportPair(); |
390 | 479 |
391 // Since we have multiple RTP transports on each side, we need an RTP | 480 // Since we have multiple RTP transports on each side, we need an RTP |
392 // transport controller. | 481 // transport controller. |
393 auto transport_controllers = CreateRtpTransportControllerPair(); | 482 auto transport_controllers = CreateRtpTransportControllerPair(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 // Senders and receivers are connected and configured; audio and video frames | 582 // Senders and receivers are connected and configured; audio and video frames |
494 // should be able to flow at this point. | 583 // should be able to flow at this point. |
495 EXPECT_TRUE_WAIT( | 584 EXPECT_TRUE_WAIT( |
496 fake_audio_capture_module1_->frames_received() > kDefaultNumFrames && | 585 fake_audio_capture_module1_->frames_received() > kDefaultNumFrames && |
497 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames && | 586 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames && |
498 fake_audio_capture_module2_->frames_received() > kDefaultNumFrames && | 587 fake_audio_capture_module2_->frames_received() > kDefaultNumFrames && |
499 fake_video_renderer2.num_rendered_frames() > kDefaultNumFrames, | 588 fake_video_renderer2.num_rendered_frames() > kDefaultNumFrames, |
500 kDefaultTimeout); | 589 kDefaultTimeout); |
501 } | 590 } |
502 | 591 |
592 TEST_F(OrtcFactoryIntegrationTest, | |
Taylor Brandstetter
2017/03/01 19:18:07
Could these new tests be added above the "FullTwoW
Zhi Huang
2017/03/02 23:35:39
Done.
| |
593 BasicTwoWayAudioVideoSrtpSendersAndReceivers) { | |
594 auto udp_transports = CreateAndConnectUdpTransportPair(); | |
595 auto srtp_transports = CreateSrtpTransportPairAndSetKeys( | |
596 MakeRtcpMuxParameters(), udp_transports); | |
597 BasicsTwoWayRtpSendersAndReceiversTest(std::move(udp_transports), | |
598 std::move(srtp_transports), | |
599 true /*expect_success*/); | |
600 } | |
601 | |
602 // Tests that the packet cannot be decoded if the keys are mismatched. | |
Taylor Brandstetter
2017/03/01 19:18:07
nit: "Tests that packets..."
Zhi Huang
2017/03/02 23:35:39
Done.
| |
603 TEST_F(OrtcFactoryIntegrationTest, SrtpSendersAndReceiversWithMismatchingKeys) { | |
604 auto udp_transports = CreateAndConnectUdpTransportPair(); | |
605 auto srtp_transports = CreateSrtpTransportPairAndSetMismatchingKeys( | |
606 MakeRtcpMuxParameters(), udp_transports); | |
607 BasicsTwoWayRtpSendersAndReceiversTest(std::move(udp_transports), | |
608 std::move(srtp_transports), | |
609 false /*expect_success*/); | |
610 // No frame is expected to be decoded. | |
Taylor Brandstetter
2017/03/01 19:18:08
nit: "No frames are..."
Zhi Huang
2017/03/02 23:35:39
Done.
| |
611 EXPECT_TRUE(received_audio_frame1_ == 0 && received_audio_frame2_ == 0 && | |
612 rendered_video_frame1_ == 0 && rendered_video_frame2_ == 0); | |
613 } | |
614 | |
615 // Tests that the frame cannot be decoded if only one side uses SRTP. | |
616 TEST_F(OrtcFactoryIntegrationTest, OneSideSrtpSenderAndReceiver) { | |
617 auto rtcp_parameters = MakeRtcpMuxParameters(); | |
618 auto udp_transports = CreateAndConnectUdpTransportPair(); | |
619 auto rtcp_udp_transports = UdpTransportPair(); | |
620 auto transport_controllers = RtpTransportControllerPair(); | |
621 auto transport_result1 = ortc_factory1_->CreateRtpTransport( | |
622 rtcp_parameters, udp_transports.first.get(), | |
623 rtcp_udp_transports.first.get(), transport_controllers.first.get()); | |
624 auto transport_result2 = ortc_factory2_->CreateSrtpTransport( | |
625 rtcp_parameters, udp_transports.second.get(), | |
626 rtcp_udp_transports.second.get(), transport_controllers.second.get()); | |
627 | |
628 auto rtp_transport = transport_result1.MoveValue(); | |
629 auto srtp_transport = transport_result2.MoveValue(); | |
630 EXPECT_TRUE(srtp_transport->SetSrtpSendKey(kTestCryptoParams1).ok()); | |
631 EXPECT_TRUE(srtp_transport->SetSrtpReceiveKey(kTestCryptoParams2).ok()); | |
632 BasicsTwoWayRtpSendersAndReceiversTest( | |
633 std::move(udp_transports), | |
634 {std::move(rtp_transport), std::move(srtp_transport)}, | |
635 false /*expect_success*/); | |
636 | |
637 // The SRTP side is not expected to decode any audio and video frames. | |
Taylor Brandstetter
2017/03/01 19:18:07
nit: "audio or video"
Zhi Huang
2017/03/02 23:35:39
Done.
| |
638 // The RTP side is not expected to decode any video frames while it is | |
639 // possible that the encrypted audio frames can be accidentally decoded. | |
Taylor Brandstetter
2017/03/01 19:18:08
Could you add: "which is why received_audio_frames
Zhi Huang
2017/03/02 23:35:39
Done.
| |
640 EXPECT_TRUE(received_audio_frame2_ == 0 && rendered_video_frame1_ == 0 && | |
641 rendered_video_frame2_ == 0); | |
642 } | |
643 | |
503 // TODO(deadbeef): End-to-end test for multiple senders/receivers of the same | 644 // TODO(deadbeef): End-to-end test for multiple senders/receivers of the same |
504 // media type, once that's supported. Currently, it is not because the | 645 // media type, once that's supported. Currently, it is not because the |
505 // BaseChannel model relies on there being a single VoiceChannel and | 646 // BaseChannel model relies on there being a single VoiceChannel and |
506 // VideoChannel, and these only support a single set of codecs/etc. per | 647 // VideoChannel, and these only support a single set of codecs/etc. per |
507 // send/receive direction. | 648 // send/receive direction. |
508 | 649 |
509 // TODO(deadbeef): End-to-end test for simulcast, once that's supported by this | 650 // TODO(deadbeef): End-to-end test for simulcast, once that's supported by this |
510 // API. | 651 // API. |
511 | 652 |
512 } // namespace webrtc | 653 } // namespace webrtc |
OLD | NEW |