Migrate modules/congestion_controller to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: I284eaebf863e0c63d2aa162a5df56380f9cf4838
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178841
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31659}
diff --git a/modules/congestion_controller/BUILD.gn b/modules/congestion_controller/BUILD.gn
index 6f2b853..231ff5e 100644
--- a/modules/congestion_controller/BUILD.gn
+++ b/modules/congestion_controller/BUILD.gn
@@ -28,6 +28,7 @@
     "..:module_api",
     "../../api/transport:field_trial_based_config",
     "../../api/transport:network_control",
+    "../../rtc_base/synchronization:mutex",
     "../pacing",
     "../remote_bitrate_estimator",
     "../rtp_rtcp:rtp_rtcp_format",
diff --git a/modules/congestion_controller/include/receive_side_congestion_controller.h b/modules/congestion_controller/include/receive_side_congestion_controller.h
index 4f13b4d..6cd8be3 100644
--- a/modules/congestion_controller/include/receive_side_congestion_controller.h
+++ b/modules/congestion_controller/include/receive_side_congestion_controller.h
@@ -19,7 +19,7 @@
 #include "modules/include/module.h"
 #include "modules/remote_bitrate_estimator/remote_estimator_proxy.h"
 #include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
 
 namespace webrtc {
 class RemoteBitrateEstimator;
@@ -87,11 +87,11 @@
 
    private:
     void PickEstimatorFromHeader(const RTPHeader& header)
-        RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
-    void PickEstimator() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+        RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+    void PickEstimator() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
     RemoteBitrateObserver* observer_;
     Clock* const clock_;
-    rtc::CriticalSection crit_sect_;
+    mutable Mutex mutex_;
     std::unique_ptr<RemoteBitrateEstimator> rbe_;
     bool using_absolute_send_time_;
     uint32_t packets_since_absolute_send_time_;
diff --git a/modules/congestion_controller/receive_side_congestion_controller.cc b/modules/congestion_controller/receive_side_congestion_controller.cc
index 7448ec2..638cb2d 100644
--- a/modules/congestion_controller/receive_side_congestion_controller.cc
+++ b/modules/congestion_controller/receive_side_congestion_controller.cc
@@ -38,45 +38,45 @@
     int64_t arrival_time_ms,
     size_t payload_size,
     const RTPHeader& header) {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   PickEstimatorFromHeader(header);
   rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
 }
 
 void ReceiveSideCongestionController::WrappingBitrateEstimator::Process() {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   rbe_->Process();
 }
 
 int64_t ReceiveSideCongestionController::WrappingBitrateEstimator::
     TimeUntilNextProcess() {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   return rbe_->TimeUntilNextProcess();
 }
 
 void ReceiveSideCongestionController::WrappingBitrateEstimator::OnRttUpdate(
     int64_t avg_rtt_ms,
     int64_t max_rtt_ms) {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
 }
 
 void ReceiveSideCongestionController::WrappingBitrateEstimator::RemoveStream(
     unsigned int ssrc) {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   rbe_->RemoveStream(ssrc);
 }
 
 bool ReceiveSideCongestionController::WrappingBitrateEstimator::LatestEstimate(
     std::vector<unsigned int>* ssrcs,
     unsigned int* bitrate_bps) const {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   return rbe_->LatestEstimate(ssrcs, bitrate_bps);
 }
 
 void ReceiveSideCongestionController::WrappingBitrateEstimator::SetMinBitrate(
     int min_bitrate_bps) {
-  rtc::CritScope cs(&crit_sect_);
+  MutexLock lock(&mutex_);
   rbe_->SetMinBitrate(min_bitrate_bps);
   min_bitrate_bps_ = min_bitrate_bps;
 }
diff --git a/modules/congestion_controller/rtp/BUILD.gn b/modules/congestion_controller/rtp/BUILD.gn
index 45c53ed..2f97b67 100644
--- a/modules/congestion_controller/rtp/BUILD.gn
+++ b/modules/congestion_controller/rtp/BUILD.gn
@@ -58,6 +58,7 @@
     "../../../rtc_base:checks",
     "../../../rtc_base:rtc_base_approved",
     "../../../rtc_base/network:sent_packet",
+    "../../../rtc_base/synchronization:mutex",
     "../../../system_wrappers",
     "../../../system_wrappers:field_trial",
     "../../rtp_rtcp:rtp_rtcp_format",
diff --git a/modules/congestion_controller/rtp/transport_feedback_demuxer.cc b/modules/congestion_controller/rtp/transport_feedback_demuxer.cc
index 045ba38..c958a1c 100644
--- a/modules/congestion_controller/rtp/transport_feedback_demuxer.cc
+++ b/modules/congestion_controller/rtp/transport_feedback_demuxer.cc
@@ -18,7 +18,7 @@
 void TransportFeedbackDemuxer::RegisterStreamFeedbackObserver(
     std::vector<uint32_t> ssrcs,
     StreamFeedbackObserver* observer) {
-  rtc::CritScope cs(&observers_lock_);
+  MutexLock lock(&observers_lock_);
   RTC_DCHECK(observer);
   RTC_DCHECK(absl::c_find_if(observers_, [=](const auto& pair) {
                return pair.second == observer;
@@ -28,7 +28,7 @@
 
 void TransportFeedbackDemuxer::DeRegisterStreamFeedbackObserver(
     StreamFeedbackObserver* observer) {
-  rtc::CritScope cs(&observers_lock_);
+  MutexLock lock(&observers_lock_);
   RTC_DCHECK(observer);
   const auto it = absl::c_find_if(
       observers_, [=](const auto& pair) { return pair.second == observer; });
@@ -37,7 +37,7 @@
 }
 
 void TransportFeedbackDemuxer::AddPacket(const RtpPacketSendInfo& packet_info) {
-  rtc::CritScope cs(&lock_);
+  MutexLock lock(&lock_);
   if (packet_info.ssrc != 0) {
     StreamFeedbackObserver::StreamPacketInfo info;
     info.ssrc = packet_info.ssrc;
@@ -56,7 +56,7 @@
     const rtcp::TransportFeedback& feedback) {
   std::vector<StreamFeedbackObserver::StreamPacketInfo> stream_feedbacks;
   {
-    rtc::CritScope cs(&lock_);
+    MutexLock lock(&lock_);
     for (const auto& packet : feedback.GetAllPackets()) {
       int64_t seq_num =
           seq_num_unwrapper_.UnwrapWithoutUpdate(packet.sequence_number());
@@ -71,7 +71,7 @@
     }
   }
 
-  rtc::CritScope cs(&observers_lock_);
+  MutexLock lock(&observers_lock_);
   for (auto& observer : observers_) {
     std::vector<StreamFeedbackObserver::StreamPacketInfo> selected_feedback;
     for (const auto& packet_info : stream_feedbacks) {
diff --git a/modules/congestion_controller/rtp/transport_feedback_demuxer.h b/modules/congestion_controller/rtp/transport_feedback_demuxer.h
index bcd25d5..634a37ea 100644
--- a/modules/congestion_controller/rtp/transport_feedback_demuxer.h
+++ b/modules/congestion_controller/rtp/transport_feedback_demuxer.h
@@ -16,7 +16,7 @@
 
 #include "modules/include/module_common_types_public.h"
 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
 
 namespace webrtc {
 
@@ -32,7 +32,7 @@
   void OnTransportFeedback(const rtcp::TransportFeedback& feedback);
 
  private:
-  rtc::CriticalSection lock_;
+  Mutex lock_;
   SequenceNumberUnwrapper seq_num_unwrapper_ RTC_GUARDED_BY(&lock_);
   std::map<int64_t, StreamFeedbackObserver::StreamPacketInfo> history_
       RTC_GUARDED_BY(&lock_);
@@ -40,7 +40,7 @@
   // Maps a set of ssrcs to corresponding observer. Vectors are used rather than
   // set/map to ensure that the processing order is consistent independently of
   // the randomized ssrcs.
-  rtc::CriticalSection observers_lock_;
+  Mutex observers_lock_;
   std::vector<std::pair<std::vector<uint32_t>, StreamFeedbackObserver*>>
       observers_ RTC_GUARDED_BY(&observers_lock_);
 };