Fix data race in channel_send.cc
'configured_bitrate_bps_' is accessed from different threads in
SetBitrate and GetBitrate (one comes back from OnNetworkRouteChange
callback, the other one is used in GetStats()) and so it should be
protected by a critical section.
Bug: webrtc:10010
Change-Id: I029baa729e0203b9f2d180d8835d61add26e6cef
Reviewed-on: https://webrtc-review.googlesource.com/c/111281
Commit-Queue: Peter Slatala <psla@webrtc.org>
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25675}
diff --git a/audio/channel_send.cc b/audio/channel_send.cc
index abdb980..a8b93cc 100644
--- a/audio/channel_send.cc
+++ b/audio/channel_send.cc
@@ -641,6 +641,7 @@
}
void ChannelSend::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) {
+ rtc::CritScope lock(&bitrate_crit_section_);
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
if (*encoder) {
(*encoder)->OnReceivedUplinkBandwidth(bitrate_bps, probing_interval_ms);
@@ -651,6 +652,7 @@
}
int ChannelSend::GetBitRate() const {
+ rtc::CritScope lock(&bitrate_crit_section_);
return configured_bitrate_bps_;
}
diff --git a/audio/channel_send.h b/audio/channel_send.h
index 6fefd28..63e8d04 100644
--- a/audio/channel_send.h
+++ b/audio/channel_send.h
@@ -324,7 +324,9 @@
rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor_;
// E2EE Frame Encryption Options
webrtc::CryptoOptions crypto_options_;
- int configured_bitrate_bps_ = 0;
+
+ rtc::CriticalSection bitrate_crit_section_;
+ int configured_bitrate_bps_ RTC_GUARDED_BY(bitrate_crit_section_) = 0;
};
} // namespace voe