diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /third_party/libwebrtc/call/call.cc | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/call/call.cc')
-rw-r--r-- | third_party/libwebrtc/call/call.cc | 150 |
1 files changed, 66 insertions, 84 deletions
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; } |