From 988e63eb06c0a46722882e8ae91247e36fa9c50c Mon Sep 17 00:00:00 2001 From: Bjorn A Mellem Date: Mon, 23 Sep 2019 11:09:22 -0700 Subject: [PATCH] Proxy OnRtcpPacketReceived to the worker thread in channel tests. https://webrtc-review.googlesource.com/c/src/+/152740 changed the way OnRtcpPacketReceived is invoked, so that Channel no longer handles the hop to the worker thread internally. This change updates the test to hop to the worker thread before calling channel, which fixes a test-only tsan failure. Bug: webrtc:10983 Change-Id: Ia31920791fc6eeee86c0d59aa091d708d706bcf0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/154244 Reviewed-by: Seth Hampson Commit-Queue: Bjorn Mellem Cr-Commit-Position: refs/heads/master@{#29271} --- pc/channel_unittest.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pc/channel_unittest.cc b/pc/channel_unittest.cc index 40ccf8d90f..3565569736 100644 --- a/pc/channel_unittest.cc +++ b/pc/channel_unittest.cc @@ -62,6 +62,26 @@ const int kAudioPts[] = {0, 8}; const int kVideoPts[] = {97, 99}; enum class NetworkIsWorker { Yes, No }; +// Helper to proxy received RTCP packets to the worker thread. This is done by +// the channel's caller (eg. PeerConnection) in production. +class RtcpThreadHelper : public sigslot::has_slots<> { + public: + explicit RtcpThreadHelper(rtc::Thread* worker_thread) + : worker_thread_(worker_thread) {} + + void OnRtcpPacketReceived(rtc::CopyOnWriteBuffer* packet, + int64_t packet_time_us) { + worker_thread_->Invoke(RTC_FROM_HERE, [this, packet, packet_time_us] { + SignalRtcpPacketReceived(packet, packet_time_us); + }); + } + + sigslot::signal2 SignalRtcpPacketReceived; + + private: + rtc::Thread* const worker_thread_; +}; + } // namespace template { int rtcp_mux_activated_callbacks2_ = 0; cricket::CandidatePairInterface* last_selected_candidate_pair_; rtc::UniqueRandomIdGenerator ssrc_generator_; + std::vector> rtcp_thread_helpers_; }; template <> @@ -1544,9 +1565,13 @@ std::unique_ptr ChannelTest::CreateChannel( std::unique_ptr ch, webrtc::RtpTransportInternal* rtp_transport, int flags) { + auto helper = std::make_unique(worker_thread); rtp_transport->SignalRtcpPacketReceived.connect( + helper.get(), &RtcpThreadHelper::OnRtcpPacketReceived); + helper->SignalRtcpPacketReceived.connect( static_cast*>(ch.get()), &cricket::RtpHelper::OnRtcpPacketReceived); + rtcp_thread_helpers_.push_back(std::move(helper)); rtc::Thread* signaling_thread = rtc::Thread::Current(); auto channel = std::make_unique( worker_thread, network_thread, signaling_thread, std::move(ch), @@ -1630,9 +1655,13 @@ std::unique_ptr ChannelTest::CreateChannel( std::unique_ptr ch, webrtc::RtpTransportInternal* rtp_transport, int flags) { + auto helper = std::make_unique(worker_thread); rtp_transport->SignalRtcpPacketReceived.connect( + helper.get(), &RtcpThreadHelper::OnRtcpPacketReceived); + helper->SignalRtcpPacketReceived.connect( static_cast*>(ch.get()), &cricket::RtpHelper::OnRtcpPacketReceived); + rtcp_thread_helpers_.push_back(std::move(helper)); rtc::Thread* signaling_thread = rtc::Thread::Current(); auto channel = std::make_unique( worker_thread, network_thread, signaling_thread, std::move(ch), @@ -2444,9 +2473,13 @@ std::unique_ptr ChannelTest::CreateChannel( std::unique_ptr ch, webrtc::RtpTransportInternal* rtp_transport, int flags) { + auto helper = std::make_unique(worker_thread); rtp_transport->SignalRtcpPacketReceived.connect( + helper.get(), &RtcpThreadHelper::OnRtcpPacketReceived); + helper->SignalRtcpPacketReceived.connect( static_cast*>(ch.get()), &cricket::RtpHelper::OnRtcpPacketReceived); + rtcp_thread_helpers_.push_back(std::move(helper)); rtc::Thread* signaling_thread = rtc::Thread::Current(); auto channel = std::make_unique( worker_thread, network_thread, signaling_thread, std::move(ch),