Migrate audio/ to use webrtc::Mutex

Bug: webrtc:11567
Change-Id: Ic6a753f09aafb508690f4b8dadd4c99433fcfeb6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176741
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31635}
diff --git a/audio/BUILD.gn b/audio/BUILD.gn
index d2826d5..78f6aff 100644
--- a/audio/BUILD.gn
+++ b/audio/BUILD.gn
@@ -90,6 +90,7 @@
     "../rtc_base:rtc_task_queue",
     "../rtc_base:safe_minmax",
     "../rtc_base/experiments:field_trial_parser",
+    "../rtc_base/synchronization:mutex",
     "../rtc_base/synchronization:sequence_checker",
     "../rtc_base/task_utils:to_queued_task",
     "../system_wrappers",
diff --git a/audio/audio_level.cc b/audio/audio_level.cc
index 06702b4..7874b73 100644
--- a/audio/audio_level.cc
+++ b/audio/audio_level.cc
@@ -22,7 +22,7 @@
 AudioLevel::~AudioLevel() {}
 
 void AudioLevel::Reset() {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   abs_max_ = 0;
   count_ = 0;
   current_level_full_range_ = 0;
@@ -31,24 +31,24 @@
 }
 
 int16_t AudioLevel::LevelFullRange() const {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   return current_level_full_range_;
 }
 
 void AudioLevel::ResetLevelFullRange() {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   abs_max_ = 0;
   count_ = 0;
   current_level_full_range_ = 0;
 }
 
 double AudioLevel::TotalEnergy() const {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   return total_energy_;
 }
 
 double AudioLevel::TotalDuration() const {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   return total_duration_;
 }
 
@@ -63,7 +63,7 @@
 
   // Protect member access using a lock since this method is called on a
   // dedicated audio thread in the RecordedDataIsAvailable() callback.
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
 
   if (abs_value > abs_max_)
     abs_max_ = abs_value;
diff --git a/audio/audio_level.h b/audio/audio_level.h
index 430edb1..acd1231 100644
--- a/audio/audio_level.h
+++ b/audio/audio_level.h
@@ -11,7 +11,7 @@
 #ifndef AUDIO_AUDIO_LEVEL_H_
 #define AUDIO_AUDIO_LEVEL_H_
 
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/thread_annotations.h"
 
 namespace webrtc {
@@ -59,14 +59,14 @@
  private:
   enum { kUpdateFrequency = 10 };
 
-  rtc::CriticalSection crit_sect_;
+  mutable Mutex mutex_;
 
-  int16_t abs_max_ RTC_GUARDED_BY(crit_sect_);
-  int16_t count_ RTC_GUARDED_BY(crit_sect_);
-  int16_t current_level_full_range_ RTC_GUARDED_BY(crit_sect_);
+  int16_t abs_max_ RTC_GUARDED_BY(mutex_);
+  int16_t count_ RTC_GUARDED_BY(mutex_);
+  int16_t current_level_full_range_ RTC_GUARDED_BY(mutex_);
 
-  double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0;
-  double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0;
+  double total_energy_ RTC_GUARDED_BY(mutex_) = 0.0;
+  double total_duration_ RTC_GUARDED_BY(mutex_) = 0.0;
 };
 
 }  // namespace voe
diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc
index 301e42d..1856902 100644
--- a/audio/audio_send_stream.cc
+++ b/audio/audio_send_stream.cc
@@ -347,7 +347,7 @@
 
   // Set currently known overhead (used in ANA, opus only).
   {
-    rtc::CritScope cs(&overhead_per_packet_lock_);
+    MutexLock lock(&overhead_per_packet_lock_);
     UpdateOverheadForEncoder();
   }
 
@@ -422,7 +422,7 @@
     // TODO(https://crbug.com/webrtc/10771): All "media-source" related stats
     // should move from send-streams to the local audio sources or tracks; a
     // send-stream should not be required to read the microphone audio levels.
-    rtc::CritScope cs(&audio_level_lock_);
+    MutexLock lock(&audio_level_lock_);
     audio_level_.ComputeLevel(*audio_frame, duration);
   }
   channel_send_->ProcessAndEncodeAudio(std::move(audio_frame));
@@ -488,7 +488,7 @@
   }
 
   {
-    rtc::CritScope cs(&audio_level_lock_);
+    MutexLock lock(&audio_level_lock_);
     stats.audio_level = audio_level_.LevelFullRange();
     stats.total_input_energy = audio_level_.TotalEnergy();
     stats.total_input_duration = audio_level_.TotalDuration();
@@ -513,7 +513,7 @@
   worker_queue_->PostTask([&]() {
     // Poll if overhead has changed, which it can do if ack triggers us to stop
     // sending mid/rid.
-    rtc::CritScope cs(&overhead_per_packet_lock_);
+    MutexLock lock(&overhead_per_packet_lock_);
     UpdateOverheadForEncoder();
   });
 }
@@ -538,7 +538,7 @@
 void AudioSendStream::SetTransportOverhead(
     int transport_overhead_per_packet_bytes) {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope cs(&overhead_per_packet_lock_);
+  MutexLock lock(&overhead_per_packet_lock_);
   transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes;
   UpdateOverheadForEncoder();
 }
@@ -570,7 +570,7 @@
 }
 
 size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const {
-  rtc::CritScope cs(&overhead_per_packet_lock_);
+  MutexLock lock(&overhead_per_packet_lock_);
   return GetPerPacketOverheadBytes();
 }
 
@@ -670,7 +670,7 @@
   // Set currently known overhead (used in ANA, opus only).
   // If overhead changes later, it will be updated in UpdateOverheadForEncoder.
   {
-    rtc::CritScope cs(&overhead_per_packet_lock_);
+    MutexLock lock(&overhead_per_packet_lock_);
     size_t overhead = GetPerPacketOverheadBytes();
     if (overhead > 0) {
       encoder->OnReceivedOverhead(overhead);
diff --git a/audio/audio_send_stream.h b/audio/audio_send_stream.h
index 13166d4..bb2e7b1 100644
--- a/audio/audio_send_stream.h
+++ b/audio/audio_send_stream.h
@@ -24,6 +24,7 @@
 #include "rtc_base/constructor_magic.h"
 #include "rtc_base/experiments/struct_parameters_parser.h"
 #include "rtc_base/race_checker.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/task_queue.h"
 #include "rtc_base/thread_checker.h"
 
@@ -166,7 +167,7 @@
   int encoder_sample_rate_hz_ = 0;
   size_t encoder_num_channels_ = 0;
   bool sending_ = false;
-  rtc::CriticalSection audio_level_lock_;
+  mutable Mutex audio_level_lock_;
   // Keeps track of audio level, total audio energy and total samples duration.
   // https://w3c.github.io/webrtc-stats/#dom-rtcaudiohandlerstats-totalaudioenergy
   webrtc::voe::AudioLevel audio_level_;
@@ -194,7 +195,7 @@
       const std::vector<RtpExtension>& extensions);
   static int TransportSeqNumId(const Config& config);
 
-  rtc::CriticalSection overhead_per_packet_lock_;
+  mutable Mutex overhead_per_packet_lock_;
   size_t overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
 
   // Current transport overhead (ICE, TURN, etc.)
diff --git a/audio/audio_transport_impl.cc b/audio/audio_transport_impl.cc
index 7648fb9..11b37ff 100644
--- a/audio/audio_transport_impl.cc
+++ b/audio/audio_transport_impl.cc
@@ -118,7 +118,7 @@
   size_t send_num_channels = 0;
   bool swap_stereo_channels = false;
   {
-    rtc::CritScope lock(&capture_lock_);
+    MutexLock lock(&capture_lock_);
     send_sample_rate_hz = send_sample_rate_hz_;
     send_num_channels = send_num_channels_;
     swap_stereo_channels = swap_stereo_channels_;
@@ -149,7 +149,7 @@
   // Copy frame and push to each sending stream. The copy is required since an
   // encoding task will be posted internally to each stream.
   {
-    rtc::CritScope lock(&capture_lock_);
+    MutexLock lock(&capture_lock_);
     typing_noise_detected_ = typing_detected;
 
     RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0);
@@ -237,19 +237,19 @@
 void AudioTransportImpl::UpdateAudioSenders(std::vector<AudioSender*> senders,
                                             int send_sample_rate_hz,
                                             size_t send_num_channels) {
-  rtc::CritScope lock(&capture_lock_);
+  MutexLock lock(&capture_lock_);
   audio_senders_ = std::move(senders);
   send_sample_rate_hz_ = send_sample_rate_hz;
   send_num_channels_ = send_num_channels;
 }
 
 void AudioTransportImpl::SetStereoChannelSwapping(bool enable) {
-  rtc::CritScope lock(&capture_lock_);
+  MutexLock lock(&capture_lock_);
   swap_stereo_channels_ = enable;
 }
 
 bool AudioTransportImpl::typing_noise_detected() const {
-  rtc::CritScope lock(&capture_lock_);
+  MutexLock lock(&capture_lock_);
   return typing_noise_detected_;
 }
 }  // namespace webrtc
diff --git a/audio/audio_transport_impl.h b/audio/audio_transport_impl.h
index 2d9b4cf..1643a29 100644
--- a/audio/audio_transport_impl.h
+++ b/audio/audio_transport_impl.h
@@ -20,7 +20,7 @@
 #include "modules/audio_processing/include/audio_processing.h"
 #include "modules/audio_processing/typing_detection.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 {
@@ -71,7 +71,7 @@
   AudioProcessing* audio_processing_ = nullptr;
 
   // Capture side.
-  rtc::CriticalSection capture_lock_;
+  mutable Mutex capture_lock_;
   std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
   int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
   size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;
diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc
index 34b6d09..9cbaabb 100644
--- a/audio/channel_receive.cc
+++ b/audio/channel_receive.cc
@@ -40,12 +40,12 @@
 #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
 #include "modules/utility/include/process_thread.h"
 #include "rtc_base/checks.h"
-#include "rtc_base/critical_section.h"
 #include "rtc_base/format_macros.h"
 #include "rtc_base/location.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/numerics/safe_minmax.h"
 #include "rtc_base/race_checker.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/thread_checker.h"
 #include "rtc_base/time_utils.h"
 #include "system_wrappers/include/metrics.h"
@@ -188,7 +188,7 @@
       rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
 
   bool Playing() const {
-    rtc::CritScope lock(&playing_lock_);
+    MutexLock lock(&playing_lock_);
     return playing_;
   }
 
@@ -204,10 +204,10 @@
   // audio thread to another, but access is still sequential.
   rtc::RaceChecker audio_thread_race_checker_;
   rtc::RaceChecker video_capture_thread_race_checker_;
-  rtc::CriticalSection _callbackCritSect;
-  rtc::CriticalSection volume_settings_critsect_;
+  Mutex callback_mutex_;
+  Mutex volume_settings_mutex_;
 
-  rtc::CriticalSection playing_lock_;
+  mutable Mutex playing_lock_;
   bool playing_ RTC_GUARDED_BY(&playing_lock_) = false;
 
   RtcEventLog* const event_log_;
@@ -221,7 +221,7 @@
 
   // Info for GetSyncInfo is updated on network or worker thread, and queried on
   // the worker thread.
-  rtc::CriticalSection sync_info_lock_;
+  mutable Mutex sync_info_lock_;
   absl::optional<uint32_t> last_received_rtp_timestamp_
       RTC_GUARDED_BY(&sync_info_lock_);
   absl::optional<int64_t> last_received_rtp_system_time_ms_
@@ -237,7 +237,7 @@
   // Timestamp of the audio pulled from NetEq.
   absl::optional<uint32_t> jitter_buffer_playout_timestamp_;
 
-  rtc::CriticalSection video_sync_lock_;
+  mutable Mutex video_sync_lock_;
   uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
   absl::optional<int64_t> playout_timestamp_rtp_time_ms_
       RTC_GUARDED_BY(video_sync_lock_);
@@ -247,7 +247,7 @@
   absl::optional<int64_t> playout_timestamp_ntp_time_ms_
       RTC_GUARDED_BY(video_sync_lock_);
 
-  rtc::CriticalSection ts_stats_lock_;
+  mutable Mutex ts_stats_lock_;
 
   std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
   // The rtp timestamp of the first played out audio frame.
@@ -259,10 +259,10 @@
   // uses
   ProcessThread* _moduleProcessThreadPtr;
   AudioDeviceModule* _audioDeviceModulePtr;
-  float _outputGain RTC_GUARDED_BY(volume_settings_critsect_);
+  float _outputGain RTC_GUARDED_BY(volume_settings_mutex_);
 
   // An associated send channel.
-  rtc::CriticalSection assoc_send_channel_lock_;
+  mutable Mutex assoc_send_channel_lock_;
   const ChannelSendInterface* associated_send_channel_
       RTC_GUARDED_BY(assoc_send_channel_lock_);
 
@@ -359,7 +359,7 @@
     // scaling/panning, as that applies to the mix operation.
     // External recipients of the audio (e.g. via AudioTrack), will do their
     // own mixing/dynamic processing.
-    rtc::CritScope cs(&_callbackCritSect);
+    MutexLock lock(&callback_mutex_);
     if (audio_sink_) {
       AudioSinkInterface::Data data(
           audio_frame->data(), audio_frame->samples_per_channel_,
@@ -371,7 +371,7 @@
 
   float output_gain = 1.0f;
   {
-    rtc::CritScope cs(&volume_settings_critsect_);
+    MutexLock lock(&volume_settings_mutex_);
     output_gain = _outputGain;
   }
 
@@ -403,7 +403,7 @@
         (GetRtpTimestampRateHz() / 1000);
 
     {
-      rtc::CritScope lock(&ts_stats_lock_);
+      MutexLock lock(&ts_stats_lock_);
       // Compute ntp time.
       audio_frame->ntp_time_ms_ =
           ntp_estimator_.Estimate(audio_frame->timestamp_);
@@ -421,7 +421,7 @@
     RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.TargetJitterBufferDelayMs",
                               acm_receiver_.TargetDelayMs());
     const int jitter_buffer_delay = acm_receiver_.FilteredCurrentDelayMs();
-    rtc::CritScope lock(&video_sync_lock_);
+    MutexLock lock(&video_sync_lock_);
     RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDelayEstimateMs",
                               jitter_buffer_delay + playout_delay_ms_);
     RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverJitterBufferDelayMs",
@@ -532,19 +532,19 @@
 
 void ChannelReceive::SetSink(AudioSinkInterface* sink) {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope cs(&_callbackCritSect);
+  MutexLock lock(&callback_mutex_);
   audio_sink_ = sink;
 }
 
 void ChannelReceive::StartPlayout() {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope lock(&playing_lock_);
+  MutexLock lock(&playing_lock_);
   playing_ = true;
 }
 
 void ChannelReceive::StopPlayout() {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope lock(&playing_lock_);
+  MutexLock lock(&playing_lock_);
   playing_ = false;
   _outputAudioLevel.ResetLevelFullRange();
 }
@@ -570,7 +570,7 @@
   int64_t now_ms = rtc::TimeMillis();
 
   {
-    rtc::CritScope cs(&sync_info_lock_);
+    MutexLock lock(&sync_info_lock_);
     last_received_rtp_timestamp_ = packet.Timestamp();
     last_received_rtp_system_time_ms_ = now_ms;
   }
@@ -677,7 +677,7 @@
   }
 
   {
-    rtc::CritScope lock(&ts_stats_lock_);
+    MutexLock lock(&ts_stats_lock_);
     ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
   }
 }
@@ -699,7 +699,7 @@
 
 void ChannelReceive::SetChannelOutputVolumeScaling(float scaling) {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope cs(&volume_settings_critsect_);
+  MutexLock lock(&volume_settings_mutex_);
   _outputGain = scaling;
 }
 
@@ -759,7 +759,7 @@
 
   // --- Timestamps
   {
-    rtc::CritScope lock(&ts_stats_lock_);
+    MutexLock lock(&ts_stats_lock_);
     stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_;
   }
   return stats;
@@ -787,7 +787,7 @@
 void ChannelReceive::SetAssociatedSendChannel(
     const ChannelSendInterface* channel) {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope lock(&assoc_send_channel_lock_);
+  MutexLock lock(&assoc_send_channel_lock_);
   associated_send_channel_ = channel;
 }
 
@@ -818,7 +818,7 @@
 uint32_t ChannelReceive::GetDelayEstimate() const {
   RTC_DCHECK(worker_thread_checker_.IsCurrent() ||
              module_process_thread_checker_.IsCurrent());
-  rtc::CritScope lock(&video_sync_lock_);
+  MutexLock lock(&video_sync_lock_);
   return acm_receiver_.FilteredCurrentDelayMs() + playout_delay_ms_;
 }
 
@@ -838,7 +838,7 @@
                                             int64_t* time_ms) const {
   RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
   {
-    rtc::CritScope lock(&video_sync_lock_);
+    MutexLock lock(&video_sync_lock_);
     if (!playout_timestamp_rtp_time_ms_)
       return false;
     *rtp_timestamp = playout_timestamp_rtp_;
@@ -850,7 +850,7 @@
 void ChannelReceive::SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
                                                        int64_t time_ms) {
   RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
-  rtc::CritScope lock(&video_sync_lock_);
+  MutexLock lock(&video_sync_lock_);
   playout_timestamp_ntp_ = ntp_timestamp_ms;
   playout_timestamp_ntp_time_ms_ = time_ms;
 }
@@ -858,7 +858,7 @@
 absl::optional<int64_t>
 ChannelReceive::GetCurrentEstimatedPlayoutNtpTimestampMs(int64_t now_ms) const {
   RTC_DCHECK(worker_thread_checker_.IsCurrent());
-  rtc::CritScope lock(&video_sync_lock_);
+  MutexLock lock(&video_sync_lock_);
   if (!playout_timestamp_ntp_ || !playout_timestamp_ntp_time_ms_)
     return absl::nullopt;
 
@@ -883,7 +883,7 @@
     return absl::nullopt;
   }
   {
-    rtc::CritScope cs(&sync_info_lock_);
+    MutexLock lock(&sync_info_lock_);
     if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
       return absl::nullopt;
     }
@@ -917,7 +917,7 @@
   playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000));
 
   {
-    rtc::CritScope lock(&video_sync_lock_);
+    MutexLock lock(&video_sync_lock_);
     if (!rtcp && playout_timestamp != playout_timestamp_rtp_) {
       playout_timestamp_rtp_ = playout_timestamp;
       playout_timestamp_rtp_time_ms_ = now_ms;
@@ -947,7 +947,7 @@
   // TODO(nisse): Could we check the return value from the ->RTT() call below,
   // instead of checking if we have any report blocks?
   if (report_blocks.empty()) {
-    rtc::CritScope lock(&assoc_send_channel_lock_);
+    MutexLock lock(&assoc_send_channel_lock_);
     // Tries to get RTT from an associated channel.
     if (!associated_send_channel_) {
       return 0;
diff --git a/audio/channel_send.cc b/audio/channel_send.cc
index 2e7ca72..80e7ab2 100644
--- a/audio/channel_send.cc
+++ b/audio/channel_send.cc
@@ -39,6 +39,7 @@
 #include "rtc_base/numerics/safe_conversions.h"
 #include "rtc_base/race_checker.h"
 #include "rtc_base/rate_limiter.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/task_queue.h"
 #include "rtc_base/thread_checker.h"
 #include "rtc_base/time_utils.h"
@@ -186,7 +187,7 @@
   // audio thread to another, but access is still sequential.
   rtc::RaceChecker audio_thread_race_checker_;
 
-  rtc::CriticalSection volume_settings_critsect_;
+  mutable Mutex volume_settings_mutex_;
 
   bool sending_ RTC_GUARDED_BY(&worker_thread_checker_) = false;
 
@@ -201,7 +202,7 @@
   // uses
   ProcessThread* const _moduleProcessThreadPtr;
   RmsLevel rms_level_ RTC_GUARDED_BY(encoder_queue_);
-  bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_);
+  bool input_mute_ RTC_GUARDED_BY(volume_settings_mutex_);
   bool previous_frame_muted_ RTC_GUARDED_BY(encoder_queue_);
   // VoeRTP_RTCP
   // TODO(henrika): can today be accessed on the main thread and on the
@@ -234,8 +235,8 @@
   rtc::scoped_refptr<ChannelSendFrameTransformerDelegate>
       frame_transformer_delegate_ RTC_GUARDED_BY(encoder_queue_);
 
-  rtc::CriticalSection bitrate_crit_section_;
-  int configured_bitrate_bps_ RTC_GUARDED_BY(bitrate_crit_section_) = 0;
+  mutable Mutex bitrate_mutex_;
+  int configured_bitrate_bps_ RTC_GUARDED_BY(bitrate_mutex_) = 0;
 
   // Defined last to ensure that there are no running tasks when the other
   // members are destroyed.
@@ -250,20 +251,20 @@
 
   void SetPacketPacer(RtpPacketSender* rtp_packet_pacer) {
     RTC_DCHECK(thread_checker_.IsCurrent());
-    rtc::CritScope lock(&crit_);
+    MutexLock lock(&mutex_);
     rtp_packet_pacer_ = rtp_packet_pacer;
   }
 
   void EnqueuePackets(
       std::vector<std::unique_ptr<RtpPacketToSend>> packets) override {
-    rtc::CritScope lock(&crit_);
+    MutexLock lock(&mutex_);
     rtp_packet_pacer_->EnqueuePackets(std::move(packets));
   }
 
  private:
   rtc::ThreadChecker thread_checker_;
-  rtc::CriticalSection crit_;
-  RtpPacketSender* rtp_packet_pacer_ RTC_GUARDED_BY(&crit_);
+  Mutex mutex_;
+  RtpPacketSender* rtp_packet_pacer_ RTC_GUARDED_BY(&mutex_);
 };
 
 class VoERtcpObserver : public RtcpBandwidthObserver {
@@ -273,12 +274,12 @@
   ~VoERtcpObserver() override {}
 
   void SetBandwidthObserver(RtcpBandwidthObserver* bandwidth_observer) {
-    rtc::CritScope lock(&crit_);
+    MutexLock lock(&mutex_);
     bandwidth_observer_ = bandwidth_observer;
   }
 
   void OnReceivedEstimatedBitrate(uint32_t bitrate) override {
-    rtc::CritScope lock(&crit_);
+    MutexLock lock(&mutex_);
     if (bandwidth_observer_) {
       bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate);
     }
@@ -288,7 +289,7 @@
                                     int64_t rtt,
                                     int64_t now_ms) override {
     {
-      rtc::CritScope lock(&crit_);
+      MutexLock lock(&mutex_);
       if (bandwidth_observer_) {
         bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, rtt,
                                                           now_ms);
@@ -336,8 +337,8 @@
   ChannelSend* owner_;
   // Maps remote side ssrc to extended highest sequence number received.
   std::map<uint32_t, uint32_t> extended_max_sequence_number_;
-  rtc::CriticalSection crit_;
-  RtcpBandwidthObserver* bandwidth_observer_ RTC_GUARDED_BY(crit_);
+  Mutex mutex_;
+  RtcpBandwidthObserver* bandwidth_observer_ RTC_GUARDED_BY(mutex_);
 };
 
 int32_t ChannelSend::SendData(AudioFrameType frameType,
@@ -606,7 +607,7 @@
   // rules.
   // RTC_DCHECK(worker_thread_checker_.IsCurrent() ||
   //            module_process_thread_checker_.IsCurrent());
-  rtc::CritScope lock(&bitrate_crit_section_);
+  MutexLock lock(&bitrate_mutex_);
 
   CallEncoder([&](AudioEncoder* encoder) {
     encoder->OnReceivedUplinkAllocation(update);
@@ -616,7 +617,7 @@
 }
 
 int ChannelSend::GetBitrate() const {
-  rtc::CritScope lock(&bitrate_crit_section_);
+  MutexLock lock(&bitrate_mutex_);
   return configured_bitrate_bps_;
 }
 
@@ -651,12 +652,12 @@
 
 void ChannelSend::SetInputMute(bool enable) {
   RTC_DCHECK_RUN_ON(&worker_thread_checker_);
-  rtc::CritScope cs(&volume_settings_critsect_);
+  MutexLock lock(&volume_settings_mutex_);
   input_mute_ = enable;
 }
 
 bool ChannelSend::InputMute() const {
-  rtc::CritScope cs(&volume_settings_critsect_);
+  MutexLock lock(&volume_settings_mutex_);
   return input_mute_;
 }
 
diff --git a/audio/channel_send_frame_transformer_delegate.cc b/audio/channel_send_frame_transformer_delegate.cc
index 53b573e..72a459d 100644
--- a/audio/channel_send_frame_transformer_delegate.cc
+++ b/audio/channel_send_frame_transformer_delegate.cc
@@ -77,7 +77,7 @@
   frame_transformer_->UnregisterTransformedFrameCallback();
   frame_transformer_ = nullptr;
 
-  rtc::CritScope lock(&send_lock_);
+  MutexLock lock(&send_lock_);
   send_frame_callback_ = SendFrameCallback();
 }
 
@@ -97,7 +97,7 @@
 
 void ChannelSendFrameTransformerDelegate::OnTransformedFrame(
     std::unique_ptr<TransformableFrameInterface> frame) {
-  rtc::CritScope lock(&send_lock_);
+  MutexLock lock(&send_lock_);
   if (!send_frame_callback_)
     return;
   rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = this;
@@ -109,7 +109,7 @@
 
 void ChannelSendFrameTransformerDelegate::SendFrame(
     std::unique_ptr<TransformableFrameInterface> frame) const {
-  rtc::CritScope lock(&send_lock_);
+  MutexLock lock(&send_lock_);
   RTC_DCHECK_RUN_ON(encoder_queue_);
   if (!send_frame_callback_)
     return;
diff --git a/audio/channel_send_frame_transformer_delegate.h b/audio/channel_send_frame_transformer_delegate.h
index 5added7..531d1bc 100644
--- a/audio/channel_send_frame_transformer_delegate.h
+++ b/audio/channel_send_frame_transformer_delegate.h
@@ -16,7 +16,7 @@
 #include "api/frame_transformer_interface.h"
 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
 #include "rtc_base/buffer.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/synchronization/sequence_checker.h"
 #include "rtc_base/task_queue.h"
 
@@ -72,7 +72,7 @@
   ~ChannelSendFrameTransformerDelegate() override = default;
 
  private:
-  rtc::CriticalSection send_lock_;
+  mutable Mutex send_lock_;
   SendFrameCallback send_frame_callback_ RTC_GUARDED_BY(send_lock_);
   rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_;
   rtc::TaskQueue* encoder_queue_ RTC_GUARDED_BY(send_lock_);
diff --git a/audio/voip/BUILD.gn b/audio/voip/BUILD.gn
index 84a0ad7..52f9d07 100644
--- a/audio/voip/BUILD.gn
+++ b/audio/voip/BUILD.gn
@@ -26,6 +26,7 @@
     "../../modules/utility:utility",
     "../../rtc_base:criticalsection",
     "../../rtc_base:logging",
+    "../../rtc_base/synchronization:mutex",
   ]
   absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
 }
@@ -74,6 +75,7 @@
     "../../rtc_base:logging",
     "../../rtc_base:safe_minmax",
     "../../rtc_base:timeutils",
+    "../../rtc_base/synchronization:mutex",
     "../utility:audio_frame_operations",
   ]
 }
@@ -95,6 +97,7 @@
     "../../rtc_base:rtc_task_queue",
     "../../rtc_base:thread_checker",
     "../../rtc_base:timeutils",
+    "../../rtc_base/synchronization:mutex",
     "../utility:audio_frame_operations",
   ]
 }
diff --git a/audio/voip/audio_egress.h b/audio/voip/audio_egress.h
index 20b0bac..8ec048f 100644
--- a/audio/voip/audio_egress.h
+++ b/audio/voip/audio_egress.h
@@ -22,6 +22,7 @@
 #include "modules/rtp_rtcp/include/report_block_data.h"
 #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
 #include "modules/rtp_rtcp/source/rtp_sender_audio.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/task_queue.h"
 #include "rtc_base/thread_checker.h"
 #include "rtc_base/time_utils.h"
@@ -72,7 +73,7 @@
   // Retrieve current encoder format info. This returns encoder format set
   // by SetEncoder() and if encoder is not set, this will return nullopt.
   absl::optional<SdpAudioFormat> GetEncoderFormat() const {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     return encoder_format_;
   }
 
@@ -99,11 +100,11 @@
 
  private:
   void SetEncoderFormat(const SdpAudioFormat& encoder_format) {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     encoder_format_ = encoder_format;
   }
 
-  rtc::CriticalSection lock_;
+  mutable Mutex lock_;
 
   // Current encoder format selected by caller.
   absl::optional<SdpAudioFormat> encoder_format_ RTC_GUARDED_BY(lock_);
diff --git a/audio/voip/audio_ingress.cc b/audio/voip/audio_ingress.cc
index 68864eb..560055d 100644
--- a/audio/voip/audio_ingress.cc
+++ b/audio/voip/audio_ingress.cc
@@ -17,7 +17,6 @@
 #include "api/audio_codecs/audio_format.h"
 #include "audio/utility/audio_frame_operations.h"
 #include "modules/audio_coding/include/audio_coding_module.h"
-#include "rtc_base/critical_section.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/numerics/safe_minmax.h"
 
@@ -83,7 +82,7 @@
     // Compute elapsed and NTP times.
     int64_t unwrap_timestamp;
     {
-      rtc::CritScope lock(&lock_);
+      MutexLock lock(&lock_);
       unwrap_timestamp =
           timestamp_wrap_handler_.Unwrap(audio_frame->timestamp_);
       audio_frame->ntp_time_ms_ =
@@ -107,7 +106,7 @@
 void AudioIngress::SetReceiveCodecs(
     const std::map<int, SdpAudioFormat>& codecs) {
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     for (const auto& kv : codecs) {
       receive_codec_info_[kv.first] = kv.second.clockrate_hz;
     }
@@ -125,7 +124,7 @@
 
   // Set payload type's sampling rate before we feed it into ReceiveStatistics.
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     const auto& it =
         receive_codec_info_.find(rtp_packet_received.PayloadType());
     // If sampling rate info is not available in our received codec set, it
@@ -185,7 +184,7 @@
   }
 
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
   }
 }
diff --git a/audio/voip/audio_ingress.h b/audio/voip/audio_ingress.h
index 15f7900..5a8df21 100644
--- a/audio/voip/audio_ingress.h
+++ b/audio/voip/audio_ingress.h
@@ -28,7 +28,7 @@
 #include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
 #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/time_utils.h"
 
 namespace webrtc {
@@ -131,7 +131,7 @@
   // Synchronizaton is handled internally by voe::AudioLevel.
   voe::AudioLevel output_audio_level_;
 
-  rtc::CriticalSection lock_;
+  Mutex lock_;
 
   RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(lock_);
 
diff --git a/audio/voip/voip_core.cc b/audio/voip/voip_core.cc
index 3275f02..7292644 100644
--- a/audio/voip/voip_core.cc
+++ b/audio/voip/voip_core.cc
@@ -15,7 +15,6 @@
 #include <utility>
 
 #include "api/audio_codecs/audio_format.h"
-#include "rtc_base/critical_section.h"
 #include "rtc_base/logging.h"
 
 namespace webrtc {
@@ -134,7 +133,7 @@
           process_thread_.get(), audio_mixer_.get(), decoder_factory_);
 
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
 
     channel = static_cast<ChannelId>(next_channel_id_);
     channels_[*channel] = audio_channel;
@@ -154,7 +153,7 @@
   // Destroy channel outside of the lock.
   rtc::scoped_refptr<AudioChannel> audio_channel;
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
 
     auto iter = channels_.find(channel);
     if (iter != channels_.end()) {
@@ -170,7 +169,7 @@
 rtc::scoped_refptr<AudioChannel> VoipCore::GetChannel(ChannelId channel) {
   rtc::scoped_refptr<AudioChannel> audio_channel;
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     auto iter = channels_.find(channel);
     if (iter != channels_.end()) {
       audio_channel = iter->second;
@@ -191,7 +190,7 @@
   int max_sampling_rate = 8000;
   size_t max_num_channels = 1;
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     // Reserve to prevent run time vector re-allocation.
     audio_senders.reserve(channels_.size());
     for (auto kv : channels_) {
@@ -290,7 +289,7 @@
 
   bool stop_device = true;
   {
-    rtc::CritScope lock(&lock_);
+    MutexLock lock(&lock_);
     for (auto kv : channels_) {
       rtc::scoped_refptr<AudioChannel>& channel = kv.second;
       if (channel->IsPlaying()) {
diff --git a/audio/voip/voip_core.h b/audio/voip/voip_core.h
index 08929d3..22a65599 100644
--- a/audio/voip/voip_core.h
+++ b/audio/voip/voip_core.h
@@ -31,7 +31,7 @@
 #include "modules/audio_mixer/audio_mixer_impl.h"
 #include "modules/audio_processing/include/audio_processing.h"
 #include "modules/utility/include/process_thread.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
 
 namespace webrtc {
 
@@ -123,7 +123,7 @@
   // Must be placed before |channels_| for proper destruction.
   std::unique_ptr<ProcessThread> process_thread_;
 
-  rtc::CriticalSection lock_;
+  Mutex lock_;
 
   // Member to track a next ChannelId for new AudioChannel.
   int next_channel_id_ RTC_GUARDED_BY(lock_) = 0;