Migrate modules/audio_coding, audio_mixer/ and audio_processing/ to webrtc::Mutex.
Bug: webrtc:11567
Change-Id: I03b78bd2e411e9bcca199f85e4457511826cd17e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176745
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Magnus Flodman <mflodman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31649}
diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn
index 3480e70..be97051 100644
--- a/modules/audio_coding/BUILD.gn
+++ b/modules/audio_coding/BUILD.gn
@@ -54,6 +54,7 @@
"../../rtc_base:checks",
"../../rtc_base:deprecation",
"../../rtc_base:rtc_base_approved",
+ "../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../system_wrappers:metrics",
]
@@ -1007,6 +1008,7 @@
"../../rtc_base:safe_minmax",
"../../rtc_base:sanitizer",
"../../rtc_base/experiments:field_trial_parser",
+ "../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../system_wrappers:field_trial",
"../../system_wrappers:metrics",
@@ -1388,6 +1390,7 @@
"../../common_audio",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
+ "../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:rw_lock_wrapper",
"../../system_wrappers",
"../../test:fileutils",
@@ -2061,6 +2064,7 @@
"../../rtc_base:rtc_base_tests_utils",
"../../rtc_base:sanitizer",
"../../rtc_base:timeutils",
+ "../../rtc_base/synchronization:mutex",
"../../rtc_base/system:arch",
"../../system_wrappers",
"../../system_wrappers:cpu_features_api",
diff --git a/modules/audio_coding/acm2/acm_receiver.cc b/modules/audio_coding/acm2/acm_receiver.cc
index 29eff19..33142c7 100644
--- a/modules/audio_coding/acm2/acm_receiver.cc
+++ b/modules/audio_coding/acm2/acm_receiver.cc
@@ -86,7 +86,7 @@
}
absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (!last_decoder_) {
return absl::nullopt;
}
@@ -118,7 +118,7 @@
}
{
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (absl::EqualsIgnoreCase(format->sdp_format.name, "cn")) {
if (last_decoder_ && last_decoder_->num_channels > 1) {
// This is a CNG and the audio codec is not mono, so skip pushing in
@@ -131,7 +131,7 @@
/*num_channels=*/format->num_channels,
/*sdp_format=*/std::move(format->sdp_format)};
}
- } // |crit_sect_| is released.
+ } // |mutex_| is released.
if (neteq_->InsertPacket(rtp_header, incoming_payload) < 0) {
RTC_LOG(LERROR) << "AcmReceiver::InsertPacket "
@@ -147,7 +147,7 @@
bool* muted) {
RTC_DCHECK(muted);
// Accessing members, take the lock.
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (neteq_->GetAudio(audio_frame, muted) != NetEq::kOK) {
RTC_LOG(LERROR) << "AcmReceiver::GetAudio - NetEq Failed.";
@@ -217,7 +217,7 @@
}
void AcmReceiver::RemoveAllCodecs() {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
neteq_->RemoveAllPayloadTypes();
last_decoder_ = absl::nullopt;
}
@@ -236,7 +236,7 @@
absl::optional<std::pair<int, SdpAudioFormat>> AcmReceiver::LastDecoder()
const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (!last_decoder_) {
return absl::nullopt;
}
@@ -327,7 +327,7 @@
void AcmReceiver::GetDecodingCallStatistics(
AudioDecodingCallStats* stats) const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
*stats = call_stats_.GetDecodingStatistics();
}
diff --git a/modules/audio_coding/acm2/acm_receiver.h b/modules/audio_coding/acm2/acm_receiver.h
index 1512656..d451a94 100644
--- a/modules/audio_coding/acm2/acm_receiver.h
+++ b/modules/audio_coding/acm2/acm_receiver.h
@@ -26,7 +26,7 @@
#include "modules/audio_coding/acm2/acm_resampler.h"
#include "modules/audio_coding/acm2/call_statistics.h"
#include "modules/audio_coding/include/audio_coding_module.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@@ -212,14 +212,14 @@
uint32_t NowInTimestamp(int decoder_sampling_rate) const;
- rtc::CriticalSection crit_sect_;
- absl::optional<DecoderInfo> last_decoder_ RTC_GUARDED_BY(crit_sect_);
- ACMResampler resampler_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<int16_t[]> last_audio_buffer_ RTC_GUARDED_BY(crit_sect_);
- CallStatistics call_stats_ RTC_GUARDED_BY(crit_sect_);
+ mutable Mutex mutex_;
+ absl::optional<DecoderInfo> last_decoder_ RTC_GUARDED_BY(mutex_);
+ ACMResampler resampler_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<int16_t[]> last_audio_buffer_ RTC_GUARDED_BY(mutex_);
+ CallStatistics call_stats_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<NetEq> neteq_; // NetEq is thread-safe; no lock needed.
Clock* const clock_;
- bool resampled_last_output_frame_ RTC_GUARDED_BY(crit_sect_);
+ bool resampled_last_output_frame_ RTC_GUARDED_BY(mutex_);
};
} // namespace acm2
diff --git a/modules/audio_coding/acm2/audio_coding_module.cc b/modules/audio_coding/acm2/audio_coding_module.cc
index a2d08ac..648ae6e 100644
--- a/modules/audio_coding/acm2/audio_coding_module.cc
+++ b/modules/audio_coding/acm2/audio_coding_module.cc
@@ -23,9 +23,9 @@
#include "modules/include/module_common_types_public.h"
#include "rtc_base/buffer.h"
#include "rtc_base/checks.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/metrics.h"
@@ -105,7 +105,7 @@
std::vector<int16_t> buffer;
};
- InputData input_data_ RTC_GUARDED_BY(acm_crit_sect_);
+ InputData input_data_ RTC_GUARDED_BY(acm_mutex_);
// This member class writes values to the named UMA histogram, but only if
// the value has changed since the last time (and always for the first call).
@@ -124,18 +124,18 @@
};
int Add10MsDataInternal(const AudioFrame& audio_frame, InputData* input_data)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_mutex_);
// TODO(bugs.webrtc.org/10739): change |absolute_capture_timestamp_ms| to
// int64_t when it always receives a valid value.
int Encode(const InputData& input_data,
absl::optional<int64_t> absolute_capture_timestamp_ms)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_mutex_);
- int InitializeReceiverSafe() RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);
+ int InitializeReceiverSafe() RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_mutex_);
bool HaveValidEncoder(const char* caller_name) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_mutex_);
// Preprocessing of input audio, including resampling and down-mixing if
// required, before pushing audio into encoder's buffer.
@@ -150,38 +150,38 @@
// 0: otherwise.
int PreprocessToAddData(const AudioFrame& in_frame,
const AudioFrame** ptr_out)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_mutex_);
// Change required states after starting to receive the codec corresponding
// to |index|.
int UpdateUponReceivingCodec(int index);
- rtc::CriticalSection acm_crit_sect_;
- rtc::Buffer encode_buffer_ RTC_GUARDED_BY(acm_crit_sect_);
- uint32_t expected_codec_ts_ RTC_GUARDED_BY(acm_crit_sect_);
- uint32_t expected_in_ts_ RTC_GUARDED_BY(acm_crit_sect_);
- acm2::ACMResampler resampler_ RTC_GUARDED_BY(acm_crit_sect_);
+ mutable Mutex acm_mutex_;
+ rtc::Buffer encode_buffer_ RTC_GUARDED_BY(acm_mutex_);
+ uint32_t expected_codec_ts_ RTC_GUARDED_BY(acm_mutex_);
+ uint32_t expected_in_ts_ RTC_GUARDED_BY(acm_mutex_);
+ acm2::ACMResampler resampler_ RTC_GUARDED_BY(acm_mutex_);
acm2::AcmReceiver receiver_; // AcmReceiver has it's own internal lock.
- ChangeLogger bitrate_logger_ RTC_GUARDED_BY(acm_crit_sect_);
+ ChangeLogger bitrate_logger_ RTC_GUARDED_BY(acm_mutex_);
// Current encoder stack, provided by a call to RegisterEncoder.
- std::unique_ptr<AudioEncoder> encoder_stack_ RTC_GUARDED_BY(acm_crit_sect_);
+ std::unique_ptr<AudioEncoder> encoder_stack_ RTC_GUARDED_BY(acm_mutex_);
// This is to keep track of CN instances where we can send DTMFs.
- uint8_t previous_pltype_ RTC_GUARDED_BY(acm_crit_sect_);
+ uint8_t previous_pltype_ RTC_GUARDED_BY(acm_mutex_);
- bool receiver_initialized_ RTC_GUARDED_BY(acm_crit_sect_);
+ bool receiver_initialized_ RTC_GUARDED_BY(acm_mutex_);
- AudioFrame preprocess_frame_ RTC_GUARDED_BY(acm_crit_sect_);
- bool first_10ms_data_ RTC_GUARDED_BY(acm_crit_sect_);
+ AudioFrame preprocess_frame_ RTC_GUARDED_BY(acm_mutex_);
+ bool first_10ms_data_ RTC_GUARDED_BY(acm_mutex_);
- bool first_frame_ RTC_GUARDED_BY(acm_crit_sect_);
- uint32_t last_timestamp_ RTC_GUARDED_BY(acm_crit_sect_);
- uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(acm_crit_sect_);
+ bool first_frame_ RTC_GUARDED_BY(acm_mutex_);
+ uint32_t last_timestamp_ RTC_GUARDED_BY(acm_mutex_);
+ uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(acm_mutex_);
- rtc::CriticalSection callback_crit_sect_;
+ Mutex callback_mutex_;
AudioPacketizationCallback* packetization_callback_
- RTC_GUARDED_BY(callback_crit_sect_);
+ RTC_GUARDED_BY(callback_mutex_);
int codec_histogram_bins_log_[static_cast<size_t>(
AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes)];
@@ -298,7 +298,7 @@
}
{
- rtc::CritScope lock(&callback_crit_sect_);
+ MutexLock lock(&callback_mutex_);
if (packetization_callback_) {
packetization_callback_->SendData(
frame_type, encoded_info.payload_type, encoded_info.encoded_timestamp,
@@ -316,7 +316,7 @@
void AudioCodingModuleImpl::ModifyEncoder(
rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) {
- rtc::CritScope lock(&acm_crit_sect_);
+ MutexLock lock(&acm_mutex_);
modifier(&encoder_stack_);
}
@@ -324,14 +324,14 @@
// the encoded buffers.
int AudioCodingModuleImpl::RegisterTransportCallback(
AudioPacketizationCallback* transport) {
- rtc::CritScope lock(&callback_crit_sect_);
+ MutexLock lock(&callback_mutex_);
packetization_callback_ = transport;
return 0;
}
// Add 10MS of raw (PCM) audio data to the encoder.
int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) {
- rtc::CritScope lock(&acm_crit_sect_);
+ MutexLock lock(&acm_mutex_);
int r = Add10MsDataInternal(audio_frame, &input_data_);
// TODO(bugs.webrtc.org/10739): add dcheck that
// |audio_frame.absolute_capture_timestamp_ms()| always has a value.
@@ -519,7 +519,7 @@
//
int AudioCodingModuleImpl::SetPacketLossRate(int loss_rate) {
- rtc::CritScope lock(&acm_crit_sect_);
+ MutexLock lock(&acm_mutex_);
if (HaveValidEncoder("SetPacketLossRate")) {
encoder_stack_->OnReceivedUplinkPacketLossFraction(loss_rate / 100.0);
}
@@ -531,7 +531,7 @@
//
int AudioCodingModuleImpl::InitializeReceiver() {
- rtc::CritScope lock(&acm_crit_sect_);
+ MutexLock lock(&acm_mutex_);
return InitializeReceiverSafe();
}
@@ -550,7 +550,7 @@
void AudioCodingModuleImpl::SetReceiveCodecs(
const std::map<int, SdpAudioFormat>& codecs) {
- rtc::CritScope lock(&acm_crit_sect_);
+ MutexLock lock(&acm_mutex_);
receiver_.SetCodecs(codecs);
}
@@ -597,7 +597,7 @@
}
ANAStats AudioCodingModuleImpl::GetANAStats() const {
- rtc::CritScope lock(&acm_crit_sect_);
+ MutexLock lock(&acm_mutex_);
if (encoder_stack_)
return encoder_stack_->GetANAStats();
// If no encoder is set, return default stats.
diff --git a/modules/audio_coding/acm2/audio_coding_module_unittest.cc b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
index b53d456..efd7b04 100644
--- a/modules/audio_coding/acm2/audio_coding_module_unittest.cc
+++ b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
@@ -39,12 +39,12 @@
#include "modules/audio_coding/neteq/tools/output_wav_file.h"
#include "modules/audio_coding/neteq/tools/packet.h"
#include "modules/audio_coding/neteq/tools/rtp_file_source.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/message_digest.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/ref_counted_object.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/arch.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
@@ -113,7 +113,7 @@
const uint8_t* payload_data,
size_t payload_len_bytes,
int64_t absolute_capture_timestamp_ms) override {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
++num_calls_;
last_frame_type_ = frame_type;
last_payload_type_ = payload_type;
@@ -123,42 +123,42 @@
}
int num_calls() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return num_calls_;
}
int last_payload_len_bytes() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return rtc::checked_cast<int>(last_payload_vec_.size());
}
AudioFrameType last_frame_type() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return last_frame_type_;
}
int last_payload_type() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return last_payload_type_;
}
uint32_t last_timestamp() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return last_timestamp_;
}
void SwapBuffers(std::vector<uint8_t>* payload) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
last_payload_vec_.swap(*payload);
}
private:
- int num_calls_ RTC_GUARDED_BY(crit_sect_);
- AudioFrameType last_frame_type_ RTC_GUARDED_BY(crit_sect_);
- int last_payload_type_ RTC_GUARDED_BY(crit_sect_);
- uint32_t last_timestamp_ RTC_GUARDED_BY(crit_sect_);
- std::vector<uint8_t> last_payload_vec_ RTC_GUARDED_BY(crit_sect_);
- rtc::CriticalSection crit_sect_;
+ int num_calls_ RTC_GUARDED_BY(mutex_);
+ AudioFrameType last_frame_type_ RTC_GUARDED_BY(mutex_);
+ int last_payload_type_ RTC_GUARDED_BY(mutex_);
+ uint32_t last_timestamp_ RTC_GUARDED_BY(mutex_);
+ std::vector<uint8_t> last_payload_vec_ RTC_GUARDED_BY(mutex_);
+ mutable Mutex mutex_;
};
class AudioCodingModuleTestOldApi : public ::testing::Test {
@@ -472,7 +472,7 @@
virtual bool TestDone() {
if (packet_cb_.num_calls() > kNumPackets) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (pull_audio_count_ > kNumPullCalls) {
// Both conditions for completion are met. End the test.
return true;
@@ -515,7 +515,7 @@
void CbInsertPacketImpl() {
SleepMs(1);
{
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (clock_->TimeInMilliseconds() < next_insert_packet_time_ms_) {
return;
}
@@ -537,7 +537,7 @@
void CbPullAudioImpl() {
SleepMs(1);
{
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
// Don't let the insert thread fall behind.
if (next_insert_packet_time_ms_ < clock_->TimeInMilliseconds()) {
return;
@@ -558,9 +558,9 @@
rtc::Event test_complete_;
int send_count_;
int insert_packet_count_;
- int pull_audio_count_ RTC_GUARDED_BY(crit_sect_);
- rtc::CriticalSection crit_sect_;
- int64_t next_insert_packet_time_ms_ RTC_GUARDED_BY(crit_sect_);
+ int pull_audio_count_ RTC_GUARDED_BY(mutex_);
+ Mutex mutex_;
+ int64_t next_insert_packet_time_ms_ RTC_GUARDED_BY(mutex_);
std::unique_ptr<SimulatedClock> fake_clock_;
};
@@ -658,7 +658,7 @@
// run).
bool TestDone() override {
if (packet_cb_.num_calls() > kNumPackets) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (pull_audio_count_ > kNumPullCalls) {
// Both conditions for completion are met. End the test.
return true;
@@ -758,7 +758,7 @@
rtc::Buffer encoded;
AudioEncoder::EncodedInfo info;
{
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (clock_->TimeInMilliseconds() < next_insert_packet_time_ms_) {
return true;
}
@@ -812,7 +812,7 @@
// End the test early if a fatal failure (ASSERT_*) has occurred.
test_complete_.Set();
}
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (!codec_registered_ &&
receive_packet_count_ > kRegisterAfterNumPackets) {
// Register the iSAC encoder.
@@ -831,10 +831,10 @@
std::atomic<bool> quit_;
rtc::Event test_complete_;
- rtc::CriticalSection crit_sect_;
- bool codec_registered_ RTC_GUARDED_BY(crit_sect_);
- int receive_packet_count_ RTC_GUARDED_BY(crit_sect_);
- int64_t next_insert_packet_time_ms_ RTC_GUARDED_BY(crit_sect_);
+ Mutex mutex_;
+ bool codec_registered_ RTC_GUARDED_BY(mutex_);
+ int receive_packet_count_ RTC_GUARDED_BY(mutex_);
+ int64_t next_insert_packet_time_ms_ RTC_GUARDED_BY(mutex_);
std::unique_ptr<AudioEncoderIsacFloatImpl> isac_encoder_;
std::unique_ptr<SimulatedClock> fake_clock_;
test::AudioLoop audio_loop_;
diff --git a/modules/audio_coding/neteq/neteq_impl.cc b/modules/audio_coding/neteq/neteq_impl.cc
index f1cd801..643fb1e 100644
--- a/modules/audio_coding/neteq/neteq_impl.cc
+++ b/modules/audio_coding/neteq/neteq_impl.cc
@@ -193,7 +193,7 @@
rtc::ArrayView<const uint8_t> payload) {
rtc::MsanCheckInitialized(payload);
TRACE_EVENT0("webrtc", "NetEqImpl::InsertPacket");
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (InsertPacketInternal(rtp_header, payload) != 0) {
return kFail;
}
@@ -204,7 +204,7 @@
// TODO(henrik.lundin) Handle NACK as well. This will make use of the
// rtp_header parameter.
// https://bugs.chromium.org/p/webrtc/issues/detail?id=7611
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
controller_->RegisterEmptyPacket();
}
@@ -260,7 +260,7 @@
bool* muted,
absl::optional<Operation> action_override) {
TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio");
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (GetAudioInternal(audio_frame, muted, action_override) != 0) {
return kFail;
}
@@ -300,7 +300,7 @@
}
void NetEqImpl::SetCodecs(const std::map<int, SdpAudioFormat>& codecs) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
const std::vector<int> changed_payload_types =
decoder_database_->SetCodecs(codecs);
for (const int pt : changed_payload_types) {
@@ -313,13 +313,13 @@
RTC_LOG(LS_VERBOSE) << "NetEqImpl::RegisterPayloadType: payload type "
<< rtp_payload_type << ", codec "
<< rtc::ToString(audio_format);
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return decoder_database_->RegisterPayload(rtp_payload_type, audio_format) ==
DecoderDatabase::kOK;
}
int NetEqImpl::RemovePayloadType(uint8_t rtp_payload_type) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
int ret = decoder_database_->Remove(rtp_payload_type);
if (ret == DecoderDatabase::kOK || ret == DecoderDatabase::kDecoderNotFound) {
packet_buffer_->DiscardPacketsWithPayloadType(rtp_payload_type,
@@ -330,12 +330,12 @@
}
void NetEqImpl::RemoveAllPayloadTypes() {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
decoder_database_->RemoveAll();
}
bool NetEqImpl::SetMinimumDelay(int delay_ms) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (delay_ms >= 0 && delay_ms <= 10000) {
assert(controller_.get());
return controller_->SetMinimumDelay(
@@ -345,7 +345,7 @@
}
bool NetEqImpl::SetMaximumDelay(int delay_ms) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (delay_ms >= 0 && delay_ms <= 10000) {
assert(controller_.get());
return controller_->SetMaximumDelay(
@@ -355,7 +355,7 @@
}
bool NetEqImpl::SetBaseMinimumDelayMs(int delay_ms) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (delay_ms >= 0 && delay_ms <= 10000) {
return controller_->SetBaseMinimumDelay(delay_ms);
}
@@ -363,18 +363,18 @@
}
int NetEqImpl::GetBaseMinimumDelayMs() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return controller_->GetBaseMinimumDelay();
}
int NetEqImpl::TargetDelayMs() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(controller_.get());
return controller_->TargetLevelMs() + output_delay_chain_ms_;
}
int NetEqImpl::FilteredCurrentDelayMs() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
// Sum up the filtered packet buffer level with the future length of the sync
// buffer.
const int delay_samples =
@@ -385,7 +385,7 @@
}
int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
assert(decoder_database_.get());
const size_t total_samples_in_buffers =
packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) +
@@ -406,12 +406,12 @@
}
NetEqLifetimeStatistics NetEqImpl::GetLifetimeStatistics() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return stats_->GetLifetimeStatistics();
}
NetEqOperationsAndState NetEqImpl::GetOperationsAndState() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
auto result = stats_->GetOperationsAndState();
result.current_buffer_size_ms =
(packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) +
@@ -425,19 +425,19 @@
}
void NetEqImpl::EnableVad() {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
assert(vad_.get());
vad_->Enable();
}
void NetEqImpl::DisableVad() {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
assert(vad_.get());
vad_->Disable();
}
absl::optional<uint32_t> NetEqImpl::GetPlayoutTimestamp() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (first_packet_ || last_mode_ == Mode::kRfc3389Cng ||
last_mode_ == Mode::kCodecInternalCng) {
// We don't have a valid RTP timestamp until we have decoded our first
@@ -455,14 +455,14 @@
}
int NetEqImpl::last_output_sample_rate_hz() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return delayed_last_output_sample_rate_hz_.value_or(
last_output_sample_rate_hz_);
}
absl::optional<NetEq::DecoderFormat> NetEqImpl::GetDecoderFormat(
int payload_type) const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
const DecoderDatabase::DecoderInfo* const di =
decoder_database_->GetDecoderInfo(payload_type);
if (di) {
@@ -480,7 +480,7 @@
}
void NetEqImpl::FlushBuffers() {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
RTC_LOG(LS_VERBOSE) << "FlushBuffers";
packet_buffer_->Flush();
assert(sync_buffer_.get());
@@ -493,7 +493,7 @@
}
void NetEqImpl::EnableNack(size_t max_nack_list_size) {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (!nack_enabled_) {
const int kNackThresholdPackets = 2;
nack_.reset(NackTracker::Create(kNackThresholdPackets));
@@ -504,13 +504,13 @@
}
void NetEqImpl::DisableNack() {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
nack_.reset();
nack_enabled_ = false;
}
std::vector<uint16_t> NetEqImpl::GetNackList(int64_t round_trip_time_ms) const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (!nack_enabled_) {
return std::vector<uint16_t>();
}
@@ -519,23 +519,23 @@
}
std::vector<uint32_t> NetEqImpl::LastDecodedTimestamps() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return last_decoded_timestamps_;
}
int NetEqImpl::SyncBufferSizeMs() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return rtc::dchecked_cast<int>(sync_buffer_->FutureLength() /
rtc::CheckedDivExact(fs_hz_, 1000));
}
const SyncBuffer* NetEqImpl::sync_buffer_for_test() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return sync_buffer_.get();
}
NetEq::Operation NetEqImpl::last_operation_for_test() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return last_operation_;
}
diff --git a/modules/audio_coding/neteq/neteq_impl.h b/modules/audio_coding/neteq/neteq_impl.h
index 623968a..0ade6b5 100644
--- a/modules/audio_coding/neteq/neteq_impl.h
+++ b/modules/audio_coding/neteq/neteq_impl.h
@@ -30,7 +30,7 @@
#include "modules/audio_coding/neteq/random_vector.h"
#include "modules/audio_coding/neteq/statistics_calculator.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@@ -210,14 +210,14 @@
// TODO(hlundin): Merge this with InsertPacket above?
int InsertPacketInternal(const RTPHeader& rtp_header,
rtc::ArrayView<const uint8_t> payload)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Delivers 10 ms of audio data. The data is written to |audio_frame|.
// Returns 0 on success, otherwise an error code.
int GetAudioInternal(AudioFrame* audio_frame,
bool* muted,
absl::optional<Operation> action_override)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Provides a decision to the GetAudioInternal method. The decision what to
// do is written to |operation|. Packets to decode are written to
@@ -229,7 +229,7 @@
DtmfEvent* dtmf_event,
bool* play_dtmf,
absl::optional<Operation> action_override)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Decodes the speech packets in |packet_list|, and writes the results to
// |decoded_buffer|, which is allocated to hold |decoded_buffer_length|
@@ -241,13 +241,13 @@
Operation* operation,
int* decoded_length,
AudioDecoder::SpeechType* speech_type)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method to Decode(). Performs codec internal CNG.
int DecodeCng(AudioDecoder* decoder,
int* decoded_length,
AudioDecoder::SpeechType* speech_type)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method to Decode(). Performs the actual decoding.
int DecodeLoop(PacketList* packet_list,
@@ -255,24 +255,24 @@
AudioDecoder* decoder,
int* decoded_length,
AudioDecoder::SpeechType* speech_type)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Normal class to perform the normal operation.
void DoNormal(const int16_t* decoded_buffer,
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
- bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Merge class to perform the merge operation.
void DoMerge(int16_t* decoded_buffer,
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
- bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- bool DoCodecPlc() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool DoCodecPlc() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Expand class to perform the expand operation.
- int DoExpand(bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ int DoExpand(bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Accelerate class to perform the accelerate
// operation.
@@ -280,144 +280,136 @@
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
bool play_dtmf,
- bool fast_accelerate)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool fast_accelerate) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the PreemptiveExpand class to perform the
// preemtive expand operation.
int DoPreemptiveExpand(int16_t* decoded_buffer,
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
- bool play_dtmf)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the ComfortNoise class to generate RFC 3389 comfort
// noise. |packet_list| can either contain one SID frame to update the
// noise parameters, or no payload at all, in which case the previously
// received parameters are used.
int DoRfc3389Cng(PacketList* packet_list, bool play_dtmf)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Calls the audio decoder to generate codec-internal comfort noise when
// no packet was received.
void DoCodecInternalCng(const int16_t* decoded_buffer, size_t decoded_length)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Calls the DtmfToneGenerator class to generate DTMF tones.
int DoDtmf(const DtmfEvent& dtmf_event, bool* play_dtmf)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Overdub DTMF on top of |output|.
int DtmfOverdub(const DtmfEvent& dtmf_event,
size_t num_channels,
- int16_t* output) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ int16_t* output) const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Extracts packets from |packet_buffer_| to produce at least
// |required_samples| samples. The packets are inserted into |packet_list|.
// Returns the number of samples that the packets in the list will produce, or
// -1 in case of an error.
int ExtractPackets(size_t required_samples, PacketList* packet_list)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Resets various variables and objects to new values based on the sample rate
// |fs_hz| and |channels| number audio channels.
void SetSampleRateAndChannels(int fs_hz, size_t channels)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns the output type for the audio produced by the latest call to
// GetAudio().
- OutputType LastOutputType() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ OutputType LastOutputType() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Updates Expand and Merge.
virtual void UpdatePlcComponents(int fs_hz, size_t channels)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* const clock_;
- rtc::CriticalSection crit_sect_;
- const std::unique_ptr<TickTimer> tick_timer_ RTC_GUARDED_BY(crit_sect_);
+ mutable Mutex mutex_;
+ const std::unique_ptr<TickTimer> tick_timer_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<DecoderDatabase> decoder_database_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<DtmfBuffer> dtmf_buffer_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<DtmfBuffer> dtmf_buffer_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<DtmfToneGenerator> dtmf_tone_generator_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<PacketBuffer> packet_buffer_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<PacketBuffer> packet_buffer_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<RedPayloadSplitter> red_payload_splitter_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<TimestampScaler> timestamp_scaler_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<PostDecodeVad> vad_ RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<ExpandFactory> expand_factory_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<PostDecodeVad> vad_ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<ExpandFactory> expand_factory_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<AccelerateFactory> accelerate_factory_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<PreemptiveExpandFactory> preemptive_expand_factory_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<StatisticsCalculator> stats_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<StatisticsCalculator> stats_ RTC_GUARDED_BY(mutex_);
- std::unique_ptr<BackgroundNoise> background_noise_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<NetEqController> controller_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<AudioMultiVector> algorithm_buffer_
- RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<SyncBuffer> sync_buffer_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Expand> expand_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Normal> normal_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Merge> merge_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Accelerate> accelerate_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<PreemptiveExpand> preemptive_expand_
- RTC_GUARDED_BY(crit_sect_);
- RandomVector random_vector_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<ComfortNoise> comfort_noise_ RTC_GUARDED_BY(crit_sect_);
- int fs_hz_ RTC_GUARDED_BY(crit_sect_);
- int fs_mult_ RTC_GUARDED_BY(crit_sect_);
- int last_output_sample_rate_hz_ RTC_GUARDED_BY(crit_sect_);
- size_t output_size_samples_ RTC_GUARDED_BY(crit_sect_);
- size_t decoder_frame_length_ RTC_GUARDED_BY(crit_sect_);
- Mode last_mode_ RTC_GUARDED_BY(crit_sect_);
- Operation last_operation_ RTC_GUARDED_BY(crit_sect_);
- size_t decoded_buffer_length_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<int16_t[]> decoded_buffer_ RTC_GUARDED_BY(crit_sect_);
- uint32_t playout_timestamp_ RTC_GUARDED_BY(crit_sect_);
- bool new_codec_ RTC_GUARDED_BY(crit_sect_);
- uint32_t timestamp_ RTC_GUARDED_BY(crit_sect_);
- bool reset_decoder_ RTC_GUARDED_BY(crit_sect_);
- absl::optional<uint8_t> current_rtp_payload_type_ RTC_GUARDED_BY(crit_sect_);
- absl::optional<uint8_t> current_cng_rtp_payload_type_
- RTC_GUARDED_BY(crit_sect_);
- bool first_packet_ RTC_GUARDED_BY(crit_sect_);
- bool enable_fast_accelerate_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<NackTracker> nack_ RTC_GUARDED_BY(crit_sect_);
- bool nack_enabled_ RTC_GUARDED_BY(crit_sect_);
- const bool enable_muted_state_ RTC_GUARDED_BY(crit_sect_);
- AudioFrame::VADActivity last_vad_activity_ RTC_GUARDED_BY(crit_sect_) =
+ std::unique_ptr<BackgroundNoise> background_noise_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<NetEqController> controller_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<AudioMultiVector> algorithm_buffer_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<SyncBuffer> sync_buffer_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Expand> expand_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Normal> normal_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Merge> merge_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Accelerate> accelerate_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<PreemptiveExpand> preemptive_expand_ RTC_GUARDED_BY(mutex_);
+ RandomVector random_vector_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<ComfortNoise> comfort_noise_ RTC_GUARDED_BY(mutex_);
+ int fs_hz_ RTC_GUARDED_BY(mutex_);
+ int fs_mult_ RTC_GUARDED_BY(mutex_);
+ int last_output_sample_rate_hz_ RTC_GUARDED_BY(mutex_);
+ size_t output_size_samples_ RTC_GUARDED_BY(mutex_);
+ size_t decoder_frame_length_ RTC_GUARDED_BY(mutex_);
+ Mode last_mode_ RTC_GUARDED_BY(mutex_);
+ Operation last_operation_ RTC_GUARDED_BY(mutex_);
+ size_t decoded_buffer_length_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<int16_t[]> decoded_buffer_ RTC_GUARDED_BY(mutex_);
+ uint32_t playout_timestamp_ RTC_GUARDED_BY(mutex_);
+ bool new_codec_ RTC_GUARDED_BY(mutex_);
+ uint32_t timestamp_ RTC_GUARDED_BY(mutex_);
+ bool reset_decoder_ RTC_GUARDED_BY(mutex_);
+ absl::optional<uint8_t> current_rtp_payload_type_ RTC_GUARDED_BY(mutex_);
+ absl::optional<uint8_t> current_cng_rtp_payload_type_ RTC_GUARDED_BY(mutex_);
+ bool first_packet_ RTC_GUARDED_BY(mutex_);
+ bool enable_fast_accelerate_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<NackTracker> nack_ RTC_GUARDED_BY(mutex_);
+ bool nack_enabled_ RTC_GUARDED_BY(mutex_);
+ const bool enable_muted_state_ RTC_GUARDED_BY(mutex_);
+ AudioFrame::VADActivity last_vad_activity_ RTC_GUARDED_BY(mutex_) =
AudioFrame::kVadPassive;
std::unique_ptr<TickTimer::Stopwatch> generated_noise_stopwatch_
- RTC_GUARDED_BY(crit_sect_);
- std::vector<uint32_t> last_decoded_timestamps_ RTC_GUARDED_BY(crit_sect_);
- std::vector<RtpPacketInfo> last_decoded_packet_infos_
- RTC_GUARDED_BY(crit_sect_);
- ExpandUmaLogger expand_uma_logger_ RTC_GUARDED_BY(crit_sect_);
- ExpandUmaLogger speech_expand_uma_logger_ RTC_GUARDED_BY(crit_sect_);
- bool no_time_stretching_ RTC_GUARDED_BY(crit_sect_); // Only used for test.
- rtc::BufferT<int16_t> concealment_audio_ RTC_GUARDED_BY(crit_sect_);
- const bool enable_rtx_handling_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ std::vector<uint32_t> last_decoded_timestamps_ RTC_GUARDED_BY(mutex_);
+ std::vector<RtpPacketInfo> last_decoded_packet_infos_ RTC_GUARDED_BY(mutex_);
+ ExpandUmaLogger expand_uma_logger_ RTC_GUARDED_BY(mutex_);
+ ExpandUmaLogger speech_expand_uma_logger_ RTC_GUARDED_BY(mutex_);
+ bool no_time_stretching_ RTC_GUARDED_BY(mutex_); // Only used for test.
+ rtc::BufferT<int16_t> concealment_audio_ RTC_GUARDED_BY(mutex_);
+ const bool enable_rtx_handling_ RTC_GUARDED_BY(mutex_);
// Data members used for adding extra delay to the output of NetEq.
// The delay in ms (which is 10 times the number of elements in
// output_delay_chain_).
- const int output_delay_chain_ms_ RTC_GUARDED_BY(crit_sect_);
+ const int output_delay_chain_ms_ RTC_GUARDED_BY(mutex_);
// Vector of AudioFrames which contains the delayed audio. Accessed as a
// circular buffer.
- std::vector<AudioFrame> output_delay_chain_ RTC_GUARDED_BY(crit_sect_);
+ std::vector<AudioFrame> output_delay_chain_ RTC_GUARDED_BY(mutex_);
// Index into output_delay_chain_.
- size_t output_delay_chain_ix_ RTC_GUARDED_BY(crit_sect_) = 0;
+ size_t output_delay_chain_ix_ RTC_GUARDED_BY(mutex_) = 0;
// Did output_delay_chain_ get populated yet?
- bool output_delay_chain_empty_ RTC_GUARDED_BY(crit_sect_) = true;
+ bool output_delay_chain_empty_ RTC_GUARDED_BY(mutex_) = true;
// Contains the sample rate of the AudioFrame last emitted from the delay
// chain. If the extra output delay chain is not used, or if no audio has been
// emitted yet, the variable is empty.
absl::optional<int> delayed_last_output_sample_rate_hz_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
private:
RTC_DISALLOW_COPY_AND_ASSIGN(NetEqImpl);
diff --git a/modules/audio_coding/test/Channel.cc b/modules/audio_coding/test/Channel.cc
index 3590891..9456145 100644
--- a/modules/audio_coding/test/Channel.cc
+++ b/modules/audio_coding/test/Channel.cc
@@ -58,7 +58,7 @@
}
}
- _channelCritSect.Enter();
+ _channelCritSect.Lock();
if (_saveBitStream) {
// fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile);
}
@@ -69,7 +69,7 @@
_useLastFrameSize = false;
_lastInTimestamp = timeStamp;
_totalBytes += payloadDataSize;
- _channelCritSect.Leave();
+ _channelCritSect.Unlock();
if (_useFECTestWithPacketLoss) {
_packetLoss += 1;
@@ -238,7 +238,7 @@
void Channel::ResetStats() {
int n;
int k;
- _channelCritSect.Enter();
+ _channelCritSect.Lock();
_lastPayloadType = -1;
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
_payloadStats[n].payloadType = -1;
@@ -253,23 +253,23 @@
}
_beginTime = rtc::TimeMillis();
_totalBytes = 0;
- _channelCritSect.Leave();
+ _channelCritSect.Unlock();
}
uint32_t Channel::LastInTimestamp() {
uint32_t timestamp;
- _channelCritSect.Enter();
+ _channelCritSect.Lock();
timestamp = _lastInTimestamp;
- _channelCritSect.Leave();
+ _channelCritSect.Unlock();
return timestamp;
}
double Channel::BitRate() {
double rate;
uint64_t currTime = rtc::TimeMillis();
- _channelCritSect.Enter();
+ _channelCritSect.Lock();
rate = ((double)_totalBytes * 8.0) / (double)(currTime - _beginTime);
- _channelCritSect.Leave();
+ _channelCritSect.Unlock();
return rate;
}
diff --git a/modules/audio_coding/test/Channel.h b/modules/audio_coding/test/Channel.h
index 78129e5..7a8829e 100644
--- a/modules/audio_coding/test/Channel.h
+++ b/modules/audio_coding/test/Channel.h
@@ -15,7 +15,7 @@
#include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/include/module_common_types.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@@ -88,7 +88,7 @@
// 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
uint8_t _payloadData[60 * 32 * 2 * 2];
- rtc::CriticalSection _channelCritSect;
+ Mutex _channelCritSect;
FILE* _bitStreamFile;
bool _saveBitStream;
int16_t _lastPayloadType;
diff --git a/modules/audio_mixer/BUILD.gn b/modules/audio_mixer/BUILD.gn
index a4b71f6..7ce35ff 100644
--- a/modules/audio_mixer/BUILD.gn
+++ b/modules/audio_mixer/BUILD.gn
@@ -46,6 +46,7 @@
"../../common_audio",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
+ "../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../system_wrappers:metrics",
"../audio_processing:api",
diff --git a/modules/audio_mixer/audio_mixer_impl.cc b/modules/audio_mixer/audio_mixer_impl.cc
index abfda25..6552953 100644
--- a/modules/audio_mixer/audio_mixer_impl.cc
+++ b/modules/audio_mixer/audio_mixer_impl.cc
@@ -126,7 +126,7 @@
CalculateOutputFrequency();
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
const size_t number_of_streams = audio_source_list_.size();
frame_combiner_.Combine(GetAudioFromSources(), number_of_channels,
OutputFrequency(), number_of_streams,
@@ -138,7 +138,7 @@
void AudioMixerImpl::CalculateOutputFrequency() {
RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
std::vector<int> preferred_rates;
std::transform(audio_source_list_.begin(), audio_source_list_.end(),
@@ -159,7 +159,7 @@
bool AudioMixerImpl::AddSource(Source* audio_source) {
RTC_DCHECK(audio_source);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(FindSourceInList(audio_source, &audio_source_list_) ==
audio_source_list_.end())
<< "Source already added to mixer";
@@ -169,7 +169,7 @@
void AudioMixerImpl::RemoveSource(Source* audio_source) {
RTC_DCHECK(audio_source);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
const auto iter = FindSourceInList(audio_source, &audio_source_list_);
RTC_DCHECK(iter != audio_source_list_.end()) << "Source not present in mixer";
audio_source_list_.erase(iter);
@@ -227,7 +227,7 @@
bool AudioMixerImpl::GetAudioSourceMixabilityStatusForTest(
AudioMixerImpl::Source* audio_source) const {
RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
const auto iter = FindSourceInList(audio_source, &audio_source_list_);
if (iter != audio_source_list_.end()) {
diff --git a/modules/audio_mixer/audio_mixer_impl.h b/modules/audio_mixer/audio_mixer_impl.h
index c503932..57b1f5e 100644
--- a/modules/audio_mixer/audio_mixer_impl.h
+++ b/modules/audio_mixer/audio_mixer_impl.h
@@ -22,8 +22,8 @@
#include "modules/audio_mixer/frame_combiner.h"
#include "modules/audio_mixer/output_rate_calculator.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/race_checker.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@@ -63,7 +63,7 @@
void Mix(size_t number_of_channels,
AudioFrame* audio_frame_for_mixing) override
- RTC_LOCKS_EXCLUDED(crit_);
+ RTC_LOCKS_EXCLUDED(mutex_);
// Returns true if the source was mixed last round. Returns
// false and logs an error if the source was never added to the
@@ -83,12 +83,12 @@
// Compute what audio sources to mix from audio_source_list_. Ramp
// in and out. Update mixed status. Mixes up to
// kMaximumAmountOfMixedAudioSources audio sources.
- AudioFrameList GetAudioFromSources() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ AudioFrameList GetAudioFromSources() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// The critical section lock guards audio source insertion and
// removal, which can be done from any thread. The race checker
// checks that mixing is done sequentially.
- rtc::CriticalSection crit_;
+ mutable Mutex mutex_;
rtc::RaceChecker race_checker_;
std::unique_ptr<OutputRateCalculator> output_rate_calculator_;
@@ -97,7 +97,7 @@
size_t sample_size_ RTC_GUARDED_BY(race_checker_);
// List of all audio sources. Note all lists are disjunct
- SourceStatusList audio_source_list_ RTC_GUARDED_BY(crit_); // May be mixed.
+ SourceStatusList audio_source_list_ RTC_GUARDED_BY(mutex_); // May be mixed.
// Component that handles actual adding of audio frames.
FrameCombiner frame_combiner_ RTC_GUARDED_BY(race_checker_);
diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn
index 22e128d..1510930 100644
--- a/modules/audio_processing/BUILD.gn
+++ b/modules/audio_processing/BUILD.gn
@@ -187,6 +187,7 @@
"../../rtc_base:refcount",
"../../rtc_base:safe_minmax",
"../../rtc_base:sanitizer",
+ "../../rtc_base/synchronization:mutex",
"../../rtc_base/system:rtc_export",
"../../system_wrappers:cpu_features_api",
"../../system_wrappers:field_trial",
@@ -370,6 +371,7 @@
"../../rtc_base:rtc_base_tests_utils",
"../../rtc_base:safe_minmax",
"../../rtc_base:task_queue_for_test",
+ "../../rtc_base/synchronization:mutex",
"../../rtc_base/system:arch",
"../../rtc_base/system:file_wrapper",
"../../system_wrappers",
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 7dd6b7d..b155bdb 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -313,8 +313,8 @@
int AudioProcessingImpl::Initialize() {
// Run in a single-threaded manner during initialization.
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
return InitializeLocked();
}
@@ -340,8 +340,8 @@
int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) {
// Run in a single-threaded manner during initialization.
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
return InitializeLocked(processing_config);
}
@@ -352,7 +352,7 @@
return kNoError;
}
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
return InitializeLocked(processing_config);
}
@@ -526,8 +526,8 @@
RTC_LOG(LS_INFO) << "AudioProcessing::ApplyConfig: " << config.ToString();
// Run in a single-threaded manner when applying the settings.
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
const bool pipeline_config_changed =
config_.pipeline.multi_channel_render !=
@@ -643,7 +643,7 @@
void AudioProcessingImpl::OverrideSubmoduleCreationForTesting(
const ApmSubmoduleCreationOverrides& overrides) {
- rtc::CritScope cs(&crit_capture_);
+ MutexLock lock(&mutex_capture_);
submodule_creation_overrides_ = overrides;
}
@@ -689,7 +689,7 @@
}
void AudioProcessingImpl::set_output_will_be_muted(bool muted) {
- rtc::CritScope cs(&crit_capture_);
+ MutexLock lock(&mutex_capture_);
capture_.output_will_be_muted = muted;
if (submodules_.agc_manager.get()) {
submodules_.agc_manager->SetCaptureMuted(capture_.output_will_be_muted);
@@ -751,7 +751,7 @@
// Acquire the capture lock in order to access api_format. The lock is
// released immediately, as we may need to acquire the render lock as part
// of the conditional reinitialization.
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
processing_config = formats_.api_format;
reinitialization_required = UpdateActiveSubmoduleStates();
}
@@ -767,8 +767,8 @@
}
if (reinitialization_required) {
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
RETURN_ON_ERR(InitializeLocked(processing_config));
}
return kNoError;
@@ -785,7 +785,7 @@
RETURN_ON_ERR(MaybeInitializeCapture(input_config, output_config));
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
if (aec_dump_) {
RecordUnprocessedCaptureStream(src);
@@ -991,7 +991,7 @@
}
void AudioProcessingImpl::EmptyQueuedRenderAudio() {
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
EmptyQueuedRenderAudioLocked();
}
@@ -1023,7 +1023,7 @@
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame");
RETURN_ON_ERR(MaybeInitializeCapture(input_config, output_config));
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
if (aec_dump_) {
RecordUnprocessedCaptureStream(src, input_config);
@@ -1320,7 +1320,7 @@
const float* const* data,
const StreamConfig& reverse_config) {
TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_StreamConfig");
- rtc::CritScope cs(&crit_render_);
+ MutexLock lock(&mutex_render_);
return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config);
}
@@ -1329,7 +1329,7 @@
const StreamConfig& output_config,
float* const* dest) {
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig");
- rtc::CritScope cs(&crit_render_);
+ MutexLock lock(&mutex_render_);
RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, input_config, output_config));
if (submodule_states_.RenderMultiBandProcessingActive() ||
submodule_states_.RenderFullBandProcessingActive()) {
@@ -1390,7 +1390,7 @@
return AudioProcessing::Error::kBadNumberChannelsError;
}
- rtc::CritScope cs(&crit_render_);
+ MutexLock lock(&mutex_render_);
ProcessingConfig processing_config = formats_.api_format;
processing_config.reverse_input_stream().set_sample_rate_hz(
input_config.sample_rate_hz());
@@ -1457,7 +1457,7 @@
}
int AudioProcessingImpl::set_stream_delay_ms(int delay) {
- rtc::CritScope cs(&crit_capture_);
+ MutexLock lock(&mutex_capture_);
Error retval = kNoError;
capture_.was_stream_delay_set = true;
@@ -1478,7 +1478,7 @@
bool AudioProcessingImpl::GetLinearAecOutput(
rtc::ArrayView<std::array<float, 160>> linear_output) const {
- rtc::CritScope cs(&crit_capture_);
+ MutexLock lock(&mutex_capture_);
AudioBuffer* linear_aec_buffer = capture_.linear_aec_output.get();
RTC_DCHECK(linear_aec_buffer);
@@ -1507,12 +1507,12 @@
}
void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) {
- rtc::CritScope cs(&crit_capture_);
+ MutexLock lock(&mutex_capture_);
capture_.key_pressed = key_pressed;
}
void AudioProcessingImpl::set_stream_analog_level(int level) {
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
if (submodules_.agc_manager) {
submodules_.agc_manager->set_stream_analog_level(level);
@@ -1527,7 +1527,7 @@
}
int AudioProcessingImpl::recommended_stream_analog_level() const {
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_capture(&mutex_capture_);
return recommended_stream_analog_level_locked();
}
@@ -1569,8 +1569,8 @@
void AudioProcessingImpl::AttachAecDump(std::unique_ptr<AecDump> aec_dump) {
RTC_DCHECK(aec_dump);
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
// The previously attached AecDump will be destroyed with the
// 'aec_dump' parameter, which is after locks are released.
@@ -1585,23 +1585,23 @@
// the render and capture locks.
std::unique_ptr<AecDump> aec_dump = nullptr;
{
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
aec_dump = std::move(aec_dump_);
}
}
void AudioProcessingImpl::MutateConfig(
rtc::FunctionView<void(AudioProcessing::Config*)> mutator) {
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
mutator(&config_);
ApplyConfig(config_);
}
AudioProcessing::Config AudioProcessingImpl::GetConfig() const {
- rtc::CritScope cs_render(&crit_render_);
- rtc::CritScope cs_capture(&crit_capture_);
+ MutexLock lock_render(&mutex_render_);
+ MutexLock lock_capture(&mutex_capture_);
return config_;
}
@@ -2054,7 +2054,7 @@
AudioProcessingImpl::ApmStatsReporter::~ApmStatsReporter() = default;
AudioProcessingStats AudioProcessingImpl::ApmStatsReporter::GetStatistics() {
- rtc::CritScope cs_stats(&crit_stats_);
+ MutexLock lock_stats(&mutex_stats_);
bool new_stats_available = stats_message_queue_.Remove(&cached_stats_);
// If the message queue is full, return the cached stats.
static_cast<void>(new_stats_available);
diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h
index 676e3cd..dfd5f63 100644
--- a/modules/audio_processing/audio_processing_impl.h
+++ b/modules/audio_processing/audio_processing_impl.h
@@ -39,10 +39,10 @@
#include "modules/audio_processing/rms_level.h"
#include "modules/audio_processing/transient/transient_suppressor.h"
#include "modules/audio_processing/voice_detection.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/gtest_prod_util.h"
#include "rtc_base/ignore_wundef.h"
#include "rtc_base/swap_queue.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@@ -101,7 +101,7 @@
void set_stream_key_pressed(bool key_pressed) override;
void set_stream_analog_level(int level) override;
int recommended_stream_analog_level() const
- RTC_LOCKS_EXCLUDED(crit_capture_) override;
+ RTC_LOCKS_EXCLUDED(mutex_capture_) override;
// Render-side exclusive methods possibly running APM in a
// multi-threaded manner. Acquire the render lock.
@@ -141,7 +141,7 @@
protected:
// Overridden in a mock.
virtual int InitializeLocked()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
private:
// TODO(peah): These friend classes should be removed as soon as the new
@@ -157,7 +157,7 @@
BitexactWithDisabledModules);
int recommended_stream_analog_level_locked() const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void OverrideSubmoduleCreationForTesting(
const ApmSubmoduleCreationOverrides& overrides);
@@ -238,7 +238,7 @@
// Called by render: Holds the render lock when reading the format struct and
// acquires both locks if reinitialization is required.
int MaybeInitializeRender(const ProcessingConfig& processing_config)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
// Called by capture: Holds the capture lock when reading the format struct
// and acquires both locks if reinitialization is needed.
int MaybeInitializeCapture(const StreamConfig& input_config,
@@ -247,57 +247,58 @@
// Method for updating the state keeping track of the active submodules.
// Returns a bool indicating whether the state has changed.
bool UpdateActiveSubmoduleStates()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Methods requiring APM running in a single-threaded manner, requiring both
// the render and capture lock to be acquired.
int InitializeLocked(const ProcessingConfig& config)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
void InitializeResidualEchoDetector()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
void InitializeEchoController()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
// Initializations of capture-only submodules, requiring the capture lock
// already acquired.
void InitializeHighPassFilter(bool forced_reset)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializeVoiceDetector() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializeGainController1() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializeVoiceDetector() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializeGainController1() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void InitializeTransientSuppressor()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializeNoiseSuppressor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializePreAmplifier() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializePostProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void InitializeAnalyzer() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializeNoiseSuppressor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializePreAmplifier() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializePostProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void InitializeAnalyzer() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Initializations of render-only submodules, requiring the render lock
// already acquired.
- void InitializePreProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
+ void InitializePreProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
// Sample rate used for the fullband processing.
int proc_fullband_sample_rate_hz() const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Empties and handles the respective RuntimeSetting queues.
void HandleCaptureRuntimeSettings()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
- void HandleRenderRuntimeSettings() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ void HandleRenderRuntimeSettings()
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
- void EmptyQueuedRenderAudio() RTC_LOCKS_EXCLUDED(crit_capture_);
+ void EmptyQueuedRenderAudio() RTC_LOCKS_EXCLUDED(mutex_capture_);
void EmptyQueuedRenderAudioLocked()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void AllocateRenderQueue()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
void QueueBandedRenderAudio(AudioBuffer* audio)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
void QueueNonbandedRenderAudio(AudioBuffer* audio)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
// Capture-side exclusive methods possibly running APM in a multi-threaded
// manner that are called with the render lock already acquired.
- int ProcessCaptureStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ int ProcessCaptureStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Render-side exclusive methods possibly running APM in a multi-threaded
// manner that are called with the render lock already acquired.
@@ -305,8 +306,8 @@
int AnalyzeReverseStreamLocked(const float* const* src,
const StreamConfig& input_config,
const StreamConfig& output_config)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
- int ProcessRenderStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
+ int ProcessRenderStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
// Collects configuration settings from public and private
// submodules to be saved as an audioproc::Config message on the
@@ -314,29 +315,30 @@
// config if it is different from the last saved one; if |forced|,
// writes the config regardless of the last saved.
void WriteAecDumpConfigMessage(bool forced)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Notifies attached AecDump of current configuration and capture data.
void RecordUnprocessedCaptureStream(const float* const* capture_stream)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void RecordUnprocessedCaptureStream(const int16_t* const data,
const StreamConfig& config)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Notifies attached AecDump of current configuration and
// processed capture data and issues a capture stream recording
// request.
void RecordProcessedCaptureStream(
const float* const* processed_capture_stream)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void RecordProcessedCaptureStream(const int16_t* const data,
const StreamConfig& config)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Notifies attached AecDump about current state (delay, drift, etc).
- void RecordAudioProcessingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+ void RecordAudioProcessingState()
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// AecDump instance used for optionally logging APM config, input
// and output to file in the AEC-dump format defined in debug.proto.
@@ -344,18 +346,18 @@
// Hold the last config written with AecDump for avoiding writing
// the same config twice.
- InternalAPMConfig apm_config_for_aec_dump_ RTC_GUARDED_BY(crit_capture_);
+ InternalAPMConfig apm_config_for_aec_dump_ RTC_GUARDED_BY(mutex_capture_);
// Critical sections.
- rtc::CriticalSection crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_);
- rtc::CriticalSection crit_capture_;
+ mutable Mutex mutex_render_ RTC_ACQUIRED_BEFORE(mutex_capture_);
+ mutable Mutex mutex_capture_;
// Struct containing the Config specifying the behavior of APM.
AudioProcessing::Config config_;
// Overrides for testing the exclusion of some submodules from the build.
ApmSubmoduleCreationOverrides submodule_creation_overrides_
- RTC_GUARDED_BY(crit_capture_);
+ RTC_GUARDED_BY(mutex_capture_);
// Class containing information about what submodules are active.
SubmoduleStates submodule_states_;
@@ -444,7 +446,7 @@
const float* keyboard_data = nullptr;
} keyboard_info;
int cached_stream_analog_level_ = 0;
- } capture_ RTC_GUARDED_BY(crit_capture_);
+ } capture_ RTC_GUARDED_BY(mutex_capture_);
struct ApmCaptureNonLockedState {
ApmCaptureNonLockedState()
@@ -465,7 +467,7 @@
~ApmRenderState();
std::unique_ptr<AudioConverter> render_converter;
std::unique_ptr<AudioBuffer> render_audio;
- } render_ RTC_GUARDED_BY(crit_render_);
+ } render_ RTC_GUARDED_BY(mutex_render_);
// Class for statistics reporting. The class is thread-safe and no lock is
// needed when accessing it.
@@ -481,27 +483,28 @@
void UpdateStatistics(const AudioProcessingStats& new_stats);
private:
- rtc::CriticalSection crit_stats_;
- AudioProcessingStats cached_stats_ RTC_GUARDED_BY(crit_stats_);
+ Mutex mutex_stats_;
+ AudioProcessingStats cached_stats_ RTC_GUARDED_BY(mutex_stats_);
SwapQueue<AudioProcessingStats> stats_message_queue_;
} stats_reporter_;
- std::vector<int16_t> aecm_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
- std::vector<int16_t> aecm_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
+ std::vector<int16_t> aecm_render_queue_buffer_ RTC_GUARDED_BY(mutex_render_);
+ std::vector<int16_t> aecm_capture_queue_buffer_
+ RTC_GUARDED_BY(mutex_capture_);
- size_t agc_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
- RTC_GUARDED_BY(crit_capture_) = 0;
- std::vector<int16_t> agc_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
- std::vector<int16_t> agc_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
+ size_t agc_render_queue_element_max_size_ RTC_GUARDED_BY(mutex_render_)
+ RTC_GUARDED_BY(mutex_capture_) = 0;
+ std::vector<int16_t> agc_render_queue_buffer_ RTC_GUARDED_BY(mutex_render_);
+ std::vector<int16_t> agc_capture_queue_buffer_ RTC_GUARDED_BY(mutex_capture_);
- size_t red_render_queue_element_max_size_ RTC_GUARDED_BY(crit_render_)
- RTC_GUARDED_BY(crit_capture_) = 0;
- std::vector<float> red_render_queue_buffer_ RTC_GUARDED_BY(crit_render_);
- std::vector<float> red_capture_queue_buffer_ RTC_GUARDED_BY(crit_capture_);
+ size_t red_render_queue_element_max_size_ RTC_GUARDED_BY(mutex_render_)
+ RTC_GUARDED_BY(mutex_capture_) = 0;
+ std::vector<float> red_render_queue_buffer_ RTC_GUARDED_BY(mutex_render_);
+ std::vector<float> red_capture_queue_buffer_ RTC_GUARDED_BY(mutex_capture_);
- RmsLevel capture_input_rms_ RTC_GUARDED_BY(crit_capture_);
- RmsLevel capture_output_rms_ RTC_GUARDED_BY(crit_capture_);
- int capture_rms_interval_counter_ RTC_GUARDED_BY(crit_capture_) = 0;
+ RmsLevel capture_input_rms_ RTC_GUARDED_BY(mutex_capture_);
+ RmsLevel capture_output_rms_ RTC_GUARDED_BY(mutex_capture_);
+ int capture_rms_interval_counter_ RTC_GUARDED_BY(mutex_capture_) = 0;
// Lock protection not needed.
std::unique_ptr<
diff --git a/modules/audio_processing/audio_processing_impl_locking_unittest.cc b/modules/audio_processing/audio_processing_impl_locking_unittest.cc
index 5005394..ec165aa 100644
--- a/modules/audio_processing/audio_processing_impl_locking_unittest.cc
+++ b/modules/audio_processing/audio_processing_impl_locking_unittest.cc
@@ -16,10 +16,10 @@
#include "modules/audio_processing/audio_processing_impl.h"
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
#include "modules/audio_processing/test/test_utils.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/random.h"
+#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/sleep.h"
#include "test/gtest.h"
@@ -62,23 +62,23 @@
RandomGenerator() : rand_gen_(42U) {}
int RandInt(int min, int max) {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return rand_gen_.Rand(min, max);
}
int RandInt(int max) {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return rand_gen_.Rand(max);
}
float RandFloat() {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return rand_gen_.Rand<float>();
}
private:
- rtc::CriticalSection crit_;
- Random rand_gen_ RTC_GUARDED_BY(crit_);
+ Mutex mutex_;
+ Random rand_gen_ RTC_GUARDED_BY(mutex_);
};
// Variables related to the audio data and formats.
@@ -258,27 +258,27 @@
class FrameCounters {
public:
void IncreaseRenderCounter() {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
render_count++;
}
void IncreaseCaptureCounter() {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
capture_count++;
}
int GetCaptureCounter() const {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return capture_count;
}
int GetRenderCounter() const {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return render_count;
}
int CaptureMinusRenderCounters() const {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return capture_count - render_count;
}
@@ -287,14 +287,14 @@
}
bool BothCountersExceedeThreshold(int threshold) {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return (render_count > threshold && capture_count > threshold);
}
private:
- rtc::CriticalSection crit_;
- int render_count RTC_GUARDED_BY(crit_) = 0;
- int capture_count RTC_GUARDED_BY(crit_) = 0;
+ mutable Mutex mutex_;
+ int render_count RTC_GUARDED_BY(mutex_) = 0;
+ int capture_count RTC_GUARDED_BY(mutex_) = 0;
};
// Class for handling the capture side processing.