diff options
Diffstat (limited to 'third_party/libwebrtc/call')
-rw-r--r-- | third_party/libwebrtc/call/BUILD.gn | 14 | ||||
-rw-r--r-- | third_party/libwebrtc/call/call.cc | 150 | ||||
-rw-r--r-- | third_party/libwebrtc/call/call.h | 6 | ||||
-rw-r--r-- | third_party/libwebrtc/call/call_config.cc | 26 | ||||
-rw-r--r-- | third_party/libwebrtc/call/call_config.h | 30 | ||||
-rw-r--r-- | third_party/libwebrtc/call/create_call.cc (renamed from third_party/libwebrtc/call/call_factory.cc) | 31 | ||||
-rw-r--r-- | third_party/libwebrtc/call/create_call.h (renamed from third_party/libwebrtc/call/call_factory.h) | 20 | ||||
-rw-r--r-- | third_party/libwebrtc/call/rtp_transport_config.h | 20 | ||||
-rw-r--r-- | third_party/libwebrtc/call/rtp_transport_controller_send.cc | 81 | ||||
-rw-r--r-- | third_party/libwebrtc/call/rtp_transport_controller_send.h | 10 | ||||
-rw-r--r-- | third_party/libwebrtc/call/rtp_transport_controller_send_factory.h | 6 | ||||
-rw-r--r-- | third_party/libwebrtc/call/rtp_transport_controller_send_factory_interface.h | 7 | ||||
-rw-r--r-- | third_party/libwebrtc/call/rtp_video_sender_unittest.cc | 26 | ||||
-rw-r--r-- | third_party/libwebrtc/call/version.cc | 2 |
14 files changed, 164 insertions, 265 deletions
diff --git a/third_party/libwebrtc/call/BUILD.gn b/third_party/libwebrtc/call/BUILD.gn index 626ed95066..50a8257631 100644 --- a/third_party/libwebrtc/call/BUILD.gn +++ b/third_party/libwebrtc/call/BUILD.gn @@ -46,10 +46,8 @@ rtc_library("call_interfaces") { ":rtp_interfaces", ":video_stream_api", "../api:fec_controller_api", - "../api:field_trials_view", "../api:frame_transformer_interface", "../api:network_state_predictor_api", - "../api:rtc_error", "../api:rtp_headers", "../api:rtp_parameters", "../api:rtp_sender_setparameters_callback", @@ -116,20 +114,20 @@ rtc_library("rtp_interfaces") { deps = [ "../api:array_view", "../api:fec_controller_api", - "../api:field_trials_view", "../api:frame_transformer_interface", "../api:network_state_predictor_api", "../api:rtp_headers", "../api:rtp_parameters", "../api/crypto:options", + "../api/environment", "../api/rtc_event_log", "../api/transport:bitrate_settings", "../api/transport:network_control", + "../api/units:time_delta", "../api/units:timestamp", "../common_video:frame_counts", "../modules/rtp_rtcp:rtp_rtcp_format", "../rtc_base:checks", - "../rtc_base:rtc_task_queue", "../rtc_base:stringutils", ] absl_deps = [ @@ -191,6 +189,7 @@ rtc_library("rtp_sender") { "../api:rtp_parameters", "../api:sequence_checker", "../api:transport_api", + "../api/environment", "../api/rtc_event_log", "../api/task_queue:pending_task_safety_flag", "../api/task_queue:task_queue", @@ -280,8 +279,8 @@ rtc_library("bitrate_allocator") { rtc_library("call") { sources = [ "call.cc", - "call_factory.cc", - "call_factory.h", + "create_call.cc", + "create_call.h", "degraded_call.cc", "degraded_call.h", "flexfec_receive_stream_impl.cc", @@ -301,7 +300,6 @@ rtc_library("call") { ":version", ":video_stream_api", "../api:array_view", - "../api:callfactory_api", "../api:fec_controller_api", "../api:field_trials_view", "../api:rtp_headers", @@ -355,7 +353,7 @@ rtc_library("call") { ] if (build_with_mozilla) { # See Bug 1820869. sources -= [ - "call_factory.cc", + "create_call.cc", "degraded_call.cc", ] deps -= [ diff --git a/third_party/libwebrtc/call/call.cc b/third_party/libwebrtc/call/call.cc index 63dc370f1a..71511b2559 100644 --- a/third_party/libwebrtc/call/call.cc +++ b/third_party/libwebrtc/call/call.cc @@ -70,7 +70,7 @@ #include "video/send_delay_stats.h" #include "video/stats_counter.h" #include "video/video_receive_stream2.h" -#include "video/video_send_stream.h" +#include "video/video_send_stream_impl.h" namespace webrtc { @@ -183,10 +183,8 @@ class Call final : public webrtc::Call, public TargetTransferRateObserver, public BitrateAllocator::LimitObserver { public: - Call(Clock* clock, - const CallConfig& config, - std::unique_ptr<RtpTransportControllerSendInterface> transport_send, - TaskQueueFactory* task_queue_factory); + Call(const CallConfig& config, + std::unique_ptr<RtpTransportControllerSendInterface> transport_send); ~Call() override; Call(const Call&) = delete; @@ -345,8 +343,7 @@ class Call final : public webrtc::Call, // callbacks have been registered. void EnsureStarted() RTC_RUN_ON(worker_thread_); - Clock* const clock_; - TaskQueueFactory* const task_queue_factory_; + const Environment env_; TaskQueueBase* const worker_thread_; TaskQueueBase* const network_thread_; const std::unique_ptr<DecodeSynchronizer> decode_sync_; @@ -356,8 +353,6 @@ class Call final : public webrtc::Call, const std::unique_ptr<CallStats> call_stats_; const std::unique_ptr<BitrateAllocator> bitrate_allocator_; const CallConfig config_ RTC_GUARDED_BY(worker_thread_); - // Maps to config_.trials, can be used from any thread via `trials()`. - const FieldTrialsView& trials_; NetworkState audio_network_state_ RTC_GUARDED_BY(worker_thread_); NetworkState video_network_state_ RTC_GUARDED_BY(worker_thread_); @@ -393,9 +388,10 @@ class Call final : public webrtc::Call, // should be accessed on the network thread. std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ RTC_GUARDED_BY(worker_thread_); - std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ + std::map<uint32_t, VideoSendStreamImpl*> video_send_ssrcs_ + RTC_GUARDED_BY(worker_thread_); + std::set<VideoSendStreamImpl*> video_send_streams_ RTC_GUARDED_BY(worker_thread_); - std::set<VideoSendStream*> video_send_streams_ RTC_GUARDED_BY(worker_thread_); // True if `video_send_streams_` is empty, false if not. The atomic variable // is used to decide UMA send statistics behavior and enables avoiding a // PostTask(). @@ -413,8 +409,6 @@ class Call final : public webrtc::Call, RtpPayloadStateMap suspended_video_payload_states_ RTC_GUARDED_BY(worker_thread_); - webrtc::RtcEventLog* const event_log_; - // TODO(bugs.webrtc.org/11993) ready to move stats access to the network // thread. ReceiveStats receive_stats_ RTC_GUARDED_BY(worker_thread_); @@ -460,25 +454,17 @@ class Call final : public webrtc::Call, }; } // namespace internal -/* Mozilla: Avoid this since it could use GetRealTimeClock(). std::unique_ptr<Call> Call::Create(const CallConfig& config) { - Clock* clock = - config.env.has_value() ? &config.env->clock() : Clock::GetRealTimeClock(); - return Create(config, clock, - RtpTransportControllerSendFactory().Create( - config.ExtractTransportConfig(), clock)); -} - */ + std::unique_ptr<RtpTransportControllerSendInterface> transport_send; + if (config.rtp_transport_controller_send_factory != nullptr) { + transport_send = config.rtp_transport_controller_send_factory->Create( + config.ExtractTransportConfig()); + } else { + transport_send = RtpTransportControllerSendFactory().Create( + config.ExtractTransportConfig()); + } -std::unique_ptr<Call> Call::Create( - const CallConfig& config, - Clock* clock, - std::unique_ptr<RtpTransportControllerSendInterface> - transportControllerSend) { - RTC_DCHECK(config.task_queue_factory); - return std::make_unique<internal::Call>(clock, config, - std::move(transportControllerSend), - config.task_queue_factory); + return std::make_unique<internal::Call>(config, std::move(transport_send)); } // This method here to avoid subclasses has to implement this method. @@ -644,47 +630,41 @@ void Call::SendStats::SetMinAllocatableRate(BitrateAllocationLimits limits) { min_allocated_send_bitrate_bps_ = limits.min_allocatable_rate.bps(); } -Call::Call(Clock* clock, - const CallConfig& config, - std::unique_ptr<RtpTransportControllerSendInterface> transport_send, - TaskQueueFactory* task_queue_factory) - : clock_(clock), - task_queue_factory_(task_queue_factory), +Call::Call(const CallConfig& config, + std::unique_ptr<RtpTransportControllerSendInterface> transport_send) + : env_(config.env), worker_thread_(GetCurrentTaskQueueOrThread()), // If `network_task_queue_` was set to nullptr, network related calls // must be made on `worker_thread_` (i.e. they're one and the same). network_thread_(config.network_task_queue_ ? config.network_task_queue_ : worker_thread_), - decode_sync_(config.metronome - ? std::make_unique<DecodeSynchronizer>(clock_, - config.metronome, - worker_thread_) - : nullptr), + decode_sync_( + config.decode_metronome + ? std::make_unique<DecodeSynchronizer>(&env_.clock(), + config.decode_metronome, + worker_thread_) + : nullptr), num_cpu_cores_(CpuInfo::DetectNumberOfCores()), - call_stats_(new CallStats(clock_, worker_thread_)), + call_stats_(new CallStats(&env_.clock(), worker_thread_)), bitrate_allocator_(new BitrateAllocator(this)), config_(config), - trials_(*config.trials), audio_network_state_(kNetworkDown), video_network_state_(kNetworkDown), aggregate_network_up_(false), - event_log_(config.event_log), - receive_stats_(clock_), - send_stats_(clock_), - receive_side_cc_(clock, + receive_stats_(&env_.clock()), + send_stats_(&env_.clock()), + receive_side_cc_(&env_.clock(), absl::bind_front(&PacketRouter::SendCombinedRtcpPacket, transport_send->packet_router()), absl::bind_front(&PacketRouter::SendRemb, transport_send->packet_router()), /*network_state_estimator=*/nullptr), receive_time_calculator_( - ReceiveTimeCalculator::CreateFromFieldTrial(*config.trials)), - video_send_delay_stats_(new SendDelayStats(clock_)), - start_of_call_(clock_->CurrentTime()), + ReceiveTimeCalculator::CreateFromFieldTrial(env_.field_trials())), + video_send_delay_stats_(new SendDelayStats(&env_.clock())), + start_of_call_(env_.clock().CurrentTime()), transport_send_ptr_(transport_send.get()), transport_send_(std::move(transport_send)) { - RTC_DCHECK(config.event_log != nullptr); - RTC_DCHECK(config.trials != nullptr); RTC_DCHECK(network_thread_); RTC_DCHECK(worker_thread_->IsCurrent()); @@ -702,7 +682,7 @@ Call::Call(Clock* clock, receive_side_cc_periodic_task_ = RepeatingTaskHandle::Start( worker_thread_, [receive_side_cc] { return receive_side_cc->MaybeProcess(); }, - TaskQueueBase::DelayPrecision::kLow, clock_); + TaskQueueBase::DelayPrecision::kLow, &env_.clock()); } Call::~Call() { @@ -720,7 +700,7 @@ Call::~Call() { RTC_HISTOGRAM_COUNTS_100000( "WebRTC.Call.LifetimeInSeconds", - (clock_->CurrentTime() - start_of_call_).seconds()); + (env_.clock().CurrentTime() - start_of_call_).seconds()); } void Call::EnsureStarted() { @@ -765,8 +745,8 @@ webrtc::AudioSendStream* Call::CreateAudioSendStream( } AudioSendStream* send_stream = new AudioSendStream( - clock_, config, config_.audio_state, task_queue_factory_, - transport_send_.get(), bitrate_allocator_.get(), event_log_, + &env_.clock(), config, config_.audio_state, &env_.task_queue_factory(), + transport_send_.get(), bitrate_allocator_.get(), &env_.event_log(), call_stats_->AsRtcpRttStats(), suspended_rtp_state, trials()); RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == audio_send_ssrcs_.end()); @@ -818,12 +798,12 @@ webrtc::AudioReceiveStreamInterface* Call::CreateAudioReceiveStream( TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); RTC_DCHECK_RUN_ON(worker_thread_); EnsureStarted(); - event_log_->Log(std::make_unique<RtcEventAudioReceiveStreamConfig>( + env_.event_log().Log(std::make_unique<RtcEventAudioReceiveStreamConfig>( CreateRtcLogStreamConfig(config))); AudioReceiveStreamImpl* receive_stream = new AudioReceiveStreamImpl( - clock_, transport_send_->packet_router(), config_.neteq_factory, config, - config_.audio_state, event_log_); + &env_.clock(), transport_send_->packet_router(), config_.neteq_factory, + config, config_.audio_state, &env_.event_log()); audio_receive_streams_.insert(receive_stream); // TODO(bugs.webrtc.org/11993): Make the registration on the network thread @@ -885,7 +865,7 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream( video_send_delay_stats_->AddSsrcs(config); for (size_t ssrc_index = 0; ssrc_index < config.rtp.ssrcs.size(); ++ssrc_index) { - event_log_->Log(std::make_unique<RtcEventVideoSendStreamConfig>( + env_.event_log().Log(std::make_unique<RtcEventVideoSendStreamConfig>( CreateRtcLogStreamConfig(config, ssrc_index))); } @@ -894,13 +874,14 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream( // Copy ssrcs from `config` since `config` is moved. std::vector<uint32_t> ssrcs = config.rtp.ssrcs; - VideoSendStream* send_stream = new VideoSendStream( - clock_, num_cpu_cores_, task_queue_factory_, network_thread_, + VideoSendStreamImpl* send_stream = new VideoSendStreamImpl( + &env_.clock(), num_cpu_cores_, &env_.task_queue_factory(), call_stats_->AsRtcpRttStats(), transport_send_.get(), - bitrate_allocator_.get(), video_send_delay_stats_.get(), event_log_, - std::move(config), std::move(encoder_config), suspended_video_send_ssrcs_, + config_.encode_metronome, bitrate_allocator_.get(), + video_send_delay_stats_.get(), &env_.event_log(), std::move(config), + std::move(encoder_config), suspended_video_send_ssrcs_, suspended_video_payload_states_, std::move(fec_controller), - *config_.trials); + env_.field_trials()); for (uint32_t ssrc : ssrcs) { RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); @@ -928,8 +909,8 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream( } std::unique_ptr<FecController> fec_controller = config_.fec_controller_factory - ? config_.fec_controller_factory->CreateFecController() - : std::make_unique<FecControllerDefault>(clock_); + ? config_.fec_controller_factory->CreateFecController(env_) + : std::make_unique<FecControllerDefault>(env_); return CreateVideoSendStream(std::move(config), std::move(encoder_config), std::move(fec_controller)); } @@ -939,12 +920,12 @@ void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { RTC_DCHECK(send_stream != nullptr); RTC_DCHECK_RUN_ON(worker_thread_); - VideoSendStream* send_stream_impl = - static_cast<VideoSendStream*>(send_stream); + VideoSendStreamImpl* send_stream_impl = + static_cast<VideoSendStreamImpl*>(send_stream); auto it = video_send_ssrcs_.begin(); while (it != video_send_ssrcs_.end()) { - if (it->second == static_cast<VideoSendStream*>(send_stream)) { + if (it->second == static_cast<VideoSendStreamImpl*>(send_stream)) { send_stream_impl = it->second; video_send_ssrcs_.erase(it++); } else { @@ -960,8 +941,8 @@ void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { if (video_send_streams_.empty()) video_send_streams_empty_.store(true, std::memory_order_relaxed); - VideoSendStream::RtpStateMap rtp_states; - VideoSendStream::RtpPayloadStateMap rtp_payload_states; + VideoSendStreamImpl::RtpStateMap rtp_states; + VideoSendStreamImpl::RtpPayloadStateMap rtp_payload_states; send_stream_impl->StopPermanentlyAndGetRtpStates(&rtp_states, &rtp_payload_states); for (const auto& kv : rtp_states) { @@ -984,7 +965,7 @@ webrtc::VideoReceiveStreamInterface* Call::CreateVideoReceiveStream( EnsureStarted(); - event_log_->Log(std::make_unique<RtcEventVideoReceiveStreamConfig>( + env_.event_log().Log(std::make_unique<RtcEventVideoReceiveStreamConfig>( CreateRtcLogStreamConfig(configuration))); // TODO(bugs.webrtc.org/11993): Move the registration between `receive_stream` @@ -994,10 +975,10 @@ webrtc::VideoReceiveStreamInterface* Call::CreateVideoReceiveStream( // TODO(crbug.com/1381982): Re-enable decode synchronizer once the Chromium // API has adapted to the new Metronome interface. VideoReceiveStream2* receive_stream = new VideoReceiveStream2( - task_queue_factory_, this, num_cpu_cores_, - transport_send_->packet_router(), std::move(configuration), - call_stats_.get(), clock_, std::make_unique<VCMTiming>(clock_, trials()), - &nack_periodic_processor_, decode_sync_.get(), event_log_); + env_, this, num_cpu_cores_, transport_send_->packet_router(), + std::move(configuration), call_stats_.get(), + std::make_unique<VCMTiming>(&env_.clock(), trials()), + &nack_periodic_processor_, decode_sync_.get()); // TODO(bugs.webrtc.org/11993): Set this up asynchronously on the network // thread. receive_stream->RegisterWithTransport(&video_receiver_controller_); @@ -1040,7 +1021,7 @@ FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( // OnRtpPacket until the constructor is finished and the object is // in a valid state, since OnRtpPacket runs on the same thread. FlexfecReceiveStreamImpl* receive_stream = new FlexfecReceiveStreamImpl( - clock_, std::move(config), &video_receiver_controller_, + &env_.clock(), std::move(config), &video_receiver_controller_, call_stats_->AsRtcpRttStats()); // TODO(bugs.webrtc.org/11993): Set this up asynchronously on the network @@ -1104,7 +1085,7 @@ Call::Stats Call::GetStats() const { } const FieldTrialsView& Call::trials() const { - return trials_; + return env_.field_trials(); } TaskQueueBase* Call::network_thread() const { @@ -1244,7 +1225,7 @@ void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { // on a ProcessThread. This is alright as is since we forward the call to // implementations that either just do a PostTask or use locking. video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, - clock_->CurrentTime()); + env_.clock().CurrentTime()); transport_send_->OnSentPacket(sent_packet); } @@ -1341,7 +1322,7 @@ void Call::DeliverRtcpPacket(rtc::CopyOnWriteBuffer packet) { rtcp_delivered = true; } - for (VideoSendStream* stream : video_send_streams_) { + for (VideoSendStreamImpl* stream : video_send_streams_) { stream->DeliverRtcp(packet.cdata(), packet.size()); rtcp_delivered = true; } @@ -1352,7 +1333,7 @@ void Call::DeliverRtcpPacket(rtc::CopyOnWriteBuffer packet) { } if (rtcp_delivered) { - event_log_->Log(std::make_unique<RtcEventRtcpPacketIncoming>(packet)); + env_.event_log().Log(std::make_unique<RtcEventRtcpPacketIncoming>(packet)); } } @@ -1368,13 +1349,14 @@ void Call::DeliverRtpPacket( // Repair packet_time_us for clock resets by comparing a new read of // the same clock (TimeUTCMicros) to a monotonic clock reading. packet_time_us = receive_time_calculator_->ReconcileReceiveTimes( - packet_time_us, rtc::TimeUTCMicros(), clock_->TimeInMicroseconds()); + packet_time_us, rtc::TimeUTCMicros(), + env_.clock().TimeInMicroseconds()); packet.set_arrival_time(Timestamp::Micros(packet_time_us)); } NotifyBweOfReceivedPacket(packet, media_type); - event_log_->Log(std::make_unique<RtcEventRtpPacketIncoming>(packet)); + env_.event_log().Log(std::make_unique<RtcEventRtpPacketIncoming>(packet)); if (media_type != MediaType::AUDIO && media_type != MediaType::VIDEO) { return; } diff --git a/third_party/libwebrtc/call/call.h b/third_party/libwebrtc/call/call.h index b36872f5b5..e7d37c0abd 100644 --- a/third_party/libwebrtc/call/call.h +++ b/third_party/libwebrtc/call/call.h @@ -25,7 +25,6 @@ #include "call/call_config.h" #include "call/flexfec_receive_stream.h" #include "call/packet_receiver.h" -#include "call/rtp_transport_controller_send_interface.h" #include "call/video_receive_stream.h" #include "call/video_send_stream.h" #include "rtc_base/copy_on_write_buffer.h" @@ -49,11 +48,6 @@ class Call { using Stats = CallBasicStats; static std::unique_ptr<Call> Create(const CallConfig& config); - static std::unique_ptr<Call> Create( - const CallConfig& config, - Clock* clock, - std::unique_ptr<RtpTransportControllerSendInterface> - transportControllerSend); virtual AudioSendStream* CreateAudioSendStream( const AudioSendStream::Config& config) = 0; diff --git a/third_party/libwebrtc/call/call_config.cc b/third_party/libwebrtc/call/call_config.cc index 5832969b9c..0a6ad2c2ec 100644 --- a/third_party/libwebrtc/call/call_config.cc +++ b/third_party/libwebrtc/call/call_config.cc @@ -10,37 +10,27 @@ #include "call/call_config.h" -#include "rtc_base/checks.h" +#include "api/environment/environment.h" +#include "api/task_queue/task_queue_base.h" namespace webrtc { CallConfig::CallConfig(const Environment& env, TaskQueueBase* network_task_queue) : env(env), - event_log(&env.event_log()), - task_queue_factory(&env.task_queue_factory()), - trials(&env.field_trials()), network_task_queue_(network_task_queue) {} -CallConfig::CallConfig(RtcEventLog* event_log, - TaskQueueBase* network_task_queue /* = nullptr*/) - : event_log(event_log), network_task_queue_(network_task_queue) { - RTC_DCHECK(event_log); -} - CallConfig::CallConfig(const CallConfig& config) = default; RtpTransportConfig CallConfig::ExtractTransportConfig() const { - RtpTransportConfig transportConfig; - transportConfig.bitrate_config = bitrate_config; - transportConfig.event_log = event_log; - transportConfig.network_controller_factory = network_controller_factory; - transportConfig.network_state_predictor_factory = + RtpTransportConfig transport_config = {.env = env}; + transport_config.bitrate_config = bitrate_config; + transport_config.network_controller_factory = network_controller_factory; + transport_config.network_state_predictor_factory = network_state_predictor_factory; - transportConfig.task_queue_factory = task_queue_factory; - transportConfig.trials = trials; + transport_config.pacer_burst_interval = pacer_burst_interval; - return transportConfig; + return transport_config; } CallConfig::~CallConfig() = default; diff --git a/third_party/libwebrtc/call/call_config.h b/third_party/libwebrtc/call/call_config.h index 1b1f696fee..6fd9179a43 100644 --- a/third_party/libwebrtc/call/call_config.h +++ b/third_party/libwebrtc/call/call_config.h @@ -10,15 +10,11 @@ #ifndef CALL_CALL_CONFIG_H_ #define CALL_CALL_CONFIG_H_ -#include "absl/types/optional.h" #include "api/environment/environment.h" #include "api/fec_controller.h" -#include "api/field_trials_view.h" #include "api/metronome/metronome.h" #include "api/neteq/neteq_factory.h" #include "api/network_state_predictor.h" -#include "api/rtc_error.h" -#include "api/task_queue/task_queue_factory.h" #include "api/transport/bitrate_settings.h" #include "api/transport/network_control.h" #include "call/audio_state.h" @@ -28,7 +24,6 @@ namespace webrtc { class AudioProcessing; -class RtcEventLog; struct CallConfig { // If `network_task_queue` is set to nullptr, Call will assume that network @@ -37,19 +32,13 @@ struct CallConfig { explicit CallConfig(const Environment& env, TaskQueueBase* network_task_queue = nullptr); - // TODO(bugs.webrtc.org/15656): Deprecate and delete constructor below. - explicit CallConfig(RtcEventLog* event_log, - TaskQueueBase* network_task_queue = nullptr); - CallConfig(const CallConfig&); ~CallConfig(); RtpTransportConfig ExtractTransportConfig() const; - // TODO(bugs.webrtc.org/15656): Make non-optional when constructor that - // doesn't pass Environment is removed. - absl::optional<Environment> env; + Environment env; // Bitrate config used until valid bitrate estimates are calculated. Also // used to cap total bitrate used. This comes from the remote connection. @@ -61,16 +50,9 @@ struct CallConfig { // Audio Processing Module to be used in this call. AudioProcessing* audio_processing = nullptr; - // RtcEventLog to use for this call. Required. - // Use webrtc::RtcEventLog::CreateNull() for a null implementation. - RtcEventLog* const event_log = nullptr; - // FecController to use for this call. FecControllerFactoryInterface* fec_controller_factory = nullptr; - // Task Queue Factory to be used in this call. Required. - TaskQueueFactory* task_queue_factory = nullptr; - // NetworkStatePredictor to use for this call. NetworkStatePredictorFactoryInterface* network_state_predictor_factory = nullptr; @@ -81,16 +63,16 @@ struct CallConfig { // NetEq factory to use for this call. NetEqFactory* neteq_factory = nullptr; - // Key-value mapping of internal configurations to apply, - // e.g. field trials. - const FieldTrialsView* trials = nullptr; - TaskQueueBase* const network_task_queue_ = nullptr; // RtpTransportControllerSend to use for this call. RtpTransportControllerSendFactoryInterface* rtp_transport_controller_send_factory = nullptr; - Metronome* metronome = nullptr; + Metronome* decode_metronome = nullptr; + Metronome* encode_metronome = nullptr; + + // The burst interval of the pacer, see TaskQueuePacedSender constructor. + absl::optional<TimeDelta> pacer_burst_interval; // Enables send packet batching from the egress RTP sender. bool enable_send_packet_batching = false; diff --git a/third_party/libwebrtc/call/call_factory.cc b/third_party/libwebrtc/call/create_call.cc index 78a4f1635f..8b565745a8 100644 --- a/third_party/libwebrtc/call/call_factory.cc +++ b/third_party/libwebrtc/call/create_call.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "call/call_factory.h" +#include "call/create_call.h" #include <stdio.h> @@ -22,7 +22,6 @@ #include "api/units/time_delta.h" #include "call/call.h" #include "call/degraded_call.h" -#include "call/rtp_transport_config.h" #include "rtc_base/checks.h" #include "rtc_base/experiments/field_trial_list.h" #include "rtc_base/experiments/field_trial_parser.h" @@ -78,29 +77,14 @@ std::vector<TimeScopedNetworkConfig> GetNetworkConfigs( } // namespace -CallFactory::CallFactory() { - call_thread_.Detach(); -} - -std::unique_ptr<Call> CallFactory::CreateCall(const CallConfig& config) { - RTC_DCHECK_RUN_ON(&call_thread_); - RTC_DCHECK(config.trials); - +std::unique_ptr<Call> CreateCall(const CallConfig& config) { std::vector<DegradedCall::TimeScopedNetworkConfig> send_degradation_configs = - GetNetworkConfigs(*config.trials, /*send=*/true); + GetNetworkConfigs(config.env.field_trials(), /*send=*/true); std::vector<DegradedCall::TimeScopedNetworkConfig> receive_degradation_configs = - GetNetworkConfigs(*config.trials, /*send=*/false); + GetNetworkConfigs(config.env.field_trials(), /*send=*/false); - RtpTransportConfig transportConfig = config.ExtractTransportConfig(); - - RTC_CHECK(false); - return nullptr; - /* Mozilla: Avoid this since it could use GetRealTimeClock(). - std::unique_ptr<Call> call = - Call::Create(config, Clock::GetRealTimeClock(), - config.rtp_transport_controller_send_factory->Create( - transportConfig, Clock::GetRealTimeClock())); + std::unique_ptr<Call> call = Call::Create(config); if (!send_degradation_configs.empty() || !receive_degradation_configs.empty()) { @@ -109,11 +93,6 @@ std::unique_ptr<Call> CallFactory::CreateCall(const CallConfig& config) { } return call; - */ -} - -std::unique_ptr<CallFactoryInterface> CreateCallFactory() { - return std::make_unique<CallFactory>(); } } // namespace webrtc diff --git a/third_party/libwebrtc/call/call_factory.h b/third_party/libwebrtc/call/create_call.h index f75b1bd71b..afba08800e 100644 --- a/third_party/libwebrtc/call/call_factory.h +++ b/third_party/libwebrtc/call/create_call.h @@ -8,30 +8,18 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef CALL_CALL_FACTORY_H_ -#define CALL_CALL_FACTORY_H_ +#ifndef CALL_CREATE_CALL_H_ +#define CALL_CREATE_CALL_H_ #include <memory> -#include "api/call/call_factory_interface.h" -#include "api/sequence_checker.h" #include "call/call.h" #include "call/call_config.h" -#include "rtc_base/system/no_unique_address.h" namespace webrtc { -class CallFactory : public CallFactoryInterface { - public: - CallFactory(); - ~CallFactory() override = default; - - private: - std::unique_ptr<Call> CreateCall(const CallConfig& config) override; - - RTC_NO_UNIQUE_ADDRESS SequenceChecker call_thread_; -}; +std::unique_ptr<Call> CreateCall(const CallConfig& config); } // namespace webrtc -#endif // CALL_CALL_FACTORY_H_ +#endif // CALL_CREATE_CALL_H_ diff --git a/third_party/libwebrtc/call/rtp_transport_config.h b/third_party/libwebrtc/call/rtp_transport_config.h index f2030b3672..cce5214fc8 100644 --- a/third_party/libwebrtc/call/rtp_transport_config.h +++ b/third_party/libwebrtc/call/rtp_transport_config.h @@ -13,27 +13,22 @@ #include <memory> -#include "api/field_trials_view.h" +#include "absl/types/optional.h" +#include "api/environment/environment.h" #include "api/network_state_predictor.h" -#include "api/rtc_event_log/rtc_event_log.h" #include "api/transport/bitrate_settings.h" #include "api/transport/network_control.h" -#include "rtc_base/task_queue.h" +#include "api/units/time_delta.h" namespace webrtc { struct RtpTransportConfig { + Environment env; + // Bitrate config used until valid bitrate estimates are calculated. Also // used to cap total bitrate used. This comes from the remote connection. BitrateConstraints bitrate_config; - // RtcEventLog to use for this call. Required. - // Use webrtc::RtcEventLog::CreateNull() for a null implementation. - RtcEventLog* event_log = nullptr; - - // Task Queue Factory to be used in this call. Required. - TaskQueueFactory* task_queue_factory = nullptr; - // NetworkStatePredictor to use for this call. NetworkStatePredictorFactoryInterface* network_state_predictor_factory = nullptr; @@ -41,9 +36,8 @@ struct RtpTransportConfig { // Network controller factory to use for this call. NetworkControllerFactoryInterface* network_controller_factory = nullptr; - // Key-value mapping of internal configurations to apply, - // e.g. field trials. - const FieldTrialsView* trials = nullptr; + // The burst interval of the pacer, see TaskQueuePacedSender constructor. + absl::optional<TimeDelta> pacer_burst_interval; }; } // namespace webrtc diff --git a/third_party/libwebrtc/call/rtp_transport_controller_send.cc b/third_party/libwebrtc/call/rtp_transport_controller_send.cc index 8d24f7551e..600d4e2620 100644 --- a/third_party/libwebrtc/call/rtp_transport_controller_send.cc +++ b/third_party/libwebrtc/call/rtp_transport_controller_send.cc @@ -62,55 +62,56 @@ TargetRateConstraints ConvertConstraints(const BitrateConstraints& contraints, contraints.start_bitrate_bps, clock); } -bool IsEnabled(const FieldTrialsView& trials, absl::string_view key) { - return absl::StartsWith(trials.Lookup(key), "Enabled"); -} - bool IsRelayed(const rtc::NetworkRoute& route) { return route.local.uses_turn() || route.remote.uses_turn(); } } // namespace RtpTransportControllerSend::RtpTransportControllerSend( - Clock* clock, const RtpTransportConfig& config) - : clock_(clock), - event_log_(config.event_log), - task_queue_factory_(config.task_queue_factory), + : env_(config.env), task_queue_(TaskQueueBase::Current()), bitrate_configurator_(config.bitrate_config), pacer_started_(false), - pacer_(clock, &packet_router_, *config.trials, TimeDelta::Millis(5), 3), + pacer_(&env_.clock(), + &packet_router_, + env_.field_trials(), + TimeDelta::Millis(5), + 3), observer_(nullptr), controller_factory_override_(config.network_controller_factory), controller_factory_fallback_( std::make_unique<GoogCcNetworkControllerFactory>( config.network_state_predictor_factory)), process_interval_(controller_factory_fallback_->GetProcessInterval()), - last_report_block_time_(Timestamp::Millis(clock_->TimeInMilliseconds())), + last_report_block_time_( + Timestamp::Millis(env_.clock().TimeInMilliseconds())), reset_feedback_on_route_change_( - !IsEnabled(*config.trials, "WebRTC-Bwe-NoFeedbackReset")), - add_pacing_to_cwin_( - IsEnabled(*config.trials, - "WebRTC-AddPacingToCongestionWindowPushback")), + !env_.field_trials().IsEnabled("WebRTC-Bwe-NoFeedbackReset")), + add_pacing_to_cwin_(env_.field_trials().IsEnabled( + "WebRTC-AddPacingToCongestionWindowPushback")), relay_bandwidth_cap_("relay_cap", DataRate::PlusInfinity()), transport_overhead_bytes_per_packet_(0), network_available_(false), congestion_window_size_(DataSize::PlusInfinity()), is_congested_(false), - retransmission_rate_limiter_(clock, kRetransmitWindowSizeMs), - field_trials_(*config.trials) { - ParseFieldTrial({&relay_bandwidth_cap_}, - config.trials->Lookup("WebRTC-Bwe-NetworkRouteConstraints")); + retransmission_rate_limiter_(&env_.clock(), kRetransmitWindowSizeMs) { + ParseFieldTrial( + {&relay_bandwidth_cap_}, + env_.field_trials().Lookup("WebRTC-Bwe-NetworkRouteConstraints")); initial_config_.constraints = - ConvertConstraints(config.bitrate_config, clock_); - initial_config_.event_log = config.event_log; - initial_config_.key_value_config = config.trials; + ConvertConstraints(config.bitrate_config, &env_.clock()); + initial_config_.event_log = &env_.event_log(); + initial_config_.key_value_config = &env_.field_trials(); RTC_DCHECK(config.bitrate_config.start_bitrate_bps > 0); pacer_.SetPacingRates( DataRate::BitsPerSec(config.bitrate_config.start_bitrate_bps), DataRate::Zero()); + if (config.pacer_burst_interval) { + // Default burst interval overriden by config. + pacer_.SetSendBurstInterval(*config.pacer_burst_interval); + } } RtpTransportControllerSend::~RtpTransportControllerSend() { @@ -133,14 +134,14 @@ RtpVideoSenderInterface* RtpTransportControllerSend::CreateRtpVideoSender( rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) { RTC_DCHECK_RUN_ON(&sequence_checker_); video_rtp_senders_.push_back(std::make_unique<RtpVideoSender>( - clock_, suspended_ssrcs, states, rtp_config, rtcp_report_interval_ms, - send_transport, observers, + &env_.clock(), suspended_ssrcs, states, rtp_config, + rtcp_report_interval_ms, send_transport, observers, // TODO(holmer): Remove this circular dependency by injecting // the parts of RtpTransportControllerSendInterface that are really used. this, event_log, &retransmission_rate_limiter_, std::move(fec_controller), frame_encryption_config.frame_encryptor, frame_encryption_config.crypto_options, std::move(frame_transformer), - field_trials_, task_queue_factory_)); + env_.field_trials(), &env_.task_queue_factory())); return video_rtp_senders_.back().get(); } @@ -302,13 +303,11 @@ void RtpTransportControllerSend::OnNetworkRouteChanged( << " bps."; RTC_DCHECK_GT(bitrate_config.start_bitrate_bps, 0); - if (event_log_) { - event_log_->Log(std::make_unique<RtcEventRouteChange>( - network_route.connected, network_route.packet_overhead)); - } + env_.event_log().Log(std::make_unique<RtcEventRouteChange>( + network_route.connected, network_route.packet_overhead)); NetworkRouteChange msg; - msg.at_time = Timestamp::Millis(clock_->TimeInMilliseconds()); - msg.constraints = ConvertConstraints(bitrate_config, clock_); + msg.at_time = Timestamp::Millis(env_.clock().TimeInMilliseconds()); + msg.constraints = ConvertConstraints(bitrate_config, &env_.clock()); transport_overhead_bytes_per_packet_ = network_route.packet_overhead; if (reset_feedback_on_route_change_) { transport_feedback_adapter_.SetNetworkRoute(network_route); @@ -327,7 +326,7 @@ void RtpTransportControllerSend::OnNetworkAvailability(bool network_available) { RTC_LOG(LS_VERBOSE) << "SignalNetworkState " << (network_available ? "Up" : "Down"); NetworkAvailability msg; - msg.at_time = Timestamp::Millis(clock_->TimeInMilliseconds()); + msg.at_time = Timestamp::Millis(env_.clock().TimeInMilliseconds()); msg.network_available = network_available; network_available_ = network_available; if (network_available) { @@ -425,7 +424,7 @@ void RtpTransportControllerSend::OnReceivedPacket( void RtpTransportControllerSend::UpdateBitrateConstraints( const BitrateConstraints& updated) { RTC_DCHECK_RUN_ON(&sequence_checker_); - TargetRateConstraints msg = ConvertConstraints(updated, clock_); + TargetRateConstraints msg = ConvertConstraints(updated, &env_.clock()); if (controller_) { PostUpdates(controller_->OnTargetRateConstraints(msg)); } else { @@ -528,7 +527,8 @@ void RtpTransportControllerSend::OnRttUpdate(Timestamp receive_time, void RtpTransportControllerSend::OnAddPacket( const RtpPacketSendInfo& packet_info) { RTC_DCHECK_RUN_ON(&sequence_checker_); - Timestamp creation_time = Timestamp::Millis(clock_->TimeInMilliseconds()); + Timestamp creation_time = + Timestamp::Millis(env_.clock().TimeInMilliseconds()); feedback_demuxer_.AddPacket(packet_info); transport_feedback_adapter_.AddPacket( packet_info, transport_overhead_bytes_per_packet_, creation_time); @@ -554,11 +554,9 @@ void RtpTransportControllerSend::OnTransportFeedback( void RtpTransportControllerSend::OnRemoteNetworkEstimate( NetworkStateEstimate estimate) { RTC_DCHECK_RUN_ON(&sequence_checker_); - if (event_log_) { - event_log_->Log(std::make_unique<RtcEventRemoteEstimate>( - estimate.link_capacity_lower, estimate.link_capacity_upper)); - } - estimate.update_time = Timestamp::Millis(clock_->TimeInMilliseconds()); + env_.event_log().Log(std::make_unique<RtcEventRemoteEstimate>( + estimate.link_capacity_lower, estimate.link_capacity_upper)); + estimate.update_time = Timestamp::Millis(env_.clock().TimeInMilliseconds()); if (controller_) PostUpdates(controller_->OnNetworkStateEstimate(estimate)); } @@ -572,7 +570,7 @@ void RtpTransportControllerSend::MaybeCreateControllers() { control_handler_ = std::make_unique<CongestionControlHandler>(); initial_config_.constraints.at_time = - Timestamp::Millis(clock_->TimeInMilliseconds()); + Timestamp::Millis(env_.clock().TimeInMilliseconds()); initial_config_.stream_based_config = streams_config_; // TODO(srte): Use fallback controller if no feedback is available. @@ -623,14 +621,15 @@ void RtpTransportControllerSend::StartProcessPeriodicTasks() { void RtpTransportControllerSend::UpdateControllerWithTimeInterval() { RTC_DCHECK(controller_); ProcessInterval msg; - msg.at_time = Timestamp::Millis(clock_->TimeInMilliseconds()); + msg.at_time = Timestamp::Millis(env_.clock().TimeInMilliseconds()); if (add_pacing_to_cwin_) msg.pacer_queue = pacer_.QueueSizeData(); PostUpdates(controller_->OnProcessInterval(msg)); } void RtpTransportControllerSend::UpdateStreamsConfig() { - streams_config_.at_time = Timestamp::Millis(clock_->TimeInMilliseconds()); + streams_config_.at_time = + Timestamp::Millis(env_.clock().TimeInMilliseconds()); if (controller_) PostUpdates(controller_->OnStreamsConfig(streams_config_)); } diff --git a/third_party/libwebrtc/call/rtp_transport_controller_send.h b/third_party/libwebrtc/call/rtp_transport_controller_send.h index 1aace1ce65..c0bca41a2b 100644 --- a/third_party/libwebrtc/call/rtp_transport_controller_send.h +++ b/third_party/libwebrtc/call/rtp_transport_controller_send.h @@ -18,6 +18,7 @@ #include <vector> #include "absl/strings/string_view.h" +#include "api/environment/environment.h" #include "api/network_state_predictor.h" #include "api/sequence_checker.h" #include "api/task_queue/task_queue_base.h" @@ -41,7 +42,6 @@ #include "rtc_base/task_utils/repeating_task.h" namespace webrtc { -class Clock; class FrameEncryptorInterface; class RtcEventLog; @@ -51,7 +51,7 @@ class RtpTransportControllerSend final public TransportFeedbackObserver, public NetworkStateEstimateObserver { public: - RtpTransportControllerSend(Clock* clock, const RtpTransportConfig& config); + explicit RtpTransportControllerSend(const RtpTransportConfig& config); ~RtpTransportControllerSend() override; RtpTransportControllerSend(const RtpTransportControllerSend&) = delete; @@ -146,9 +146,7 @@ class RtpTransportControllerSend final void ProcessSentPacketUpdates(NetworkControlUpdate updates) RTC_RUN_ON(sequence_checker_); - Clock* const clock_; - RtcEventLog* const event_log_; - TaskQueueFactory* const task_queue_factory_; + const Environment env_; SequenceChecker sequence_checker_; TaskQueueBase* task_queue_; PacketRouter packet_router_; @@ -207,8 +205,6 @@ class RtpTransportControllerSend final RateLimiter retransmission_rate_limiter_; ScopedTaskSafety safety_; - - const FieldTrialsView& field_trials_; }; } // namespace webrtc diff --git a/third_party/libwebrtc/call/rtp_transport_controller_send_factory.h b/third_party/libwebrtc/call/rtp_transport_controller_send_factory.h index 6349302e45..cd5a3c58ae 100644 --- a/third_party/libwebrtc/call/rtp_transport_controller_send_factory.h +++ b/third_party/libwebrtc/call/rtp_transport_controller_send_factory.h @@ -22,10 +22,8 @@ class RtpTransportControllerSendFactory : public RtpTransportControllerSendFactoryInterface { public: std::unique_ptr<RtpTransportControllerSendInterface> Create( - const RtpTransportConfig& config, - Clock* clock) override { - RTC_CHECK(config.trials); - return std::make_unique<RtpTransportControllerSend>(clock, config); + const RtpTransportConfig& config) override { + return std::make_unique<RtpTransportControllerSend>(config); } virtual ~RtpTransportControllerSendFactory() {} diff --git a/third_party/libwebrtc/call/rtp_transport_controller_send_factory_interface.h b/third_party/libwebrtc/call/rtp_transport_controller_send_factory_interface.h index 0f4c36c221..8683a34c9e 100644 --- a/third_party/libwebrtc/call/rtp_transport_controller_send_factory_interface.h +++ b/third_party/libwebrtc/call/rtp_transport_controller_send_factory_interface.h @@ -20,11 +20,10 @@ namespace webrtc { // controller. class RtpTransportControllerSendFactoryInterface { public: - virtual std::unique_ptr<RtpTransportControllerSendInterface> Create( - const RtpTransportConfig& config, - Clock* clock) = 0; + virtual ~RtpTransportControllerSendFactoryInterface() = default; - virtual ~RtpTransportControllerSendFactoryInterface() {} + virtual std::unique_ptr<RtpTransportControllerSendInterface> Create( + const RtpTransportConfig& config) = 0; }; } // namespace webrtc #endif // CALL_RTP_TRANSPORT_CONTROLLER_SEND_FACTORY_INTERFACE_H_ diff --git a/third_party/libwebrtc/call/rtp_video_sender_unittest.cc b/third_party/libwebrtc/call/rtp_video_sender_unittest.cc index 9646a81cfd..cf099afaa3 100644 --- a/third_party/libwebrtc/call/rtp_video_sender_unittest.cc +++ b/third_party/libwebrtc/call/rtp_video_sender_unittest.cc @@ -16,6 +16,8 @@ #include <utility> #include "absl/functional/any_invocable.h" +#include "api/environment/environment.h" +#include "api/environment/environment_factory.h" #include "call/rtp_transport_controller_send.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/byte_io.h" @@ -118,23 +120,21 @@ class RtpVideoSenderTestFixture { rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, const FieldTrialsView* field_trials = nullptr) : time_controller_(Timestamp::Millis(1000000)), + env_(CreateEnvironment(&field_trials_, + field_trials, + time_controller_.GetClock(), + time_controller_.CreateTaskQueueFactory())), config_(CreateVideoSendStreamConfig(&transport_, ssrcs, rtx_ssrcs, payload_type)), bitrate_config_(GetBitrateConfig()), transport_controller_( - time_controller_.GetClock(), - RtpTransportConfig{ - .bitrate_config = bitrate_config_, - .event_log = &event_log_, - .task_queue_factory = time_controller_.GetTaskQueueFactory(), - .trials = field_trials ? field_trials : &field_trials_, - }), + RtpTransportConfig{.env = env_, .bitrate_config = bitrate_config_}), stats_proxy_(time_controller_.GetClock(), config_, VideoEncoderConfig::ContentType::kRealtimeVideo, - field_trials ? *field_trials : field_trials_), + env_.field_trials()), retransmission_rate_limiter_(time_controller_.GetClock(), kRetransmitWindowSizeMs) { transport_controller_.EnsureStarted(); @@ -144,10 +144,10 @@ class RtpVideoSenderTestFixture { config_.rtp, config_.rtcp_report_interval_ms, &transport_, CreateObservers(&encoder_feedback_, &stats_proxy_, &stats_proxy_, &stats_proxy_, frame_count_observer, &stats_proxy_), - &transport_controller_, &event_log_, &retransmission_rate_limiter_, - std::make_unique<FecControllerDefault>(time_controller_.GetClock()), - nullptr, CryptoOptions{}, frame_transformer, - field_trials ? *field_trials : field_trials_, + &transport_controller_, &env_.event_log(), + &retransmission_rate_limiter_, + std::make_unique<FecControllerDefault>(env_), nullptr, CryptoOptions{}, + frame_transformer, env_.field_trials(), time_controller_.GetTaskQueueFactory()); } @@ -197,7 +197,7 @@ class RtpVideoSenderTestFixture { NiceMock<MockTransport> transport_; NiceMock<MockRtcpIntraFrameObserver> encoder_feedback_; GlobalSimulatedTimeController time_controller_; - RtcEventLogNull event_log_; + Environment env_; VideoSendStream::Config config_; BitrateConstraints bitrate_config_; RtpTransportControllerSend transport_controller_; diff --git a/third_party/libwebrtc/call/version.cc b/third_party/libwebrtc/call/version.cc index 5770253625..85fdf004ea 100644 --- a/third_party/libwebrtc/call/version.cc +++ b/third_party/libwebrtc/call/version.cc @@ -13,7 +13,7 @@ namespace webrtc { // The timestamp is always in UTC. -const char* const kSourceTimestamp = "WebRTC source stamp 2023-12-03T04:02:06"; +const char* const kSourceTimestamp = "WebRTC source stamp 2024-01-21T04:12:31"; void LoadWebRTCVersionInRegister() { // Using volatile to instruct the compiler to not optimize `p` away even |