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/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);