OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2009 Google Inc. | 3 * Copyright 2009 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 const uint8* rtcp_data, | 132 const uint8* rtcp_data, |
133 int rtcp_len) | 133 int rtcp_len) |
134 : verify_playout_(verify_playout), | 134 : verify_playout_(verify_playout), |
135 transport_controller1_(cricket::ICEROLE_CONTROLLING), | 135 transport_controller1_(cricket::ICEROLE_CONTROLLING), |
136 transport_controller2_(cricket::ICEROLE_CONTROLLED), | 136 transport_controller2_(cricket::ICEROLE_CONTROLLED), |
137 media_channel1_(NULL), | 137 media_channel1_(NULL), |
138 media_channel2_(NULL), | 138 media_channel2_(NULL), |
139 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), | 139 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), |
140 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), | 140 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), |
141 media_info_callbacks1_(), | 141 media_info_callbacks1_(), |
142 media_info_callbacks2_(), | 142 media_info_callbacks2_() {} |
143 ssrc_(0), | |
144 error_(T::MediaChannel::ERROR_NONE) {} | |
145 | 143 |
146 void CreateChannels(int flags1, int flags2) { | 144 void CreateChannels(int flags1, int flags2) { |
147 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()), | 145 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()), |
148 new typename T::MediaChannel(NULL, typename T::Options()), | 146 new typename T::MediaChannel(NULL, typename T::Options()), |
149 flags1, flags2, rtc::Thread::Current()); | 147 flags1, flags2, rtc::Thread::Current()); |
150 } | 148 } |
151 void CreateChannels( | 149 void CreateChannels( |
152 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, | 150 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, |
153 int flags1, int flags2, rtc::Thread* thread) { | 151 int flags1, int flags2, rtc::Thread* thread) { |
154 media_channel1_ = ch1; | 152 media_channel1_ = ch1; |
155 media_channel2_ = ch2; | 153 media_channel2_ = ch2; |
156 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, | 154 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, |
157 &transport_controller1_, | 155 &transport_controller1_, |
158 (flags1 & RTCP) != 0)); | 156 (flags1 & RTCP) != 0)); |
159 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, | 157 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, |
160 &transport_controller2_, | 158 &transport_controller2_, |
161 (flags2 & RTCP) != 0)); | 159 (flags2 & RTCP) != 0)); |
162 channel1_->SignalMediaMonitor.connect( | 160 channel1_->SignalMediaMonitor.connect( |
163 this, &ChannelTest<T>::OnMediaMonitor); | 161 this, &ChannelTest<T>::OnMediaMonitor); |
164 channel2_->SignalMediaMonitor.connect( | 162 channel2_->SignalMediaMonitor.connect( |
165 this, &ChannelTest<T>::OnMediaMonitor); | 163 this, &ChannelTest<T>::OnMediaMonitor); |
166 channel1_->SignalMediaError.connect( | |
167 this, &ChannelTest<T>::OnMediaChannelError); | |
168 channel2_->SignalMediaError.connect( | |
169 this, &ChannelTest<T>::OnMediaChannelError); | |
170 if ((flags1 & DTLS) && (flags2 & DTLS)) { | 164 if ((flags1 & DTLS) && (flags2 & DTLS)) { |
171 flags1 = (flags1 & ~SECURE); | 165 flags1 = (flags1 & ~SECURE); |
172 flags2 = (flags2 & ~SECURE); | 166 flags2 = (flags2 & ~SECURE); |
173 } | 167 } |
174 CreateContent(flags1, kPcmuCodec, kH264Codec, | 168 CreateContent(flags1, kPcmuCodec, kH264Codec, |
175 &local_media_content1_); | 169 &local_media_content1_); |
176 CreateContent(flags2, kPcmuCodec, kH264Codec, | 170 CreateContent(flags2, kPcmuCodec, kH264Codec, |
177 &local_media_content2_); | 171 &local_media_content2_); |
178 CopyContent(local_media_content1_, &remote_media_content1_); | 172 CopyContent(local_media_content1_, &remote_media_content1_); |
179 CopyContent(local_media_content2_, &remote_media_content2_); | 173 CopyContent(local_media_content2_, &remote_media_content2_); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 459 |
466 void OnMediaMonitor(typename T::Channel* channel, | 460 void OnMediaMonitor(typename T::Channel* channel, |
467 const typename T::MediaInfo& info) { | 461 const typename T::MediaInfo& info) { |
468 if (channel == channel1_.get()) { | 462 if (channel == channel1_.get()) { |
469 media_info_callbacks1_++; | 463 media_info_callbacks1_++; |
470 } else if (channel == channel2_.get()) { | 464 } else if (channel == channel2_.get()) { |
471 media_info_callbacks2_++; | 465 media_info_callbacks2_++; |
472 } | 466 } |
473 } | 467 } |
474 | 468 |
475 void OnMediaChannelError(typename T::Channel* channel, | |
476 uint32 ssrc, | |
477 typename T::MediaChannel::Error error) { | |
478 ssrc_ = ssrc; | |
479 error_ = error; | |
480 } | |
481 | |
482 void AddLegacyStreamInContent(uint32 ssrc, int flags, | 469 void AddLegacyStreamInContent(uint32 ssrc, int flags, |
483 typename T::Content* content) { | 470 typename T::Content* content) { |
484 // Base implementation. | 471 // Base implementation. |
485 } | 472 } |
486 | 473 |
487 // Tests that can be used by derived classes. | 474 // Tests that can be used by derived classes. |
488 | 475 |
489 // Basic sanity check. | 476 // Basic sanity check. |
490 void TestInit() { | 477 void TestInit() { |
491 CreateChannels(0, 0); | 478 CreateChannels(0, 0); |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 EXPECT_TRUE(send_rtcp1); | 1657 EXPECT_TRUE(send_rtcp1); |
1671 // The sending message is only posted. channel2_ should be empty. | 1658 // The sending message is only posted. channel2_ should be empty. |
1672 EXPECT_TRUE(CheckNoRtcp2()); | 1659 EXPECT_TRUE(CheckNoRtcp2()); |
1673 | 1660 |
1674 // When channel1_ is deleted, the RTCP packet should be sent out to | 1661 // When channel1_ is deleted, the RTCP packet should be sent out to |
1675 // channel2_. | 1662 // channel2_. |
1676 channel1_.reset(); | 1663 channel1_.reset(); |
1677 EXPECT_TRUE(CheckRtcp2()); | 1664 EXPECT_TRUE(CheckRtcp2()); |
1678 } | 1665 } |
1679 | 1666 |
1680 void TestChangeStateError() { | 1667 void TestSrtpError(int pl_type) { |
1681 CreateChannels(RTCP, RTCP); | 1668 struct SrtpErrorHandler : public sigslot::has_slots<> { |
1682 EXPECT_TRUE(SendInitiate()); | 1669 SrtpErrorHandler() : |
1683 media_channel2_->set_fail_set_send(true); | 1670 mode_(cricket::SrtpFilter::UNPROTECT), |
1684 EXPECT_TRUE(channel2_->Enable(true)); | 1671 error_(cricket::SrtpFilter::ERROR_NONE) {} |
1685 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED, | 1672 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode, |
1686 error_); | 1673 cricket::SrtpFilter::Error error) { |
1687 } | 1674 mode_ = mode; |
| 1675 error_ = error; |
| 1676 } |
| 1677 cricket::SrtpFilter::Mode mode_; |
| 1678 cricket::SrtpFilter::Error error_; |
| 1679 } error_handler; |
1688 | 1680 |
1689 void TestSrtpError(int pl_type) { | |
1690 // For Audio, only pl_type 0 is added to the bundle filter. | 1681 // For Audio, only pl_type 0 is added to the bundle filter. |
1691 // For Video, only pl_type 97 is added to the bundle filter. | 1682 // For Video, only pl_type 97 is added to the bundle filter. |
1692 // So we need to pass in pl_type so that the packet can pass through | 1683 // So we need to pass in pl_type so that the packet can pass through |
1693 // the bundle filter before it can be processed by the srtp filter. | 1684 // the bundle filter before it can be processed by the srtp filter. |
1694 // The packet is not a valid srtp packet because it is too short. | 1685 // The packet is not a valid srtp packet because it is too short. |
1695 unsigned const char kBadPacket[] = {0x84, | 1686 unsigned const char kBadPacket[] = {0x84, |
1696 static_cast<unsigned char>(pl_type), | 1687 static_cast<unsigned char>(pl_type), |
1697 0x00, | 1688 0x00, |
1698 0x01, | 1689 0x01, |
1699 0x00, | 1690 0x00, |
1700 0x00, | 1691 0x00, |
1701 0x00, | 1692 0x00, |
1702 0x00, | 1693 0x00, |
1703 0x00, | 1694 0x00, |
1704 0x00, | 1695 0x00, |
1705 0x00, | 1696 0x00, |
1706 0x01}; | 1697 0x01}; |
1707 CreateChannels(RTCP | SECURE, RTCP | SECURE); | 1698 CreateChannels(RTCP | SECURE, RTCP | SECURE); |
1708 EXPECT_FALSE(channel1_->secure()); | 1699 EXPECT_FALSE(channel1_->secure()); |
1709 EXPECT_FALSE(channel2_->secure()); | 1700 EXPECT_FALSE(channel2_->secure()); |
1710 EXPECT_TRUE(SendInitiate()); | 1701 EXPECT_TRUE(SendInitiate()); |
1711 EXPECT_TRUE(SendAccept()); | 1702 EXPECT_TRUE(SendAccept()); |
1712 EXPECT_TRUE(channel1_->secure()); | 1703 EXPECT_TRUE(channel1_->secure()); |
1713 EXPECT_TRUE(channel2_->secure()); | 1704 EXPECT_TRUE(channel2_->secure()); |
1714 channel2_->set_srtp_signal_silent_time(200); | 1705 |
| 1706 channel2_->srtp_filter()->SignalSrtpError.connect( |
| 1707 &error_handler, &SrtpErrorHandler::OnSrtpError); |
1715 | 1708 |
1716 // Testing failures in sending packets. | 1709 // Testing failures in sending packets. |
1717 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); | 1710 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); |
1718 // The first failure will trigger an error. | 1711 // The first failure will trigger an error. |
1719 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500); | 1712 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
1720 error_ = T::MediaChannel::ERROR_NONE; | 1713 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); |
| 1714 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; |
1721 // The next 1 sec failures will not trigger an error. | 1715 // The next 1 sec failures will not trigger an error. |
1722 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); | 1716 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); |
1723 // Wait for a while to ensure no message comes in. | 1717 // Wait for a while to ensure no message comes in. |
1724 rtc::Thread::Current()->ProcessMessages(210); | 1718 rtc::Thread::Current()->ProcessMessages(210); |
1725 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_); | 1719 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_); |
1726 // The error will be triggered again. | 1720 // The error will be triggered again. |
1727 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); | 1721 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); |
1728 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500); | 1722 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1723 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); |
1729 | 1724 |
1730 // Testing failures in receiving packets. | 1725 // Testing failures in receiving packets. |
1731 error_ = T::MediaChannel::ERROR_NONE; | 1726 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; |
| 1727 |
1732 cricket::TransportChannel* transport_channel = | 1728 cricket::TransportChannel* transport_channel = |
1733 channel2_->transport_channel(); | 1729 channel2_->transport_channel(); |
1734 transport_channel->SignalReadPacket( | 1730 transport_channel->SignalReadPacket( |
1735 transport_channel, reinterpret_cast<const char*>(kBadPacket), | 1731 transport_channel, reinterpret_cast<const char*>(kBadPacket), |
1736 sizeof(kBadPacket), rtc::PacketTime(), 0); | 1732 sizeof(kBadPacket), rtc::PacketTime(), 0); |
1737 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500); | 1733 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1734 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); |
1738 } | 1735 } |
1739 | 1736 |
1740 void TestOnReadyToSend() { | 1737 void TestOnReadyToSend() { |
1741 CreateChannels(RTCP, RTCP); | 1738 CreateChannels(RTCP, RTCP); |
1742 TransportChannel* rtp = channel1_->transport_channel(); | 1739 TransportChannel* rtp = channel1_->transport_channel(); |
1743 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); | 1740 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); |
1744 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1741 EXPECT_FALSE(media_channel1_->ready_to_send()); |
1745 rtp->SignalReadyToSend(rtp); | 1742 rtp->SignalReadyToSend(rtp); |
1746 EXPECT_FALSE(media_channel1_->ready_to_send()); | 1743 EXPECT_FALSE(media_channel1_->ready_to_send()); |
1747 rtcp->SignalReadyToSend(rtcp); | 1744 rtcp->SignalReadyToSend(rtcp); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 rtc::scoped_ptr<typename T::Channel> channel2_; | 1792 rtc::scoped_ptr<typename T::Channel> channel2_; |
1796 typename T::Content local_media_content1_; | 1793 typename T::Content local_media_content1_; |
1797 typename T::Content local_media_content2_; | 1794 typename T::Content local_media_content2_; |
1798 typename T::Content remote_media_content1_; | 1795 typename T::Content remote_media_content1_; |
1799 typename T::Content remote_media_content2_; | 1796 typename T::Content remote_media_content2_; |
1800 // The RTP and RTCP packets to send in the tests. | 1797 // The RTP and RTCP packets to send in the tests. |
1801 std::string rtp_packet_; | 1798 std::string rtp_packet_; |
1802 std::string rtcp_packet_; | 1799 std::string rtcp_packet_; |
1803 int media_info_callbacks1_; | 1800 int media_info_callbacks1_; |
1804 int media_info_callbacks2_; | 1801 int media_info_callbacks2_; |
1805 | |
1806 uint32 ssrc_; | |
1807 typename T::MediaChannel::Error error_; | |
1808 }; | 1802 }; |
1809 | 1803 |
1810 template<> | 1804 template<> |
1811 void ChannelTest<VoiceTraits>::CreateContent( | 1805 void ChannelTest<VoiceTraits>::CreateContent( |
1812 int flags, | 1806 int flags, |
1813 const cricket::AudioCodec& audio_codec, | 1807 const cricket::AudioCodec& audio_codec, |
1814 const cricket::VideoCodec& video_codec, | 1808 const cricket::VideoCodec& video_codec, |
1815 cricket::AudioContentDescription* audio) { | 1809 cricket::AudioContentDescription* audio) { |
1816 audio->AddCodec(audio_codec); | 1810 audio->AddCodec(audio_codec); |
1817 audio->set_rtcp_mux((flags & RTCP_MUX) != 0); | 1811 audio->set_rtcp_mux((flags & RTCP_MUX) != 0); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 } | 2155 } |
2162 | 2156 |
2163 TEST_F(VoiceChannelTest, TestReceivePrAnswer) { | 2157 TEST_F(VoiceChannelTest, TestReceivePrAnswer) { |
2164 Base::TestReceivePrAnswer(); | 2158 Base::TestReceivePrAnswer(); |
2165 } | 2159 } |
2166 | 2160 |
2167 TEST_F(VoiceChannelTest, TestFlushRtcp) { | 2161 TEST_F(VoiceChannelTest, TestFlushRtcp) { |
2168 Base::TestFlushRtcp(); | 2162 Base::TestFlushRtcp(); |
2169 } | 2163 } |
2170 | 2164 |
2171 TEST_F(VoiceChannelTest, TestChangeStateError) { | |
2172 Base::TestChangeStateError(); | |
2173 } | |
2174 | |
2175 TEST_F(VoiceChannelTest, TestSrtpError) { | 2165 TEST_F(VoiceChannelTest, TestSrtpError) { |
2176 Base::TestSrtpError(kAudioPts[0]); | 2166 Base::TestSrtpError(kAudioPts[0]); |
2177 } | 2167 } |
2178 | 2168 |
2179 TEST_F(VoiceChannelTest, TestOnReadyToSend) { | 2169 TEST_F(VoiceChannelTest, TestOnReadyToSend) { |
2180 Base::TestOnReadyToSend(); | 2170 Base::TestOnReadyToSend(); |
2181 } | 2171 } |
2182 | 2172 |
2183 TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) { | 2173 TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) { |
2184 Base::TestOnReadyToSendWithRtcpMux(); | 2174 Base::TestOnReadyToSendWithRtcpMux(); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2517 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) { | 2507 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) { |
2518 Base::SendBundleToBundle( | 2508 Base::SendBundleToBundle( |
2519 kVideoPts, ARRAY_SIZE(kVideoPts), true, false); | 2509 kVideoPts, ARRAY_SIZE(kVideoPts), true, false); |
2520 } | 2510 } |
2521 | 2511 |
2522 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) { | 2512 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) { |
2523 Base::SendBundleToBundle( | 2513 Base::SendBundleToBundle( |
2524 kVideoPts, ARRAY_SIZE(kVideoPts), true, true); | 2514 kVideoPts, ARRAY_SIZE(kVideoPts), true, true); |
2525 } | 2515 } |
2526 | 2516 |
2527 // TODO(gangji): Add VideoChannelTest.TestChangeStateError. | |
2528 | |
2529 TEST_F(VideoChannelTest, TestSrtpError) { | 2517 TEST_F(VideoChannelTest, TestSrtpError) { |
2530 Base::TestSrtpError(kVideoPts[0]); | 2518 Base::TestSrtpError(kVideoPts[0]); |
2531 } | 2519 } |
2532 | 2520 |
2533 TEST_F(VideoChannelTest, TestOnReadyToSend) { | 2521 TEST_F(VideoChannelTest, TestOnReadyToSend) { |
2534 Base::TestOnReadyToSend(); | 2522 Base::TestOnReadyToSend(); |
2535 } | 2523 } |
2536 | 2524 |
2537 TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) { | 2525 TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) { |
2538 Base::TestOnReadyToSendWithRtcpMux(); | 2526 Base::TestOnReadyToSendWithRtcpMux(); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2802 }; | 2790 }; |
2803 rtc::Buffer payload(data, 3); | 2791 rtc::Buffer payload(data, 3); |
2804 cricket::SendDataResult result; | 2792 cricket::SendDataResult result; |
2805 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); | 2793 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); |
2806 EXPECT_EQ(params.ssrc, | 2794 EXPECT_EQ(params.ssrc, |
2807 media_channel1_->last_sent_data_params().ssrc); | 2795 media_channel1_->last_sent_data_params().ssrc); |
2808 EXPECT_EQ("foo", media_channel1_->last_sent_data()); | 2796 EXPECT_EQ("foo", media_channel1_->last_sent_data()); |
2809 } | 2797 } |
2810 | 2798 |
2811 // TODO(pthatcher): TestSetReceiver? | 2799 // TODO(pthatcher): TestSetReceiver? |
OLD | NEW |