OLD | NEW |
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/fakeclock.h" | 15 #include "webrtc/base/fakeclock.h" |
16 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/sslstreamadapter.h" | 18 #include "webrtc/base/sslstreamadapter.h" |
19 #include "webrtc/media/base/fakemediaengine.h" | 19 #include "webrtc/media/base/fakemediaengine.h" |
20 #include "webrtc/media/base/fakertp.h" | 20 #include "webrtc/media/base/fakertp.h" |
21 #include "webrtc/media/base/mediachannel.h" | 21 #include "webrtc/media/base/mediachannel.h" |
22 #include "webrtc/media/base/testutils.h" | 22 #include "webrtc/media/base/testutils.h" |
| 23 #include "webrtc/p2p/base/dtlstransportinternal.h" |
23 #include "webrtc/p2p/base/faketransportcontroller.h" | 24 #include "webrtc/p2p/base/faketransportcontroller.h" |
24 #include "webrtc/p2p/base/transportchannelimpl.h" | |
25 #include "webrtc/pc/channel.h" | 25 #include "webrtc/pc/channel.h" |
26 | 26 |
27 #define MAYBE_SKIP_TEST(feature) \ | 27 #define MAYBE_SKIP_TEST(feature) \ |
28 if (!(rtc::SSLStreamAdapter::feature())) { \ | 28 if (!(rtc::SSLStreamAdapter::feature())) { \ |
29 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 29 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
30 return; \ | 30 return; \ |
31 } | 31 } |
32 | 32 |
33 using cricket::CA_OFFER; | 33 using cricket::CA_OFFER; |
34 using cricket::CA_PRANSWER; | 34 using cricket::CA_PRANSWER; |
35 using cricket::CA_ANSWER; | 35 using cricket::CA_ANSWER; |
36 using cricket::CA_UPDATE; | 36 using cricket::CA_UPDATE; |
| 37 using cricket::DtlsTransportInternal; |
37 using cricket::FakeVoiceMediaChannel; | 38 using cricket::FakeVoiceMediaChannel; |
38 using cricket::StreamParams; | 39 using cricket::StreamParams; |
39 using cricket::TransportChannel; | |
40 | 40 |
41 namespace { | 41 namespace { |
42 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1); | 42 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1); |
43 const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1); | 43 const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1); |
44 const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1); | 44 const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1); |
45 const cricket::VideoCodec kH264Codec(97, "H264"); | 45 const cricket::VideoCodec kH264Codec(97, "H264"); |
46 const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC"); | 46 const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC"); |
47 const cricket::DataCodec kGoogleDataCodec(101, "google-data"); | 47 const cricket::DataCodec kGoogleDataCodec(101, "google-data"); |
48 const uint32_t kSsrc1 = 0x1111; | 48 const uint32_t kSsrc1 = 0x1111; |
49 const uint32_t kSsrc2 = 0x2222; | 49 const uint32_t kSsrc2 = 0x2222; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return true; | 264 return true; |
265 } | 265 } |
266 | 266 |
267 bool AddStream1(int id) { | 267 bool AddStream1(int id) { |
268 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); | 268 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); |
269 } | 269 } |
270 bool RemoveStream1(int id) { | 270 bool RemoveStream1(int id) { |
271 return channel1_->RemoveRecvStream(id); | 271 return channel1_->RemoveRecvStream(id); |
272 } | 272 } |
273 | 273 |
274 std::vector<cricket::TransportChannelImpl*> GetChannels1() { | 274 std::vector<cricket::DtlsTransportInternal*> GetChannels1() { |
275 return transport_controller1_->channels_for_testing(); | 275 return transport_controller1_->channels_for_testing(); |
276 } | 276 } |
277 | 277 |
278 std::vector<cricket::TransportChannelImpl*> GetChannels2() { | 278 std::vector<cricket::DtlsTransportInternal*> GetChannels2() { |
279 return transport_controller2_->channels_for_testing(); | 279 return transport_controller2_->channels_for_testing(); |
280 } | 280 } |
281 | 281 |
282 cricket::FakeTransportChannel* GetFakeChannel1(int component) { | 282 cricket::FakeDtlsTransport* GetFakeChannel1(int component) { |
283 return transport_controller1_->GetFakeTransportChannel_n( | 283 return transport_controller1_->GetFakeDtlsTransport_n( |
284 channel1_->content_name(), component); | 284 channel1_->content_name(), component); |
285 } | 285 } |
286 | 286 |
287 cricket::FakeTransportChannel* GetFakeChannel2(int component) { | 287 cricket::FakeDtlsTransport* GetFakeChannel2(int component) { |
288 return transport_controller2_->GetFakeTransportChannel_n( | 288 return transport_controller2_->GetFakeDtlsTransport_n( |
289 channel2_->content_name(), component); | 289 channel2_->content_name(), component); |
290 } | 290 } |
291 | 291 |
292 void SendRtp1() { | 292 void SendRtp1() { |
293 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(), | 293 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(), |
294 rtc::PacketOptions()); | 294 rtc::PacketOptions()); |
295 } | 295 } |
296 void SendRtp2() { | 296 void SendRtp2() { |
297 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(), | 297 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(), |
298 rtc::PacketOptions()); | 298 rtc::PacketOptions()); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 | 924 |
925 // Tests that when the transport channel signals a candidate pair change | 925 // Tests that when the transport channel signals a candidate pair change |
926 // event, the media channel will receive a call on the network route change. | 926 // event, the media channel will receive a call on the network route change. |
927 void TestNetworkRouteChanges() { | 927 void TestNetworkRouteChanges() { |
928 constexpr uint16_t kLocalNetId = 1; | 928 constexpr uint16_t kLocalNetId = 1; |
929 constexpr uint16_t kRemoteNetId = 2; | 929 constexpr uint16_t kRemoteNetId = 2; |
930 constexpr int kLastPacketId = 100; | 930 constexpr int kLastPacketId = 100; |
931 | 931 |
932 CreateChannels(0, 0); | 932 CreateChannels(0, 0); |
933 | 933 |
934 cricket::TransportChannel* transport_channel1 = | 934 cricket::DtlsTransportInternal* transport_channel1 = |
935 channel1_->transport_channel(); | 935 channel1_->transport_channel(); |
936 ASSERT_TRUE(transport_channel1); | 936 ASSERT_TRUE(transport_channel1); |
937 typename T::MediaChannel* media_channel1 = | 937 typename T::MediaChannel* media_channel1 = |
938 static_cast<typename T::MediaChannel*>(channel1_->media_channel()); | 938 static_cast<typename T::MediaChannel*>(channel1_->media_channel()); |
939 ASSERT_TRUE(media_channel1); | 939 ASSERT_TRUE(media_channel1); |
940 | 940 |
941 media_channel1->set_num_network_route_changes(0); | 941 media_channel1->set_num_network_route_changes(0); |
942 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] { | 942 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] { |
943 // The transport channel becomes disconnected. | 943 // The transport channel becomes disconnected. |
944 transport_channel1->SignalSelectedCandidatePairChanged( | 944 transport_channel1->ice_transport()->SignalSelectedCandidatePairChanged( |
945 transport_channel1, nullptr, -1, false); | 945 transport_channel1->ice_transport(), nullptr, -1, false); |
946 }); | 946 }); |
947 WaitForThreads(); | 947 WaitForThreads(); |
948 EXPECT_EQ(1, media_channel1->num_network_route_changes()); | 948 EXPECT_EQ(1, media_channel1->num_network_route_changes()); |
949 EXPECT_FALSE(media_channel1->last_network_route().connected); | 949 EXPECT_FALSE(media_channel1->last_network_route().connected); |
950 media_channel1->set_num_network_route_changes(0); | 950 media_channel1->set_num_network_route_changes(0); |
951 | 951 |
952 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1, | 952 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1, |
953 media_channel1, kLocalNetId, | 953 media_channel1, kLocalNetId, |
954 kRemoteNetId, kLastPacketId] { | 954 kRemoteNetId, kLastPacketId] { |
955 // The transport channel becomes connected. | 955 // The transport channel becomes connected. |
956 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */); | 956 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */); |
957 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */); | 957 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */); |
958 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair( | 958 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair( |
959 transport_controller1_->CreateFakeCandidatePair( | 959 transport_controller1_->CreateFakeCandidatePair( |
960 local_address, kLocalNetId, remote_address, kRemoteNetId)); | 960 local_address, kLocalNetId, remote_address, kRemoteNetId)); |
961 transport_channel1->SignalSelectedCandidatePairChanged( | 961 transport_channel1->ice_transport()->SignalSelectedCandidatePairChanged( |
962 transport_channel1, candidate_pair.get(), kLastPacketId, true); | 962 transport_channel1->ice_transport(), candidate_pair.get(), |
| 963 kLastPacketId, true); |
963 }); | 964 }); |
964 WaitForThreads(); | 965 WaitForThreads(); |
965 EXPECT_EQ(1, media_channel1->num_network_route_changes()); | 966 EXPECT_EQ(1, media_channel1->num_network_route_changes()); |
966 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId, | 967 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId, |
967 kLastPacketId); | 968 kLastPacketId); |
968 EXPECT_EQ(expected_network_route, media_channel1->last_network_route()); | 969 EXPECT_EQ(expected_network_route, media_channel1->last_network_route()); |
969 EXPECT_EQ(kLastPacketId, | 970 EXPECT_EQ(kLastPacketId, |
970 media_channel1->last_network_route().last_sent_packet_id); | 971 media_channel1->last_network_route().last_sent_packet_id); |
971 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8). | 972 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8). |
972 EXPECT_EQ(kTransportOverheadPerPacket, | 973 EXPECT_EQ(kTransportOverheadPerPacket, |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 rtc::PacketOptions()); | 1798 rtc::PacketOptions()); |
1798 WaitForThreads(); | 1799 WaitForThreads(); |
1799 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); | 1800 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); |
1800 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); | 1801 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); |
1801 | 1802 |
1802 // Testing failures in receiving packets. | 1803 // Testing failures in receiving packets. |
1803 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; | 1804 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; |
1804 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; | 1805 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; |
1805 | 1806 |
1806 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { | 1807 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { |
1807 cricket::TransportChannel* transport_channel = | 1808 cricket::DtlsTransportInternal* transport_channel = |
1808 channel2_->transport_channel(); | 1809 channel2_->transport_channel(); |
1809 transport_channel->SignalReadPacket( | 1810 transport_channel->SignalReadPacket( |
1810 transport_channel, reinterpret_cast<const char*>(kBadPacket), | 1811 transport_channel, reinterpret_cast<const char*>(kBadPacket), |
1811 sizeof(kBadPacket), rtc::PacketTime(), 0); | 1812 sizeof(kBadPacket), rtc::PacketTime(), 0); |
1812 }); | 1813 }); |
1813 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); | 1814 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); |
1814 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); | 1815 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); |
1815 // Terminate channels before the fake clock is destroyed. | 1816 // Terminate channels before the fake clock is destroyed. |
1816 EXPECT_TRUE(SendTerminate()); | 1817 EXPECT_TRUE(SendTerminate()); |
1817 } | 1818 } |
1818 | 1819 |
1819 void TestOnReadyToSend() { | 1820 void TestOnReadyToSend() { |
1820 CreateChannels(RTCP, RTCP); | 1821 CreateChannels(RTCP, RTCP); |
1821 TransportChannel* rtp = channel1_->transport_channel(); | 1822 DtlsTransportInternal* rtp = channel1_->transport_channel(); |
1822 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); | 1823 DtlsTransportInternal* rtcp = channel1_->rtcp_transport_channel(); |
1823 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1824 EXPECT_FALSE(media_channel1_->ready_to_send()); |
1824 | 1825 |
1825 network_thread_->Invoke<void>(RTC_FROM_HERE, | 1826 network_thread_->Invoke<void>(RTC_FROM_HERE, |
1826 [rtp] { rtp->SignalReadyToSend(rtp); }); | 1827 [rtp] { rtp->SignalReadyToSend(rtp); }); |
1827 WaitForThreads(); | 1828 WaitForThreads(); |
1828 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1829 EXPECT_FALSE(media_channel1_->ready_to_send()); |
1829 | 1830 |
1830 network_thread_->Invoke<void>(RTC_FROM_HERE, | 1831 network_thread_->Invoke<void>(RTC_FROM_HERE, |
1831 [rtcp] { rtcp->SignalReadyToSend(rtcp); }); | 1832 [rtcp] { rtcp->SignalReadyToSend(rtcp); }); |
1832 WaitForThreads(); | 1833 WaitForThreads(); |
(...skipping 30 matching lines...) Expand all Loading... |
1863 | 1864 |
1864 void TestOnReadyToSendWithRtcpMux() { | 1865 void TestOnReadyToSendWithRtcpMux() { |
1865 CreateChannels(RTCP, RTCP); | 1866 CreateChannels(RTCP, RTCP); |
1866 typename T::Content content; | 1867 typename T::Content content; |
1867 CreateContent(0, kPcmuCodec, kH264Codec, &content); | 1868 CreateContent(0, kPcmuCodec, kH264Codec, &content); |
1868 // Both sides agree on mux. Should no longer be a separate RTCP channel. | 1869 // Both sides agree on mux. Should no longer be a separate RTCP channel. |
1869 content.set_rtcp_mux(true); | 1870 content.set_rtcp_mux(true); |
1870 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); | 1871 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
1871 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); | 1872 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
1872 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); | 1873 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
1873 TransportChannel* rtp = channel1_->transport_channel(); | 1874 DtlsTransportInternal* rtp = channel1_->transport_channel(); |
1874 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1875 EXPECT_FALSE(media_channel1_->ready_to_send()); |
1875 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel | 1876 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel |
1876 // should trigger the MediaChannel's OnReadyToSend. | 1877 // should trigger the MediaChannel's OnReadyToSend. |
1877 network_thread_->Invoke<void>(RTC_FROM_HERE, | 1878 network_thread_->Invoke<void>(RTC_FROM_HERE, |
1878 [rtp] { rtp->SignalReadyToSend(rtp); }); | 1879 [rtp] { rtp->SignalReadyToSend(rtp); }); |
1879 WaitForThreads(); | 1880 WaitForThreads(); |
1880 EXPECT_TRUE(media_channel1_->ready_to_send()); | 1881 EXPECT_TRUE(media_channel1_->ready_to_send()); |
1881 | 1882 |
1882 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { | 1883 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] { |
1883 channel1_->SetTransportChannelReadyToSend(false, false); | 1884 channel1_->SetTransportChannelReadyToSend(false, false); |
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3647 }; | 3648 }; |
3648 rtc::CopyOnWriteBuffer payload(data, 3); | 3649 rtc::CopyOnWriteBuffer payload(data, 3); |
3649 cricket::SendDataResult result; | 3650 cricket::SendDataResult result; |
3650 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); | 3651 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); |
3651 EXPECT_EQ(params.ssrc, | 3652 EXPECT_EQ(params.ssrc, |
3652 media_channel1_->last_sent_data_params().ssrc); | 3653 media_channel1_->last_sent_data_params().ssrc); |
3653 EXPECT_EQ("foo", media_channel1_->last_sent_data()); | 3654 EXPECT_EQ("foo", media_channel1_->last_sent_data()); |
3654 } | 3655 } |
3655 | 3656 |
3656 // TODO(pthatcher): TestSetReceiver? | 3657 // TODO(pthatcher): TestSetReceiver? |
OLD | NEW |