diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc index 2788dacf78..e9a7f18dca 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc @@ -508,7 +508,7 @@ ChannelReceive::ChannelReceive( if (frame_transformer) InitFrameTransformerDelegate(std::move(frame_transformer)); - rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(configuration); + rtp_rtcp_ = std::make_unique(configuration); rtp_rtcp_->SetSendingMediaStatus(false); rtp_rtcp_->SetRemoteSSRC(remote_ssrc_); diff --git a/audio/channel_send.cc b/audio/channel_send.cc index 80e7ab2f47..5700c13b22 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -492,10 +492,11 @@ ChannelSend::ChannelSend( retransmission_rate_limiter_.get(); configuration.extmap_allow_mixed = extmap_allow_mixed; configuration.rtcp_report_interval_ms = rtcp_report_interval_ms; + configuration.task_queue = TaskQueueBase::Current(); configuration.local_media_ssrc = ssrc; - rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(configuration); + rtp_rtcp_ = std::make_unique(configuration); rtp_rtcp_->SetSendingMediaStatus(false); rtp_sender_audio_ = std::make_unique(configuration.clock, diff --git a/audio/voip/audio_channel.cc b/audio/voip/audio_channel.cc index dc53acf3ad..cc1e4a45d0 100644 --- a/audio/voip/audio_channel.cc +++ b/audio/voip/audio_channel.cc @@ -50,8 +50,7 @@ AudioChannel::AudioChannel( rtp_config.rtcp_report_interval_ms = kRtcpReportIntervalMs; rtp_config.outgoing_transport = transport; rtp_config.local_media_ssrc = local_ssrc; - - rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(rtp_config); + rtp_rtcp_ = std::make_unique(rtp_config); rtp_rtcp_->SetSendingMediaStatus(false); rtp_rtcp_->SetRTCPStatus(RtcpMode::kCompound); diff --git a/audio/voip/test/audio_egress_unittest.cc b/audio/voip/test/audio_egress_unittest.cc index 0692ef2df4..e07df3839b 100644 --- a/audio/voip/test/audio_egress_unittest.cc +++ b/audio/voip/test/audio_egress_unittest.cc @@ -37,7 +37,7 @@ std::unique_ptr CreateRtpStack(Clock* clock, rtp_config.rtcp_report_interval_ms = 5000; rtp_config.outgoing_transport = transport; rtp_config.local_media_ssrc = remote_ssrc; - auto rtp_rtcp = ModuleRtpRtcpImpl2::Create(rtp_config); + auto rtp_rtcp = std::make_unique(rtp_config); rtp_rtcp->SetSendingMediaStatus(false); rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); return rtp_rtcp; diff --git a/audio/voip/test/audio_ingress_unittest.cc b/audio/voip/test/audio_ingress_unittest.cc index 55ecfec695..fa0038e581 100644 --- a/audio/voip/test/audio_ingress_unittest.cc +++ b/audio/voip/test/audio_ingress_unittest.cc @@ -46,7 +46,7 @@ class AudioIngressTest : public ::testing::Test { rtp_config.rtcp_report_interval_ms = 5000; rtp_config.outgoing_transport = &transport_; rtp_config.local_media_ssrc = 0xdeadc0de; - rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(rtp_config); + rtp_rtcp_ = std::make_unique(rtp_config); rtp_rtcp_->SetSendingMediaStatus(false); rtp_rtcp_->SetRTCPStatus(RtcpMode::kCompound); diff --git a/call/flexfec_receive_stream_impl.cc b/call/flexfec_receive_stream_impl.cc index e629bca347..3bcee60f0e 100644 --- a/call/flexfec_receive_stream_impl.cc +++ b/call/flexfec_receive_stream_impl.cc @@ -130,8 +130,9 @@ std::unique_ptr CreateRtpRtcpModule( configuration.receive_statistics = receive_statistics; configuration.outgoing_transport = config.rtcp_send_transport; configuration.rtt_stats = rtt_stats; + configuration.task_queue = TaskQueueBase::Current(); configuration.local_media_ssrc = config.local_ssrc; - return ModuleRtpRtcpImpl2::Create(configuration); + return std::make_unique(configuration); } } // namespace diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc index 041427a02e..088f90e9f5 100644 --- a/call/rtp_video_sender.cc +++ b/call/rtp_video_sender.cc @@ -232,6 +232,7 @@ std::vector CreateRtpStreamSenders( configuration.extmap_allow_mixed = rtp_config.extmap_allow_mixed; configuration.rtcp_report_interval_ms = rtcp_report_interval_ms; configuration.field_trials = &trials; + configuration.task_queue = TaskQueueBase::Current(); std::vector rtp_streams; @@ -252,8 +253,7 @@ std::vector CreateRtpStreamSenders( configuration.need_rtp_packet_infos = rtp_config.lntf.enabled; - std::unique_ptr rtp_rtcp( - ModuleRtpRtcpImpl2::Create(configuration)); + auto rtp_rtcp = std::make_unique(configuration); rtp_rtcp->SetSendingStatus(false); rtp_rtcp->SetSendingMediaStatus(false); rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); diff --git a/modules/rtp_rtcp/source/nack_rtx_unittest.cc b/modules/rtp_rtcp/source/nack_rtx_unittest.cc index 8afaf3ee61..0f8d37b2bc 100644 --- a/modules/rtp_rtcp/source/nack_rtx_unittest.cc +++ b/modules/rtp_rtcp/source/nack_rtx_unittest.cc @@ -136,7 +136,7 @@ class RtpRtcpRtxNackTest : public ::testing::Test { configuration.retransmission_rate_limiter = &retransmission_rate_limiter_; configuration.local_media_ssrc = kTestSsrc; configuration.rtx_send_ssrc = kTestRtxSsrc; - rtp_rtcp_module_ = ModuleRtpRtcpImpl2::Create(configuration); + rtp_rtcp_module_ = std::make_unique(configuration); FieldTrialBasedConfig field_trials; RTPSenderVideo::Config video_config; video_config.clock = &fake_clock; diff --git a/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/modules/rtp_rtcp/source/rtcp_sender_unittest.cc index 4c8038fd04..d25d10dbf6 100644 --- a/modules/rtp_rtcp/source/rtcp_sender_unittest.cc +++ b/modules/rtp_rtcp/source/rtcp_sender_unittest.cc @@ -92,7 +92,7 @@ class RtcpSenderTest : public ::testing::Test { receive_statistics_(ReceiveStatistics::Create(&clock_)), retransmission_rate_limiter_(&clock_, 1000) { RtpRtcpInterface::Configuration configuration = GetDefaultConfig(); - rtp_rtcp_impl_.reset(new ModuleRtpRtcpImpl2(configuration)); + rtp_rtcp_impl_ = std::make_unique(configuration); } RtpRtcpInterface::Configuration GetDefaultConfig() { diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc index 94dc2977e0..3d70ee808e 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc @@ -53,7 +53,7 @@ void ModuleRtpRtcpImpl2::RtpSenderContext::AssignSequenceNumber( } ModuleRtpRtcpImpl2::ModuleRtpRtcpImpl2(const Configuration& configuration) - : worker_queue_(TaskQueueBase::Current()), + : worker_queue_(configuration.task_queue), rtcp_sender_(configuration), rtcp_receiver_(configuration, this), clock_(configuration.clock), @@ -66,7 +66,6 @@ ModuleRtpRtcpImpl2::ModuleRtpRtcpImpl2(const Configuration& configuration) remote_bitrate_(configuration.remote_bitrate_estimator), rtt_stats_(configuration.rtt_stats), rtt_ms_(0) { - RTC_DCHECK(worker_queue_); process_thread_checker_.Detach(); if (!configuration.receiver_only) { rtp_sender_ = std::make_unique(configuration); @@ -82,6 +81,7 @@ ModuleRtpRtcpImpl2::ModuleRtpRtcpImpl2(const Configuration& configuration) SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize); if (rtt_stats_) { + RTC_DCHECK(worker_queue_); rtt_update_task_ = RepeatingTaskHandle::DelayedStart( worker_queue_, kRttUpdateInterval, [this]() { PeriodicUpdate(); @@ -91,16 +91,10 @@ ModuleRtpRtcpImpl2::ModuleRtpRtcpImpl2(const Configuration& configuration) } ModuleRtpRtcpImpl2::~ModuleRtpRtcpImpl2() { - RTC_DCHECK_RUN_ON(worker_queue_); - rtt_update_task_.Stop(); -} - -// static -std::unique_ptr ModuleRtpRtcpImpl2::Create( - const Configuration& configuration) { - RTC_DCHECK(configuration.clock); - RTC_DCHECK(TaskQueueBase::Current()); - return std::make_unique(configuration); + if (worker_queue_) { + RTC_DCHECK_RUN_ON(worker_queue_); + rtt_update_task_.Stop(); + } } // Returns the number of milliseconds until the module want a worker thread diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl2.h b/modules/rtp_rtcp/source/rtp_rtcp_impl2.h index 9431e75884..6cdd149c42 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl2.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl2.h @@ -55,13 +55,6 @@ class ModuleRtpRtcpImpl2 final : public RtpRtcpInterface, const RtpRtcpInterface::Configuration& configuration); ~ModuleRtpRtcpImpl2() override; - // This method is provided to easy with migrating away from the - // RtpRtcp::Create factory method. Since this is an internal implementation - // detail though, creating an instance of ModuleRtpRtcpImpl2 directly should - // be fine. - static std::unique_ptr Create( - const Configuration& configuration); - // Returns the number of milliseconds until the module want a worker thread to // call Process. int64_t TimeUntilNextProcess() override; diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl2_unittest.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl2_unittest.cc index 3b666422b8..e107ebb425 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl2_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl2_unittest.cc @@ -161,8 +161,9 @@ class RtpRtcpModule : public RtcpPacketTypeCounterObserver { config.local_media_ssrc = is_sender_ ? kSenderSsrc : kReceiverSsrc; config.need_rtp_packet_infos = true; config.non_sender_rtt_measurement = true; + config.task_queue = TaskQueueBase::Current(); - impl_.reset(new ModuleRtpRtcpImpl2(config)); + impl_ = std::make_unique(config); impl_->SetRemoteSSRC(is_sender_ ? kReceiverSsrc : kSenderSsrc); impl_->SetRTCPStatus(RtcpMode::kCompound); } diff --git a/modules/rtp_rtcp/source/rtp_rtcp_interface.h b/modules/rtp_rtcp/source/rtp_rtcp_interface.h index 5bb3eb55e2..30b66eff74 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_interface.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_interface.h @@ -18,6 +18,7 @@ #include "absl/types/optional.h" #include "api/frame_transformer_interface.h" #include "api/scoped_refptr.h" +#include "api/task_queue/task_queue_base.h" #include "api/transport/webrtc_key_value_config.h" #include "api/video/video_bitrate_allocation.h" #include "modules/rtp_rtcp/include/receive_statistics.h" @@ -86,6 +87,11 @@ class RtpRtcpInterface : public RtcpFeedbackSenderInterface { RtcpCnameCallback* rtcp_cname_callback = nullptr; ReportBlockDataObserver* report_block_data_observer = nullptr; + // For RtpRtcpImpl2 only. Used for periodic RTT updates, when rtt_stats + // (above) is non-null. If provided, destruction of the RtpRtcp object must + // occur on this task queue, while construction is allowed on any thread. + TaskQueueBase* task_queue = nullptr; + // Estimates the bandwidth available for a set of streams from the same // client. RemoteBitrateEstimator* remote_bitrate_estimator = nullptr; diff --git a/modules/rtp_rtcp/source/rtp_sender_audio_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_audio_unittest.cc index d75f4e8947..07849fa5b7 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_sender_audio_unittest.cc @@ -69,7 +69,7 @@ class RtpSenderAudioTest : public ::testing::Test { public: RtpSenderAudioTest() : fake_clock_(kStartTime), - rtp_module_(ModuleRtpRtcpImpl2::Create([&] { + rtp_module_(std::make_unique([&] { RtpRtcpInterface::Configuration config; config.audio = true; config.clock = &fake_clock_; diff --git a/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc index 55bafdc790..9feacf0e6d 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc @@ -176,7 +176,7 @@ class RtpSenderVideoTest : public ::testing::TestWithParam { : field_trials_(GetParam()), fake_clock_(kStartTime), retransmission_rate_limiter_(&fake_clock_, 1000), - rtp_module_(ModuleRtpRtcpImpl2::Create([&] { + rtp_module_(std::make_unique([&] { RtpRtcpInterface::Configuration config; config.clock = &fake_clock_; config.outgoing_transport = &transport_; @@ -1167,7 +1167,7 @@ class RtpSenderVideoWithFrameTransformerTest : public ::testing::Test { RtpSenderVideoWithFrameTransformerTest() : fake_clock_(kStartTime), retransmission_rate_limiter_(&fake_clock_, 1000), - rtp_module_(ModuleRtpRtcpImpl2::Create([&] { + rtp_module_(std::make_unique([&] { RtpRtcpInterface::Configuration config; config.clock = &fake_clock_; config.outgoing_transport = &transport_; diff --git a/video/end_to_end_tests/bandwidth_tests.cc b/video/end_to_end_tests/bandwidth_tests.cc index 721738393b..ac2fd57a18 100644 --- a/video/end_to_end_tests/bandwidth_tests.cc +++ b/video/end_to_end_tests/bandwidth_tests.cc @@ -245,7 +245,7 @@ TEST_F(BandwidthEndToEndTest, RembWithSendSideBwe) { config.outgoing_transport = receive_transport_; config.retransmission_rate_limiter = &retransmission_rate_limiter_; config.local_media_ssrc = (*receive_configs)[0].rtp.local_ssrc; - rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(config); + rtp_rtcp_ = std::make_unique(config); rtp_rtcp_->SetRemoteSSRC((*receive_configs)[0].rtp.remote_ssrc); rtp_rtcp_->SetRTCPStatus(RtcpMode::kReducedSize); } diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc index 63d8c3835d..2cda8c7fdb 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -97,9 +97,8 @@ std::unique_ptr CreateRtpRtcpModule( configuration.rtcp_cname_callback = rtcp_cname_callback; configuration.local_media_ssrc = local_ssrc; configuration.non_sender_rtt_measurement = non_sender_rtt_measurement; - - std::unique_ptr rtp_rtcp = - ModuleRtpRtcpImpl2::Create(configuration); + configuration.task_queue = TaskQueueBase::Current(); + auto rtp_rtcp = std::make_unique(configuration); rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); return rtp_rtcp; diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc index 52e4ddbc42..7346374041 100644 --- a/video/video_send_stream_tests.cc +++ b/video/video_send_stream_tests.cc @@ -1503,7 +1503,7 @@ TEST_F(VideoSendStreamTest, MinTransmitBitrateRespectsRemb) { config.clock = Clock::GetRealTimeClock(); config.outgoing_transport = feedback_transport_.get(); config.retransmission_rate_limiter = &retranmission_rate_limiter_; - rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(config); + rtp_rtcp_ = std::make_unique(config); rtp_rtcp_->SetRTCPStatus(RtcpMode::kReducedSize); }