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

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

Issue 2761143002: Support encrypted RTP extensions (RFC 6904) (Closed)
Patch Set: Don't negotiate extension ids in SrtpFilter, more changes after feedback from Taylor. Created 3 years, 8 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
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
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 enum Flags { 94 enum Flags {
95 RTCP_MUX = 0x1, 95 RTCP_MUX = 0x1,
96 RTCP_MUX_REQUIRED = 0x2, 96 RTCP_MUX_REQUIRED = 0x2,
97 SECURE = 0x4, 97 SECURE = 0x4,
98 SSRC_MUX = 0x8, 98 SSRC_MUX = 0x8,
99 DTLS = 0x10, 99 DTLS = 0x10,
100 GCM_CIPHER = 0x20, 100 GCM_CIPHER = 0x20,
101 // Use BaseChannel with PacketTransportInternal rather than 101 // Use BaseChannel with PacketTransportInternal rather than
102 // DtlsTransportInternal. 102 // DtlsTransportInternal.
103 RAW_PACKET_TRANSPORT = 0x40, 103 RAW_PACKET_TRANSPORT = 0x40,
104 ENCRYPTED_HEADERS = 0x80,
104 }; 105 };
105 106
106 ChannelTest(bool verify_playout, 107 ChannelTest(bool verify_playout,
107 rtc::ArrayView<const uint8_t> rtp_data, 108 rtc::ArrayView<const uint8_t> rtp_data,
108 rtc::ArrayView<const uint8_t> rtcp_data, 109 rtc::ArrayView<const uint8_t> rtcp_data,
109 NetworkIsWorker network_is_worker) 110 NetworkIsWorker network_is_worker)
110 : verify_playout_(verify_playout), 111 : verify_playout_(verify_playout),
111 rtp_packet_(rtp_data.data(), rtp_data.size()), 112 rtp_packet_(rtp_data.data(), rtp_data.size()),
112 rtcp_packet_(rtcp_data.data(), rtcp_data.size()) { 113 rtcp_packet_(rtcp_data.data(), rtcp_data.size()) {
113 if (network_is_worker == NetworkIsWorker::Yes) { 114 if (network_is_worker == NetworkIsWorker::Yes) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 rtc::PacketTransportInternal* fake_rtp_packet_transport, 259 rtc::PacketTransportInternal* fake_rtp_packet_transport,
259 rtc::PacketTransportInternal* fake_rtcp_packet_transport, 260 rtc::PacketTransportInternal* fake_rtcp_packet_transport,
260 int flags) { 261 int flags) {
261 rtc::Thread* signaling_thread = rtc::Thread::Current(); 262 rtc::Thread* signaling_thread = rtc::Thread::Current();
262 typename T::Channel* channel = new typename T::Channel( 263 typename T::Channel* channel = new typename T::Channel(
263 worker_thread, network_thread, signaling_thread, engine, ch, 264 worker_thread, network_thread, signaling_thread, engine, ch,
264 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0, 265 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0,
265 (flags & SECURE) != 0); 266 (flags & SECURE) != 0);
266 rtc::CryptoOptions crypto_options; 267 rtc::CryptoOptions crypto_options;
267 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0; 268 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
269 crypto_options.enable_encrypted_rtp_header_extensions =
270 (flags & ENCRYPTED_HEADERS) != 0;
268 channel->SetCryptoOptions(crypto_options); 271 channel->SetCryptoOptions(crypto_options);
269 if (!channel->NeedsRtcpTransport()) { 272 if (!channel->NeedsRtcpTransport()) {
270 fake_rtcp_dtls_transport = nullptr; 273 fake_rtcp_dtls_transport = nullptr;
271 } 274 }
272 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport, 275 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
273 fake_rtp_packet_transport, 276 fake_rtp_packet_transport,
274 fake_rtcp_packet_transport)) { 277 fake_rtcp_packet_transport)) {
275 delete channel; 278 delete channel;
276 channel = NULL; 279 channel = NULL;
277 } 280 }
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL)); 888 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
886 EXPECT_EQ(0u, media_channel2_->recv_streams().size()); 889 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
887 890
888 EXPECT_TRUE(channel1_->secure()); 891 EXPECT_TRUE(channel1_->secure());
889 EXPECT_TRUE(channel2_->secure()); 892 EXPECT_TRUE(channel2_->secure());
890 SendCustomRtp2(kSsrc2, 0); 893 SendCustomRtp2(kSsrc2, 0);
891 WaitForThreads(); 894 WaitForThreads();
892 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0)); 895 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
893 } 896 }
894 897
898 // Test that encrypted header extensions are working and can be changed when
899 // sending a new OFFER/ANSWER.
900 void TestChangeEncryptedHeaderExtensions(int flags) {
901 struct PacketListener : public sigslot::has_slots<> {
902 PacketListener() {}
903 void OnReadPacket(rtc::PacketTransportInternal* transport,
904 const char* data, size_t size, const rtc::PacketTime& time,
905 int flags) {
906 CompareHeaderExtensions(
907 reinterpret_cast<const char*>(kPcmuFrameWithExtensions), data,
908 encrypted_headers, false);
909 }
910 std::vector<int> encrypted_headers;
911 } packet_listener1, packet_listener2;
912
913 cricket::StreamParams stream1;
914 stream1.groupid = "group1";
915 stream1.id = "stream1";
916 stream1.ssrcs.push_back(kSsrc1);
917 stream1.cname = "stream1_cname";
918
919 cricket::StreamParams stream2;
920 stream2.groupid = "group1";
921 stream2.id = "stream2";
922 stream2.ssrcs.push_back(kSsrc2);
923 stream2.cname = "stream2_cname";
924
925 // Use SRTP when testing encrypted extensions.
926 int channel_flags = flags | SECURE | ENCRYPTED_HEADERS;
927 // Enable SDES if channel is not using DTLS.
928 int content_flags = (channel_flags & DTLS) == 0 ? SECURE : 0;
929
930 // kPcmuFrameWithExtensions contains RTP extension headers with ids 1-4.
931 // Make sure to use URIs that are supported for encryption.
932 cricket::RtpHeaderExtensions extensions1;
933 extensions1.push_back(
934 RtpExtension(RtpExtension::kAudioLevelUri, 10));
935 extensions1.push_back(
936 RtpExtension(RtpExtension::kAudioLevelUri, 1, true));
937
938 cricket::RtpHeaderExtensions extensions2;
939 extensions2.push_back(
940 RtpExtension(RtpExtension::kAudioLevelUri, 10));
941 extensions2.push_back(
942 RtpExtension(RtpExtension::kAudioLevelUri, 2, true));
943 extensions2.push_back(
944 RtpExtension(RtpExtension::kVideoRotationUri, 3));
945 extensions2.push_back(
946 RtpExtension(RtpExtension::kTimestampOffsetUri, 4, true));
947
948 // Setup a call where channel 1 send |stream1| to channel 2.
949 CreateChannels(channel_flags, channel_flags);
950 fake_rtp_dtls_transport1_->fake_ice_transport()->SignalReadPacket.connect(
951 &packet_listener1, &PacketListener::OnReadPacket);
952 fake_rtp_dtls_transport2_->fake_ice_transport()->SignalReadPacket.connect(
953 &packet_listener2, &PacketListener::OnReadPacket);
954
955 typename T::Content content1;
956 CreateContent(content_flags, kPcmuCodec, kH264Codec, &content1);
957 content1.AddStream(stream1);
958 content1.set_rtp_header_extensions(extensions1);
959 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
960 EXPECT_TRUE(channel1_->Enable(true));
961 EXPECT_EQ(1u, media_channel1_->send_streams().size());
962
963 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
964 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
965 ConnectFakeTransports();
966
967 // Channel 2 sends back |stream2|.
968 typename T::Content content2;
969 CreateContent(content_flags, kPcmuCodec, kH264Codec, &content2);
970 content2.AddStream(stream2);
971 content2.set_rtp_header_extensions(extensions1);
972 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
973 EXPECT_EQ(1u, media_channel1_->recv_streams().size());
974 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
975 EXPECT_TRUE(channel2_->Enable(true));
976 EXPECT_EQ(1u, media_channel2_->send_streams().size());
977
978 packet_listener1.encrypted_headers.push_back(1);
979 packet_listener2.encrypted_headers.push_back(1);
980
981 SendCustomRtp1(kSsrc1, 0);
982 SendCustomRtp2(kSsrc2, 0);
983 WaitForThreads();
984 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
985 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
986
987 // Let channel 2 update the encrypted header extensions.
988 typename T::Content content3;
989 CreateContent(content_flags, kPcmuCodec, kH264Codec, &content3);
990 content3.AddStream(stream2);
991 content3.set_rtp_header_extensions(extensions2);
992 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
993 ASSERT_EQ(1u, media_channel2_->send_streams().size());
994 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
995
996 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
997 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
998 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
999
1000 // Channel 1 replies with the same extensions.
1001 typename T::Content content4;
1002 CreateContent(content_flags, kPcmuCodec, kH264Codec, &content4);
1003 content4.AddStream(stream1);
1004 content4.set_rtp_header_extensions(extensions2);
1005 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
1006 EXPECT_EQ(1u, media_channel1_->send_streams().size());
1007
1008 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
1009 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
1010
1011 packet_listener1.encrypted_headers.clear();
1012 packet_listener1.encrypted_headers.push_back(2);
1013 packet_listener1.encrypted_headers.push_back(4);
1014 packet_listener2.encrypted_headers.clear();
1015 packet_listener2.encrypted_headers.push_back(2);
1016 packet_listener2.encrypted_headers.push_back(4);
1017
1018 SendCustomRtp1(kSsrc1, 0);
1019 SendCustomRtp2(kSsrc2, 0);
1020 WaitForThreads();
1021 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
1022 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
1023 }
1024
895 // Test that we only start playout and sending at the right times. 1025 // Test that we only start playout and sending at the right times.
896 void TestPlayoutAndSendingStates() { 1026 void TestPlayoutAndSendingStates() {
897 CreateChannels(0, 0); 1027 CreateChannels(0, 0);
898 if (verify_playout_) { 1028 if (verify_playout_) {
899 EXPECT_FALSE(media_channel1_->playout()); 1029 EXPECT_FALSE(media_channel1_->playout());
900 } 1030 }
901 EXPECT_FALSE(media_channel1_->sending()); 1031 EXPECT_FALSE(media_channel1_->sending());
902 if (verify_playout_) { 1032 if (verify_playout_) {
903 EXPECT_FALSE(media_channel2_->playout()); 1033 EXPECT_FALSE(media_channel2_->playout());
904 } 1034 }
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {} 2231 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2102 }; 2232 };
2103 2233
2104 class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> { 2234 class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2105 public: 2235 public:
2106 typedef ChannelTest<VoiceTraits> Base; 2236 typedef ChannelTest<VoiceTraits> Base;
2107 VoiceChannelDoubleThreadTest() 2237 VoiceChannelDoubleThreadTest()
2108 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {} 2238 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
2109 }; 2239 };
2110 2240
2241 class VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest
2242 : public ChannelTest<VoiceTraits> {
2243 public:
2244 typedef ChannelTest<VoiceTraits> Base;
2245 VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest()
2246 : Base(true, kPcmuFrameWithExtensions, kRtcpReport,
2247 NetworkIsWorker::Yes) {}
2248 };
2249
2250 class VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest
2251 : public ChannelTest<VoiceTraits> {
2252 public:
2253 typedef ChannelTest<VoiceTraits> Base;
2254 VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest()
2255 : Base(true, kPcmuFrameWithExtensions, kRtcpReport,
2256 NetworkIsWorker::No) {}
2257 };
2258
2111 // override to add NULL parameter 2259 // override to add NULL parameter
2112 template <> 2260 template <>
2113 cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel( 2261 cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
2114 rtc::Thread* worker_thread, 2262 rtc::Thread* worker_thread,
2115 rtc::Thread* network_thread, 2263 rtc::Thread* network_thread,
2116 cricket::MediaEngineInterface* engine, 2264 cricket::MediaEngineInterface* engine,
2117 cricket::FakeVideoMediaChannel* ch, 2265 cricket::FakeVideoMediaChannel* ch,
2118 cricket::DtlsTransportInternal* fake_rtp_dtls_transport, 2266 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
2119 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport, 2267 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
2120 rtc::PacketTransportInternal* fake_rtp_packet_transport, 2268 rtc::PacketTransportInternal* fake_rtp_packet_transport,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 } 2388 }
2241 2389
2242 TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) { 2390 TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2243 Base::TestUpdateStreamsInRemoteContent(); 2391 Base::TestUpdateStreamsInRemoteContent();
2244 } 2392 }
2245 2393
2246 TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) { 2394 TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2247 Base::TestChangeStreamParamsInContent(); 2395 Base::TestChangeStreamParamsInContent();
2248 } 2396 }
2249 2397
2398 TEST_F(VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest,
2399 TestChangeEncryptedHeaderExtensionsDtls) {
2400 int flags = DTLS;
2401 Base::TestChangeEncryptedHeaderExtensions(flags);
2402 }
2403
2404 TEST_F(VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest,
2405 TestChangeEncryptedHeaderExtensionsDtlsGcm) {
2406 int flags = DTLS | GCM_CIPHER;
2407 Base::TestChangeEncryptedHeaderExtensions(flags);
2408 }
2409
2410 TEST_F(VoiceChannelWithEncryptedRtpHeaderExtensionsSingleThreadTest,
2411 TestChangeEncryptedHeaderExtensionsSDES) {
2412 int flags = 0;
2413 Base::TestChangeEncryptedHeaderExtensions(flags);
2414 }
2415
2250 TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) { 2416 TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2251 Base::TestPlayoutAndSendingStates(); 2417 Base::TestPlayoutAndSendingStates();
2252 } 2418 }
2253 2419
2254 TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) { 2420 TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
2255 CreateChannels(0, 0); 2421 CreateChannels(0, 0);
2256 // Test that we can Mute the default channel even though the sending SSRC 2422 // Test that we can Mute the default channel even though the sending SSRC
2257 // is unknown. 2423 // is unknown.
2258 EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); 2424 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2259 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr)); 2425 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 } 2739 }
2574 2740
2575 TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) { 2741 TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
2576 Base::TestUpdateStreamsInRemoteContent(); 2742 Base::TestUpdateStreamsInRemoteContent();
2577 } 2743 }
2578 2744
2579 TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) { 2745 TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
2580 Base::TestChangeStreamParamsInContent(); 2746 Base::TestChangeStreamParamsInContent();
2581 } 2747 }
2582 2748
2749 TEST_F(VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest,
2750 TestChangeEncryptedHeaderExtensionsDtls) {
2751 int flags = DTLS;
2752 Base::TestChangeEncryptedHeaderExtensions(flags);
2753 }
2754
2755 TEST_F(VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest,
2756 TestChangeEncryptedHeaderExtensionsDtlsGcm) {
2757 int flags = DTLS | GCM_CIPHER;
2758 Base::TestChangeEncryptedHeaderExtensions(flags);
2759 }
2760
2761 TEST_F(VoiceChannelWithEncryptedRtpHeaderExtensionsDoubleThreadTest,
2762 TestChangeEncryptedHeaderExtensionsSDES) {
2763 int flags = 0;
2764 Base::TestChangeEncryptedHeaderExtensions(flags);
2765 }
2766
2583 TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) { 2767 TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
2584 Base::TestPlayoutAndSendingStates(); 2768 Base::TestPlayoutAndSendingStates();
2585 } 2769 }
2586 2770
2587 TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) { 2771 TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2588 CreateChannels(0, 0); 2772 CreateChannels(0, 0);
2589 // Test that we can Mute the default channel even though the sending SSRC 2773 // Test that we can Mute the default channel even though the sending SSRC
2590 // is unknown. 2774 // is unknown.
2591 EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); 2775 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2592 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr)); 2776 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
3785 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_, 3969 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_,
3786 &fake_rtcp_dtls_transport_)); 3970 &fake_rtcp_dtls_transport_));
3787 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_, 3971 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_,
3788 &fake_rtp_dtls_transport_), 3972 &fake_rtp_dtls_transport_),
3789 ""); 3973 "");
3790 } 3974 }
3791 3975
3792 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 3976 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3793 3977
3794 // TODO(pthatcher): TestSetReceiver? 3978 // TODO(pthatcher): TestSetReceiver?
OLDNEW
« webrtc/pc/channel.cc ('K') | « webrtc/pc/channel.cc ('k') | webrtc/pc/mediasession.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698