Move RtpVideoSender's worker-only state off mutex_ transport_overhead_bytes_per_packet_ and loss_mask_vector_ were guarded by mutex_, and the bitrate members weren't annotated, even though all of them are only accessed on the transport queue. Guard them with transport_checker_ instead, and DCHECK that the methods called on the transport queue run there. OnPacketFeedbackVector() no longer takes mutex_. OnBitrateUpdated() still does, for fec_allowed_, which is set on the encoder queue. Bug: webrtc:42223727 Change-Id: Id24ed32d25e960fe1bcdadd0fe2f47278884d760 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/506162 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#48784}
diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc index 66c03cd..6797ed2 100644 --- a/call/rtp_video_sender.cc +++ b/call/rtp_video_sender.cc
@@ -790,6 +790,7 @@ } void RtpVideoSender::OnNetworkAvailability(bool network_available) { + RTC_DCHECK_RUN_ON(&transport_checker_); for (const RtpStreamSender& stream : rtp_streams_) { stream.rtp_rtcp->SetRTCPStatus(network_available ? rtp_config_.rtcp_mode : RtcpMode::kOff); @@ -797,6 +798,7 @@ } std::map<uint32_t, RtpState> RtpVideoSender::GetRtpStates() const { + RTC_DCHECK_RUN_ON(&transport_checker_); std::map<uint32_t, RtpState> rtp_states; for (size_t i = 0; i < rtp_config_.ssrcs.size(); ++i) { @@ -826,6 +828,7 @@ std::map<uint32_t, RtpPayloadState> RtpVideoSender::GetRtpPayloadStates() const { + RTC_DCHECK_RUN_ON(&transport_checker_); MutexLock lock(&mutex_); std::map<uint32_t, RtpPayloadState> payload_states; for (const auto& param : params_) { @@ -837,6 +840,7 @@ void RtpVideoSender::OnBitrateUpdated(BitrateAllocationUpdate update, int framerate) { + RTC_DCHECK_RUN_ON(&transport_checker_); // Substract overhead from bitrate. MutexLock lock(&mutex_); if (transport_overhead_bytes_per_packet_ != @@ -924,10 +928,12 @@ } uint32_t RtpVideoSender::GetPayloadBitrateBps() const { + RTC_DCHECK_RUN_ON(&transport_checker_); return encoder_target_rate_bps_; } uint32_t RtpVideoSender::GetProtectionBitrateBps() const { + RTC_DCHECK_RUN_ON(&transport_checker_); return protection_bitrate_bps_; } @@ -977,8 +983,8 @@ void RtpVideoSender::OnPacketFeedbackVector( std::vector<StreamPacketInfo> packet_feedback_vector) { + RTC_DCHECK_RUN_ON(&transport_checker_); if (fec_controller_->UseLossVectorMask()) { - MutexLock lock(&mutex_); for (const StreamPacketInfo& packet : packet_feedback_vector) { loss_mask_vector_.push_back(!packet.received); } @@ -1036,11 +1042,13 @@ void RtpVideoSender::SetEncodingData(size_t width, size_t height, size_t num_temporal_layers) { + RTC_DCHECK_RUN_ON(&transport_checker_); fec_controller_->SetEncodingData(width, height, num_temporal_layers, rtp_config_.max_packet_size); } void RtpVideoSender::SetCsrcs(std::span<const uint32_t> csrcs) { + RTC_DCHECK_RUN_ON(&transport_checker_); MutexLock lock(&mutex_); csrcs_ = LimitCsrcs(csrcs); }
diff --git a/call/rtp_video_sender.h b/call/rtp_video_sender.h index 2bb12c5..11ae567 100644 --- a/call/rtp_video_sender.h +++ b/call/rtp_video_sender.h
@@ -213,11 +213,12 @@ const bool independent_frame_ids_; std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(mutex_); - size_t transport_overhead_bytes_per_packet_ RTC_GUARDED_BY(mutex_) = 0; - uint32_t protection_bitrate_bps_ = 0; - uint32_t encoder_target_rate_bps_ = 0; + size_t transport_overhead_bytes_per_packet_ + RTC_GUARDED_BY(transport_checker_) = 0; + uint32_t protection_bitrate_bps_ RTC_GUARDED_BY(transport_checker_) = 0; + uint32_t encoder_target_rate_bps_ RTC_GUARDED_BY(transport_checker_) = 0; - std::vector<bool> loss_mask_vector_ RTC_GUARDED_BY(mutex_); + std::vector<bool> loss_mask_vector_ RTC_GUARDED_BY(transport_checker_); std::vector<FrameCounts> frame_counts_ RTC_GUARDED_BY(mutex_); FrameCountObserver* const frame_count_observer_;