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),