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;