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

Side by Side Diff: talk/session/media/channel_unittest.cc

Issue 1362913004: Remove unused SignalMediaError and infrastructure. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: more Created 5 years, 2 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 | « talk/session/media/channel.cc ('k') | no next file » | 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 * 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
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
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
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() {
1681 CreateChannels(RTCP, RTCP);
1682 EXPECT_TRUE(SendInitiate());
1683 media_channel2_->set_fail_set_send(true);
1684 EXPECT_TRUE(channel2_->Enable(true));
1685 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1686 error_);
1687 }
1688
1689 void TestSrtpError(int pl_type) { 1667 void TestSrtpError(int pl_type) {
1690 // For Audio, only pl_type 0 is added to the bundle filter. 1668 // 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. 1669 // 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 1670 // 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. 1671 // 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. 1672 // The packet is not a valid srtp packet because it is too short.
1695 unsigned const char kBadPacket[] = {0x84, 1673 unsigned const char kBadPacket[] = {0x84,
1696 static_cast<unsigned char>(pl_type), 1674 static_cast<unsigned char>(pl_type),
1697 0x00, 1675 0x00,
1698 0x01, 1676 0x01,
1699 0x00, 1677 0x00,
1700 0x00, 1678 0x00,
1701 0x00, 1679 0x00,
1702 0x00, 1680 0x00,
1703 0x00, 1681 0x00,
1704 0x00, 1682 0x00,
1705 0x00, 1683 0x00,
1706 0x01}; 1684 0x01};
1707 CreateChannels(RTCP | SECURE, RTCP | SECURE); 1685 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1708 EXPECT_FALSE(channel1_->secure()); 1686 EXPECT_FALSE(channel1_->secure());
1709 EXPECT_FALSE(channel2_->secure()); 1687 EXPECT_FALSE(channel2_->secure());
1710 EXPECT_TRUE(SendInitiate()); 1688 EXPECT_TRUE(SendInitiate());
1711 EXPECT_TRUE(SendAccept()); 1689 EXPECT_TRUE(SendAccept());
1712 EXPECT_TRUE(channel1_->secure()); 1690 EXPECT_TRUE(channel1_->secure());
1713 EXPECT_TRUE(channel2_->secure()); 1691 EXPECT_TRUE(channel2_->secure());
1714 channel2_->set_srtp_signal_silent_time(200); 1692 channel2_->set_srtp_signal_silent_time(200);
1715 1693
1716 // Testing failures in sending packets. 1694 // Testing failures in sending packets.
1717 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); 1695 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1718 // The first failure will trigger an error.
1719 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1720 error_ = T::MediaChannel::ERROR_NONE;
1721 // The next 1 sec failures will not trigger an error. 1696 // The next 1 sec failures will not trigger an error.
1722 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); 1697 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1723 // Wait for a while to ensure no message comes in. 1698 // Wait for a while to ensure no message comes in.
1724 rtc::Thread::Current()->ProcessMessages(210); 1699 rtc::Thread::Current()->ProcessMessages(210);
1725 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1726 // The error will be triggered again. 1700 // The error will be triggered again.
1727 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket))); 1701 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1728 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1729 1702
1730 // Testing failures in receiving packets. 1703 // Testing failures in receiving packets.
1731 error_ = T::MediaChannel::ERROR_NONE; 1704 // TODO(solenberg): !!!!!
pthatcher1 2015/09/25 17:18:52 You're going to fix this right?
1732 cricket::TransportChannel* transport_channel = 1705 // cricket::TransportChannel* transport_channel =
1733 channel2_->transport_channel(); 1706 // channel2_->transport_channel();
1734 transport_channel->SignalReadPacket( 1707 // transport_channel->SignalReadPacket(
1735 transport_channel, reinterpret_cast<const char*>(kBadPacket), 1708 // transport_channel, reinterpret_cast<const char*>(kBadPacket),
1736 sizeof(kBadPacket), rtc::PacketTime(), 0); 1709 // sizeof(kBadPacket), rtc::PacketTime(), 0);
1737 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500); 1710 // EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
1738 } 1711 }
1739 1712
1740 void TestOnReadyToSend() { 1713 void TestOnReadyToSend() {
1741 CreateChannels(RTCP, RTCP); 1714 CreateChannels(RTCP, RTCP);
1742 TransportChannel* rtp = channel1_->transport_channel(); 1715 TransportChannel* rtp = channel1_->transport_channel();
1743 TransportChannel* rtcp = channel1_->rtcp_transport_channel(); 1716 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1744 EXPECT_FALSE(media_channel1_->ready_to_send()); 1717 EXPECT_FALSE(media_channel1_->ready_to_send());
1745 rtp->SignalReadyToSend(rtp); 1718 rtp->SignalReadyToSend(rtp);
1746 EXPECT_FALSE(media_channel1_->ready_to_send()); 1719 EXPECT_FALSE(media_channel1_->ready_to_send());
1747 rtcp->SignalReadyToSend(rtcp); 1720 rtcp->SignalReadyToSend(rtcp);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 rtc::scoped_ptr<typename T::Channel> channel2_; 1768 rtc::scoped_ptr<typename T::Channel> channel2_;
1796 typename T::Content local_media_content1_; 1769 typename T::Content local_media_content1_;
1797 typename T::Content local_media_content2_; 1770 typename T::Content local_media_content2_;
1798 typename T::Content remote_media_content1_; 1771 typename T::Content remote_media_content1_;
1799 typename T::Content remote_media_content2_; 1772 typename T::Content remote_media_content2_;
1800 // The RTP and RTCP packets to send in the tests. 1773 // The RTP and RTCP packets to send in the tests.
1801 std::string rtp_packet_; 1774 std::string rtp_packet_;
1802 std::string rtcp_packet_; 1775 std::string rtcp_packet_;
1803 int media_info_callbacks1_; 1776 int media_info_callbacks1_;
1804 int media_info_callbacks2_; 1777 int media_info_callbacks2_;
1805
1806 uint32 ssrc_;
1807 typename T::MediaChannel::Error error_;
1808 }; 1778 };
1809 1779
1810 template<> 1780 template<>
1811 void ChannelTest<VoiceTraits>::CreateContent( 1781 void ChannelTest<VoiceTraits>::CreateContent(
1812 int flags, 1782 int flags,
1813 const cricket::AudioCodec& audio_codec, 1783 const cricket::AudioCodec& audio_codec,
1814 const cricket::VideoCodec& video_codec, 1784 const cricket::VideoCodec& video_codec,
1815 cricket::AudioContentDescription* audio) { 1785 cricket::AudioContentDescription* audio) {
1816 audio->AddCodec(audio_codec); 1786 audio->AddCodec(audio_codec);
1817 audio->set_rtcp_mux((flags & RTCP_MUX) != 0); 1787 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 } 2131 }
2162 2132
2163 TEST_F(VoiceChannelTest, TestReceivePrAnswer) { 2133 TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2164 Base::TestReceivePrAnswer(); 2134 Base::TestReceivePrAnswer();
2165 } 2135 }
2166 2136
2167 TEST_F(VoiceChannelTest, TestFlushRtcp) { 2137 TEST_F(VoiceChannelTest, TestFlushRtcp) {
2168 Base::TestFlushRtcp(); 2138 Base::TestFlushRtcp();
2169 } 2139 }
2170 2140
2171 TEST_F(VoiceChannelTest, TestChangeStateError) {
2172 Base::TestChangeStateError();
2173 }
2174
2175 TEST_F(VoiceChannelTest, TestSrtpError) { 2141 TEST_F(VoiceChannelTest, TestSrtpError) {
2176 Base::TestSrtpError(kAudioPts[0]); 2142 Base::TestSrtpError(kAudioPts[0]);
2177 } 2143 }
2178 2144
2179 TEST_F(VoiceChannelTest, TestOnReadyToSend) { 2145 TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2180 Base::TestOnReadyToSend(); 2146 Base::TestOnReadyToSend();
2181 } 2147 }
2182 2148
2183 TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) { 2149 TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2184 Base::TestOnReadyToSendWithRtcpMux(); 2150 Base::TestOnReadyToSendWithRtcpMux();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) { 2483 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2518 Base::SendBundleToBundle( 2484 Base::SendBundleToBundle(
2519 kVideoPts, ARRAY_SIZE(kVideoPts), true, false); 2485 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2520 } 2486 }
2521 2487
2522 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) { 2488 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2523 Base::SendBundleToBundle( 2489 Base::SendBundleToBundle(
2524 kVideoPts, ARRAY_SIZE(kVideoPts), true, true); 2490 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
2525 } 2491 }
2526 2492
2527 // TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2528
2529 TEST_F(VideoChannelTest, TestSrtpError) { 2493 TEST_F(VideoChannelTest, TestSrtpError) {
2530 Base::TestSrtpError(kVideoPts[0]); 2494 Base::TestSrtpError(kVideoPts[0]);
2531 } 2495 }
2532 2496
2533 TEST_F(VideoChannelTest, TestOnReadyToSend) { 2497 TEST_F(VideoChannelTest, TestOnReadyToSend) {
2534 Base::TestOnReadyToSend(); 2498 Base::TestOnReadyToSend();
2535 } 2499 }
2536 2500
2537 TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) { 2501 TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2538 Base::TestOnReadyToSendWithRtcpMux(); 2502 Base::TestOnReadyToSendWithRtcpMux();
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 }; 2766 };
2803 rtc::Buffer payload(data, 3); 2767 rtc::Buffer payload(data, 3);
2804 cricket::SendDataResult result; 2768 cricket::SendDataResult result;
2805 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); 2769 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2806 EXPECT_EQ(params.ssrc, 2770 EXPECT_EQ(params.ssrc,
2807 media_channel1_->last_sent_data_params().ssrc); 2771 media_channel1_->last_sent_data_params().ssrc);
2808 EXPECT_EQ("foo", media_channel1_->last_sent_data()); 2772 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2809 } 2773 }
2810 2774
2811 // TODO(pthatcher): TestSetReceiver? 2775 // TODO(pthatcher): TestSetReceiver?
OLDNEW
« no previous file with comments | « talk/session/media/channel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698