Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: webrtc/ortc/ortcfactory_integrationtest.cc

Issue 2714813004: Create the SrtpTransportInterface. (Closed)
Patch Set: Use rtc::Optional for SRTP send and receive keys. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/ortc/ortcfactory.cc ('k') | webrtc/ortc/ortcfactory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 kReceivingDuration = 1000; // 1 second.
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:WVNfX19zZW1jdGwgKskgewkyMjA7fQp9CnVubGVz";
38 static const char kTestKeyParams2[] =
39 "inline:PS1uQCVeeCFCanVmcjkpaywjNWhcYD0mXXtxaVBR";
40 static const char kTestKeyParams3[] =
41 "inline:WVNfX19zZW1jdGwgKskgewkyMjA7fQp9CnVubGVa";
42 static const char kTestKeyParams4[] =
43 "inline:WVNfX19zZW1jdGwgKskgewkyMjA7fQp9CnVubGVb";
44 static const cricket::CryptoParams kTestCryptoParams1(1,
45 "AES_CM_128_HMAC_SHA1_80",
46 kTestKeyParams1,
47 "");
48 static const cricket::CryptoParams kTestCryptoParams2(1,
49 "AES_CM_128_HMAC_SHA1_80",
50 kTestKeyParams2,
51 "");
52 static const cricket::CryptoParams kTestCryptoParams3(1,
53 "AES_CM_128_HMAC_SHA1_80",
54 kTestKeyParams3,
55 "");
56 static const cricket::CryptoParams kTestCryptoParams4(1,
57 "AES_CM_128_HMAC_SHA1_80",
58 kTestKeyParams4,
59 "");
35 } // namespace 60 } // namespace
36 61
37 namespace webrtc { 62 namespace webrtc {
38 63
39 // Used to test that things work end-to-end when using the default 64 // Used to test that things work end-to-end when using the default
40 // implementations of threads/etc. provided by OrtcFactory, with the exception 65 // implementations of threads/etc. provided by OrtcFactory, with the exception
41 // of using a virtual network. 66 // of using a virtual network.
42 // 67 //
43 // By default, the virtual network manager doesn't enumerate any networks, but 68 // By default, the virtual network manager doesn't enumerate any networks, but
44 // sockets can still be created in this state. 69 // sockets can still be created in this state.
(...skipping 19 matching lines...) Expand all
64 .MoveValue(); 89 .MoveValue();
65 } 90 }
66 91
67 protected: 92 protected:
68 typedef std::pair<std::unique_ptr<UdpTransportInterface>, 93 typedef std::pair<std::unique_ptr<UdpTransportInterface>,
69 std::unique_ptr<UdpTransportInterface>> 94 std::unique_ptr<UdpTransportInterface>>
70 UdpTransportPair; 95 UdpTransportPair;
71 typedef std::pair<std::unique_ptr<RtpTransportInterface>, 96 typedef std::pair<std::unique_ptr<RtpTransportInterface>,
72 std::unique_ptr<RtpTransportInterface>> 97 std::unique_ptr<RtpTransportInterface>>
73 RtpTransportPair; 98 RtpTransportPair;
99 typedef std::pair<std::unique_ptr<SrtpTransportInterface>,
100 std::unique_ptr<SrtpTransportInterface>>
101 SrtpTransportPair;
74 typedef std::pair<std::unique_ptr<RtpTransportControllerInterface>, 102 typedef std::pair<std::unique_ptr<RtpTransportControllerInterface>,
75 std::unique_ptr<RtpTransportControllerInterface>> 103 std::unique_ptr<RtpTransportControllerInterface>>
76 RtpTransportControllerPair; 104 RtpTransportControllerPair;
77 105
78 // Helper function that creates one UDP transport each for |ortc_factory1_| 106 // Helper function that creates one UDP transport each for |ortc_factory1_|
79 // and |ortc_factory2_|, and connects them. 107 // and |ortc_factory2_|, and connects them.
80 UdpTransportPair CreateAndConnectUdpTransportPair() { 108 UdpTransportPair CreateAndConnectUdpTransportPair() {
81 auto transport1 = ortc_factory1_->CreateUdpTransport(AF_INET).MoveValue(); 109 auto transport1 = ortc_factory1_->CreateUdpTransport(AF_INET).MoveValue();
82 auto transport2 = ortc_factory2_->CreateUdpTransport(AF_INET).MoveValue(); 110 auto transport2 = ortc_factory2_->CreateUdpTransport(AF_INET).MoveValue();
83 transport1->SetRemoteAddress( 111 transport1->SetRemoteAddress(
(...skipping 24 matching lines...) Expand all
108 const RtpTransportControllerPair& transport_controllers) { 136 const RtpTransportControllerPair& transport_controllers) {
109 auto transport_result1 = ortc_factory1_->CreateRtpTransport( 137 auto transport_result1 = ortc_factory1_->CreateRtpTransport(
110 rtcp_parameters, rtp_udp_transports.first.get(), 138 rtcp_parameters, rtp_udp_transports.first.get(),
111 rtcp_udp_transports.first.get(), transport_controllers.first.get()); 139 rtcp_udp_transports.first.get(), transport_controllers.first.get());
112 auto transport_result2 = ortc_factory2_->CreateRtpTransport( 140 auto transport_result2 = ortc_factory2_->CreateRtpTransport(
113 rtcp_parameters, rtp_udp_transports.second.get(), 141 rtcp_parameters, rtp_udp_transports.second.get(),
114 rtcp_udp_transports.second.get(), transport_controllers.second.get()); 142 rtcp_udp_transports.second.get(), transport_controllers.second.get());
115 return {transport_result1.MoveValue(), transport_result2.MoveValue()}; 143 return {transport_result1.MoveValue(), transport_result2.MoveValue()};
116 } 144 }
117 145
146 SrtpTransportPair CreateSrtpTransportPair(
147 const RtcpParameters& rtcp_parameters,
148 const UdpTransportPair& rtp_udp_transports,
149 const UdpTransportPair& rtcp_udp_transports,
150 const RtpTransportControllerPair& transport_controllers) {
151 auto transport_result1 = ortc_factory1_->CreateSrtpTransport(
152 rtcp_parameters, rtp_udp_transports.first.get(),
153 rtcp_udp_transports.first.get(), transport_controllers.first.get());
154 auto transport_result2 = ortc_factory2_->CreateSrtpTransport(
155 rtcp_parameters, rtp_udp_transports.second.get(),
156 rtcp_udp_transports.second.get(), transport_controllers.second.get());
157 return {transport_result1.MoveValue(), transport_result2.MoveValue()};
158 }
159
118 // For convenience when |rtcp_udp_transports| and |transport_controllers| 160 // For convenience when |rtcp_udp_transports| and |transport_controllers|
119 // aren't needed. 161 // aren't needed.
120 RtpTransportPair CreateRtpTransportPair( 162 RtpTransportPair CreateRtpTransportPair(
121 const RtcpParameters& rtcp_parameters, 163 const RtcpParameters& rtcp_parameters,
122 const UdpTransportPair& rtp_udp_transports) { 164 const UdpTransportPair& rtp_udp_transports) {
123 return CreateRtpTransportPair(rtcp_parameters, rtp_udp_transports, 165 return CreateRtpTransportPair(rtcp_parameters, rtp_udp_transports,
124 UdpTransportPair(), 166 UdpTransportPair(),
125 RtpTransportControllerPair()); 167 RtpTransportControllerPair());
126 } 168 }
127 169
170 SrtpTransportPair CreateSrtpTransportPairAndSetKeys(
171 const RtcpParameters& rtcp_parameters,
172 const UdpTransportPair& rtp_udp_transports) {
173 SrtpTransportPair srtp_transports = CreateSrtpTransportPair(
174 rtcp_parameters, rtp_udp_transports, UdpTransportPair(),
175 RtpTransportControllerPair());
176 EXPECT_TRUE(srtp_transports.first->SetSrtpSendKey(kTestCryptoParams1).ok());
177 EXPECT_TRUE(
178 srtp_transports.first->SetSrtpReceiveKey(kTestCryptoParams2).ok());
179 EXPECT_TRUE(
180 srtp_transports.second->SetSrtpSendKey(kTestCryptoParams2).ok());
181 EXPECT_TRUE(
182 srtp_transports.second->SetSrtpReceiveKey(kTestCryptoParams1).ok());
183 return srtp_transports;
184 }
185
186 SrtpTransportPair CreateSrtpTransportPairAndSetMismatchingKeys(
187 const RtcpParameters& rtcp_parameters,
188 const UdpTransportPair& rtp_udp_transports) {
189 SrtpTransportPair srtp_transports = CreateSrtpTransportPair(
190 rtcp_parameters, rtp_udp_transports, UdpTransportPair(),
191 RtpTransportControllerPair());
192 EXPECT_TRUE(srtp_transports.first->SetSrtpSendKey(kTestCryptoParams1).ok());
193 EXPECT_TRUE(
194 srtp_transports.first->SetSrtpReceiveKey(kTestCryptoParams2).ok());
195 EXPECT_TRUE(
196 srtp_transports.second->SetSrtpSendKey(kTestCryptoParams1).ok());
197 EXPECT_TRUE(
198 srtp_transports.second->SetSrtpReceiveKey(kTestCryptoParams2).ok());
199 return srtp_transports;
200 }
201
128 // Ends up using fake audio capture module, which was passed into OrtcFactory 202 // Ends up using fake audio capture module, which was passed into OrtcFactory
129 // on creation. 203 // on creation.
130 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack( 204 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
131 const std::string& id, 205 const std::string& id,
132 OrtcFactoryInterface* ortc_factory) { 206 OrtcFactoryInterface* ortc_factory) {
133 // Disable echo cancellation to make test more efficient. 207 // Disable echo cancellation to make test more efficient.
134 cricket::AudioOptions options; 208 cricket::AudioOptions options;
135 options.echo_cancellation.emplace(true); 209 options.echo_cancellation.emplace(true);
136 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = 210 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
137 ortc_factory->CreateAudioSource(options); 211 ortc_factory->CreateAudioSource(options);
138 return ortc_factory->CreateAudioTrack(id, source); 212 return ortc_factory->CreateAudioTrack(id, source);
139 } 213 }
140 214
141 // Stores created capturer in |fake_video_capturers_|. 215 // Stores created capturer in |fake_video_capturers_|.
142 rtc::scoped_refptr<webrtc::VideoTrackInterface> 216 rtc::scoped_refptr<webrtc::VideoTrackInterface>
143 CreateLocalVideoTrackAndFakeCapturer(const std::string& id, 217 CreateLocalVideoTrackAndFakeCapturer(const std::string& id,
144 OrtcFactoryInterface* ortc_factory) { 218 OrtcFactoryInterface* ortc_factory) {
145 cricket::FakeVideoCapturer* fake_capturer = 219 cricket::FakeVideoCapturer* fake_capturer =
146 new webrtc::FakePeriodicVideoCapturer(); 220 new webrtc::FakePeriodicVideoCapturer();
147 fake_video_capturers_.push_back(fake_capturer); 221 fake_video_capturers_.push_back(fake_capturer);
148 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = 222 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
149 ortc_factory->CreateVideoSource( 223 ortc_factory->CreateVideoSource(
150 std::unique_ptr<cricket::VideoCapturer>(fake_capturer)); 224 std::unique_ptr<cricket::VideoCapturer>(fake_capturer));
151 return rtc::scoped_refptr<webrtc::VideoTrackInterface>( 225 return rtc::scoped_refptr<webrtc::VideoTrackInterface>(
152 ortc_factory->CreateVideoTrack(id, source)); 226 ortc_factory->CreateVideoTrack(id, source));
153 } 227 }
154 228
229 // Helper function used to test two way RTP senders and receivers with basic
230 // configurations.
231 // If |expect_success| is true, waits for kDefaultTimeout for
232 // kDefaultNumFrames frames to be received by all RtpReceivers.
233 // If |expect_success| is false, simply waits for |kReceivingDuration|, and
234 // stores the number of received frames in |received_audio_frame1_| etc.
235 void BasicTwoWayRtpSendersAndReceiversTest(RtpTransportPair srtp_transports,
236 bool expect_success) {
237 received_audio_frames1_ = 0;
238 received_audio_frames2_ = 0;
239 rendered_video_frames1_ = 0;
240 rendered_video_frames2_ = 0;
241 // Create all the senders and receivers (four per endpoint).
242 auto audio_sender_result1 = ortc_factory1_->CreateRtpSender(
243 cricket::MEDIA_TYPE_AUDIO, srtp_transports.first.get());
244 auto video_sender_result1 = ortc_factory1_->CreateRtpSender(
245 cricket::MEDIA_TYPE_VIDEO, srtp_transports.first.get());
246 auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
247 cricket::MEDIA_TYPE_AUDIO, srtp_transports.first.get());
248 auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
249 cricket::MEDIA_TYPE_VIDEO, srtp_transports.first.get());
250 ASSERT_TRUE(audio_sender_result1.ok());
251 ASSERT_TRUE(video_sender_result1.ok());
252 ASSERT_TRUE(audio_receiver_result1.ok());
253 ASSERT_TRUE(video_receiver_result1.ok());
254 auto audio_sender1 = audio_sender_result1.MoveValue();
255 auto video_sender1 = video_sender_result1.MoveValue();
256 auto audio_receiver1 = audio_receiver_result1.MoveValue();
257 auto video_receiver1 = video_receiver_result1.MoveValue();
258
259 auto audio_sender_result2 = ortc_factory2_->CreateRtpSender(
260 cricket::MEDIA_TYPE_AUDIO, srtp_transports.second.get());
261 auto video_sender_result2 = ortc_factory2_->CreateRtpSender(
262 cricket::MEDIA_TYPE_VIDEO, srtp_transports.second.get());
263 auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
264 cricket::MEDIA_TYPE_AUDIO, srtp_transports.second.get());
265 auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
266 cricket::MEDIA_TYPE_VIDEO, srtp_transports.second.get());
267 ASSERT_TRUE(audio_sender_result2.ok());
268 ASSERT_TRUE(video_sender_result2.ok());
269 ASSERT_TRUE(audio_receiver_result2.ok());
270 ASSERT_TRUE(video_receiver_result2.ok());
271 auto audio_sender2 = audio_sender_result2.MoveValue();
272 auto video_sender2 = video_sender_result2.MoveValue();
273 auto audio_receiver2 = audio_receiver_result2.MoveValue();
274 auto video_receiver2 = video_receiver_result2.MoveValue();
275
276 // Add fake tracks.
277 RTCError error = audio_sender1->SetTrack(
278 CreateLocalAudioTrack("audio", ortc_factory1_.get()));
279 EXPECT_TRUE(error.ok());
280 error = video_sender1->SetTrack(
281 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get()));
282 EXPECT_TRUE(error.ok());
283 error = audio_sender2->SetTrack(
284 CreateLocalAudioTrack("audio", ortc_factory2_.get()));
285 EXPECT_TRUE(error.ok());
286 error = video_sender2->SetTrack(
287 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get()));
288 EXPECT_TRUE(error.ok());
289
290 // "sent_X_parameters1" are the parameters that endpoint 1 sends with and
291 // endpoint 2 receives with.
292 RtpParameters sent_opus_parameters1 =
293 MakeMinimalOpusParametersWithSsrc(0xdeadbeef);
294 RtpParameters sent_vp8_parameters1 =
295 MakeMinimalVp8ParametersWithSsrc(0xbaadfeed);
296 RtpParameters sent_opus_parameters2 =
297 MakeMinimalOpusParametersWithSsrc(0x13333337);
298 RtpParameters sent_vp8_parameters2 =
299 MakeMinimalVp8ParametersWithSsrc(0x12345678);
300
301 // Configure the senders' and receivers' parameters.
302 EXPECT_TRUE(audio_receiver1->Receive(sent_opus_parameters2).ok());
303 EXPECT_TRUE(video_receiver1->Receive(sent_vp8_parameters2).ok());
304 EXPECT_TRUE(audio_receiver2->Receive(sent_opus_parameters1).ok());
305 EXPECT_TRUE(video_receiver2->Receive(sent_vp8_parameters1).ok());
306 EXPECT_TRUE(audio_sender1->Send(sent_opus_parameters1).ok());
307 EXPECT_TRUE(video_sender1->Send(sent_vp8_parameters1).ok());
308 EXPECT_TRUE(audio_sender2->Send(sent_opus_parameters2).ok());
309 EXPECT_TRUE(video_sender2->Send(sent_vp8_parameters2).ok());
310
311 FakeVideoTrackRenderer fake_video_renderer1(
312 static_cast<VideoTrackInterface*>(video_receiver1->GetTrack().get()));
313 FakeVideoTrackRenderer fake_video_renderer2(
314 static_cast<VideoTrackInterface*>(video_receiver2->GetTrack().get()));
315
316 if (expect_success) {
317 EXPECT_TRUE_WAIT(
318 fake_audio_capture_module1_->frames_received() > kDefaultNumFrames &&
319 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames &&
320 fake_audio_capture_module2_->frames_received() >
321 kDefaultNumFrames &&
322 fake_video_renderer1.num_rendered_frames() > kDefaultNumFrames,
323 kDefaultTimeout);
324 } else {
325 WAIT(false, kReceivingDuration);
326 rendered_video_frames1_ = fake_video_renderer1.num_rendered_frames();
327 rendered_video_frames2_ = fake_video_renderer2.num_rendered_frames();
328 received_audio_frames1_ = fake_audio_capture_module1_->frames_received();
329 received_audio_frames2_ = fake_audio_capture_module2_->frames_received();
330 }
331 }
332
155 rtc::PhysicalSocketServer physical_socket_server_; 333 rtc::PhysicalSocketServer physical_socket_server_;
156 rtc::VirtualSocketServer virtual_socket_server_; 334 rtc::VirtualSocketServer virtual_socket_server_;
157 rtc::Thread network_thread_; 335 rtc::Thread network_thread_;
158 rtc::FakeNetworkManager fake_network_manager_; 336 rtc::FakeNetworkManager fake_network_manager_;
159 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module1_; 337 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module1_;
160 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module2_; 338 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module2_;
161 std::unique_ptr<OrtcFactoryInterface> ortc_factory1_; 339 std::unique_ptr<OrtcFactoryInterface> ortc_factory1_;
162 std::unique_ptr<OrtcFactoryInterface> ortc_factory2_; 340 std::unique_ptr<OrtcFactoryInterface> ortc_factory2_;
163 // Actually owned by video tracks. 341 // Actually owned by video tracks.
164 std::vector<cricket::FakeVideoCapturer*> fake_video_capturers_; 342 std::vector<cricket::FakeVideoCapturer*> fake_video_capturers_;
343 int received_audio_frames1_ = 0;
344 int received_audio_frames2_ = 0;
345 int rendered_video_frames1_ = 0;
346 int rendered_video_frames2_ = 0;
165 }; 347 };
166 348
167 // Very basic end-to-end test with a single pair of audio RTP sender and 349 // Very basic end-to-end test with a single pair of audio RTP sender and
168 // receiver. 350 // receiver.
169 // 351 //
170 // Uses muxed RTCP, and minimal parameters with a hard-coded config that's 352 // Uses muxed RTCP, and minimal parameters with a hard-coded config that's
171 // known to work. 353 // known to work.
172 TEST_F(OrtcFactoryIntegrationTest, BasicOneWayAudioRtpSenderAndReceiver) { 354 TEST_F(OrtcFactoryIntegrationTest, BasicOneWayAudioRtpSenderAndReceiver) {
173 auto udp_transports = CreateAndConnectUdpTransportPair(); 355 auto udp_transports = CreateAndConnectUdpTransportPair();
174 auto rtp_transports = 356 auto rtp_transports =
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // End-to-end test with two pairs of RTP senders and receivers, for audio and 460 // End-to-end test with two pairs of RTP senders and receivers, for audio and
279 // video. 461 // video.
280 // 462 //
281 // Uses muxed RTCP, and minimal parameters with hard-coded configs that are 463 // Uses muxed RTCP, and minimal parameters with hard-coded configs that are
282 // known to work. 464 // known to work.
283 TEST_F(OrtcFactoryIntegrationTest, 465 TEST_F(OrtcFactoryIntegrationTest,
284 BasicTwoWayAudioVideoRtpSendersAndReceivers) { 466 BasicTwoWayAudioVideoRtpSendersAndReceivers) {
285 auto udp_transports = CreateAndConnectUdpTransportPair(); 467 auto udp_transports = CreateAndConnectUdpTransportPair();
286 auto rtp_transports = 468 auto rtp_transports =
287 CreateRtpTransportPair(MakeRtcpMuxParameters(), udp_transports); 469 CreateRtpTransportPair(MakeRtcpMuxParameters(), udp_transports);
470 bool expect_success = true;
471 BasicTwoWayRtpSendersAndReceiversTest(std::move(rtp_transports),
472 expect_success);
473 }
288 474
289 // Create all the senders and receivers (four per endpoint). 475 TEST_F(OrtcFactoryIntegrationTest,
290 auto audio_sender_result1 = ortc_factory1_->CreateRtpSender( 476 BasicTwoWayAudioVideoSrtpSendersAndReceivers) {
291 cricket::MEDIA_TYPE_AUDIO, rtp_transports.first.get()); 477 auto udp_transports = CreateAndConnectUdpTransportPair();
292 auto video_sender_result1 = ortc_factory1_->CreateRtpSender( 478 auto srtp_transports = CreateSrtpTransportPairAndSetKeys(
293 cricket::MEDIA_TYPE_VIDEO, rtp_transports.first.get()); 479 MakeRtcpMuxParameters(), udp_transports);
294 auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver( 480 bool expect_success = true;
295 cricket::MEDIA_TYPE_AUDIO, rtp_transports.first.get()); 481 BasicTwoWayRtpSendersAndReceiversTest(std::move(srtp_transports),
296 auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver( 482 expect_success);
297 cricket::MEDIA_TYPE_VIDEO, rtp_transports.first.get()); 483 }
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 484
307 auto audio_sender_result2 = ortc_factory2_->CreateRtpSender( 485 // Tests that the packets cannot be decoded if the keys are mismatched.
308 cricket::MEDIA_TYPE_AUDIO, rtp_transports.second.get()); 486 TEST_F(OrtcFactoryIntegrationTest, SrtpSendersAndReceiversWithMismatchingKeys) {
309 auto video_sender_result2 = ortc_factory2_->CreateRtpSender( 487 auto udp_transports = CreateAndConnectUdpTransportPair();
310 cricket::MEDIA_TYPE_VIDEO, rtp_transports.second.get()); 488 auto srtp_transports = CreateSrtpTransportPairAndSetMismatchingKeys(
311 auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver( 489 MakeRtcpMuxParameters(), udp_transports);
312 cricket::MEDIA_TYPE_AUDIO, rtp_transports.second.get()); 490 bool expect_success = false;
313 auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver( 491 BasicTwoWayRtpSendersAndReceiversTest(std::move(srtp_transports),
314 cricket::MEDIA_TYPE_VIDEO, rtp_transports.second.get()); 492 expect_success);
315 ASSERT_TRUE(audio_sender_result2.ok()); 493 // No frames are expected to be decoded.
316 ASSERT_TRUE(video_sender_result2.ok()); 494 EXPECT_TRUE(received_audio_frames1_ == 0 && received_audio_frames2_ == 0 &&
317 ASSERT_TRUE(audio_receiver_result2.ok()); 495 rendered_video_frames1_ == 0 && rendered_video_frames2_ == 0);
318 ASSERT_TRUE(video_receiver_result2.ok()); 496 }
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 497
324 // Add fake tracks. 498 // Tests that the frames cannot be decoded if only one side uses SRTP.
325 RTCError error = audio_sender1->SetTrack( 499 TEST_F(OrtcFactoryIntegrationTest, OneSideSrtpSenderAndReceiver) {
326 CreateLocalAudioTrack("audio", ortc_factory1_.get())); 500 auto rtcp_parameters = MakeRtcpMuxParameters();
327 EXPECT_TRUE(error.ok()); 501 auto udp_transports = CreateAndConnectUdpTransportPair();
328 error = video_sender1->SetTrack( 502 auto rtcp_udp_transports = UdpTransportPair();
329 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get())); 503 auto transport_controllers = RtpTransportControllerPair();
330 EXPECT_TRUE(error.ok()); 504 auto transport_result1 = ortc_factory1_->CreateRtpTransport(
331 error = audio_sender2->SetTrack( 505 rtcp_parameters, udp_transports.first.get(),
332 CreateLocalAudioTrack("audio", ortc_factory2_.get())); 506 rtcp_udp_transports.first.get(), transport_controllers.first.get());
333 EXPECT_TRUE(error.ok()); 507 auto transport_result2 = ortc_factory2_->CreateSrtpTransport(
334 error = video_sender2->SetTrack( 508 rtcp_parameters, udp_transports.second.get(),
335 CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get())); 509 rtcp_udp_transports.second.get(), transport_controllers.second.get());
336 EXPECT_TRUE(error.ok());
337 510
338 // "sent_X_parameters1" are the parameters that endpoint 1 sends with and 511 auto rtp_transport = transport_result1.MoveValue();
339 // endpoint 2 receives with. 512 auto srtp_transport = transport_result2.MoveValue();
340 RtpParameters sent_opus_parameters1 = 513 EXPECT_TRUE(srtp_transport->SetSrtpSendKey(kTestCryptoParams1).ok());
341 MakeMinimalOpusParametersWithSsrc(0xdeadbeef); 514 EXPECT_TRUE(srtp_transport->SetSrtpReceiveKey(kTestCryptoParams2).ok());
342 RtpParameters sent_vp8_parameters1 = 515 bool expect_success = false;
343 MakeMinimalVp8ParametersWithSsrc(0xbaadfeed); 516 BasicTwoWayRtpSendersAndReceiversTest(
344 RtpParameters sent_opus_parameters2 = 517 {std::move(rtp_transport), std::move(srtp_transport)}, expect_success);
345 MakeMinimalOpusParametersWithSsrc(0x13333337);
346 RtpParameters sent_vp8_parameters2 =
347 MakeMinimalVp8ParametersWithSsrc(0x12345678);
348 518
349 // Configure the senders' and receivers' parameters. 519 // The SRTP side is not expected to decode any audio or video frames.
350 EXPECT_TRUE(audio_receiver1->Receive(sent_opus_parameters2).ok()); 520 // The RTP side is not expected to decode any video frames while it is
351 EXPECT_TRUE(video_receiver1->Receive(sent_vp8_parameters2).ok()); 521 // possible that the encrypted audio frames can be accidentally decoded which
352 EXPECT_TRUE(audio_receiver2->Receive(sent_opus_parameters1).ok()); 522 // is why received_audio_frames1_ is not validated.
353 EXPECT_TRUE(video_receiver2->Receive(sent_vp8_parameters1).ok()); 523 EXPECT_TRUE(received_audio_frames2_ == 0 && rendered_video_frames1_ == 0 &&
354 EXPECT_TRUE(audio_sender1->Send(sent_opus_parameters1).ok()); 524 rendered_video_frames2_ == 0);
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 } 525 }
373 526
374 // End-to-end test with two pairs of RTP senders and receivers, for audio and 527 // 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 528 // video. Unlike the test above, this attempts to make the parameters as
376 // complex as possible. 529 // complex as possible. The senders and receivers use the SRTP transport with
530 // different keys.
377 // 531 //
378 // Uses non-muxed RTCP, with separate audio/video transports, and a full set of 532 // Uses non-muxed RTCP, with separate audio/video transports, and a full set of
379 // parameters, as would normally be used in a PeerConnection. 533 // parameters, as would normally be used in a PeerConnection.
380 // 534 //
381 // TODO(deadbeef): Update this test as more audio/video features become 535 // TODO(deadbeef): Update this test as more audio/video features become
382 // supported. 536 // supported.
383 TEST_F(OrtcFactoryIntegrationTest, FullTwoWayAudioVideoRtpSendersAndReceivers) { 537 TEST_F(OrtcFactoryIntegrationTest,
538 FullTwoWayAudioVideoSrtpSendersAndReceivers) {
384 // We want four pairs of UDP transports for this test, for audio/video and 539 // We want four pairs of UDP transports for this test, for audio/video and
385 // RTP/RTCP. 540 // RTP/RTCP.
386 auto audio_rtp_udp_transports = CreateAndConnectUdpTransportPair(); 541 auto audio_rtp_udp_transports = CreateAndConnectUdpTransportPair();
387 auto audio_rtcp_udp_transports = CreateAndConnectUdpTransportPair(); 542 auto audio_rtcp_udp_transports = CreateAndConnectUdpTransportPair();
388 auto video_rtp_udp_transports = CreateAndConnectUdpTransportPair(); 543 auto video_rtp_udp_transports = CreateAndConnectUdpTransportPair();
389 auto video_rtcp_udp_transports = CreateAndConnectUdpTransportPair(); 544 auto video_rtcp_udp_transports = CreateAndConnectUdpTransportPair();
390 545
391 // Since we have multiple RTP transports on each side, we need an RTP 546 // Since we have multiple RTP transports on each side, we need an RTP
392 // transport controller. 547 // transport controller.
393 auto transport_controllers = CreateRtpTransportControllerPair(); 548 auto transport_controllers = CreateRtpTransportControllerPair();
394 549
395 RtcpParameters audio_rtcp_parameters; 550 RtcpParameters audio_rtcp_parameters;
396 audio_rtcp_parameters.mux = false; 551 audio_rtcp_parameters.mux = false;
397 auto audio_rtp_transports = 552 auto audio_srtp_transports =
398 CreateRtpTransportPair(audio_rtcp_parameters, audio_rtp_udp_transports, 553 CreateSrtpTransportPair(audio_rtcp_parameters, audio_rtp_udp_transports,
399 audio_rtcp_udp_transports, transport_controllers); 554 audio_rtcp_udp_transports, transport_controllers);
400 555
401 RtcpParameters video_rtcp_parameters; 556 RtcpParameters video_rtcp_parameters;
402 video_rtcp_parameters.mux = false; 557 video_rtcp_parameters.mux = false;
403 video_rtcp_parameters.reduced_size = true; 558 video_rtcp_parameters.reduced_size = true;
404 auto video_rtp_transports = 559 auto video_srtp_transports =
405 CreateRtpTransportPair(video_rtcp_parameters, video_rtp_udp_transports, 560 CreateSrtpTransportPair(video_rtcp_parameters, video_rtp_udp_transports,
406 video_rtcp_udp_transports, transport_controllers); 561 video_rtcp_udp_transports, transport_controllers);
562
563 // Set keys for SRTP transports.
564 audio_srtp_transports.first->SetSrtpSendKey(kTestCryptoParams1);
565 audio_srtp_transports.first->SetSrtpReceiveKey(kTestCryptoParams2);
566 video_srtp_transports.first->SetSrtpSendKey(kTestCryptoParams3);
567 video_srtp_transports.first->SetSrtpReceiveKey(kTestCryptoParams4);
568
569 audio_srtp_transports.second->SetSrtpSendKey(kTestCryptoParams2);
570 audio_srtp_transports.second->SetSrtpReceiveKey(kTestCryptoParams1);
571 video_srtp_transports.second->SetSrtpSendKey(kTestCryptoParams4);
572 video_srtp_transports.second->SetSrtpReceiveKey(kTestCryptoParams3);
407 573
408 // Create all the senders and receivers (four per endpoint). 574 // Create all the senders and receivers (four per endpoint).
409 auto audio_sender_result1 = ortc_factory1_->CreateRtpSender( 575 auto audio_sender_result1 = ortc_factory1_->CreateRtpSender(
410 cricket::MEDIA_TYPE_AUDIO, audio_rtp_transports.first.get()); 576 cricket::MEDIA_TYPE_AUDIO, audio_srtp_transports.first.get());
411 auto video_sender_result1 = ortc_factory1_->CreateRtpSender( 577 auto video_sender_result1 = ortc_factory1_->CreateRtpSender(
412 cricket::MEDIA_TYPE_VIDEO, video_rtp_transports.first.get()); 578 cricket::MEDIA_TYPE_VIDEO, video_srtp_transports.first.get());
413 auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver( 579 auto audio_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
414 cricket::MEDIA_TYPE_AUDIO, audio_rtp_transports.first.get()); 580 cricket::MEDIA_TYPE_AUDIO, audio_srtp_transports.first.get());
415 auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver( 581 auto video_receiver_result1 = ortc_factory1_->CreateRtpReceiver(
416 cricket::MEDIA_TYPE_VIDEO, video_rtp_transports.first.get()); 582 cricket::MEDIA_TYPE_VIDEO, video_srtp_transports.first.get());
417 ASSERT_TRUE(audio_sender_result1.ok()); 583 ASSERT_TRUE(audio_sender_result1.ok());
418 ASSERT_TRUE(video_sender_result1.ok()); 584 ASSERT_TRUE(video_sender_result1.ok());
419 ASSERT_TRUE(audio_receiver_result1.ok()); 585 ASSERT_TRUE(audio_receiver_result1.ok());
420 ASSERT_TRUE(video_receiver_result1.ok()); 586 ASSERT_TRUE(video_receiver_result1.ok());
421 auto audio_sender1 = audio_sender_result1.MoveValue(); 587 auto audio_sender1 = audio_sender_result1.MoveValue();
422 auto video_sender1 = video_sender_result1.MoveValue(); 588 auto video_sender1 = video_sender_result1.MoveValue();
423 auto audio_receiver1 = audio_receiver_result1.MoveValue(); 589 auto audio_receiver1 = audio_receiver_result1.MoveValue();
424 auto video_receiver1 = video_receiver_result1.MoveValue(); 590 auto video_receiver1 = video_receiver_result1.MoveValue();
425 591
426 auto audio_sender_result2 = ortc_factory2_->CreateRtpSender( 592 auto audio_sender_result2 = ortc_factory2_->CreateRtpSender(
427 cricket::MEDIA_TYPE_AUDIO, audio_rtp_transports.second.get()); 593 cricket::MEDIA_TYPE_AUDIO, audio_srtp_transports.second.get());
428 auto video_sender_result2 = ortc_factory2_->CreateRtpSender( 594 auto video_sender_result2 = ortc_factory2_->CreateRtpSender(
429 cricket::MEDIA_TYPE_VIDEO, video_rtp_transports.second.get()); 595 cricket::MEDIA_TYPE_VIDEO, video_srtp_transports.second.get());
430 auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver( 596 auto audio_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
431 cricket::MEDIA_TYPE_AUDIO, audio_rtp_transports.second.get()); 597 cricket::MEDIA_TYPE_AUDIO, audio_srtp_transports.second.get());
432 auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver( 598 auto video_receiver_result2 = ortc_factory2_->CreateRtpReceiver(
433 cricket::MEDIA_TYPE_VIDEO, video_rtp_transports.second.get()); 599 cricket::MEDIA_TYPE_VIDEO, video_srtp_transports.second.get());
434 ASSERT_TRUE(audio_sender_result2.ok()); 600 ASSERT_TRUE(audio_sender_result2.ok());
435 ASSERT_TRUE(video_sender_result2.ok()); 601 ASSERT_TRUE(video_sender_result2.ok());
436 ASSERT_TRUE(audio_receiver_result2.ok()); 602 ASSERT_TRUE(audio_receiver_result2.ok());
437 ASSERT_TRUE(video_receiver_result2.ok()); 603 ASSERT_TRUE(video_receiver_result2.ok());
438 auto audio_sender2 = audio_sender_result2.MoveValue(); 604 auto audio_sender2 = audio_sender_result2.MoveValue();
439 auto video_sender2 = video_sender_result2.MoveValue(); 605 auto video_sender2 = video_sender_result2.MoveValue();
440 auto audio_receiver2 = audio_receiver_result2.MoveValue(); 606 auto audio_receiver2 = audio_receiver_result2.MoveValue();
441 auto video_receiver2 = video_receiver_result2.MoveValue(); 607 auto video_receiver2 = video_receiver_result2.MoveValue();
442 608
443 RTCError error = audio_sender1->SetTrack( 609 RTCError error = audio_sender1->SetTrack(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // TODO(deadbeef): End-to-end test for multiple senders/receivers of the same 669 // 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 670 // media type, once that's supported. Currently, it is not because the
505 // BaseChannel model relies on there being a single VoiceChannel and 671 // BaseChannel model relies on there being a single VoiceChannel and
506 // VideoChannel, and these only support a single set of codecs/etc. per 672 // VideoChannel, and these only support a single set of codecs/etc. per
507 // send/receive direction. 673 // send/receive direction.
508 674
509 // TODO(deadbeef): End-to-end test for simulcast, once that's supported by this 675 // TODO(deadbeef): End-to-end test for simulcast, once that's supported by this
510 // API. 676 // API.
511 677
512 } // namespace webrtc 678 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/ortc/ortcfactory.cc ('k') | webrtc/ortc/ortcfactory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698