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

Side by Side Diff: webrtc/pc/channel_unittest.cc

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the memory leak. Created 3 years, 11 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/pc/channel.cc ('k') | webrtc/pc/channelmanager.h » ('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 2009 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2009 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 12
13 #include "webrtc/base/array_view.h" 13 #include "webrtc/base/array_view.h"
14 #include "webrtc/base/buffer.h" 14 #include "webrtc/base/buffer.h"
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/fakeclock.h" 16 #include "webrtc/base/fakeclock.h"
17 #include "webrtc/base/gunit.h" 17 #include "webrtc/base/gunit.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/base/sslstreamadapter.h" 19 #include "webrtc/base/sslstreamadapter.h"
20 #include "webrtc/media/base/fakemediaengine.h" 20 #include "webrtc/media/base/fakemediaengine.h"
21 #include "webrtc/media/base/fakertp.h" 21 #include "webrtc/media/base/fakertp.h"
22 #include "webrtc/media/base/mediachannel.h" 22 #include "webrtc/media/base/mediachannel.h"
23 #include "webrtc/media/base/testutils.h" 23 #include "webrtc/media/base/testutils.h"
24 #include "webrtc/p2p/base/dtlstransportinternal.h"
24 #include "webrtc/p2p/base/faketransportcontroller.h" 25 #include "webrtc/p2p/base/faketransportcontroller.h"
25 #include "webrtc/p2p/base/transportchannelimpl.h"
26 #include "webrtc/pc/channel.h" 26 #include "webrtc/pc/channel.h"
27 27
28 #define MAYBE_SKIP_TEST(feature) \ 28 #define MAYBE_SKIP_TEST(feature) \
29 if (!(rtc::SSLStreamAdapter::feature())) { \ 29 if (!(rtc::SSLStreamAdapter::feature())) { \
30 LOG(LS_INFO) << "Feature disabled... skipping"; \ 30 LOG(LS_INFO) << "Feature disabled... skipping"; \
31 return; \ 31 return; \
32 } 32 }
33 33
34 using cricket::CA_OFFER; 34 using cricket::CA_OFFER;
35 using cricket::CA_PRANSWER; 35 using cricket::CA_PRANSWER;
36 using cricket::CA_ANSWER; 36 using cricket::CA_ANSWER;
37 using cricket::CA_UPDATE; 37 using cricket::CA_UPDATE;
38 using cricket::DtlsTransportInternal;
38 using cricket::FakeVoiceMediaChannel; 39 using cricket::FakeVoiceMediaChannel;
39 using cricket::StreamParams; 40 using cricket::StreamParams;
40 using cricket::TransportChannel;
41 41
42 namespace { 42 namespace {
43 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1); 43 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
44 const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1); 44 const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
45 const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1); 45 const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
46 const cricket::VideoCodec kH264Codec(97, "H264"); 46 const cricket::VideoCodec kH264Codec(97, "H264");
47 const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC"); 47 const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
48 const cricket::DataCodec kGoogleDataCodec(101, "google-data"); 48 const cricket::DataCodec kGoogleDataCodec(101, "google-data");
49 const uint32_t kSsrc1 = 0x1111; 49 const uint32_t kSsrc1 = 0x1111;
50 const uint32_t kSsrc2 = 0x2222; 50 const uint32_t kSsrc2 = 0x2222;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 rtc::Thread* signaling_thread = 209 rtc::Thread* signaling_thread =
210 transport_controller ? transport_controller->signaling_thread() 210 transport_controller ? transport_controller->signaling_thread()
211 : nullptr; 211 : nullptr;
212 typename T::Channel* channel = new typename T::Channel( 212 typename T::Channel* channel = new typename T::Channel(
213 worker_thread, network_thread, signaling_thread, engine, ch, 213 worker_thread, network_thread, signaling_thread, engine, ch,
214 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0, 214 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0,
215 (flags & SECURE) != 0); 215 (flags & SECURE) != 0);
216 rtc::CryptoOptions crypto_options; 216 rtc::CryptoOptions crypto_options;
217 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0; 217 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
218 channel->SetCryptoOptions(crypto_options); 218 channel->SetCryptoOptions(crypto_options);
219 cricket::TransportChannel* rtp_transport = 219 cricket::DtlsTransportInternal* rtp_dtls_transport =
220 transport_controller->CreateTransportChannel( 220 transport_controller->CreateDtlsTransport(
221 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP); 221 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
222 cricket::TransportChannel* rtcp_transport = nullptr; 222 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr;
223 if (channel->NeedsRtcpTransport()) { 223 if (channel->NeedsRtcpTransport()) {
224 rtcp_transport = transport_controller->CreateTransportChannel( 224 rtcp_dtls_transport = transport_controller->CreateDtlsTransport(
225 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP); 225 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
226 } 226 }
227 if (!channel->Init_w(rtp_transport, rtcp_transport)) { 227 if (!channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport)) {
228 delete channel; 228 delete channel;
229 channel = NULL; 229 channel = NULL;
230 } 230 }
231 return channel; 231 return channel;
232 } 232 }
233 233
234 bool SendInitiate() { 234 bool SendInitiate() {
235 bool result = channel1_->SetLocalContent(&local_media_content1_, 235 bool result = channel1_->SetLocalContent(&local_media_content1_,
236 CA_OFFER, NULL); 236 CA_OFFER, NULL);
237 if (result) { 237 if (result) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return true; 292 return true;
293 } 293 }
294 294
295 bool AddStream1(int id) { 295 bool AddStream1(int id) {
296 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); 296 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
297 } 297 }
298 bool RemoveStream1(int id) { 298 bool RemoveStream1(int id) {
299 return channel1_->RemoveRecvStream(id); 299 return channel1_->RemoveRecvStream(id);
300 } 300 }
301 301
302 std::vector<cricket::TransportChannelImpl*> GetChannels1() { 302 std::vector<cricket::DtlsTransportInternal*> GetChannels1() {
303 return transport_controller1_->channels_for_testing(); 303 return transport_controller1_->channels_for_testing();
304 } 304 }
305 305
306 std::vector<cricket::TransportChannelImpl*> GetChannels2() { 306 std::vector<cricket::DtlsTransportInternal*> GetChannels2() {
307 return transport_controller2_->channels_for_testing(); 307 return transport_controller2_->channels_for_testing();
308 } 308 }
309 309
310 cricket::FakeTransportChannel* GetFakeChannel1(int component) { 310 cricket::FakeDtlsTransport* GetFakeChannel1(int component) {
311 return transport_controller1_->GetFakeTransportChannel_n( 311 return transport_controller1_->GetFakeDtlsTransport_n(
312 channel1_->content_name(), component); 312 channel1_->content_name(), component);
313 } 313 }
314 314
315 cricket::FakeTransportChannel* GetFakeChannel2(int component) { 315 cricket::FakeDtlsTransport* GetFakeChannel2(int component) {
316 return transport_controller2_->GetFakeTransportChannel_n( 316 return transport_controller2_->GetFakeDtlsTransport_n(
317 channel2_->content_name(), component); 317 channel2_->content_name(), component);
318 } 318 }
319 319
320 void SendRtp1() { 320 void SendRtp1() {
321 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(), 321 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
322 rtc::PacketOptions()); 322 rtc::PacketOptions());
323 } 323 }
324 void SendRtp2() { 324 void SendRtp2() {
325 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(), 325 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
326 rtc::PacketOptions()); 326 rtc::PacketOptions());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 bool CheckNoRtcp1() { 404 bool CheckNoRtcp1() {
405 return media_channel1_->CheckNoRtcp(); 405 return media_channel1_->CheckNoRtcp();
406 } 406 }
407 bool CheckNoRtcp2() { 407 bool CheckNoRtcp2() {
408 return media_channel2_->CheckNoRtcp(); 408 return media_channel2_->CheckNoRtcp();
409 } 409 }
410 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags. 410 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
411 // Returns true if so. 411 // Returns true if so.
412 bool CheckGcmCipher(typename T::Channel* channel, int flags) { 412 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
413 int suite; 413 int suite;
414 if (!channel->rtp_transport()->GetSrtpCryptoSuite(&suite)) { 414 if (!channel->rtp_dtls_transport()->GetSrtpCryptoSuite(&suite)) {
415 return false; 415 return false;
416 } 416 }
417 417
418 if (flags & GCM_CIPHER) { 418 if (flags & GCM_CIPHER) {
419 return rtc::IsGcmCryptoSuite(suite); 419 return rtc::IsGcmCryptoSuite(suite);
420 } else { 420 } else {
421 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE && 421 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
422 !rtc::IsGcmCryptoSuite(suite)); 422 !rtc::IsGcmCryptoSuite(suite));
423 } 423 }
424 } 424 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); 534 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
535 ASSERT_EQ(1U, media_channel1_->codecs().size()); 535 ASSERT_EQ(1U, media_channel1_->codecs().size());
536 EXPECT_TRUE(CodecMatches(content.codecs()[0], 536 EXPECT_TRUE(CodecMatches(content.codecs()[0],
537 media_channel1_->codecs()[0])); 537 media_channel1_->codecs()[0]));
538 } 538 }
539 539
540 // Test that SetLocalContent and SetRemoteContent properly set RTCP 540 // Test that SetLocalContent and SetRemoteContent properly set RTCP
541 // mux. 541 // mux.
542 void TestSetContentsRtcpMux() { 542 void TestSetContentsRtcpMux() {
543 CreateChannels(0, 0); 543 CreateChannels(0, 0);
544 EXPECT_TRUE(channel1_->rtcp_transport() != NULL); 544 EXPECT_TRUE(channel1_->rtcp_dtls_transport() != NULL);
545 EXPECT_TRUE(channel2_->rtcp_transport() != NULL); 545 EXPECT_TRUE(channel2_->rtcp_dtls_transport() != NULL);
546 typename T::Content content; 546 typename T::Content content;
547 CreateContent(0, kPcmuCodec, kH264Codec, &content); 547 CreateContent(0, kPcmuCodec, kH264Codec, &content);
548 // Both sides agree on mux. Should no longer be a separate RTCP channel. 548 // Both sides agree on mux. Should no longer be a separate RTCP channel.
549 content.set_rtcp_mux(true); 549 content.set_rtcp_mux(true);
550 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); 550 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
551 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); 551 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
552 EXPECT_TRUE(channel1_->rtcp_transport() == NULL); 552 EXPECT_TRUE(channel1_->rtcp_dtls_transport() == NULL);
553 // Only initiator supports mux. Should still have a separate RTCP channel. 553 // Only initiator supports mux. Should still have a separate RTCP channel.
554 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL)); 554 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
555 content.set_rtcp_mux(false); 555 content.set_rtcp_mux(false);
556 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL)); 556 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
557 EXPECT_TRUE(channel2_->rtcp_transport() != NULL); 557 EXPECT_TRUE(channel2_->rtcp_dtls_transport() != NULL);
558 } 558 }
559 559
560 // Test that SetLocalContent and SetRemoteContent properly set RTCP 560 // Test that SetLocalContent and SetRemoteContent properly set RTCP
561 // mux when a provisional answer is received. 561 // mux when a provisional answer is received.
562 void TestSetContentsRtcpMuxWithPrAnswer() { 562 void TestSetContentsRtcpMuxWithPrAnswer() {
563 CreateChannels(0, 0); 563 CreateChannels(0, 0);
564 EXPECT_TRUE(channel1_->rtcp_transport() != NULL); 564 EXPECT_TRUE(channel1_->rtcp_dtls_transport() != NULL);
565 EXPECT_TRUE(channel2_->rtcp_transport() != NULL); 565 EXPECT_TRUE(channel2_->rtcp_dtls_transport() != NULL);
566 typename T::Content content; 566 typename T::Content content;
567 CreateContent(0, kPcmuCodec, kH264Codec, &content); 567 CreateContent(0, kPcmuCodec, kH264Codec, &content);
568 content.set_rtcp_mux(true); 568 content.set_rtcp_mux(true);
569 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); 569 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
570 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL)); 570 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
571 EXPECT_TRUE(channel1_->rtcp_transport() != NULL); 571 EXPECT_TRUE(channel1_->rtcp_dtls_transport() != NULL);
572 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); 572 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
573 // Both sides agree on mux. Should no longer be a separate RTCP channel. 573 // Both sides agree on mux. Should no longer be a separate RTCP channel.
574 EXPECT_TRUE(channel1_->rtcp_transport() == NULL); 574 EXPECT_TRUE(channel1_->rtcp_dtls_transport() == NULL);
575 // Only initiator supports mux. Should still have a separate RTCP channel. 575 // Only initiator supports mux. Should still have a separate RTCP channel.
576 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL)); 576 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
577 content.set_rtcp_mux(false); 577 content.set_rtcp_mux(false);
578 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL)); 578 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
579 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL)); 579 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
580 EXPECT_TRUE(channel2_->rtcp_transport() != NULL); 580 EXPECT_TRUE(channel2_->rtcp_dtls_transport() != NULL);
581 } 581 }
582 582
583 // Test that SetRemoteContent properly deals with a content update. 583 // Test that SetRemoteContent properly deals with a content update.
584 void TestSetRemoteContentUpdate() { 584 void TestSetRemoteContentUpdate() {
585 CreateChannels(0, 0); 585 CreateChannels(0, 0);
586 typename T::Content content; 586 typename T::Content content;
587 CreateContent(RTCP_MUX | SECURE, kPcmuCodec, kH264Codec, &content); 587 CreateContent(RTCP_MUX | SECURE, kPcmuCodec, kH264Codec, &content);
588 EXPECT_EQ(0U, media_channel1_->codecs().size()); 588 EXPECT_EQ(0U, media_channel1_->codecs().size());
589 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); 589 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
590 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); 590 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 950
951 // Tests that when the transport channel signals a candidate pair change 951 // Tests that when the transport channel signals a candidate pair change
952 // event, the media channel will receive a call on the network route change. 952 // event, the media channel will receive a call on the network route change.
953 void TestNetworkRouteChanges() { 953 void TestNetworkRouteChanges() {
954 constexpr uint16_t kLocalNetId = 1; 954 constexpr uint16_t kLocalNetId = 1;
955 constexpr uint16_t kRemoteNetId = 2; 955 constexpr uint16_t kRemoteNetId = 2;
956 constexpr int kLastPacketId = 100; 956 constexpr int kLastPacketId = 100;
957 957
958 CreateChannels(0, 0); 958 CreateChannels(0, 0);
959 959
960 cricket::TransportChannel* transport_channel1 = channel1_->rtp_transport(); 960 cricket::DtlsTransportInternal* transport_channel1 =
961 channel1_->rtp_dtls_transport();
961 ASSERT_TRUE(transport_channel1); 962 ASSERT_TRUE(transport_channel1);
962 typename T::MediaChannel* media_channel1 = 963 typename T::MediaChannel* media_channel1 =
963 static_cast<typename T::MediaChannel*>(channel1_->media_channel()); 964 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
964 ASSERT_TRUE(media_channel1); 965 ASSERT_TRUE(media_channel1);
965 966
966 media_channel1->set_num_network_route_changes(0); 967 media_channel1->set_num_network_route_changes(0);
967 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] { 968 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
968 // The transport channel becomes disconnected. 969 // The transport channel becomes disconnected.
969 transport_channel1->SignalSelectedCandidatePairChanged( 970 transport_channel1->ice_transport()->SignalSelectedCandidatePairChanged(
970 transport_channel1, nullptr, -1, false); 971 transport_channel1->ice_transport(), nullptr, -1, false);
971 }); 972 });
972 WaitForThreads(); 973 WaitForThreads();
973 EXPECT_EQ(1, media_channel1->num_network_route_changes()); 974 EXPECT_EQ(1, media_channel1->num_network_route_changes());
974 EXPECT_FALSE(media_channel1->last_network_route().connected); 975 EXPECT_FALSE(media_channel1->last_network_route().connected);
975 media_channel1->set_num_network_route_changes(0); 976 media_channel1->set_num_network_route_changes(0);
976 977
977 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1, 978 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
978 media_channel1, kLocalNetId, 979 media_channel1, kLocalNetId,
979 kRemoteNetId, kLastPacketId] { 980 kRemoteNetId, kLastPacketId] {
980 // The transport channel becomes connected. 981 // The transport channel becomes connected.
981 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */); 982 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
982 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */); 983 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
983 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair( 984 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
984 transport_controller1_->CreateFakeCandidatePair( 985 transport_controller1_->CreateFakeCandidatePair(
985 local_address, kLocalNetId, remote_address, kRemoteNetId)); 986 local_address, kLocalNetId, remote_address, kRemoteNetId));
986 transport_channel1->SignalSelectedCandidatePairChanged( 987 transport_channel1->ice_transport()->SignalSelectedCandidatePairChanged(
987 transport_channel1, candidate_pair.get(), kLastPacketId, true); 988 transport_channel1->ice_transport(), candidate_pair.get(),
989 kLastPacketId, true);
988 }); 990 });
989 WaitForThreads(); 991 WaitForThreads();
990 EXPECT_EQ(1, media_channel1->num_network_route_changes()); 992 EXPECT_EQ(1, media_channel1->num_network_route_changes());
991 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId, 993 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
992 kLastPacketId); 994 kLastPacketId);
993 EXPECT_EQ(expected_network_route, media_channel1->last_network_route()); 995 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
994 EXPECT_EQ(kLastPacketId, 996 EXPECT_EQ(kLastPacketId,
995 media_channel1->last_network_route().last_sent_packet_id); 997 media_channel1->last_network_route().last_sent_packet_id);
996 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8). 998 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
997 EXPECT_EQ(kTransportOverheadPerPacket, 999 EXPECT_EQ(kTransportOverheadPerPacket,
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 network_thread_->Invoke<void>( 1468 network_thread_->Invoke<void>(
1467 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetDestination(nullptr); }); 1469 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetDestination(nullptr); });
1468 EXPECT_TRUE(media_channel1_->sending()); 1470 EXPECT_TRUE(media_channel1_->sending());
1469 1471
1470 // Should fail also. 1472 // Should fail also.
1471 SendRtp1(); 1473 SendRtp1();
1472 SendRtp2(); 1474 SendRtp2();
1473 WaitForThreads(); 1475 WaitForThreads();
1474 EXPECT_TRUE(CheckRtp1()); 1476 EXPECT_TRUE(CheckRtp1());
1475 EXPECT_TRUE(CheckNoRtp2()); 1477 EXPECT_TRUE(CheckNoRtp2());
1478 EXPECT_TRUE(CheckNoRtp1());
1476 1479
1477 // Gain writability back 1480 // Gain writability back
1478 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { 1481 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1479 GetFakeChannel1(1)->SetDestination(GetFakeChannel2(1)); 1482 GetFakeChannel1(1)->SetDestination(GetFakeChannel2(1));
1480 }); 1483 });
1481 EXPECT_TRUE(media_channel1_->sending()); 1484 EXPECT_TRUE(media_channel1_->sending());
1482 SendRtp1(); 1485 SendRtp1();
1483 SendRtp2(); 1486 SendRtp2();
1484 WaitForThreads(); 1487 WaitForThreads();
1485 EXPECT_TRUE(CheckRtp1()); 1488 EXPECT_TRUE(CheckRtp1());
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 rtc::PacketOptions()); 1778 rtc::PacketOptions());
1776 WaitForThreads(); 1779 WaitForThreads();
1777 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); 1780 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
1778 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); 1781 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1779 1782
1780 // Testing failures in receiving packets. 1783 // Testing failures in receiving packets.
1781 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; 1784 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
1782 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; 1785 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1783 1786
1784 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { 1787 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1785 cricket::TransportChannel* transport_channel = channel2_->rtp_transport(); 1788 cricket::DtlsTransportInternal* transport_channel =
1789 channel2_->rtp_dtls_transport();
1786 transport_channel->SignalReadPacket( 1790 transport_channel->SignalReadPacket(
1787 transport_channel, reinterpret_cast<const char*>(kBadPacket), 1791 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1788 sizeof(kBadPacket), rtc::PacketTime(), 0); 1792 sizeof(kBadPacket), rtc::PacketTime(), 0);
1789 }); 1793 });
1790 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); 1794 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
1791 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); 1795 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1792 // Terminate channels before the fake clock is destroyed. 1796 // Terminate channels before the fake clock is destroyed.
1793 EXPECT_TRUE(SendTerminate()); 1797 EXPECT_TRUE(SendTerminate());
1794 } 1798 }
1795 1799
1796 void TestOnReadyToSend() { 1800 void TestOnReadyToSend() {
1797 CreateChannels(0, 0); 1801 CreateChannels(0, 0);
1798 TransportChannel* rtp = channel1_->rtp_transport(); 1802 DtlsTransportInternal* rtp = channel1_->rtp_dtls_transport();
1799 TransportChannel* rtcp = channel1_->rtcp_transport(); 1803 DtlsTransportInternal* rtcp = channel1_->rtcp_dtls_transport();
1800 EXPECT_FALSE(media_channel1_->ready_to_send()); 1804 EXPECT_FALSE(media_channel1_->ready_to_send());
1801 1805
1802 network_thread_->Invoke<void>(RTC_FROM_HERE, 1806 network_thread_->Invoke<void>(RTC_FROM_HERE,
1803 [rtp] { rtp->SignalReadyToSend(rtp); }); 1807 [rtp] { rtp->SignalReadyToSend(rtp); });
1804 WaitForThreads(); 1808 WaitForThreads();
1805 EXPECT_FALSE(media_channel1_->ready_to_send()); 1809 EXPECT_FALSE(media_channel1_->ready_to_send());
1806 1810
1807 network_thread_->Invoke<void>(RTC_FROM_HERE, 1811 network_thread_->Invoke<void>(RTC_FROM_HERE,
1808 [rtcp] { rtcp->SignalReadyToSend(rtcp); }); 1812 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
1809 WaitForThreads(); 1813 WaitForThreads();
(...skipping 29 matching lines...) Expand all
1839 } 1843 }
1840 1844
1841 void TestOnReadyToSendWithRtcpMux() { 1845 void TestOnReadyToSendWithRtcpMux() {
1842 CreateChannels(0, 0); 1846 CreateChannels(0, 0);
1843 typename T::Content content; 1847 typename T::Content content;
1844 CreateContent(0, kPcmuCodec, kH264Codec, &content); 1848 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1845 // Both sides agree on mux. Should no longer be a separate RTCP channel. 1849 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1846 content.set_rtcp_mux(true); 1850 content.set_rtcp_mux(true);
1847 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); 1851 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1848 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); 1852 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
1849 EXPECT_TRUE(channel1_->rtcp_transport() == NULL); 1853 EXPECT_TRUE(channel1_->rtcp_dtls_transport() == NULL);
1850 TransportChannel* rtp = channel1_->rtp_transport(); 1854 DtlsTransportInternal* rtp = channel1_->rtp_dtls_transport();
1851 EXPECT_FALSE(media_channel1_->ready_to_send()); 1855 EXPECT_FALSE(media_channel1_->ready_to_send());
1852 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel 1856 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1853 // should trigger the MediaChannel's OnReadyToSend. 1857 // should trigger the MediaChannel's OnReadyToSend.
1854 network_thread_->Invoke<void>(RTC_FROM_HERE, 1858 network_thread_->Invoke<void>(RTC_FROM_HERE,
1855 [rtp] { rtp->SignalReadyToSend(rtp); }); 1859 [rtp] { rtp->SignalReadyToSend(rtp); });
1856 WaitForThreads(); 1860 WaitForThreads();
1857 EXPECT_TRUE(media_channel1_->ready_to_send()); 1861 EXPECT_TRUE(media_channel1_->ready_to_send());
1858 1862
1859 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { 1863 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1860 channel1_->SetTransportChannelReadyToSend(false, false); 1864 channel1_->SetTransportChannelReadyToSend(false, false);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 cricket::TransportController* transport_controller, 2023 cricket::TransportController* transport_controller,
2020 int flags) { 2024 int flags) {
2021 rtc::Thread* signaling_thread = 2025 rtc::Thread* signaling_thread =
2022 transport_controller ? transport_controller->signaling_thread() : nullptr; 2026 transport_controller ? transport_controller->signaling_thread() : nullptr;
2023 cricket::VideoChannel* channel = new cricket::VideoChannel( 2027 cricket::VideoChannel* channel = new cricket::VideoChannel(
2024 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO, 2028 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
2025 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0); 2029 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
2026 rtc::CryptoOptions crypto_options; 2030 rtc::CryptoOptions crypto_options;
2027 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0; 2031 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2028 channel->SetCryptoOptions(crypto_options); 2032 channel->SetCryptoOptions(crypto_options);
2029 cricket::TransportChannel* rtp_transport = 2033 cricket::DtlsTransportInternal* rtp_dtls_transport =
2030 transport_controller->CreateTransportChannel( 2034 transport_controller->CreateDtlsTransport(
2031 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP); 2035 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
2032 cricket::TransportChannel* rtcp_transport = nullptr; 2036 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr;
2033 if (channel->NeedsRtcpTransport()) { 2037 if (channel->NeedsRtcpTransport()) {
2034 rtcp_transport = transport_controller->CreateTransportChannel( 2038 rtcp_dtls_transport = transport_controller->CreateDtlsTransport(
2035 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP); 2039 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
2036 } 2040 }
2037 if (!channel->Init_w(rtp_transport, rtcp_transport)) { 2041 if (!channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport)) {
2038 delete channel; 2042 delete channel;
2039 channel = NULL; 2043 channel = NULL;
2040 } 2044 }
2041 return channel; 2045 return channel;
2042 } 2046 }
2043 2047
2044 // override to add 0 parameter 2048 // override to add 0 parameter
2045 template<> 2049 template<>
2046 bool ChannelTest<VideoTraits>::AddStream1(int id) { 2050 bool ChannelTest<VideoTraits>::AddStream1(int id) {
2047 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); 2051 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 cricket::TransportController* transport_controller, 3257 cricket::TransportController* transport_controller,
3254 int flags) { 3258 int flags) {
3255 rtc::Thread* signaling_thread = 3259 rtc::Thread* signaling_thread =
3256 transport_controller ? transport_controller->signaling_thread() : nullptr; 3260 transport_controller ? transport_controller->signaling_thread() : nullptr;
3257 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel( 3261 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
3258 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA, 3262 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
3259 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0); 3263 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
3260 rtc::CryptoOptions crypto_options; 3264 rtc::CryptoOptions crypto_options;
3261 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0; 3265 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3262 channel->SetCryptoOptions(crypto_options); 3266 channel->SetCryptoOptions(crypto_options);
3263 cricket::TransportChannel* rtp_transport = 3267 cricket::DtlsTransportInternal* rtp_dtls_transport =
3264 transport_controller->CreateTransportChannel( 3268 transport_controller->CreateDtlsTransport(
3265 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP); 3269 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
3266 cricket::TransportChannel* rtcp_transport = nullptr; 3270 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr;
3267 if (channel->NeedsRtcpTransport()) { 3271 if (channel->NeedsRtcpTransport()) {
3268 rtcp_transport = transport_controller->CreateTransportChannel( 3272 rtcp_dtls_transport = transport_controller->CreateDtlsTransport(
3269 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP); 3273 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3270 } 3274 }
3271 if (!channel->Init_w(rtp_transport, rtcp_transport)) { 3275 if (!channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport)) {
3272 delete channel; 3276 delete channel;
3273 channel = NULL; 3277 channel = NULL;
3274 } 3278 }
3275 return channel; 3279 return channel;
3276 } 3280 }
3277 3281
3278 template <> 3282 template <>
3279 void ChannelTest<DataTraits>::CreateContent( 3283 void ChannelTest<DataTraits>::CreateContent(
3280 int flags, 3284 int flags,
3281 const cricket::AudioCodec& audio_codec, 3285 const cricket::AudioCodec& audio_codec,
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
3589 voice_channel_( 3593 voice_channel_(
3590 rtc::Thread::Current(), 3594 rtc::Thread::Current(),
3591 rtc::Thread::Current(), 3595 rtc::Thread::Current(),
3592 rtc::Thread::Current(), 3596 rtc::Thread::Current(),
3593 &fake_media_engine_, 3597 &fake_media_engine_,
3594 new cricket::FakeVoiceMediaChannel(nullptr, 3598 new cricket::FakeVoiceMediaChannel(nullptr,
3595 cricket::AudioOptions()), 3599 cricket::AudioOptions()),
3596 cricket::CN_AUDIO, 3600 cricket::CN_AUDIO,
3597 false, 3601 false,
3598 true) { 3602 true) {
3599 rtp_transport_ = fake_transport_controller_.CreateTransportChannel( 3603 rtp_transport_ = fake_transport_controller_.CreateDtlsTransport(
3600 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTP); 3604 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3601 rtcp_transport_ = fake_transport_controller_.CreateTransportChannel( 3605 rtcp_transport_ = fake_transport_controller_.CreateDtlsTransport(
3602 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP); 3606 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3603 EXPECT_TRUE(voice_channel_.Init_w(rtp_transport_, rtcp_transport_)); 3607 EXPECT_TRUE(voice_channel_.Init_w(rtp_transport_, rtcp_transport_));
3604 } 3608 }
3605 3609
3606 protected: 3610 protected:
3607 cricket::FakeTransportController fake_transport_controller_; 3611 cricket::FakeTransportController fake_transport_controller_;
3608 cricket::FakeMediaEngine fake_media_engine_; 3612 cricket::FakeMediaEngine fake_media_engine_;
3609 cricket::VoiceChannel voice_channel_; 3613 cricket::VoiceChannel voice_channel_;
3610 // Will be cleaned up by FakeTransportController, don't need to worry about 3614 // Will be cleaned up by FakeTransportController, don't need to worry about
3611 // deleting them in this test. 3615 // deleting them in this test.
3612 cricket::TransportChannel* rtp_transport_; 3616 cricket::DtlsTransportInternal* rtp_transport_;
3613 cricket::TransportChannel* rtcp_transport_; 3617 cricket::DtlsTransportInternal* rtcp_transport_;
3614 }; 3618 };
3615 3619
3616 TEST_F(BaseChannelDeathTest, SetTransportWithNullRtpTransport) { 3620 TEST_F(BaseChannelDeathTest, SetTransportWithNullRtpTransport) {
3617 cricket::TransportChannel* new_rtcp_transport = 3621 cricket::DtlsTransportInternal* new_rtcp_transport =
3618 fake_transport_controller_.CreateTransportChannel( 3622 fake_transport_controller_.CreateDtlsTransport(
3619 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP); 3623 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3620 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, new_rtcp_transport), ""); 3624 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, new_rtcp_transport), "");
3621 } 3625 }
3622 3626
3623 TEST_F(BaseChannelDeathTest, SetTransportWithMissingRtcpTransport) { 3627 TEST_F(BaseChannelDeathTest, SetTransportWithMissingRtcpTransport) {
3624 cricket::TransportChannel* new_rtp_transport = 3628 cricket::DtlsTransportInternal* new_rtp_transport =
3625 fake_transport_controller_.CreateTransportChannel( 3629 fake_transport_controller_.CreateDtlsTransport(
3626 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP); 3630 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3627 EXPECT_DEATH(voice_channel_.SetTransports(new_rtp_transport, nullptr), ""); 3631 EXPECT_DEATH(voice_channel_.SetTransports(new_rtp_transport, nullptr), "");
3628 } 3632 }
3629 3633
3630 TEST_F(BaseChannelDeathTest, SetTransportWithUnneededRtcpTransport) { 3634 TEST_F(BaseChannelDeathTest, SetTransportWithUnneededRtcpTransport) {
3631 // Activate RTCP muxing, simulating offer/answer negotiation. 3635 // Activate RTCP muxing, simulating offer/answer negotiation.
3632 cricket::AudioContentDescription content; 3636 cricket::AudioContentDescription content;
3633 content.set_rtcp_mux(true); 3637 content.set_rtcp_mux(true);
3634 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr)); 3638 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3635 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr)); 3639 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
3636 cricket::TransportChannel* new_rtp_transport = 3640 cricket::DtlsTransportInternal* new_rtp_transport =
3637 fake_transport_controller_.CreateTransportChannel( 3641 fake_transport_controller_.CreateDtlsTransport(
3638 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP); 3642 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3639 cricket::TransportChannel* new_rtcp_transport = 3643 cricket::DtlsTransportInternal* new_rtcp_transport =
3640 fake_transport_controller_.CreateTransportChannel( 3644 fake_transport_controller_.CreateDtlsTransport(
3641 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP); 3645 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3642 // After muxing is enabled, no RTCP transport should be passed in here. 3646 // After muxing is enabled, no RTCP transport should be passed in here.
3643 EXPECT_DEATH( 3647 EXPECT_DEATH(
3644 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), ""); 3648 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3645 } 3649 }
3646 3650
3647 // This test will probably go away if/when we move the transport name out of 3651 // This test will probably go away if/when we move the transport name out of
3648 // the transport classes and into their parent classes. 3652 // the transport classes and into their parent classes.
3649 TEST_F(BaseChannelDeathTest, SetTransportWithMismatchingTransportNames) { 3653 TEST_F(BaseChannelDeathTest, SetTransportWithMismatchingTransportNames) {
3650 cricket::TransportChannel* new_rtp_transport = 3654 cricket::DtlsTransportInternal* new_rtp_transport =
3651 fake_transport_controller_.CreateTransportChannel( 3655 fake_transport_controller_.CreateDtlsTransport(
3652 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP); 3656 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3653 cricket::TransportChannel* new_rtcp_transport = 3657 cricket::DtlsTransportInternal* new_rtcp_transport =
3654 fake_transport_controller_.CreateTransportChannel( 3658 fake_transport_controller_.CreateDtlsTransport(
3655 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP); 3659 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3656 EXPECT_DEATH( 3660 EXPECT_DEATH(
3657 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), ""); 3661 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3658 } 3662 }
3659 3663
3660 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 3664 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3661 3665
3662 // TODO(pthatcher): TestSetReceiver? 3666 // TODO(pthatcher): TestSetReceiver?
OLDNEW
« no previous file with comments | « webrtc/pc/channel.cc ('k') | webrtc/pc/channelmanager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698