| Index: webrtc/pc/channel_unittest.cc
|
| diff --git a/webrtc/pc/channel_unittest.cc b/webrtc/pc/channel_unittest.cc
|
| index 6039065e8321b38757834d9ef940d41ae144c113..04b6c426ce3a30a7b8c970cea60671774d33f272 100644
|
| --- a/webrtc/pc/channel_unittest.cc
|
| +++ b/webrtc/pc/channel_unittest.cc
|
| @@ -113,87 +113,133 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
|
| DTLS = 0x10 };
|
|
|
| + // TODO(danilchap): Make tests work with NetworkThread != WorkerThread.
|
| + // In particular when NetworkThread != Thread::Current.
|
| + static const bool kNetworkIsWorker = false;
|
| +
|
| ChannelTest(bool verify_playout,
|
| const uint8_t* rtp_data,
|
| int rtp_len,
|
| const uint8_t* rtcp_data,
|
| int rtcp_len)
|
| : verify_playout_(verify_playout),
|
| - transport_controller1_(cricket::ICEROLE_CONTROLLING),
|
| - transport_controller2_(cricket::ICEROLE_CONTROLLED),
|
| media_channel1_(NULL),
|
| media_channel2_(NULL),
|
| rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
|
| rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
|
| media_info_callbacks1_(),
|
| - media_info_callbacks2_() {}
|
| + media_info_callbacks2_() {
|
| + if (kNetworkIsWorker) {
|
| + network_thread_ = rtc::Thread::Current();
|
| + worker_thread_ = rtc::Thread::Current();
|
| + } else {
|
| + network_thread_ = rtc::Thread::CreateWithSocketServer().release();
|
| + network_thread_->SetName("Network", nullptr);
|
| + network_thread_->Start();
|
| + worker_thread_ = rtc::Thread::Create().release();
|
| + worker_thread_->SetName("Worker", nullptr);
|
| + worker_thread_->Start();
|
| + }
|
| + network_thread_->Invoke<void>([this] {
|
| + transport_controller1_.reset(
|
| + new cricket::FakeTransportController(cricket::ICEROLE_CONTROLLING));
|
| + transport_controller2_.reset(
|
| + new cricket::FakeTransportController(cricket::ICEROLE_CONTROLLED));
|
| + });
|
| + }
|
| + virtual ~ChannelTest() {
|
| + worker_thread_->Invoke<void>([this] {
|
| + channel2_.reset(nullptr);
|
| + channel1_.reset(nullptr);
|
| + });
|
| + // TODO(danilchap): Deinitialize tests with double-threading in mind.
|
| + transport_controller1_.release();
|
| + transport_controller2_.release();
|
| + if (!worker_thread_->IsCurrent()) {
|
| + worker_thread_->Stop();
|
| + }
|
| + if (!network_thread_->IsCurrent()) {
|
| + network_thread_->Stop();
|
| + }
|
| + if (!worker_thread_->IsCurrent()) {
|
| + delete worker_thread_;
|
| + }
|
| + if (!network_thread_->IsCurrent()) {
|
| + delete network_thread_;
|
| + }
|
| + }
|
|
|
| void CreateChannels(int flags1, int flags2) {
|
| CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
|
| new typename T::MediaChannel(NULL, typename T::Options()),
|
| - flags1, flags2, rtc::Thread::Current());
|
| + flags1, flags2);
|
| }
|
| - void CreateChannels(
|
| - typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
|
| - int flags1, int flags2, rtc::Thread* thread) {
|
| + void CreateChannels(typename T::MediaChannel* ch1,
|
| + typename T::MediaChannel* ch2,
|
| + int flags1,
|
| + int flags2) {
|
| media_channel1_ = ch1;
|
| media_channel2_ = ch2;
|
| - channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
|
| - &transport_controller1_,
|
| - (flags1 & RTCP) != 0));
|
| - channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
|
| - &transport_controller2_,
|
| - (flags2 & RTCP) != 0));
|
| - channel1_->SignalMediaMonitor.connect(
|
| - this, &ChannelTest<T>::OnMediaMonitor);
|
| - channel2_->SignalMediaMonitor.connect(
|
| - this, &ChannelTest<T>::OnMediaMonitor);
|
| - if ((flags1 & DTLS) && (flags2 & DTLS)) {
|
| - flags1 = (flags1 & ~SECURE);
|
| - flags2 = (flags2 & ~SECURE);
|
| - }
|
| - CreateContent(flags1, kPcmuCodec, kH264Codec,
|
| - &local_media_content1_);
|
| - CreateContent(flags2, kPcmuCodec, kH264Codec,
|
| - &local_media_content2_);
|
| - CopyContent(local_media_content1_, &remote_media_content1_);
|
| - CopyContent(local_media_content2_, &remote_media_content2_);
|
| -
|
| - if (flags1 & DTLS) {
|
| - // Confirmed to work with KT_RSA and KT_ECDSA.
|
| - transport_controller1_.SetLocalCertificate(
|
| - rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
|
| - rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
|
| - }
|
| - if (flags2 & DTLS) {
|
| - // Confirmed to work with KT_RSA and KT_ECDSA.
|
| - transport_controller2_.SetLocalCertificate(
|
| - rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
|
| - rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
|
| - }
|
| -
|
| - // Add stream information (SSRC) to the local content but not to the remote
|
| - // content. This means that we per default know the SSRC of what we send but
|
| - // not what we receive.
|
| - AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
|
| - AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
|
| + worker_thread_->Invoke<void>([this, ch1, ch2, &flags1, &flags2] {
|
| + channel1_.reset(
|
| + CreateChannel(worker_thread_, network_thread_, &media_engine_, ch1,
|
| + transport_controller1_.get(), (flags1 & RTCP) != 0));
|
| + channel2_.reset(
|
| + CreateChannel(worker_thread_, network_thread_, &media_engine_, ch2,
|
| + transport_controller2_.get(), (flags2 & RTCP) != 0));
|
| + channel1_->SignalMediaMonitor.connect(this,
|
| + &ChannelTest<T>::OnMediaMonitor);
|
| + channel2_->SignalMediaMonitor.connect(this,
|
| + &ChannelTest<T>::OnMediaMonitor);
|
| + if ((flags1 & DTLS) && (flags2 & DTLS)) {
|
| + flags1 = (flags1 & ~SECURE);
|
| + flags2 = (flags2 & ~SECURE);
|
| + }
|
| + CreateContent(flags1, kPcmuCodec, kH264Codec, &local_media_content1_);
|
| + CreateContent(flags2, kPcmuCodec, kH264Codec, &local_media_content2_);
|
| + CopyContent(local_media_content1_, &remote_media_content1_);
|
| + CopyContent(local_media_content2_, &remote_media_content2_);
|
| +
|
| + if (flags1 & DTLS) {
|
| + // Confirmed to work with KT_RSA and KT_ECDSA.
|
| + transport_controller1_->SetLocalCertificate(
|
| + rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
|
| + rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
|
| + }
|
| + if (flags2 & DTLS) {
|
| + // Confirmed to work with KT_RSA and KT_ECDSA.
|
| + transport_controller2_->SetLocalCertificate(
|
| + rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
|
| + rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
|
| + }
|
|
|
| - // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
|
| - if (flags1 & SSRC_MUX) {
|
| - AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
|
| - }
|
| - if (flags2 & SSRC_MUX) {
|
| - AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
|
| - }
|
| + // Add stream information (SSRC) to the local content but not to the
|
| + // remote
|
| + // content. This means that we per default know the SSRC of what we send
|
| + // but
|
| + // not what we receive.
|
| + AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
|
| + AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
|
| + // If SSRC_MUX is used we also need to know the SSRC of the incoming
|
| + // stream.
|
| + if (flags1 & SSRC_MUX) {
|
| + AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
|
| + }
|
| + if (flags2 & SSRC_MUX) {
|
| + AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
|
| + }
|
| + });
|
| }
|
| typename T::Channel* CreateChannel(
|
| - rtc::Thread* thread,
|
| + rtc::Thread* worker_thread,
|
| + rtc::Thread* network_thread,
|
| cricket::MediaEngineInterface* engine,
|
| typename T::MediaChannel* ch,
|
| cricket::TransportController* transport_controller,
|
| bool rtcp) {
|
| - typename T::Channel* channel = new typename T::Channel(
|
| - thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
|
| + typename T::Channel* channel =
|
| + new typename T::Channel(worker_thread, network_thread, engine, ch,
|
| + transport_controller, cricket::CN_AUDIO, rtcp);
|
| if (!channel->Init()) {
|
| delete channel;
|
| channel = NULL;
|
| @@ -209,7 +255,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| result = channel2_->SetRemoteContent(&remote_media_content1_,
|
| CA_OFFER, NULL);
|
| if (result) {
|
| - transport_controller1_.Connect(&transport_controller2_);
|
| + transport_controller1_->Connect(transport_controller2_.get());
|
|
|
| result = channel2_->SetLocalContent(&local_media_content2_,
|
| CA_ANSWER, NULL);
|
| @@ -242,7 +288,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| channel2_->Enable(true);
|
| result = channel1_->SetRemoteContent(&remote_media_content2_,
|
| CA_PRANSWER, NULL);
|
| - transport_controller1_.Connect(&transport_controller2_);
|
| + transport_controller1_->Connect(transport_controller2_.get());
|
| }
|
| return result;
|
| }
|
| @@ -257,8 +303,10 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| }
|
|
|
| bool SendTerminate() {
|
| - channel1_.reset();
|
| - channel2_.reset();
|
| + worker_thread_->Invoke<void>([this] {
|
| + channel1_.reset();
|
| + channel2_.reset();
|
| + });
|
| return true;
|
| }
|
|
|
| @@ -269,31 +317,42 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| return channel1_->RemoveRecvStream(id);
|
| }
|
|
|
| - // Calling "_w" method here is ok since we only use one thread for this test
|
| cricket::FakeTransport* GetTransport1() {
|
| - return transport_controller1_.GetTransport_w(channel1_->content_name());
|
| + std::string name = channel1_->content_name();
|
| + return network_thread_->Invoke<cricket::FakeTransport*>(
|
| + [this, name] { return transport_controller1_->GetTransport_n(name); });
|
| }
|
| cricket::FakeTransport* GetTransport2() {
|
| - return transport_controller2_.GetTransport_w(channel2_->content_name());
|
| + std::string name = channel2_->content_name();
|
| + return network_thread_->Invoke<cricket::FakeTransport*>(
|
| + [this, name] { return transport_controller2_->GetTransport_n(name); });
|
| }
|
|
|
| bool SendRtp1() {
|
| - return media_channel1_->SendRtp(rtp_packet_.c_str(),
|
| - static_cast<int>(rtp_packet_.size()),
|
| - rtc::PacketOptions());
|
| + bool res = media_channel1_->SendRtp(rtp_packet_.c_str(),
|
| + static_cast<int>(rtp_packet_.size()),
|
| + rtc::PacketOptions());
|
| + WaitForThreads();
|
| + return res;
|
| }
|
| bool SendRtp2() {
|
| - return media_channel2_->SendRtp(rtp_packet_.c_str(),
|
| - static_cast<int>(rtp_packet_.size()),
|
| - rtc::PacketOptions());
|
| + bool res = media_channel2_->SendRtp(rtp_packet_.c_str(),
|
| + static_cast<int>(rtp_packet_.size()),
|
| + rtc::PacketOptions());
|
| + WaitForThreads();
|
| + return res;
|
| }
|
| bool SendRtcp1() {
|
| - return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
|
| - static_cast<int>(rtcp_packet_.size()));
|
| + bool res = media_channel1_->SendRtcp(rtcp_packet_.c_str(),
|
| + static_cast<int>(rtcp_packet_.size()));
|
| + WaitForThreads();
|
| + return res;
|
| }
|
| bool SendRtcp2() {
|
| - return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
|
| - static_cast<int>(rtcp_packet_.size()));
|
| + bool res = media_channel2_->SendRtcp(rtcp_packet_.c_str(),
|
| + static_cast<int>(rtcp_packet_.size()));
|
| + WaitForThreads();
|
| + return res;
|
| }
|
| // Methods to send custom data.
|
| bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
|
| @@ -792,7 +851,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
|
|
| EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
|
| EXPECT_EQ(1u, media_channel2_->recv_streams().size());
|
| - transport_controller1_.Connect(&transport_controller2_);
|
| + transport_controller1_->Connect(transport_controller2_.get());
|
|
|
| // Channel 2 do not send anything.
|
| typename T::Content content2;
|
| @@ -867,7 +926,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| EXPECT_FALSE(media_channel2_->playout());
|
| }
|
| EXPECT_FALSE(media_channel2_->sending());
|
| - transport_controller1_.Connect(&transport_controller2_);
|
| + transport_controller1_->Connect(transport_controller2_.get());
|
| if (verify_playout_) {
|
| EXPECT_TRUE(media_channel1_->playout());
|
| }
|
| @@ -915,7 +974,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
|
| EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
|
| EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
|
| - transport_controller1_.Connect(&transport_controller2_);
|
| + transport_controller1_->Connect(transport_controller2_.get());
|
|
|
| if (verify_playout_) {
|
| EXPECT_TRUE(media_channel1_->playout());
|
| @@ -962,36 +1021,38 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
|
|
| cricket::TransportChannel* transport_channel1 =
|
| channel1_->transport_channel();
|
| - ASSERT_TRUE(transport_channel1 != nullptr);
|
| + ASSERT_TRUE(transport_channel1);
|
| typename T::MediaChannel* media_channel1 =
|
| static_cast<typename T::MediaChannel*>(channel1_->media_channel());
|
| - ASSERT_TRUE(media_channel1 != nullptr);
|
| + ASSERT_TRUE(media_channel1);
|
|
|
| media_channel1_->set_num_network_route_changes(0);
|
| - // The transport channel becomes disconnected.
|
| - transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1,
|
| - nullptr, -1);
|
| - EXPECT_EQ(1, media_channel1_->num_network_route_changes());
|
| - EXPECT_FALSE(media_channel1->last_network_route().connected);
|
| -
|
| - media_channel1_->set_num_network_route_changes(0);
|
| - // The transport channel becomes connected.
|
| - rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
|
| - rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
|
| - uint16_t local_net_id = 1;
|
| - uint16_t remote_net_id = 2;
|
| - int last_packet_id = 100;
|
| - std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
|
| - transport_controller1_.CreateFakeCandidatePair(
|
| - local_address, local_net_id, remote_address, remote_net_id));
|
| - transport_channel1->SignalSelectedCandidatePairChanged(
|
| - transport_channel1, candidate_pair.get(), last_packet_id);
|
| - EXPECT_EQ(1, media_channel1_->num_network_route_changes());
|
| - rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id,
|
| - last_packet_id);
|
| - EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
|
| - EXPECT_EQ(last_packet_id,
|
| - media_channel1->last_network_route().last_sent_packet_id);
|
| + network_thread_->Invoke<void>([this, transport_channel1, media_channel1] {
|
| + // The transport channel becomes disconnected.
|
| + transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1,
|
| + nullptr, -1);
|
| + EXPECT_EQ(1, media_channel1_->num_network_route_changes());
|
| + EXPECT_FALSE(media_channel1->last_network_route().connected);
|
| +
|
| + media_channel1_->set_num_network_route_changes(0);
|
| + // The transport channel becomes connected.
|
| + rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
|
| + rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
|
| + uint16_t local_net_id = 1;
|
| + uint16_t remote_net_id = 2;
|
| + int last_packet_id = 100;
|
| + rtc::scoped_ptr<cricket::CandidatePairInterface> candidate_pair(
|
| + transport_controller1_->CreateFakeCandidatePair(
|
| + local_address, local_net_id, remote_address, remote_net_id));
|
| + transport_channel1->SignalSelectedCandidatePairChanged(
|
| + transport_channel1, candidate_pair.get(), last_packet_id);
|
| + EXPECT_EQ(1, media_channel1_->num_network_route_changes());
|
| + rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id,
|
| + last_packet_id);
|
| + EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
|
| + EXPECT_EQ(last_packet_id,
|
| + media_channel1->last_network_route().last_sent_packet_id);
|
| + });
|
| }
|
|
|
| // Test setting up a call.
|
| @@ -1029,8 +1090,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| }
|
| };
|
| CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
|
| - RTCP | RTCP_MUX, RTCP | RTCP_MUX,
|
| - rtc::Thread::Current());
|
| + RTCP | RTCP_MUX, RTCP | RTCP_MUX);
|
| EXPECT_TRUE(SendInitiate());
|
| EXPECT_TRUE(SendAccept());
|
| EXPECT_TRUE(SendTerminate());
|
| @@ -1470,14 +1530,16 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| EXPECT_TRUE(CheckNoRtp2());
|
|
|
| // Lose writability, which should fail.
|
| - GetTransport1()->SetWritable(false);
|
| + network_thread_->Invoke<void>(
|
| + [this] { GetTransport1()->SetWritable(false); });
|
| EXPECT_FALSE(SendRtp1());
|
| EXPECT_TRUE(SendRtp2());
|
| EXPECT_TRUE(CheckRtp1());
|
| EXPECT_TRUE(CheckNoRtp2());
|
|
|
| // Regain writability
|
| - GetTransport1()->SetWritable(true);
|
| + network_thread_->Invoke<void>(
|
| + [this] { GetTransport1()->SetWritable(true); });
|
| EXPECT_TRUE(media_channel1_->sending());
|
| EXPECT_TRUE(SendRtp1());
|
| EXPECT_TRUE(SendRtp2());
|
| @@ -1487,7 +1549,8 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| EXPECT_TRUE(CheckNoRtp2());
|
|
|
| // Lose writability completely
|
| - GetTransport1()->SetDestination(NULL);
|
| + network_thread_->Invoke<void>(
|
| + [this] { GetTransport1()->SetDestination(NULL); });
|
| EXPECT_TRUE(media_channel1_->sending());
|
|
|
| // Should fail also.
|
| @@ -1497,7 +1560,8 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| EXPECT_TRUE(CheckNoRtp2());
|
|
|
| // Gain writability back
|
| - GetTransport1()->SetDestination(GetTransport2());
|
| + network_thread_->Invoke<void>(
|
| + [this] { GetTransport1()->SetDestination(GetTransport2()); });
|
| EXPECT_TRUE(media_channel1_->sending());
|
| EXPECT_TRUE(SendRtp1());
|
| EXPECT_TRUE(SendRtp2());
|
| @@ -1721,7 +1785,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
|
|
| // When channel1_ is deleted, the RTCP packet should be sent out to
|
| // channel2_.
|
| - channel1_.reset();
|
| + worker_thread_->Invoke<void>([this] { channel1_.reset(); });
|
| EXPECT_TRUE(CheckRtcp2());
|
| }
|
|
|
| @@ -1793,11 +1857,13 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
|
| error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
|
|
|
| - cricket::TransportChannel* transport_channel =
|
| - channel2_->transport_channel();
|
| - transport_channel->SignalReadPacket(
|
| - transport_channel, reinterpret_cast<const char*>(kBadPacket),
|
| - sizeof(kBadPacket), rtc::PacketTime(), 0);
|
| + network_thread_->Invoke<void>([this, kBadPacket] {
|
| + cricket::TransportChannel* transport_channel =
|
| + channel2_->transport_channel();
|
| + transport_channel->SignalReadPacket(
|
| + transport_channel, reinterpret_cast<const char*>(kBadPacket),
|
| + sizeof(kBadPacket), rtc::PacketTime(), 0);
|
| + });
|
| EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
|
| EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
|
| }
|
| @@ -1815,15 +1881,15 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| EXPECT_TRUE(media_channel1_->ready_to_send());
|
|
|
| // rtp channel becomes not ready to send will be propagated to mediachannel
|
| - channel1_->SetReadyToSend(false, false);
|
| + channel1_->SetReadyToSend_n(false, false);
|
| EXPECT_FALSE(media_channel1_->ready_to_send());
|
| - channel1_->SetReadyToSend(false, true);
|
| + channel1_->SetReadyToSend_n(false, true);
|
| EXPECT_TRUE(media_channel1_->ready_to_send());
|
|
|
| // rtcp channel becomes not ready to send will be propagated to mediachannel
|
| - channel1_->SetReadyToSend(true, false);
|
| + channel1_->SetReadyToSend_n(true, false);
|
| EXPECT_FALSE(media_channel1_->ready_to_send());
|
| - channel1_->SetReadyToSend(true, true);
|
| + channel1_->SetReadyToSend_n(true, true);
|
| EXPECT_TRUE(media_channel1_->ready_to_send());
|
| }
|
|
|
| @@ -1842,7 +1908,7 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| // should trigger the MediaChannel's OnReadyToSend.
|
| rtp->SignalReadyToSend(rtp);
|
| EXPECT_TRUE(media_channel1_->ready_to_send());
|
| - channel1_->SetReadyToSend(false, false);
|
| + channel1_->SetReadyToSend_n(false, false);
|
| EXPECT_FALSE(media_channel1_->ready_to_send());
|
| }
|
|
|
| @@ -1894,11 +1960,42 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> {
|
| }
|
|
|
| protected:
|
| + void WaitForThreads() {
|
| + rtc::Thread* threads[] = {worker_thread_, network_thread_};
|
| +
|
| + rtc::Event waiter(false, false);
|
| + class EventWaiter : public rtc::MessageHandler {
|
| + public:
|
| + EventWaiter(rtc::Event* event) : event_(event) {}
|
| + void OnMessage(rtc::Message* /* msg */) override { event_->Set(); }
|
| +
|
| + private:
|
| + rtc::Event* const event_;
|
| + } handler(&waiter);
|
| +
|
| + bool all_empty = false;
|
| + while (!all_empty) {
|
| + all_empty = true;
|
| + for (rtc::Thread* thread : threads) {
|
| + if (thread->empty()) {
|
| + continue;
|
| + }
|
| + all_empty = false;
|
| + // Ensure all messages are processed by posting own to end of the queue
|
| + // and waiting for it.
|
| + RTC_CHECK(!thread->IsCurrent());
|
| + thread->Post(&handler);
|
| + RTC_CHECK(waiter.Wait(1000));
|
| + }
|
| + }
|
| + }
|
| // TODO(pbos): Remove playout from all media channels and let renderers mute
|
| // themselves.
|
| const bool verify_playout_;
|
| - cricket::FakeTransportController transport_controller1_;
|
| - cricket::FakeTransportController transport_controller2_;
|
| + std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
|
| + std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
|
| + rtc::Thread* network_thread_;
|
| + rtc::Thread* worker_thread_;
|
| cricket::FakeMediaEngine media_engine_;
|
| // The media channels are owned by the voice channel objects below.
|
| typename T::MediaChannel* media_channel1_;
|
| @@ -1969,13 +2066,15 @@ class VoiceChannelTest
|
| // override to add NULL parameter
|
| template <>
|
| cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
|
| - rtc::Thread* thread,
|
| + rtc::Thread* worker_thread,
|
| + rtc::Thread* network_thread,
|
| cricket::MediaEngineInterface* engine,
|
| cricket::FakeVideoMediaChannel* ch,
|
| cricket::TransportController* transport_controller,
|
| bool rtcp) {
|
| - cricket::VideoChannel* channel = new cricket::VideoChannel(
|
| - thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
|
| + cricket::VideoChannel* channel =
|
| + new cricket::VideoChannel(worker_thread, network_thread, ch,
|
| + transport_controller, cricket::CN_VIDEO, rtcp);
|
| if (!channel->Init()) {
|
| delete channel;
|
| channel = NULL;
|
| @@ -2623,13 +2722,15 @@ class DataChannelTest
|
| // Override to avoid engine channel parameter.
|
| template <>
|
| cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
|
| - rtc::Thread* thread,
|
| + rtc::Thread* worker_thread,
|
| + rtc::Thread* network_thread,
|
| cricket::MediaEngineInterface* engine,
|
| cricket::FakeDataMediaChannel* ch,
|
| cricket::TransportController* transport_controller,
|
| bool rtcp) {
|
| - cricket::DataChannel* channel = new cricket::DataChannel(
|
| - thread, ch, transport_controller, cricket::CN_DATA, rtcp);
|
| + cricket::DataChannel* channel =
|
| + new cricket::DataChannel(worker_thread, network_thread, ch,
|
| + transport_controller, cricket::CN_DATA, rtcp);
|
| if (!channel->Init()) {
|
| delete channel;
|
| channel = NULL;
|
|
|