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}
This commit is contained in:
Piotr (Peter) Slatala 2018-11-16 09:03:35 -08:00 committed by Commit Bot
parent b5bb513066
commit 1eebec9808
2 changed files with 5 additions and 1 deletions

View File

@ -641,6 +641,7 @@ void ChannelSend::ModifyEncoder(
}
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 @@ void ChannelSend::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) {
}
int ChannelSend::GetBitRate() const {
rtc::CritScope lock(&bitrate_crit_section_);
return configured_bitrate_bps_;
}

View File

@ -324,7 +324,9 @@ class ChannelSend
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