Replaced CriticalSectionWrapper with rtc::CriticalSection in rtp_rtcp module

Review URL: https://codereview.webrtc.org/1877253002

Cr-Commit-Position: refs/heads/master@{#12359}
diff --git a/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h b/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h
index fae8641..6ce6434 100644
--- a/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h
+++ b/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h
@@ -13,6 +13,7 @@
 
 #include <map>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
@@ -122,7 +123,7 @@
   const RtpUtility::Payload* PayloadTypeToPayload(uint8_t payload_type) const;
 
   void ResetLastReceivedPayloadTypes() {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     last_received_payload_type_ = -1;
     last_received_media_payload_type_ = -1;
   }
@@ -136,34 +137,34 @@
   bool ReportMediaPayloadType(uint8_t media_payload_type);
 
   int8_t red_payload_type() const {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     return red_payload_type_;
   }
   int8_t ulpfec_payload_type() const {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     return ulpfec_payload_type_;
   }
   int8_t last_received_payload_type() const {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     return last_received_payload_type_;
   }
   void set_last_received_payload_type(int8_t last_received_payload_type) {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     last_received_payload_type_ = last_received_payload_type;
   }
 
   int8_t last_received_media_payload_type() const {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     return last_received_media_payload_type_;
   }
 
   bool use_rtx_payload_mapping_on_restore() const {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     return use_rtx_payload_mapping_on_restore_;
   }
 
   void set_use_rtx_payload_mapping_on_restore(bool val) {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     use_rtx_payload_mapping_on_restore_ = val;
   }
 
@@ -178,7 +179,7 @@
 
   bool IsRtxInternal(const RTPHeader& header) const;
 
-  rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
+  rtc::CriticalSection crit_sect_;
   RtpUtility::PayloadTypeMap payload_type_map_;
   rtc::scoped_ptr<RTPPayloadStrategy> rtp_payload_strategy_;
   int8_t  red_payload_type_;
diff --git a/webrtc/modules/rtp_rtcp/source/bitrate.cc b/webrtc/modules/rtp_rtcp/source/bitrate.cc
index 4e9fc72..49a2359 100644
--- a/webrtc/modules/rtp_rtcp/source/bitrate.cc
+++ b/webrtc/modules/rtp_rtcp/source/bitrate.cc
@@ -11,13 +11,11 @@
 #include "webrtc/modules/rtp_rtcp/source/bitrate.h"
 
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 
 Bitrate::Bitrate(Clock* clock, Observer* observer)
     : clock_(clock),
-      crit_(CriticalSectionWrapper::CreateCriticalSection()),
       packet_rate_(0),
       bitrate_(0),
       bitrate_next_idx_(0),
@@ -33,23 +31,23 @@
 Bitrate::~Bitrate() {}
 
 void Bitrate::Update(const size_t bytes) {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   bytes_count_ += bytes;
   packet_count_++;
 }
 
 uint32_t Bitrate::PacketRate() const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   return packet_rate_;
 }
 
 uint32_t Bitrate::BitrateLast() const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   return bitrate_;
 }
 
 uint32_t Bitrate::BitrateNow() const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   int64_t now = clock_->TimeInMilliseconds();
   int64_t diff_ms = now - time_last_rate_update_;
 
@@ -67,7 +65,7 @@
 }
 
 int64_t Bitrate::time_last_rate_update() const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   return time_last_rate_update_;
 }
 
@@ -75,7 +73,7 @@
 void Bitrate::Process() {
   BitrateStatistics stats;
   {
-    CriticalSectionScoped cs(crit_.get());
+    rtc::CritScope cs(&crit_);
     int64_t now = clock_->CurrentNtpInMilliseconds();
     int64_t diff_ms = now - time_last_rate_update_;
 
diff --git a/webrtc/modules/rtp_rtcp/source/bitrate.h b/webrtc/modules/rtp_rtcp/source/bitrate.h
index 393d05d..7aaaead 100644
--- a/webrtc/modules/rtp_rtcp/source/bitrate.h
+++ b/webrtc/modules/rtp_rtcp/source/bitrate.h
@@ -15,7 +15,7 @@
 
 #include <list>
 
-#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
 #include "webrtc/typedefs.h"
@@ -23,7 +23,6 @@
 namespace webrtc {
 
 class Clock;
-class CriticalSectionWrapper;
 
 class Bitrate {
  public:
@@ -60,7 +59,7 @@
   Clock* clock_;
 
  private:
-  rtc::scoped_ptr<CriticalSectionWrapper> crit_;
+  rtc::CriticalSection crit_;
   uint32_t packet_rate_;
   uint32_t bitrate_;
   uint8_t bitrate_next_idx_;
diff --git a/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc b/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc
index ab21b87..81e8b59 100644
--- a/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc
+++ b/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc
@@ -13,20 +13,16 @@
 #include <string.h>
 
 namespace webrtc {
-DTMFqueue::DTMFqueue()
-    : dtmf_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
-      next_empty_index_(0) {
+DTMFqueue::DTMFqueue() : next_empty_index_(0) {
   memset(dtmf_key_, 0, sizeof(dtmf_key_));
   memset(dtmf_length, 0, sizeof(dtmf_length));
   memset(dtmf_level_, 0, sizeof(dtmf_level_));
 }
 
-DTMFqueue::~DTMFqueue() {
-  delete dtmf_critsect_;
-}
+DTMFqueue::~DTMFqueue() {}
 
 int32_t DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) {
-  CriticalSectionScoped lock(dtmf_critsect_);
+  rtc::CritScope lock(&dtmf_critsect_);
 
   if (next_empty_index_ >= DTMF_OUTBAND_MAX) {
     return -1;
@@ -40,7 +36,7 @@
 }
 
 int8_t DTMFqueue::NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level) {
-  CriticalSectionScoped lock(dtmf_critsect_);
+  rtc::CritScope lock(&dtmf_critsect_);
   if (next_empty_index_ == 0)
     return -1;
 
@@ -60,12 +56,12 @@
 }
 
 bool DTMFqueue::PendingDTMF() {
-  CriticalSectionScoped lock(dtmf_critsect_);
+  rtc::CritScope lock(&dtmf_critsect_);
   return next_empty_index_ > 0;
 }
 
 void DTMFqueue::ResetDTMF() {
-  CriticalSectionScoped lock(dtmf_critsect_);
+  rtc::CritScope lock(&dtmf_critsect_);
   next_empty_index_ = 0;
 }
 }  // namespace webrtc
diff --git a/webrtc/modules/rtp_rtcp/source/dtmf_queue.h b/webrtc/modules/rtp_rtcp/source/dtmf_queue.h
index d1b3f56..c0e616f 100644
--- a/webrtc/modules/rtp_rtcp/source/dtmf_queue.h
+++ b/webrtc/modules/rtp_rtcp/source/dtmf_queue.h
@@ -11,8 +11,8 @@
 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_DTMF_QUEUE_H_
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_DTMF_QUEUE_H_
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -27,7 +27,7 @@
   void ResetDTMF();
 
  private:
-  CriticalSectionWrapper* dtmf_critsect_;
+  rtc::CriticalSection dtmf_critsect_;
   uint8_t next_empty_index_;
   uint8_t dtmf_key_[DTMF_OUTBAND_MAX];
   uint16_t dtmf_length[DTMF_OUTBAND_MAX];
diff --git a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc
index 2109574..28e98ba 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.cc
@@ -16,7 +16,6 @@
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 // RFC 5109
 namespace webrtc {
@@ -26,8 +25,7 @@
 }
 
 FecReceiverImpl::FecReceiverImpl(RtpData* callback)
-    : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
-      recovered_packet_callback_(callback),
+    : recovered_packet_callback_(callback),
       fec_(new ForwardErrorCorrection()) {}
 
 FecReceiverImpl::~FecReceiverImpl() {
@@ -42,7 +40,7 @@
 }
 
 FecPacketCounter FecReceiverImpl::GetPacketCounter() const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   return packet_counter_;
 }
 
@@ -77,7 +75,7 @@
 int32_t FecReceiverImpl::AddReceivedRedPacket(
     const RTPHeader& header, const uint8_t* incoming_rtp_packet,
     size_t packet_length, uint8_t ulpfec_payload_type) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   uint8_t REDHeaderLength = 1;
   size_t payload_data_length = packet_length - header.headerLength;
 
@@ -219,21 +217,21 @@
 }
 
 int32_t FecReceiverImpl::ProcessReceivedFec() {
-  crit_sect_->Enter();
+  crit_sect_.Enter();
   if (!received_packet_list_.empty()) {
     // Send received media packet to VCM.
     if (!received_packet_list_.front()->is_fec) {
       ForwardErrorCorrection::Packet* packet =
           received_packet_list_.front()->pkt;
-      crit_sect_->Leave();
+      crit_sect_.Leave();
       if (!recovered_packet_callback_->OnRecoveredPacket(packet->data,
                                                          packet->length)) {
         return -1;
       }
-      crit_sect_->Enter();
+      crit_sect_.Enter();
     }
     if (fec_->DecodeFEC(&received_packet_list_, &recovered_packet_list_) != 0) {
-      crit_sect_->Leave();
+      crit_sect_.Leave();
       return -1;
     }
     assert(received_packet_list_.empty());
@@ -246,15 +244,15 @@
       continue;
     ForwardErrorCorrection::Packet* packet = (*it)->pkt;
     ++packet_counter_.num_recovered_packets;
-    crit_sect_->Leave();
+    crit_sect_.Leave();
     if (!recovered_packet_callback_->OnRecoveredPacket(packet->data,
                                                        packet->length)) {
       return -1;
     }
-    crit_sect_->Enter();
+    crit_sect_.Enter();
     (*it)->returned = true;
   }
-  crit_sect_->Leave();
+  crit_sect_.Leave();
   return 0;
 }
 
diff --git a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h
index 6a63813..0ebca9b 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/fec_receiver_impl.h
@@ -13,7 +13,7 @@
 
 // This header is included to get the nested declaration of Packet structure.
 
-#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
@@ -21,8 +21,6 @@
 
 namespace webrtc {
 
-class CriticalSectionWrapper;
-
 class FecReceiverImpl : public FecReceiver {
  public:
   explicit FecReceiverImpl(RtpData* callback);
@@ -38,7 +36,7 @@
   FecPacketCounter GetPacketCounter() const override;
 
  private:
-  rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
+  rtc::CriticalSection crit_sect_;
   RtpData* recovered_packet_callback_;
   ForwardErrorCorrection* fec_;
   // TODO(holmer): In the current version received_packet_list_ is never more
diff --git a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
index 022fc96..1e7b355 100644
--- a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.cc
@@ -12,10 +12,8 @@
 
 #include <math.h>
 
-#include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/source/bitrate.h"
 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 
@@ -29,7 +27,6 @@
     RtcpStatisticsCallback* rtcp_callback,
     StreamDataCountersCallback* rtp_callback)
     : clock_(clock),
-      stream_lock_(CriticalSectionWrapper::CreateCriticalSection()),
       incoming_bitrate_(clock, NULL),
       ssrc_(0),
       max_reordering_threshold_(kDefaultMaxReorderingThreshold),
@@ -59,7 +56,7 @@
 void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header,
                                             size_t packet_length,
                                             bool retransmitted) {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   bool in_order = InOrderPacketInternal(header.sequenceNumber);
   ssrc_ = header.ssrc;
   incoming_bitrate_.Update(packet_length);
@@ -150,7 +147,7 @@
   StreamDataCounters data;
   uint32_t ssrc;
   {
-    CriticalSectionScoped cs(stream_lock_.get());
+    rtc::CritScope cs(&stream_lock_);
     data = receive_counters_;
     ssrc = ssrc_;
   }
@@ -161,7 +158,7 @@
   RtcpStatistics data;
   uint32_t ssrc;
   {
-    CriticalSectionScoped cs(stream_lock_.get());
+    rtc::CritScope cs(&stream_lock_);
     data = last_reported_statistics_;
     ssrc = ssrc_;
   }
@@ -171,7 +168,7 @@
 void StreamStatisticianImpl::FecPacketReceived(const RTPHeader& header,
                                                size_t packet_length) {
   {
-    CriticalSectionScoped cs(stream_lock_.get());
+    rtc::CritScope cs(&stream_lock_);
     receive_counters_.fec.AddPacket(packet_length, header);
   }
   NotifyRtpCallback();
@@ -179,14 +176,14 @@
 
 void StreamStatisticianImpl::SetMaxReorderingThreshold(
     int max_reordering_threshold) {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   max_reordering_threshold_ = max_reordering_threshold;
 }
 
 bool StreamStatisticianImpl::GetStatistics(RtcpStatistics* statistics,
                                            bool reset) {
   {
-    CriticalSectionScoped cs(stream_lock_.get());
+    rtc::CritScope cs(&stream_lock_);
     if (received_seq_first_ == 0 &&
         receive_counters_.transmitted.payload_bytes == 0) {
       // We have not received anything.
@@ -282,7 +279,7 @@
 
 void StreamStatisticianImpl::GetDataCounters(
     size_t* bytes_received, uint32_t* packets_received) const {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   if (bytes_received) {
     *bytes_received = receive_counters_.transmitted.payload_bytes +
                       receive_counters_.transmitted.header_bytes +
@@ -295,30 +292,30 @@
 
 void StreamStatisticianImpl::GetReceiveStreamDataCounters(
     StreamDataCounters* data_counters) const {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   *data_counters = receive_counters_;
 }
 
 uint32_t StreamStatisticianImpl::BitrateReceived() const {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   return incoming_bitrate_.BitrateNow();
 }
 
 void StreamStatisticianImpl::ProcessBitrate() {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   incoming_bitrate_.Process();
 }
 
 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs,
                                                 uint32_t* frac) const {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   *secs = last_receive_time_ntp_.seconds();
   *frac = last_receive_time_ntp_.fractions();
 }
 
 bool StreamStatisticianImpl::IsRetransmitOfOldPacket(
     const RTPHeader& header, int64_t min_rtt) const {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   if (InOrderPacketInternal(header.sequenceNumber)) {
     return false;
   }
@@ -352,7 +349,7 @@
 }
 
 bool StreamStatisticianImpl::IsPacketInOrder(uint16_t sequence_number) const {
-  CriticalSectionScoped cs(stream_lock_.get());
+  rtc::CritScope cs(&stream_lock_);
   return InOrderPacketInternal(sequence_number);
 }
 
@@ -377,7 +374,6 @@
 
 ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock)
     : clock_(clock),
-      receive_statistics_lock_(CriticalSectionWrapper::CreateCriticalSection()),
       last_rate_update_ms_(0),
       rtcp_stats_callback_(NULL),
       rtp_stats_callback_(NULL) {}
@@ -394,7 +390,7 @@
                                            bool retransmitted) {
   StreamStatisticianImpl* impl;
   {
-    CriticalSectionScoped cs(receive_statistics_lock_.get());
+    rtc::CritScope cs(&receive_statistics_lock_);
     StatisticianImplMap::iterator it = statisticians_.find(header.ssrc);
     if (it != statisticians_.end()) {
       impl = it->second;
@@ -412,7 +408,7 @@
 
 void ReceiveStatisticsImpl::FecPacketReceived(const RTPHeader& header,
                                               size_t packet_length) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   StatisticianImplMap::iterator it = statisticians_.find(header.ssrc);
   // Ignore FEC if it is the first packet.
   if (it != statisticians_.end()) {
@@ -421,7 +417,7 @@
 }
 
 StatisticianMap ReceiveStatisticsImpl::GetActiveStatisticians() const {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   StatisticianMap active_statisticians;
   for (StatisticianImplMap::const_iterator it = statisticians_.begin();
        it != statisticians_.end(); ++it) {
@@ -438,7 +434,7 @@
 
 StreamStatistician* ReceiveStatisticsImpl::GetStatistician(
     uint32_t ssrc) const {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   StatisticianImplMap::const_iterator it = statisticians_.find(ssrc);
   if (it == statisticians_.end())
     return NULL;
@@ -447,7 +443,7 @@
 
 void ReceiveStatisticsImpl::SetMaxReorderingThreshold(
     int max_reordering_threshold) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   for (StatisticianImplMap::iterator it = statisticians_.begin();
        it != statisticians_.end(); ++it) {
     it->second->SetMaxReorderingThreshold(max_reordering_threshold);
@@ -455,7 +451,7 @@
 }
 
 void ReceiveStatisticsImpl::Process() {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   for (StatisticianImplMap::iterator it = statisticians_.begin();
        it != statisticians_.end(); ++it) {
     it->second->ProcessBitrate();
@@ -464,7 +460,7 @@
 }
 
 int64_t ReceiveStatisticsImpl::TimeUntilNextProcess() {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   int64_t time_since_last_update = clock_->TimeInMilliseconds() -
       last_rate_update_ms_;
   return std::max<int64_t>(
@@ -473,7 +469,7 @@
 
 void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback(
     RtcpStatisticsCallback* callback) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   if (callback != NULL)
     assert(rtcp_stats_callback_ == NULL);
   rtcp_stats_callback_ = callback;
@@ -481,20 +477,20 @@
 
 void ReceiveStatisticsImpl::StatisticsUpdated(const RtcpStatistics& statistics,
                                               uint32_t ssrc) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   if (rtcp_stats_callback_)
     rtcp_stats_callback_->StatisticsUpdated(statistics, ssrc);
 }
 
 void ReceiveStatisticsImpl::CNameChanged(const char* cname, uint32_t ssrc) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   if (rtcp_stats_callback_)
     rtcp_stats_callback_->CNameChanged(cname, ssrc);
 }
 
 void ReceiveStatisticsImpl::RegisterRtpStatisticsCallback(
     StreamDataCountersCallback* callback) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   if (callback != NULL)
     assert(rtp_stats_callback_ == NULL);
   rtp_stats_callback_ = callback;
@@ -502,7 +498,7 @@
 
 void ReceiveStatisticsImpl::DataCountersUpdated(const StreamDataCounters& stats,
                                                 uint32_t ssrc) {
-  CriticalSectionScoped cs(receive_statistics_lock_.get());
+  rtc::CritScope cs(&receive_statistics_lock_);
   if (rtp_stats_callback_) {
     rtp_stats_callback_->DataCountersUpdated(stats, ssrc);
   }
diff --git a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h
index 6da8334..3967967 100644
--- a/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h
@@ -16,15 +16,12 @@
 #include <algorithm>
 #include <map>
 
-#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/source/bitrate.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/ntp_time.h"
 
 namespace webrtc {
 
-class CriticalSectionWrapper;
-
 class StreamStatisticianImpl : public StreamStatistician {
  public:
   StreamStatisticianImpl(Clock* clock,
@@ -57,11 +54,11 @@
   void UpdateCounters(const RTPHeader& rtp_header,
                       size_t packet_length,
                       bool retransmitted);
-  void NotifyRtpCallback() LOCKS_EXCLUDED(stream_lock_.get());
-  void NotifyRtcpCallback() LOCKS_EXCLUDED(stream_lock_.get());
+  void NotifyRtpCallback() LOCKS_EXCLUDED(stream_lock_);
+  void NotifyRtcpCallback() LOCKS_EXCLUDED(stream_lock_);
 
   Clock* clock_;
-  rtc::scoped_ptr<CriticalSectionWrapper> stream_lock_;
+  rtc::CriticalSection stream_lock_;
   Bitrate incoming_bitrate_;
   uint32_t ssrc_;
   int max_reordering_threshold_;  // In number of packets or sequence numbers.
@@ -131,7 +128,7 @@
   typedef std::map<uint32_t, StreamStatisticianImpl*> StatisticianImplMap;
 
   Clock* clock_;
-  rtc::scoped_ptr<CriticalSectionWrapper> receive_statistics_lock_;
+  rtc::CriticalSection receive_statistics_lock_;
   int64_t last_rate_update_ms_;
   StatisticianImplMap statisticians_;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
index 0faf2a4..3e8e47f 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
@@ -49,13 +49,9 @@
       receiver_only_(receiver_only),
       _lastReceived(0),
       _rtpRtcp(*owner),
-      _criticalSectionFeedbacks(
-          CriticalSectionWrapper::CreateCriticalSection()),
       _cbRtcpBandwidthObserver(rtcp_bandwidth_observer),
       _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer),
       _cbTransportFeedbackObserver(transport_feedback_observer),
-      _criticalSectionRTCPReceiver(
-          CriticalSectionWrapper::CreateCriticalSection()),
       main_ssrc_(0),
       _remoteSSRC(0),
       _remoteSenderInfo(),
@@ -76,9 +72,6 @@
 }
 
 RTCPReceiver::~RTCPReceiver() {
-  delete _criticalSectionRTCPReceiver;
-  delete _criticalSectionFeedbacks;
-
   ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
   for (; it != _receivedReportBlockMap.end(); ++it) {
     ReportBlockInfoMap* info_map = &(it->second);
@@ -103,12 +96,12 @@
 }
 
 int64_t RTCPReceiver::LastReceived() {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   return _lastReceived;
 }
 
 int64_t RTCPReceiver::LastReceivedReceiverReport() const {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   int64_t last_received_rr = -1;
   for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin();
        it != _receivedInfoMap.end(); ++it) {
@@ -120,7 +113,7 @@
 }
 
 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   // new SSRC reset old reports
   memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
@@ -131,7 +124,7 @@
 }
 
 uint32_t RTCPReceiver::RemoteSSRC() const {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   return _remoteSSRC;
 }
 
@@ -139,7 +132,7 @@
                             const std::set<uint32_t>& registered_ssrcs) {
   uint32_t old_ssrc = 0;
   {
-    CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+    rtc::CritScope lock(&_criticalSectionRTCPReceiver);
     old_ssrc = main_ssrc_;
     main_ssrc_ = main_ssrc;
     registered_ssrcs_ = registered_ssrcs;
@@ -156,7 +149,7 @@
                           int64_t* avgRTT,
                           int64_t* minRTT,
                           int64_t* maxRTT) const {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   RTCPReportBlockInformation* reportBlock =
       GetReportBlockInformation(remoteSSRC, main_ssrc_);
@@ -180,13 +173,13 @@
 }
 
 void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   xr_rrtr_status_ = enable;
 }
 
 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) {
   assert(rtt_ms);
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   if (xr_rr_rtt_ms_ == 0) {
     return false;
   }
@@ -202,7 +195,7 @@
                        uint32_t* RTCPArrivalTimeFrac,
                        uint32_t* rtcp_timestamp) const
 {
-    CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+    rtc::CritScope lock(&_criticalSectionRTCPReceiver);
     if(ReceivedNTPsecs)
     {
         *ReceivedNTPsecs = _remoteSenderInfo.NTPseconds; // NTP from incoming SendReport
@@ -228,7 +221,7 @@
 bool RTCPReceiver::LastReceivedXrReferenceTimeInfo(
     RtcpReceiveTimeInfo* info) const {
   assert(info);
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   if (_lastReceivedXRNTPsecs == 0 && _lastReceivedXRNTPfrac == 0) {
     return false;
   }
@@ -251,7 +244,7 @@
 
 int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const {
   assert(senderInfo);
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   if (_lastReceivedSRNTPsecs == 0) {
     return -1;
   }
@@ -264,7 +257,7 @@
 int32_t RTCPReceiver::StatisticsReceived(
     std::vector<RTCPReportBlock>* receiveBlocks) const {
   assert(receiveBlocks);
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   ReportBlockMap::const_iterator it = _receivedReportBlockMap.begin();
   for (; it != _receivedReportBlockMap.end(); ++it) {
     const ReportBlockInfoMap* info_map = &(it->second);
@@ -280,7 +273,7 @@
 RTCPReceiver::IncomingRTCPPacket(RTCPPacketInformation& rtcpPacketInformation,
                                  RTCPUtility::RTCPParserV2* rtcpParser)
 {
-    CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+    rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
     _lastReceived = _clock->TimeInMilliseconds();
 
@@ -590,7 +583,7 @@
 
 RTCPCnameInformation*
 RTCPReceiver::CreateCnameInformation(uint32_t remoteSSRC) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   std::map<uint32_t, RTCPCnameInformation*>::iterator it =
       _receivedCnameMap.find(remoteSSRC);
@@ -606,7 +599,7 @@
 
 RTCPCnameInformation*
 RTCPReceiver::GetCnameInformation(uint32_t remoteSSRC) const {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   std::map<uint32_t, RTCPCnameInformation*>::const_iterator it =
       _receivedCnameMap.find(remoteSSRC);
@@ -619,7 +612,7 @@
 
 RTCPReceiveInformation*
 RTCPReceiver::CreateReceiveInformation(uint32_t remoteSSRC) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
       _receivedInfoMap.find(remoteSSRC);
@@ -634,7 +627,7 @@
 
 RTCPReceiveInformation*
 RTCPReceiver::GetReceiveInformation(uint32_t remoteSSRC) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
       _receivedInfoMap.find(remoteSSRC);
@@ -651,7 +644,7 @@
 }
 
 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   if (_lastReceivedRrMs == 0)
     return false;
 
@@ -665,7 +658,7 @@
 }
 
 bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   if (_lastIncreasedSequenceNumberMs == 0)
     return false;
 
@@ -680,7 +673,7 @@
 }
 
 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   bool updateBoundingSet = false;
   int64_t timeNow = _clock->TimeInMilliseconds();
@@ -724,7 +717,7 @@
 }
 
 int32_t RTCPReceiver::BoundingSet(bool* tmmbrOwner, TMMBRSet* boundingSetRec) {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
       _receivedInfoMap.find(_remoteSSRC);
@@ -773,7 +766,7 @@
   cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0;
   strncpy(cnameInfo->name, rtcpPacket.CName.CName, RTCP_CNAME_SIZE - 1);
   {
-    CriticalSectionScoped lock(_criticalSectionFeedbacks);
+    rtc::CritScope lock(&_criticalSectionFeedbacks);
     if (stats_callback_ != NULL) {
       stats_callback_->CNameChanged(rtcpPacket.CName.CName,
                                     rtcpPacket.CName.SenderSSRC);
@@ -1283,12 +1276,12 @@
 
 void RTCPReceiver::RegisterRtcpStatisticsCallback(
     RtcpStatisticsCallback* callback) {
-  CriticalSectionScoped cs(_criticalSectionFeedbacks);
+  rtc::CritScope cs(&_criticalSectionFeedbacks);
   stats_callback_ = callback;
 }
 
 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() {
-  CriticalSectionScoped cs(_criticalSectionFeedbacks);
+  rtc::CritScope cs(&_criticalSectionFeedbacks);
   return stats_callback_;
 }
 
@@ -1305,7 +1298,7 @@
   std::set<uint32_t> registered_ssrcs;
   {
     // We don't want to hold this critsect when triggering the callbacks below.
-    CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+    rtc::CritScope lock(&_criticalSectionRTCPReceiver);
     local_ssrc = main_ssrc_;
     registered_ssrcs = registered_ssrcs_;
   }
@@ -1378,7 +1371,7 @@
   }
 
   if (!receiver_only_) {
-    CriticalSectionScoped cs(_criticalSectionFeedbacks);
+    rtc::CritScope cs(&_criticalSectionFeedbacks);
     if (stats_callback_) {
       for (ReportBlockList::const_iterator it =
           rtcpPacketInformation.report_blocks.begin();
@@ -1400,7 +1393,7 @@
                             char cName[RTCP_CNAME_SIZE]) const {
   assert(cName);
 
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
   RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC);
   if (cnameInfo == NULL) {
     return -1;
@@ -1414,7 +1407,7 @@
 int32_t RTCPReceiver::TMMBRReceived(uint32_t size,
                                     uint32_t accNumCandidates,
                                     TMMBRSet* candidateSet) const {
-  CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
+  rtc::CritScope lock(&_criticalSectionRTCPReceiver);
 
   std::map<uint32_t, RTCPReceiveInformation*>::const_iterator
       receiveInfoIt = _receivedInfoMap.begin();
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
index 475ab1e..28c28cb6 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
@@ -15,6 +15,7 @@
 #include <set>
 #include <vector>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
@@ -267,12 +268,12 @@
   int64_t _lastReceived;
   ModuleRtpRtcpImpl& _rtpRtcp;
 
-  CriticalSectionWrapper* _criticalSectionFeedbacks;
+  rtc::CriticalSection _criticalSectionFeedbacks;
   RtcpBandwidthObserver* const _cbRtcpBandwidthObserver;
   RtcpIntraFrameObserver* const _cbRtcpIntraFrameObserver;
   TransportFeedbackObserver* const _cbTransportFeedbackObserver;
 
-  CriticalSectionWrapper* _criticalSectionRTCPReceiver;
+  rtc::CriticalSection _criticalSectionRTCPReceiver;
   uint32_t main_ssrc_ GUARDED_BY(_criticalSectionRTCPReceiver);
   uint32_t _remoteSSRC GUARDED_BY(_criticalSectionRTCPReceiver);
   std::set<uint32_t> registered_ssrcs_ GUARDED_BY(_criticalSectionRTCPReceiver);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc b/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc
index d4cbe54..2cec8a3 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc
@@ -9,10 +9,9 @@
  */
 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
 
-#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 
@@ -30,7 +29,7 @@
   bool DeregisterRtpHeaderExtension(RTPExtensionType type) override;
 
  private:
-  rtc::scoped_ptr<CriticalSectionWrapper> critical_section_;
+  rtc::CriticalSection critical_section_;
   RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(critical_section_);
 };
 
@@ -38,8 +37,7 @@
   return new RtpHeaderParserImpl;
 }
 
-RtpHeaderParserImpl::RtpHeaderParserImpl()
-    : critical_section_(CriticalSectionWrapper::CreateCriticalSection()) {}
+RtpHeaderParserImpl::RtpHeaderParserImpl() {}
 
 bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) {
   RtpUtility::RtpHeaderParser rtp_parser(packet, length);
@@ -54,7 +52,7 @@
 
   RtpHeaderExtensionMap map;
   {
-    CriticalSectionScoped cs(critical_section_.get());
+    rtc::CritScope cs(&critical_section_);
     rtp_header_extension_map_.GetCopy(&map);
   }
 
@@ -67,12 +65,12 @@
 
 bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type,
                                                      uint8_t id) {
-  CriticalSectionScoped cs(critical_section_.get());
+  rtc::CritScope cs(&critical_section_);
   return rtp_header_extension_map_.Register(type, id) == 0;
 }
 
 bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RTPExtensionType type) {
-  CriticalSectionScoped cs(critical_section_.get());
+  rtc::CritScope cs(&critical_section_);
   return rtp_header_extension_map_.Deregister(type) == 0;
 }
 }  // namespace webrtc
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc
index 49f9d85..713fba8 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.cc
@@ -21,7 +21,6 @@
 #include "webrtc/base/checks.h"
 #include "webrtc/base/logging.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 
@@ -29,7 +28,6 @@
 
 RTPPacketHistory::RTPPacketHistory(Clock* clock)
     : clock_(clock),
-      critsect_(CriticalSectionWrapper::CreateCriticalSection()),
       store_(false),
       prev_index_(0) {}
 
@@ -38,7 +36,7 @@
 
 void RTPPacketHistory::SetStorePacketsStatus(bool enable,
                                              uint16_t number_to_store) {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   if (enable) {
     if (store_) {
       LOG(LS_WARNING) << "Purging packet history in order to re-set status.";
@@ -70,7 +68,7 @@
 }
 
 bool RTPPacketHistory::StorePackets() const {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   return store_;
 }
 
@@ -78,7 +76,7 @@
                                        size_t packet_length,
                                        int64_t capture_time_ms,
                                        StorageType type) {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   if (!store_) {
     return 0;
   }
@@ -131,7 +129,7 @@
 }
 
 bool RTPPacketHistory::HasRTPPacket(uint16_t sequence_number) const {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   if (!store_) {
     return false;
   }
@@ -150,7 +148,7 @@
 }
 
 bool RTPPacketHistory::SetSent(uint16_t sequence_number) {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   if (!store_) {
     return false;
   }
@@ -176,7 +174,7 @@
                                                uint8_t* packet,
                                                size_t* packet_length,
                                                int64_t* stored_time_ms) {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   RTC_CHECK_GE(*packet_length, static_cast<size_t>(IP_PACKET_SIZE));
   if (!store_)
     return false;
@@ -232,7 +230,7 @@
 bool RTPPacketHistory::GetBestFittingPacket(uint8_t* packet,
                                             size_t* packet_length,
                                             int64_t* stored_time_ms) {
-  CriticalSectionScoped cs(critsect_.get());
+  rtc::CritScope cs(&critsect_);
   if (!store_)
     return false;
   int index = FindBestFittingPacket(*packet_length);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h
index 8e1a732..b4d48aa 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_packet_history.h
@@ -15,6 +15,7 @@
 
 #include <vector>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/modules/include/module_common_types.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@@ -23,7 +24,6 @@
 namespace webrtc {
 
 class Clock;
-class CriticalSectionWrapper;
 
 static const size_t kMaxHistoryCapacity = 9600;
 
@@ -71,19 +71,19 @@
                  uint8_t* packet,
                  size_t* packet_length,
                  int64_t* stored_time_ms) const
-      EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
-  void Allocate(size_t number_to_store) EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
-  void Free() EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
+      EXCLUSIVE_LOCKS_REQUIRED(critsect_);
+  void Allocate(size_t number_to_store) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
+  void Free() EXCLUSIVE_LOCKS_REQUIRED(critsect_);
   void VerifyAndAllocatePacketLength(size_t packet_length, uint32_t start_index)
-      EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
+      EXCLUSIVE_LOCKS_REQUIRED(critsect_);
   bool FindSeqNum(uint16_t sequence_number, int32_t* index) const
-      EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
+      EXCLUSIVE_LOCKS_REQUIRED(critsect_);
   int FindBestFittingPacket(size_t size) const
-      EXCLUSIVE_LOCKS_REQUIRED(*critsect_);
+      EXCLUSIVE_LOCKS_REQUIRED(critsect_);
 
  private:
   Clock* clock_;
-  rtc::scoped_ptr<CriticalSectionWrapper> critsect_;
+  rtc::CriticalSection critsect_;
   bool store_ GUARDED_BY(critsect_);
   uint32_t prev_index_ GUARDED_BY(critsect_);
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
index f3793d0..e379580 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc
@@ -16,8 +16,7 @@
 namespace webrtc {
 
 RTPPayloadRegistry::RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy)
-    : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
-      rtp_payload_strategy_(rtp_payload_strategy),
+    : rtp_payload_strategy_(rtp_payload_strategy),
       red_payload_type_(-1),
       ulpfec_payload_type_(-1),
       incoming_payload_type_(-1),
@@ -67,7 +66,7 @@
 
   size_t payload_name_length = strlen(payload_name);
 
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
 
   RtpUtility::PayloadTypeMap::iterator it =
       payload_type_map_.find(payload_type);
@@ -122,7 +121,7 @@
 
 int32_t RTPPayloadRegistry::DeRegisterReceivePayload(
     const int8_t payload_type) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   RtpUtility::PayloadTypeMap::iterator it =
       payload_type_map_.find(payload_type);
   assert(it != payload_type_map_.end());
@@ -176,7 +175,7 @@
   assert(payload_type);
   size_t payload_name_length = strlen(payload_name);
 
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
 
   RtpUtility::PayloadTypeMap::const_iterator it = payload_type_map_.begin();
 
@@ -218,12 +217,12 @@
 }
 
 bool RTPPayloadRegistry::RtxEnabled() const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   return rtx_;
 }
 
 bool RTPPayloadRegistry::IsRtx(const RTPHeader& header) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   return IsRtxInternal(header);
 }
 
@@ -264,7 +263,7 @@
                                        original_sequence_number);
   ByteWriter<uint32_t>::WriteBigEndian(restored_packet + 8, original_ssrc);
 
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   if (!rtx_)
     return true;
 
@@ -290,20 +289,20 @@
 }
 
 void RTPPayloadRegistry::SetRtxSsrc(uint32_t ssrc) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ssrc_rtx_ = ssrc;
   rtx_ = true;
 }
 
 bool RTPPayloadRegistry::GetRtxSsrc(uint32_t* ssrc) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   *ssrc = ssrc_rtx_;
   return rtx_;
 }
 
 void RTPPayloadRegistry::SetRtxPayloadType(int payload_type,
                                            int associated_payload_type) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   if (payload_type < 0) {
     LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type;
     return;
@@ -315,7 +314,7 @@
 }
 
 bool RTPPayloadRegistry::IsRed(const RTPHeader& header) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   return red_payload_type_ == header.payloadType;
 }
 
@@ -325,7 +324,7 @@
 
 bool RTPPayloadRegistry::GetPayloadSpecifics(uint8_t payload_type,
                                              PayloadUnion* payload) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   RtpUtility::PayloadTypeMap::const_iterator it =
       payload_type_map_.find(payload_type);
 
@@ -343,13 +342,13 @@
   if (!payload) {
     return -1;
   }
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   return rtp_payload_strategy_->GetPayloadTypeFrequency(*payload);
 }
 
 const RtpUtility::Payload* RTPPayloadRegistry::PayloadTypeToPayload(
     uint8_t payload_type) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
 
   RtpUtility::PayloadTypeMap::const_iterator it =
       payload_type_map_.find(payload_type);
@@ -363,13 +362,13 @@
 }
 
 void RTPPayloadRegistry::SetIncomingPayloadType(const RTPHeader& header) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   if (!IsRtxInternal(header))
     incoming_payload_type_ = header.payloadType;
 }
 
 bool RTPPayloadRegistry::ReportMediaPayloadType(uint8_t media_payload_type) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   if (last_received_media_payload_type_ == media_payload_type) {
     // Media type unchanged.
     return true;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc
index 9de65ab..38b2830 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.cc
@@ -16,7 +16,6 @@
 
 #include "webrtc/base/logging.h"
 #include "webrtc/base/trace_event.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 RTPReceiverStrategy* RTPReceiverStrategy::CreateAudioStrategy(
@@ -46,26 +45,26 @@
 // Outband TelephoneEvent(DTMF) detection
 void RTPReceiverAudio::SetTelephoneEventForwardToDecoder(
     bool forward_to_decoder) {
-  CriticalSectionScoped lock(crit_sect_.get());
+  rtc::CritScope lock(&crit_sect_);
   telephone_event_forward_to_decoder_ = forward_to_decoder;
 }
 
 // Is forwarding of outband telephone events turned on/off?
 bool RTPReceiverAudio::TelephoneEventForwardToDecoder() const {
-  CriticalSectionScoped lock(crit_sect_.get());
+  rtc::CritScope lock(&crit_sect_);
   return telephone_event_forward_to_decoder_;
 }
 
 bool RTPReceiverAudio::TelephoneEventPayloadType(
     int8_t payload_type) const {
-  CriticalSectionScoped lock(crit_sect_.get());
+  rtc::CritScope lock(&crit_sect_);
   return telephone_event_payload_type_ == payload_type;
 }
 
 bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type,
                                       uint32_t* frequency,
                                       bool* cng_payload_type_has_changed) {
-  CriticalSectionScoped lock(crit_sect_.get());
+  rtc::CritScope lock(&crit_sect_);
   *cng_payload_type_has_changed = false;
 
   //  We can have four CNG on 8000Hz, 16000Hz, 32000Hz and 48000Hz.
@@ -152,7 +151,7 @@
     const char payload_name[RTP_PAYLOAD_NAME_SIZE],
     int8_t payload_type,
     uint32_t frequency) {
-  CriticalSectionScoped lock(crit_sect_.get());
+  rtc::CritScope lock(&crit_sect_);
 
   if (RtpUtility::StringCompare(payload_name, "telephone-event", 15)) {
     telephone_event_payload_type_ = payload_type;
@@ -206,7 +205,7 @@
 }
 
 int RTPReceiverAudio::GetPayloadTypeFrequency() const {
-  CriticalSectionScoped lock(crit_sect_.get());
+  rtc::CritScope lock(&crit_sect_);
   if (last_received_g722_) {
     return 8000;
   }
@@ -249,7 +248,7 @@
 }
 
 int RTPReceiverAudio::Energy(uint8_t array_of_energy[kRtpCsrcSize]) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
 
   assert(num_energy_ <= kRtpCsrcSize);
 
@@ -291,7 +290,7 @@
   bool telephone_event_packet =
       TelephoneEventPayloadType(rtp_header->header.payloadType);
   if (telephone_event_packet) {
-    CriticalSectionScoped lock(crit_sect_.get());
+    rtc::CritScope lock(&crit_sect_);
 
     // RFC 4733 2.3
     // 0                   1                   2                   3
@@ -336,7 +335,7 @@
   }
 
   {
-    CriticalSectionScoped lock(crit_sect_.get());
+    rtc::CritScope lock(&crit_sect_);
 
     if (!telephone_event_packet) {
       last_received_frequency_ = audio_specific.frequency;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h
index f10613b..bec1578 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h
@@ -14,7 +14,6 @@
 #include <set>
 
 #include "webrtc/base/onetimeevent.h"
-#include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
@@ -23,8 +22,6 @@
 
 namespace webrtc {
 
-class CriticalSectionWrapper;
-
 // Handles audio RTP packets. This class is thread-safe.
 class RTPReceiverAudio : public RTPReceiverStrategy,
                          public TelephoneEventHandler {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc
index 6f2efe7..04725ae 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.cc
@@ -61,8 +61,6 @@
       rtp_payload_registry_(rtp_payload_registry),
       rtp_media_receiver_(rtp_media_receiver),
       cb_rtp_feedback_(incoming_messages_callback),
-      critical_section_rtp_receiver_(
-          CriticalSectionWrapper::CreateCriticalSection()),
       last_receive_time_(0),
       last_received_payload_length_(0),
       ssrc_(0),
@@ -89,7 +87,7 @@
     const uint32_t frequency,
     const size_t channels,
     const uint32_t rate) {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
 
   // TODO(phoglund): Try to streamline handling of the RED codec and some other
   // cases which makes it necessary to keep track of whether we created a
@@ -111,29 +109,29 @@
 
 int32_t RtpReceiverImpl::DeRegisterReceivePayload(
     const int8_t payload_type) {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
   return rtp_payload_registry_->DeRegisterReceivePayload(payload_type);
 }
 
 NACKMethod RtpReceiverImpl::NACK() const {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
   return nack_method_;
 }
 
 // Turn negative acknowledgment requests on/off.
 void RtpReceiverImpl::SetNACKStatus(const NACKMethod method) {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
   nack_method_ = method;
 }
 
 uint32_t RtpReceiverImpl::SSRC() const {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
   return ssrc_;
 }
 
 // Get remote CSRC.
 int32_t RtpReceiverImpl::CSRCs(uint32_t array_of_csrcs[kRtpCsrcSize]) const {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
 
   assert(num_csrcs_ <= kRtpCsrcSize);
 
@@ -179,7 +177,7 @@
 
   bool is_first_packet_in_frame = false;
   {
-    CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+    rtc::CritScope lock(&critical_section_rtp_receiver_);
     if (HaveReceivedFrame()) {
       is_first_packet_in_frame =
           last_received_sequence_number_ + 1 == rtp_header.sequenceNumber &&
@@ -198,7 +196,7 @@
   }
 
   {
-    CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+    rtc::CritScope lock(&critical_section_rtp_receiver_);
 
     last_receive_time_ = clock_->TimeInMilliseconds();
     last_received_payload_length_ = payload_data_length;
@@ -219,7 +217,7 @@
 }
 
 bool RtpReceiverImpl::Timestamp(uint32_t* timestamp) const {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
   if (!HaveReceivedFrame())
     return false;
   *timestamp = last_received_timestamp_;
@@ -227,7 +225,7 @@
 }
 
 bool RtpReceiverImpl::LastReceivedTimeMs(int64_t* receive_time_ms) const {
-  CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+  rtc::CritScope lock(&critical_section_rtp_receiver_);
   if (!HaveReceivedFrame())
     return false;
   *receive_time_ms = last_received_frame_time_ms_;
@@ -247,7 +245,7 @@
   uint32_t rate = 0;
 
   {
-    CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+    rtc::CritScope lock(&critical_section_rtp_receiver_);
 
     int8_t last_received_payload_type =
         rtp_payload_registry_->last_received_payload_type();
@@ -318,7 +316,7 @@
   int8_t payload_type = rtp_header.payloadType;
 
   {
-    CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+    rtc::CritScope lock(&critical_section_rtp_receiver_);
 
     int8_t last_received_payload_type =
         rtp_payload_registry_->last_received_payload_type();
@@ -401,7 +399,7 @@
   uint8_t old_num_csrcs = 0;
 
   {
-    CriticalSectionScoped lock(critical_section_rtp_receiver_.get());
+    rtc::CritScope lock(&critical_section_rtp_receiver_);
 
     if (!rtp_media_receiver_->ShouldReportCsrcChanges(
         rtp_header.header.payloadType)) {
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h
index 63b65fe..7c6287c 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h
@@ -11,11 +11,11 @@
 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -79,7 +79,7 @@
 
   RtpFeedback* cb_rtp_feedback_;
 
-  rtc::scoped_ptr<CriticalSectionWrapper> critical_section_rtp_receiver_;
+  rtc::CriticalSection critical_section_rtp_receiver_;
   int64_t last_receive_time_;
   size_t last_received_payload_length_;
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.cc
index 3797b1b..69d079f 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.cc
@@ -12,25 +12,22 @@
 
 #include <stdlib.h>
 
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-
 namespace webrtc {
 
 RTPReceiverStrategy::RTPReceiverStrategy(RtpData* data_callback)
-    : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
-      data_callback_(data_callback) {
+    : data_callback_(data_callback) {
   memset(&last_payload_, 0, sizeof(last_payload_));
 }
 
 void RTPReceiverStrategy::GetLastMediaSpecificPayload(
     PayloadUnion* payload) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   memcpy(payload, &last_payload_, sizeof(*payload));
 }
 
 void RTPReceiverStrategy::SetLastMediaSpecificPayload(
     const PayloadUnion& payload) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   memcpy(&last_payload_, &payload, sizeof(last_payload_));
 }
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h
index f2a60ff..663b883 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h
@@ -11,11 +11,10 @@
 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
 
-#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -95,7 +94,7 @@
   // packet.
   explicit RTPReceiverStrategy(RtpData* data_callback);
 
-  rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
+  rtc::CriticalSection crit_sect_;
   PayloadUnion last_payload_;
   RtpData* data_callback_;
 };
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc
index 72fb1b2..f53f55a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.cc
@@ -21,7 +21,6 @@
 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h
index 7500232..dc89b8f 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h
@@ -12,7 +12,6 @@
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_VIDEO_H_
 
 #include "webrtc/base/onetimeevent.h"
-#include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/bitrate.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
index 5875529..64f64d8 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
@@ -112,7 +112,6 @@
       key_frame_req_method_(kKeyFrameReqPliRtcp),
       remote_bitrate_(configuration.remote_bitrate_estimator),
       rtt_stats_(configuration.rtt_stats),
-      critical_section_rtt_(CriticalSectionWrapper::CreateCriticalSection()),
       rtt_ms_(0) {
   // Make sure that RTCP objects are aware of our SSRC.
   uint32_t SSRC = rtp_sender_.SSRC();
@@ -982,12 +981,12 @@
 }
 
 void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
-  CriticalSectionScoped cs(critical_section_rtt_.get());
+  rtc::CritScope cs(&critical_section_rtt_);
   rtt_ms_ = rtt_ms;
 }
 
 int64_t ModuleRtpRtcpImpl::rtt_ms() const {
-  CriticalSectionScoped cs(critical_section_rtt_.get());
+  rtc::CritScope cs(&critical_section_rtt_);
   return rtt_ms_;
 }
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h
index 76faca0..ec8e84a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h
@@ -16,8 +16,8 @@
 #include <utility>
 #include <vector>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/gtest_prod_util.h"
-#include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
 #include "webrtc/modules/rtp_rtcp/source/packet_loss_stats.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h"
@@ -362,7 +362,7 @@
   PacketLossStats receive_loss_stats_;
 
   // The processed RTT from RtcpRttStats.
-  rtc::scoped_ptr<CriticalSectionWrapper> critical_section_rtt_;
+  rtc::CriticalSection critical_section_rtt_;
   int64_t rtt_ms_;
 };
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
index 3fbca7b..f7b72b8 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc
@@ -24,7 +24,6 @@
 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h"
 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/tick_util.h"
 
 namespace webrtc {
@@ -147,7 +146,6 @@
       nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()),
       packet_history_(clock),
       // Statistics
-      statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()),
       rtp_stats_callback_(NULL),
       frame_count_observer_(frame_count_observer),
       send_side_delay_observer_(send_side_delay_observer),
@@ -166,7 +164,6 @@
       last_packet_marker_bit_(false),
       csrcs_(),
       rtx_(kRtxOff),
-      target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
       target_bitrate_(0) {
   memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_));
   memset(nack_byte_count_, 0, sizeof(nack_byte_count_));
@@ -210,12 +207,12 @@
 }
 
 void RTPSender::SetTargetBitrate(uint32_t bitrate) {
-  CriticalSectionScoped cs(target_bitrate_critsect_.get());
+  rtc::CritScope cs(&target_bitrate_critsect_);
   target_bitrate_ = bitrate;
 }
 
 uint32_t RTPSender::GetTargetBitrate() {
-  CriticalSectionScoped cs(target_bitrate_critsect_.get());
+  rtc::CritScope cs(&target_bitrate_critsect_);
   return target_bitrate_;
 }
 
@@ -532,7 +529,7 @@
                           payload_size, fragmentation, rtp_hdr);
   }
 
-  CriticalSectionScoped cs(statistics_crit_.get());
+  rtc::CritScope cs(&statistics_crit_);
   // Note: This is currently only counting for video.
   if (frame_type == kVideoFrameKey) {
     ++frame_counts_.key_frames;
@@ -966,7 +963,7 @@
   // Get ssrc before taking statistics_crit_ to avoid possible deadlock.
   uint32_t ssrc = is_rtx ? RtxSsrc() : SSRC();
 
-  CriticalSectionScoped lock(statistics_crit_.get());
+  rtc::CritScope lock(&statistics_crit_);
   if (is_rtx) {
     counters = &rtx_rtp_stats_;
   } else {
@@ -1109,7 +1106,7 @@
     ssrc = ssrc_;
   }
   {
-    CriticalSectionScoped cs(statistics_crit_.get());
+    rtc::CritScope cs(&statistics_crit_);
     // TODO(holmer): Compute this iteratively instead.
     send_delays_[now_ms] = now_ms - capture_time_ms;
     send_delays_.erase(send_delays_.begin(),
@@ -1157,7 +1154,7 @@
 
 void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats,
                                 StreamDataCounters* rtx_stats) const {
-  CriticalSectionScoped lock(statistics_crit_.get());
+  rtc::CritScope lock(&statistics_crit_);
   *rtp_stats = rtp_stats_;
   *rtx_stats = rtx_rtp_stats_;
 }
@@ -1858,12 +1855,12 @@
 
 void RTPSender::RegisterRtpStatisticsCallback(
     StreamDataCountersCallback* callback) {
-  CriticalSectionScoped cs(statistics_crit_.get());
+  rtc::CritScope cs(&statistics_crit_);
   rtp_stats_callback_ = callback;
 }
 
 StreamDataCountersCallback* RTPSender::GetRtpStatisticsCallback() const {
-  CriticalSectionScoped cs(statistics_crit_.get());
+  rtc::CritScope cs(&statistics_crit_);
   return rtp_stats_callback_;
 }
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.h b/webrtc/modules/rtp_rtcp/source/rtp_sender.h
index 4344df6..df75f11 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.h
@@ -454,7 +454,7 @@
   RTPPacketHistory packet_history_;
 
   // Statistics
-  rtc::scoped_ptr<CriticalSectionWrapper> statistics_crit_;
+  rtc::CriticalSection statistics_crit_;
   SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
   FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
   StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
@@ -489,7 +489,7 @@
   // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
   // that by the time the function returns there is no guarantee
   // that the target bitrate is still valid.
-  rtc::scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_;
+  rtc::CriticalSection target_bitrate_critsect_;
   uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_);
 
   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc
index c85a197..6d0f7a4 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.cc
@@ -25,7 +25,6 @@
 RTPSenderAudio::RTPSenderAudio(Clock* clock, RTPSender* rtpSender)
     : _clock(clock),
       _rtpSender(rtpSender),
-      _sendAudioCritsect(CriticalSectionWrapper::CreateCriticalSection()),
       _packetSizeSamples(160),
       _dtmfEventIsOn(false),
       _dtmfEventFirstPacketSent(false),
@@ -54,7 +53,7 @@
 // set audio packet size, used to determine when it's time to send a DTMF packet
 // in silence (CNG)
 int32_t RTPSenderAudio::SetAudioPacketSize(uint16_t packetSizeSamples) {
-  CriticalSectionScoped cs(_sendAudioCritsect.get());
+  rtc::CritScope cs(&_sendAudioCritsect);
 
   _packetSizeSamples = packetSizeSamples;
   return 0;
@@ -68,7 +67,7 @@
     const uint32_t rate,
     RtpUtility::Payload** payload) {
   if (RtpUtility::StringCompare(payloadName, "cn", 2)) {
-    CriticalSectionScoped cs(_sendAudioCritsect.get());
+    rtc::CritScope cs(&_sendAudioCritsect);
     //  we can have multiple CNG payload types
     switch (frequency) {
       case 8000:
@@ -87,7 +86,7 @@
         return -1;
     }
   } else if (RtpUtility::StringCompare(payloadName, "telephone-event", 15)) {
-    CriticalSectionScoped cs(_sendAudioCritsect.get());
+    rtc::CritScope cs(&_sendAudioCritsect);
     // Don't add it to the list
     // we dont want to allow send with a DTMF payloadtype
     _dtmfPayloadType = payloadType;
@@ -105,7 +104,7 @@
 }
 
 bool RTPSenderAudio::MarkerBit(FrameType frameType, int8_t payload_type) {
-  CriticalSectionScoped cs(_sendAudioCritsect.get());
+  rtc::CritScope cs(&_sendAudioCritsect);
   // for audio true for first packet in a speech burst
   bool markerBit = false;
   if (_lastPayloadType != payload_type) {
@@ -163,7 +162,7 @@
   int8_t dtmf_payload_type;
   uint16_t packet_size_samples;
   {
-    CriticalSectionScoped cs(_sendAudioCritsect.get());
+    rtc::CritScope cs(&_sendAudioCritsect);
     red_payload_type = _REDPayloadType;
     audio_level_dbov = _audioLevel_dBov;
     dtmf_payload_type = _dtmfPayloadType;
@@ -336,7 +335,7 @@
   }
 
   {
-    CriticalSectionScoped cs(_sendAudioCritsect.get());
+    rtc::CritScope cs(&_sendAudioCritsect);
     _lastPayloadType = payloadType;
   }
   // Update audio level extension, if included.
@@ -365,7 +364,7 @@
   if (level_dBov > 127) {
     return -1;
   }
-  CriticalSectionScoped cs(_sendAudioCritsect.get());
+  rtc::CritScope cs(&_sendAudioCritsect);
   _audioLevel_dBov = level_dBov;
   return 0;
 }
@@ -375,14 +374,14 @@
   if (payloadType < -1) {
     return -1;
   }
-  CriticalSectionScoped cs(_sendAudioCritsect.get());
+  rtc::CritScope cs(&_sendAudioCritsect);
   _REDPayloadType = payloadType;
   return 0;
 }
 
 // Get payload type for Redundant Audio Data RFC 2198
 int32_t RTPSenderAudio::RED(int8_t* payloadType) const {
-  CriticalSectionScoped cs(_sendAudioCritsect.get());
+  rtc::CritScope cs(&_sendAudioCritsect);
   if (_REDPayloadType == -1) {
     // not configured
     return -1;
@@ -396,7 +395,7 @@
                                            uint16_t time_ms,
                                            uint8_t level) {
   {
-    CriticalSectionScoped lock(_sendAudioCritsect.get());
+    rtc::CritScope lock(&_sendAudioCritsect);
     if (_dtmfPayloadType < 0) {
       // TelephoneEvent payloadtype not configured
       return -1;
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h
index 2ba10d2..4bc0266 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h
@@ -12,6 +12,7 @@
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
 
 #include "webrtc/common_types.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/onetimeevent.h"
 #include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
@@ -73,7 +74,7 @@
   Clock* const _clock;
   RTPSender* const _rtpSender;
 
-  rtc::scoped_ptr<CriticalSectionWrapper> _sendAudioCritsect;
+  rtc::CriticalSection _sendAudioCritsect;
 
   uint16_t _packetSizeSamples GUARDED_BY(_sendAudioCritsect);
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
index 87c975d..d617f10 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
@@ -24,14 +24,12 @@
 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 enum { REDForFECHeaderLength = 1 };
 
 RTPSenderVideo::RTPSenderVideo(Clock* clock, RTPSenderInterface* rtpSender)
     : _rtpSender(*rtpSender),
-      crit_(CriticalSectionWrapper::CreateCriticalSection()),
       _videoType(kRtpVideoGeneric),
       _retransmissionSettings(kRetransmitBaseLayer),
       // Generic FEC
@@ -119,7 +117,7 @@
   uint16_t next_fec_sequence_number = 0;
   {
     // Only protect while creating RED and FEC packets, not when sending.
-    CriticalSectionScoped cs(crit_.get());
+    rtc::CritScope cs(&crit_);
     red_packet.reset(producer_fec_.BuildRedPacket(
         data_buffer, payload_length, rtp_header_length, red_payload_type_));
     if (protect) {
@@ -170,7 +168,7 @@
 void RTPSenderVideo::SetGenericFECStatus(const bool enable,
                                          const uint8_t payloadTypeRED,
                                          const uint8_t payloadTypeFEC) {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   fec_enabled_ = enable;
   red_payload_type_ = payloadTypeRED;
   fec_payload_type_ = payloadTypeFEC;
@@ -184,14 +182,14 @@
 void RTPSenderVideo::GenericFECStatus(bool* enable,
                                       uint8_t* payloadTypeRED,
                                       uint8_t* payloadTypeFEC) const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   *enable = fec_enabled_;
   *payloadTypeRED = red_payload_type_;
   *payloadTypeFEC = fec_payload_type_;
 }
 
 size_t RTPSenderVideo::FECPacketOverhead() const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   if (fec_enabled_) {
     // Overhead is FEC headers plus RED for FEC header plus anything in RTP
     // header beyond the 12 bytes base header (CSRC list, extensions...)
@@ -206,7 +204,7 @@
 
 void RTPSenderVideo::SetFecParameters(const FecProtectionParams* delta_params,
                                       const FecProtectionParams* key_params) {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   RTC_DCHECK(delta_params);
   RTC_DCHECK(key_params);
   delta_fec_params_ = *delta_params;
@@ -234,7 +232,7 @@
   bool fec_enabled;
   bool first_frame = first_frame_sent_();
   {
-    CriticalSectionScoped cs(crit_.get());
+    rtc::CritScope cs(&crit_);
     FecProtectionParams* fec_params =
         frameType == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_;
     producer_fec_.SetFecParameters(fec_params, 0);
@@ -345,12 +343,12 @@
 }
 
 int RTPSenderVideo::SelectiveRetransmissions() const {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   return _retransmissionSettings;
 }
 
 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) {
-  CriticalSectionScoped cs(crit_.get());
+  rtc::CritScope cs(&crit_);
   _retransmissionSettings = settings;
 }
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h
index 3ea9168..8307b83 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h
+++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h
@@ -13,8 +13,8 @@
 
 #include <list>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/onetimeevent.h"
-#include "webrtc/base/scoped_ptr.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@@ -28,7 +28,6 @@
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
-class CriticalSectionWrapper;
 
 class RTPSenderVideo {
  public:
@@ -98,7 +97,7 @@
   RTPSenderInterface& _rtpSender;
 
   // Should never be held when calling out of this class.
-  const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
+  const rtc::CriticalSection crit_;
 
   RtpVideoCodecTypes _videoType;
   int32_t _retransmissionSettings GUARDED_BY(crit_);
diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
index da43204..af95090 100644
--- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
+++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
@@ -67,8 +67,7 @@
 }
 
 TMMBRHelp::TMMBRHelp()
-    : _criticalSection(CriticalSectionWrapper::CreateCriticalSection()),
-      _candidateSet(),
+    : _candidateSet(),
       _boundingSet(),
       _boundingSetToSend(),
       _ptrIntersectionBoundingSet(NULL),
@@ -80,13 +79,12 @@
   delete [] _ptrMaxPRBoundingSet;
   _ptrIntersectionBoundingSet = 0;
   _ptrMaxPRBoundingSet = 0;
-  delete _criticalSection;
 }
 
 TMMBRSet*
 TMMBRHelp::VerifyAndAllocateBoundingSet(uint32_t minimumSize)
 {
-    CriticalSectionScoped lock(_criticalSection);
+    rtc::CritScope lock(&_criticalSection);
 
     if(minimumSize > _boundingSet.capacity())
     {
@@ -110,7 +108,7 @@
 int32_t
 TMMBRHelp::SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend)
 {
-    CriticalSectionScoped lock(_criticalSection);
+    rtc::CritScope lock(&_criticalSection);
 
     if (boundingSetToSend == NULL)
     {
@@ -134,7 +132,7 @@
 int32_t
 TMMBRHelp::VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize)
 {
-    CriticalSectionScoped lock(_criticalSection);
+    rtc::CritScope lock(&_criticalSection);
 
     _boundingSetToSend.VerifyAndAllocateSet(minimumSize);
     return 0;
@@ -143,7 +141,7 @@
 TMMBRSet*
 TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize)
 {
-    CriticalSectionScoped lock(_criticalSection);
+    rtc::CritScope lock(&_criticalSection);
 
     _candidateSet.VerifyAndAllocateSet(minimumSize);
     return &_candidateSet;
@@ -164,7 +162,7 @@
 int32_t
 TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
 {
-    CriticalSectionScoped lock(_criticalSection);
+    rtc::CritScope lock(&_criticalSection);
 
     // Work on local variable, will be modified
     TMMBRSet    candidateSet;
@@ -207,7 +205,7 @@
 int32_t
 TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
 {
-    CriticalSectionScoped lock(_criticalSection);
+    rtc::CritScope lock(&_criticalSection);
 
     uint32_t numBoundingSet = 0;
     VerifyAndAllocateBoundingSet(candidateSet.capacity());
@@ -412,7 +410,7 @@
 
 bool TMMBRHelp::IsOwner(const uint32_t ssrc,
                         const uint32_t length) const {
-  CriticalSectionScoped lock(_criticalSection);
+  rtc::CritScope lock(&_criticalSection);
 
   if (length == 0) {
     // Empty bounding set.
@@ -428,7 +426,7 @@
 }
 
 bool TMMBRHelp::CalcMinBitRate( uint32_t* minBitrateKbit) const {
-  CriticalSectionScoped lock(_criticalSection);
+  rtc::CritScope lock(&_criticalSection);
 
   if (_candidateSet.size() == 0) {
     // Empty bounding set.
diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.h b/webrtc/modules/rtp_rtcp/source/tmmbr_help.h
index 6236d5d..c73d53b 100644
--- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.h
+++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.h
@@ -12,8 +12,8 @@
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_
 
 #include <vector>
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -80,7 +80,7 @@
     int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet);
 
 private:
-    CriticalSectionWrapper* _criticalSection;
+    rtc::CriticalSection    _criticalSection;
     TMMBRSet                _candidateSet;
     TMMBRSet                _boundingSet;
     TMMBRSet                _boundingSetToSend;