Migrate modules/remote_bitrate_estimator to webrtc::Mutex.
Bug: webrtc:11567 Change-Id: Ib3c8f73459088434a70ee86b044dbbbe14db1777 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178810 Reviewed-by: Sebastian Jansson <srte@webrtc.org> Commit-Queue: Markus Handell <handellm@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31652}
This commit is contained in:

committed by
Commit Bot

parent
9bbff07b20
commit
edcb90755a
@ -56,6 +56,7 @@ rtc_library("remote_bitrate_estimator") {
|
||||
"../../rtc_base:rtc_numerics",
|
||||
"../../rtc_base:safe_minmax",
|
||||
"../../rtc_base/experiments:field_trial_parser",
|
||||
"../../rtc_base/synchronization:mutex",
|
||||
"../../system_wrappers",
|
||||
"../../system_wrappers:field_trial",
|
||||
"../../system_wrappers:metrics",
|
||||
|
@ -282,7 +282,7 @@ void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo(
|
||||
uint32_t target_bitrate_bps = 0;
|
||||
std::vector<uint32_t> ssrcs;
|
||||
{
|
||||
rtc::CritScope lock(&crit_);
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
TimeoutStreams(now_ms);
|
||||
RTC_DCHECK(inter_arrival_.get());
|
||||
@ -391,12 +391,12 @@ void RemoteBitrateEstimatorAbsSendTime::TimeoutStreams(int64_t now_ms) {
|
||||
|
||||
void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avg_rtt_ms,
|
||||
int64_t max_rtt_ms) {
|
||||
rtc::CritScope lock(&crit_);
|
||||
MutexLock lock(&mutex_);
|
||||
remote_rate_.SetRtt(TimeDelta::Millis(avg_rtt_ms));
|
||||
}
|
||||
|
||||
void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc) {
|
||||
rtc::CritScope lock(&crit_);
|
||||
MutexLock lock(&mutex_);
|
||||
ssrcs_.erase(ssrc);
|
||||
}
|
||||
|
||||
@ -409,7 +409,7 @@ bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate(
|
||||
// thread.
|
||||
RTC_DCHECK(ssrcs);
|
||||
RTC_DCHECK(bitrate_bps);
|
||||
rtc::CritScope lock(&crit_);
|
||||
MutexLock lock(&mutex_);
|
||||
if (!remote_rate_.ValidEstimate()) {
|
||||
return false;
|
||||
}
|
||||
@ -425,7 +425,7 @@ bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate(
|
||||
void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int min_bitrate_bps) {
|
||||
// Called from both the configuration thread and the network thread. Shouldn't
|
||||
// be called from the network thread in the future.
|
||||
rtc::CritScope lock(&crit_);
|
||||
MutexLock lock(&mutex_);
|
||||
remote_rate_.SetMinBitrate(DataRate::BitsPerSec(min_bitrate_bps));
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
@ -28,9 +28,9 @@
|
||||
#include "modules/remote_bitrate_estimator/overuse_estimator.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
#include "rtc_base/critical_section.h"
|
||||
#include "rtc_base/race_checker.h"
|
||||
#include "rtc_base/rate_statistics.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
|
||||
@ -114,12 +114,12 @@ class RemoteBitrateEstimatorAbsSendTime : public RemoteBitrateEstimator {
|
||||
|
||||
// Returns true if a probe which changed the estimate was detected.
|
||||
ProbeResult ProcessClusters(int64_t now_ms)
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_);
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_);
|
||||
|
||||
bool IsBitrateImproving(int probe_bitrate_bps) const
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_);
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_);
|
||||
|
||||
void TimeoutStreams(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_);
|
||||
void TimeoutStreams(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_);
|
||||
|
||||
rtc::RaceChecker network_race_;
|
||||
Clock* const clock_;
|
||||
@ -138,9 +138,9 @@ class RemoteBitrateEstimatorAbsSendTime : public RemoteBitrateEstimator {
|
||||
int64_t last_update_ms_;
|
||||
bool uma_recorded_;
|
||||
|
||||
rtc::CriticalSection crit_;
|
||||
Ssrcs ssrcs_ RTC_GUARDED_BY(&crit_);
|
||||
AimdRateControl remote_rate_ RTC_GUARDED_BY(&crit_);
|
||||
mutable Mutex mutex_;
|
||||
Ssrcs ssrcs_ RTC_GUARDED_BY(&mutex_);
|
||||
AimdRateControl remote_rate_ RTC_GUARDED_BY(&mutex_);
|
||||
|
||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteBitrateEstimatorAbsSendTime);
|
||||
};
|
||||
|
@ -95,7 +95,7 @@ void RemoteBitrateEstimatorSingleStream::IncomingPacket(
|
||||
uint32_t rtp_timestamp =
|
||||
header.timestamp + header.extension.transmissionTimeOffset;
|
||||
int64_t now_ms = clock_->TimeInMilliseconds();
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.find(ssrc);
|
||||
if (it == overuse_detectors_.end()) {
|
||||
// This is a new SSRC. Adding to map.
|
||||
@ -158,7 +158,7 @@ void RemoteBitrateEstimatorSingleStream::IncomingPacket(
|
||||
|
||||
void RemoteBitrateEstimatorSingleStream::Process() {
|
||||
{
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
UpdateEstimate(clock_->TimeInMilliseconds());
|
||||
}
|
||||
last_process_time_ = clock_->TimeInMilliseconds();
|
||||
@ -168,7 +168,7 @@ int64_t RemoteBitrateEstimatorSingleStream::TimeUntilNextProcess() {
|
||||
if (last_process_time_ < 0) {
|
||||
return 0;
|
||||
}
|
||||
rtc::CritScope cs_(&crit_sect_);
|
||||
MutexLock lock_(&mutex_);
|
||||
RTC_DCHECK_GT(process_interval_ms_, 0);
|
||||
return last_process_time_ + process_interval_ms_ -
|
||||
clock_->TimeInMilliseconds();
|
||||
@ -217,12 +217,12 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) {
|
||||
|
||||
void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avg_rtt_ms,
|
||||
int64_t max_rtt_ms) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
GetRemoteRate()->SetRtt(TimeDelta::Millis(avg_rtt_ms));
|
||||
}
|
||||
|
||||
void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.find(ssrc);
|
||||
if (it != overuse_detectors_.end()) {
|
||||
delete it->second;
|
||||
@ -233,7 +233,7 @@ void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) {
|
||||
bool RemoteBitrateEstimatorSingleStream::LatestEstimate(
|
||||
std::vector<uint32_t>* ssrcs,
|
||||
uint32_t* bitrate_bps) const {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
assert(bitrate_bps);
|
||||
if (!remote_rate_->ValidEstimate()) {
|
||||
return false;
|
||||
@ -264,7 +264,7 @@ AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate() {
|
||||
}
|
||||
|
||||
void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
remote_rate_->SetMinBitrate(DataRate::BitsPerSec(min_bitrate_bps));
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include "modules/remote_bitrate_estimator/aimd_rate_control.h"
|
||||
#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
#include "rtc_base/critical_section.h"
|
||||
#include "rtc_base/rate_statistics.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -54,26 +54,25 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator {
|
||||
typedef std::map<uint32_t, Detector*> SsrcOveruseEstimatorMap;
|
||||
|
||||
// Triggers a new estimate calculation.
|
||||
void UpdateEstimate(int64_t time_now)
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
|
||||
void UpdateEstimate(int64_t time_now) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
void GetSsrcs(std::vector<uint32_t>* ssrcs) const
|
||||
RTC_SHARED_LOCKS_REQUIRED(crit_sect_);
|
||||
RTC_SHARED_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Returns |remote_rate_| if the pointed to object exists,
|
||||
// otherwise creates it.
|
||||
AimdRateControl* GetRemoteRate() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
|
||||
AimdRateControl* GetRemoteRate() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
Clock* const clock_;
|
||||
const FieldTrialBasedConfig field_trials_;
|
||||
SsrcOveruseEstimatorMap overuse_detectors_ RTC_GUARDED_BY(crit_sect_);
|
||||
RateStatistics incoming_bitrate_ RTC_GUARDED_BY(crit_sect_);
|
||||
uint32_t last_valid_incoming_bitrate_ RTC_GUARDED_BY(crit_sect_);
|
||||
std::unique_ptr<AimdRateControl> remote_rate_ RTC_GUARDED_BY(crit_sect_);
|
||||
RemoteBitrateObserver* const observer_ RTC_GUARDED_BY(crit_sect_);
|
||||
rtc::CriticalSection crit_sect_;
|
||||
SsrcOveruseEstimatorMap overuse_detectors_ RTC_GUARDED_BY(mutex_);
|
||||
RateStatistics incoming_bitrate_ RTC_GUARDED_BY(mutex_);
|
||||
uint32_t last_valid_incoming_bitrate_ RTC_GUARDED_BY(mutex_);
|
||||
std::unique_ptr<AimdRateControl> remote_rate_ RTC_GUARDED_BY(mutex_);
|
||||
RemoteBitrateObserver* const observer_ RTC_GUARDED_BY(mutex_);
|
||||
mutable Mutex mutex_;
|
||||
int64_t last_process_time_;
|
||||
int64_t process_interval_ms_ RTC_GUARDED_BY(crit_sect_);
|
||||
int64_t process_interval_ms_ RTC_GUARDED_BY(mutex_);
|
||||
bool uma_recorded_;
|
||||
|
||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteBitrateEstimatorSingleStream);
|
||||
|
@ -61,7 +61,7 @@ void RemoteEstimatorProxy::IncomingPacket(int64_t arrival_time_ms,
|
||||
RTC_LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time_ms;
|
||||
return;
|
||||
}
|
||||
rtc::CritScope cs(&lock_);
|
||||
MutexLock lock(&lock_);
|
||||
media_ssrc_ = header.ssrc;
|
||||
int64_t seq = 0;
|
||||
|
||||
@ -134,7 +134,7 @@ bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs,
|
||||
}
|
||||
|
||||
int64_t RemoteEstimatorProxy::TimeUntilNextProcess() {
|
||||
rtc::CritScope cs(&lock_);
|
||||
MutexLock lock(&lock_);
|
||||
if (!send_periodic_feedback_) {
|
||||
// Wait a day until next process.
|
||||
return 24 * 60 * 60 * 1000;
|
||||
@ -147,7 +147,7 @@ int64_t RemoteEstimatorProxy::TimeUntilNextProcess() {
|
||||
}
|
||||
|
||||
void RemoteEstimatorProxy::Process() {
|
||||
rtc::CritScope cs(&lock_);
|
||||
MutexLock lock(&lock_);
|
||||
if (!send_periodic_feedback_) {
|
||||
return;
|
||||
}
|
||||
@ -169,7 +169,7 @@ void RemoteEstimatorProxy::OnBitrateChanged(int bitrate_bps) {
|
||||
kTwccReportSize * 8.0 * 1000.0 / send_config_.min_interval->ms();
|
||||
|
||||
// Let TWCC reports occupy 5% of total bandwidth.
|
||||
rtc::CritScope cs(&lock_);
|
||||
MutexLock lock(&lock_);
|
||||
send_interval_ms_ = static_cast<int>(
|
||||
0.5 + kTwccReportSize * 8.0 * 1000.0 /
|
||||
rtc::SafeClamp(send_config_.bandwidth_fraction * bitrate_bps,
|
||||
@ -178,7 +178,7 @@ void RemoteEstimatorProxy::OnBitrateChanged(int bitrate_bps) {
|
||||
|
||||
void RemoteEstimatorProxy::SetSendPeriodicFeedback(
|
||||
bool send_periodic_feedback) {
|
||||
rtc::CritScope cs(&lock_);
|
||||
MutexLock lock(&lock_);
|
||||
send_periodic_feedback_ = send_periodic_feedback;
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,9 @@
|
||||
#include "api/transport/network_control.h"
|
||||
#include "api/transport/webrtc_key_value_config.h"
|
||||
#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
|
||||
#include "rtc_base/critical_section.h"
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
#include "rtc_base/numerics/sequence_number_util.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -92,7 +92,7 @@ class RemoteEstimatorProxy : public RemoteBitrateEstimator {
|
||||
const TransportWideFeedbackConfig send_config_;
|
||||
int64_t last_process_time_ms_;
|
||||
|
||||
rtc::CriticalSection lock_;
|
||||
Mutex lock_;
|
||||
// |network_state_estimator_| may be null.
|
||||
NetworkStateEstimator* const network_state_estimator_
|
||||
RTC_PT_GUARDED_BY(&lock_);
|
||||
|
@ -61,27 +61,27 @@ Logging* Logging::GetInstance() {
|
||||
}
|
||||
|
||||
void Logging::SetGlobalContext(uint32_t name) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
thread_map_[rtc::CurrentThreadId()].global_state.tag = ToString(name);
|
||||
}
|
||||
|
||||
void Logging::SetGlobalContext(const std::string& name) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
thread_map_[rtc::CurrentThreadId()].global_state.tag = name;
|
||||
}
|
||||
|
||||
void Logging::SetGlobalContext(const char* name) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
thread_map_[rtc::CurrentThreadId()].global_state.tag = name;
|
||||
}
|
||||
|
||||
void Logging::SetGlobalEnable(bool enabled) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
thread_map_[rtc::CurrentThreadId()].global_state.enabled = enabled;
|
||||
}
|
||||
|
||||
void Logging::Log(const char format[], ...) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -118,7 +118,7 @@ void Logging::Plot(int figure,
|
||||
double value,
|
||||
uint32_t ssrc,
|
||||
const std::string& alg_name) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -132,7 +132,7 @@ void Logging::PlotBar(int figure,
|
||||
const std::string& name,
|
||||
double value,
|
||||
int flow_id) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -145,7 +145,7 @@ void Logging::PlotBaselineBar(int figure,
|
||||
const std::string& name,
|
||||
double value,
|
||||
int flow_id) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -161,7 +161,7 @@ void Logging::PlotErrorBar(int figure,
|
||||
double yhigh,
|
||||
const std::string& error_title,
|
||||
int flow_id) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -180,7 +180,7 @@ void Logging::PlotLimitErrorBar(int figure,
|
||||
double ymax,
|
||||
const std::string& limit_title,
|
||||
int flow_id) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -195,7 +195,7 @@ void Logging::PlotLabel(int figure,
|
||||
const std::string& title,
|
||||
const std::string& y_label,
|
||||
int num_flows) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
const State& state = it->second.stack.top();
|
||||
@ -229,7 +229,7 @@ void Logging::State::MergePrevious(const State& previous) {
|
||||
void Logging::PushState(const std::string& append_to_tag,
|
||||
int64_t timestamp_ms,
|
||||
bool enabled) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
State new_state(append_to_tag, timestamp_ms, enabled);
|
||||
ThreadState* thread_state = &thread_map_[rtc::CurrentThreadId()];
|
||||
std::stack<State>* stack = &thread_state->stack;
|
||||
@ -242,7 +242,7 @@ void Logging::PushState(const std::string& append_to_tag,
|
||||
}
|
||||
|
||||
void Logging::PopState() {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
|
||||
RTC_DCHECK(it != thread_map_.end());
|
||||
std::stack<State>* stack = &it->second.stack;
|
||||
|
@ -129,7 +129,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
#include "rtc_base/critical_section.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
|
||||
#define BWE_TEST_LOGGING_GLOBAL_CONTEXT(name) \
|
||||
do { \
|
||||
@ -345,7 +345,7 @@ class Logging {
|
||||
bool enabled);
|
||||
void PopState();
|
||||
|
||||
rtc::CriticalSection crit_sect_;
|
||||
Mutex mutex_;
|
||||
ThreadMap thread_map_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(Logging);
|
||||
|
Reference in New Issue
Block a user