Migrate media/ to webrtc::Mutex.
Bug: webrtc:11567
Change-Id: I69e4a1b37737ac8dd852a032612623c4c4f3a30b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176744
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31648}
diff --git a/media/BUILD.gn b/media/BUILD.gn
index f1ead11..72bec31 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -115,6 +115,7 @@
"../rtc_base:rtc_task_queue",
"../rtc_base:sanitizer",
"../rtc_base:stringutils",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker",
"../rtc_base/system:file_wrapper",
"../rtc_base/system:rtc_export",
@@ -324,6 +325,7 @@
"../rtc_base/experiments:min_video_bitrate_experiment",
"../rtc_base/experiments:normalize_simulcast_size_experiment",
"../rtc_base/experiments:rate_control_settings",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/system:rtc_export",
"../rtc_base/third_party/base64",
"../system_wrappers",
@@ -408,6 +410,7 @@
"../p2p:rtc_p2p",
"../rtc_base",
"../rtc_base:rtc_base_approved",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot",
"../system_wrappers",
]
@@ -478,6 +481,7 @@
"../rtc_base:rtc_base_approved",
"../rtc_base:rtc_task_queue",
"../rtc_base:stringutils",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot",
"../test:test_support",
"//testing/gtest",
@@ -589,6 +593,7 @@
"../rtc_base:rtc_task_queue",
"../rtc_base:stringutils",
"../rtc_base/experiments:min_video_bitrate_experiment",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot",
"../test:audio_codec_mocks",
"../test:fake_video_codecs",
diff --git a/media/base/adapted_video_track_source.cc b/media/base/adapted_video_track_source.cc
index c491872..2fce973 100644
--- a/media/base/adapted_video_track_source.cc
+++ b/media/base/adapted_video_track_source.cc
@@ -27,7 +27,7 @@
AdaptedVideoTrackSource::~AdaptedVideoTrackSource() = default;
bool AdaptedVideoTrackSource::GetStats(Stats* stats) {
- rtc::CritScope lock(&stats_crit_);
+ webrtc::MutexLock lock(&stats_mutex_);
if (!stats_) {
return false;
@@ -93,7 +93,7 @@
int* crop_x,
int* crop_y) {
{
- rtc::CritScope lock(&stats_crit_);
+ webrtc::MutexLock lock(&stats_mutex_);
stats_ = Stats{width, height};
}
diff --git a/media/base/adapted_video_track_source.h b/media/base/adapted_video_track_source.h
index 7dbab54..59ae036 100644
--- a/media/base/adapted_video_track_source.h
+++ b/media/base/adapted_video_track_source.h
@@ -21,7 +21,7 @@
#include "api/video/video_source_interface.h"
#include "media/base/video_adapter.h"
#include "media/base/video_broadcaster.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread_annotations.h"
@@ -89,8 +89,8 @@
cricket::VideoAdapter video_adapter_;
- rtc::CriticalSection stats_crit_;
- absl::optional<Stats> stats_ RTC_GUARDED_BY(stats_crit_);
+ webrtc::Mutex stats_mutex_;
+ absl::optional<Stats> stats_ RTC_GUARDED_BY(stats_mutex_);
VideoBroadcaster broadcaster_;
};
diff --git a/media/base/fake_network_interface.h b/media/base/fake_network_interface.h
index 28fbb31..eb08f69 100644
--- a/media/base/fake_network_interface.h
+++ b/media/base/fake_network_interface.h
@@ -19,9 +19,9 @@
#include "media/base/rtp_utils.h"
#include "rtc_base/byte_order.h"
#include "rtc_base/copy_on_write_buffer.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/dscp.h"
#include "rtc_base/message_handler.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h"
namespace cricket {
@@ -44,14 +44,14 @@
// the transport will send multiple copies of the packet with the specified
// SSRCs. This allows us to simulate receiving media from multiple sources.
void SetConferenceMode(bool conf, const std::vector<uint32_t>& ssrcs)
- RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
conf_ = conf;
conf_sent_ssrcs_ = ssrcs;
}
- int NumRtpBytes() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ int NumRtpBytes() RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
int bytes = 0;
for (size_t i = 0; i < rtp_packets_.size(); ++i) {
bytes += static_cast<int>(rtp_packets_[i].size());
@@ -59,49 +59,49 @@
return bytes;
}
- int NumRtpBytes(uint32_t ssrc) RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ int NumRtpBytes(uint32_t ssrc) RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
int bytes = 0;
GetNumRtpBytesAndPackets(ssrc, &bytes, NULL);
return bytes;
}
- int NumRtpPackets() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ int NumRtpPackets() RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
return static_cast<int>(rtp_packets_.size());
}
- int NumRtpPackets(uint32_t ssrc) RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ int NumRtpPackets(uint32_t ssrc) RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
int packets = 0;
GetNumRtpBytesAndPackets(ssrc, NULL, &packets);
return packets;
}
- int NumSentSsrcs() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ int NumSentSsrcs() RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
return static_cast<int>(sent_ssrcs_.size());
}
// Note: callers are responsible for deleting the returned buffer.
const rtc::CopyOnWriteBuffer* GetRtpPacket(int index)
- RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
if (index >= static_cast<int>(rtp_packets_.size())) {
return NULL;
}
return new rtc::CopyOnWriteBuffer(rtp_packets_[index]);
}
- int NumRtcpPackets() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ int NumRtcpPackets() RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
return static_cast<int>(rtcp_packets_.size());
}
// Note: callers are responsible for deleting the returned buffer.
const rtc::CopyOnWriteBuffer* GetRtcpPacket(int index)
- RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
if (index >= static_cast<int>(rtcp_packets_.size())) {
return NULL;
}
@@ -116,8 +116,8 @@
protected:
virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options)
- RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
uint32_t cur_ssrc = 0;
if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) {
@@ -142,8 +142,8 @@
virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options)
- RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope cs(&crit_);
+ RTC_LOCKS_EXCLUDED(mutex_) {
+ webrtc::MutexLock lock(&mutex_);
rtcp_packets_.push_back(*packet);
options_ = options;
if (!conf_) {
@@ -217,7 +217,7 @@
std::map<uint32_t, uint32_t> sent_ssrcs_;
// Map to track packet-number that needs to be dropped per ssrc.
std::map<uint32_t, std::set<uint32_t> > drop_map_;
- rtc::CriticalSection crit_;
+ webrtc::Mutex mutex_;
std::vector<rtc::CopyOnWriteBuffer> rtp_packets_;
std::vector<rtc::CopyOnWriteBuffer> rtcp_packets_;
int sendbuf_size_;
diff --git a/media/base/fake_video_renderer.cc b/media/base/fake_video_renderer.cc
index 801f81d..b3ceb35 100644
--- a/media/base/fake_video_renderer.cc
+++ b/media/base/fake_video_renderer.cc
@@ -15,7 +15,7 @@
FakeVideoRenderer::FakeVideoRenderer() = default;
void FakeVideoRenderer::OnFrame(const webrtc::VideoFrame& frame) {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
// TODO(zhurunz) Check with VP8 team to see if we can remove this
// tolerance on Y values. Some unit tests produce Y values close
// to 16 rather than close to zero, for supposedly black frames.
diff --git a/media/base/fake_video_renderer.h b/media/base/fake_video_renderer.h
index ba67bf0..9f3c87c 100644
--- a/media/base/fake_video_renderer.h
+++ b/media/base/fake_video_renderer.h
@@ -18,8 +18,8 @@
#include "api/video/video_frame_buffer.h"
#include "api/video/video_rotation.h"
#include "api/video/video_sink_interface.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
+#include "rtc_base/synchronization/mutex.h"
namespace cricket {
@@ -33,46 +33,46 @@
int errors() const { return errors_; }
int width() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return width_;
}
int height() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return height_;
}
webrtc::VideoRotation rotation() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return rotation_;
}
int64_t timestamp_us() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return timestamp_us_;
}
int num_rendered_frames() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return num_rendered_frames_;
}
bool black_frame() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return black_frame_;
}
int64_t ntp_time_ms() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return ntp_timestamp_ms_;
}
absl::optional<webrtc::ColorSpace> color_space() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return color_space_;
}
webrtc::RtpPacketInfos packet_infos() const {
- rtc::CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return packet_infos_;
}
@@ -140,7 +140,7 @@
int num_rendered_frames_ = 0;
int64_t ntp_timestamp_ms_ = 0;
bool black_frame_ = false;
- rtc::CriticalSection crit_;
+ mutable webrtc::Mutex mutex_;
rtc::Event frame_rendered_event_;
absl::optional<webrtc::ColorSpace> color_space_;
webrtc::RtpPacketInfos packet_infos_;
diff --git a/media/base/media_channel.cc b/media/base/media_channel.cc
index 5b0ed26..0cef36e 100644
--- a/media/base/media_channel.cc
+++ b/media/base/media_channel.cc
@@ -24,7 +24,7 @@
MediaChannel::~MediaChannel() {}
void MediaChannel::SetInterface(NetworkInterface* iface) {
- rtc::CritScope cs(&network_interface_crit_);
+ webrtc::MutexLock lock(&network_interface_mutex_);
network_interface_ = iface;
UpdateDscp();
}
diff --git a/media/base/media_channel.h b/media/base/media_channel.h
index 07be28c..416f5e9 100644
--- a/media/base/media_channel.h
+++ b/media/base/media_channel.h
@@ -45,13 +45,13 @@
#include "rtc_base/buffer.h"
#include "rtc_base/callback.h"
#include "rtc_base/copy_on_write_buffer.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/dscp.h"
#include "rtc_base/logging.h"
#include "rtc_base/network_route.h"
#include "rtc_base/socket.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/strings/string_builder.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
namespace rtc {
@@ -196,7 +196,7 @@
// Sets the abstract interface class for sending RTP/RTCP data.
virtual void SetInterface(NetworkInterface* iface)
- RTC_LOCKS_EXCLUDED(network_interface_crit_);
+ RTC_LOCKS_EXCLUDED(network_interface_mutex_);
// Called when a RTP packet is received.
virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us) = 0;
@@ -257,8 +257,8 @@
int SetOption(NetworkInterface::SocketType type,
rtc::Socket::Option opt,
- int option) RTC_LOCKS_EXCLUDED(network_interface_crit_) {
- rtc::CritScope cs(&network_interface_crit_);
+ int option) RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
+ webrtc::MutexLock lock(&network_interface_mutex_);
return SetOptionLocked(type, opt, option);
}
@@ -287,7 +287,7 @@
int SetOptionLocked(NetworkInterface::SocketType type,
rtc::Socket::Option opt,
int option)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_mutex_) {
if (!network_interface_)
return -1;
return network_interface_->SetOption(type, opt, option);
@@ -298,14 +298,14 @@
// This is the DSCP value used for both RTP and RTCP channels if DSCP is
// enabled. It can be changed at any time via |SetPreferredDscp|.
rtc::DiffServCodePoint PreferredDscp() const
- RTC_LOCKS_EXCLUDED(network_interface_crit_) {
- rtc::CritScope cs(&network_interface_crit_);
+ RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
+ webrtc::MutexLock lock(&network_interface_mutex_);
return preferred_dscp_;
}
int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp)
- RTC_LOCKS_EXCLUDED(network_interface_crit_) {
- rtc::CritScope cs(&network_interface_crit_);
+ RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
+ webrtc::MutexLock lock(&network_interface_mutex_);
if (preferred_dscp == preferred_dscp_) {
return 0;
}
@@ -316,7 +316,7 @@
private:
// Apply the preferred DSCP setting to the underlying network interface RTP
// and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
- int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) {
+ int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_mutex_) {
rtc::DiffServCodePoint value =
enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
int ret =
@@ -331,8 +331,8 @@
bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
bool rtcp,
const rtc::PacketOptions& options)
- RTC_LOCKS_EXCLUDED(network_interface_crit_) {
- rtc::CritScope cs(&network_interface_crit_);
+ RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
+ webrtc::MutexLock lock(&network_interface_mutex_);
if (!network_interface_)
return false;
@@ -344,11 +344,11 @@
// |network_interface_| can be accessed from the worker_thread and
// from any MediaEngine threads. This critical section is to protect accessing
// of network_interface_ object.
- rtc::CriticalSection network_interface_crit_;
- NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) =
- nullptr;
+ mutable webrtc::Mutex network_interface_mutex_;
+ NetworkInterface* network_interface_
+ RTC_GUARDED_BY(network_interface_mutex_) = nullptr;
rtc::DiffServCodePoint preferred_dscp_
- RTC_GUARDED_BY(network_interface_crit_) = rtc::DSCP_DEFAULT;
+ RTC_GUARDED_BY(network_interface_mutex_) = rtc::DSCP_DEFAULT;
bool extmap_allow_mixed_ = false;
};
diff --git a/media/base/video_broadcaster.cc b/media/base/video_broadcaster.cc
index 700478d..e6a9136 100644
--- a/media/base/video_broadcaster.cc
+++ b/media/base/video_broadcaster.cc
@@ -28,7 +28,7 @@
VideoSinkInterface<webrtc::VideoFrame>* sink,
const VideoSinkWants& wants) {
RTC_DCHECK(sink != nullptr);
- rtc::CritScope cs(&sinks_and_wants_lock_);
+ webrtc::MutexLock lock(&sinks_and_wants_lock_);
if (!FindSinkPair(sink)) {
// |Sink| is a new sink, which didn't receive previous frame.
previous_frame_sent_to_all_sinks_ = false;
@@ -40,23 +40,23 @@
void VideoBroadcaster::RemoveSink(
VideoSinkInterface<webrtc::VideoFrame>* sink) {
RTC_DCHECK(sink != nullptr);
- rtc::CritScope cs(&sinks_and_wants_lock_);
+ webrtc::MutexLock lock(&sinks_and_wants_lock_);
VideoSourceBase::RemoveSink(sink);
UpdateWants();
}
bool VideoBroadcaster::frame_wanted() const {
- rtc::CritScope cs(&sinks_and_wants_lock_);
+ webrtc::MutexLock lock(&sinks_and_wants_lock_);
return !sink_pairs().empty();
}
VideoSinkWants VideoBroadcaster::wants() const {
- rtc::CritScope cs(&sinks_and_wants_lock_);
+ webrtc::MutexLock lock(&sinks_and_wants_lock_);
return current_wants_;
}
void VideoBroadcaster::OnFrame(const webrtc::VideoFrame& frame) {
- rtc::CritScope cs(&sinks_and_wants_lock_);
+ webrtc::MutexLock lock(&sinks_and_wants_lock_);
bool current_frame_was_discarded = false;
for (auto& sink_pair : sink_pairs()) {
if (sink_pair.wants.rotation_applied &&
diff --git a/media/base/video_broadcaster.h b/media/base/video_broadcaster.h
index 898ef2a..0703862 100644
--- a/media/base/video_broadcaster.h
+++ b/media/base/video_broadcaster.h
@@ -15,7 +15,7 @@
#include "api/video/video_frame_buffer.h"
#include "api/video/video_source_interface.h"
#include "media/base/video_source_base.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
@@ -56,7 +56,7 @@
int width,
int height) RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_);
- rtc::CriticalSection sinks_and_wants_lock_;
+ mutable webrtc::Mutex sinks_and_wants_lock_;
VideoSinkWants current_wants_ RTC_GUARDED_BY(sinks_and_wants_lock_);
rtc::scoped_refptr<webrtc::VideoFrameBuffer> black_frame_buffer_;
diff --git a/media/engine/fake_webrtc_video_engine.cc b/media/engine/fake_webrtc_video_engine.cc
index 91f7e53..d767522 100644
--- a/media/engine/fake_webrtc_video_engine.cc
+++ b/media/engine/fake_webrtc_video_engine.cc
@@ -148,7 +148,7 @@
int32_t FakeWebRtcVideoEncoder::InitEncode(
const webrtc::VideoCodec* codecSettings,
const VideoEncoder::Settings& settings) {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
codec_settings_ = *codecSettings;
init_encode_event_.Set();
return WEBRTC_VIDEO_CODEC_OK;
@@ -157,7 +157,7 @@
int32_t FakeWebRtcVideoEncoder::Encode(
const webrtc::VideoFrame& inputImage,
const std::vector<webrtc::VideoFrameType>* frame_types) {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
++num_frames_encoded_;
init_encode_event_.Set();
return WEBRTC_VIDEO_CODEC_OK;
@@ -188,12 +188,12 @@
}
webrtc::VideoCodec FakeWebRtcVideoEncoder::GetCodecSettings() {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return codec_settings_;
}
int FakeWebRtcVideoEncoder::GetNumEncodedFrames() {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return num_frames_encoded_;
}
@@ -219,7 +219,7 @@
std::unique_ptr<webrtc::VideoEncoder>
FakeWebRtcVideoEncoderFactory::CreateVideoEncoder(
const webrtc::SdpVideoFormat& format) {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
std::unique_ptr<webrtc::VideoEncoder> encoder;
if (IsFormatSupported(formats_, format)) {
if (absl::EqualsIgnoreCase(format.name, kVp8CodecName) &&
@@ -262,7 +262,7 @@
void FakeWebRtcVideoEncoderFactory::EncoderDestroyed(
FakeWebRtcVideoEncoder* encoder) {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
encoders_.erase(std::remove(encoders_.begin(), encoders_.end(), encoder),
encoders_.end());
}
@@ -286,13 +286,13 @@
}
int FakeWebRtcVideoEncoderFactory::GetNumCreatedEncoders() {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return num_created_encoders_;
}
const std::vector<FakeWebRtcVideoEncoder*>
FakeWebRtcVideoEncoderFactory::encoders() {
- rtc::CritScope lock(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return encoders_;
}
diff --git a/media/engine/fake_webrtc_video_engine.h b/media/engine/fake_webrtc_video_engine.h
index 28dc4fe..9adb5a4 100644
--- a/media/engine/fake_webrtc_video_engine.h
+++ b/media/engine/fake_webrtc_video_engine.h
@@ -29,8 +29,8 @@
#include "api/video_codecs/video_encoder.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "modules/video_coding/include/video_codec_interface.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace cricket {
@@ -101,10 +101,10 @@
int GetNumEncodedFrames();
private:
- rtc::CriticalSection crit_;
+ webrtc::Mutex mutex_;
rtc::Event init_encode_event_;
- int num_frames_encoded_ RTC_GUARDED_BY(crit_);
- webrtc::VideoCodec codec_settings_ RTC_GUARDED_BY(crit_);
+ int num_frames_encoded_ RTC_GUARDED_BY(mutex_);
+ webrtc::VideoCodec codec_settings_ RTC_GUARDED_BY(mutex_);
FakeWebRtcVideoEncoderFactory* factory_;
};
@@ -128,11 +128,11 @@
const std::vector<FakeWebRtcVideoEncoder*> encoders();
private:
- rtc::CriticalSection crit_;
+ webrtc::Mutex mutex_;
rtc::Event created_video_encoder_event_;
std::vector<webrtc::SdpVideoFormat> formats_;
- std::vector<FakeWebRtcVideoEncoder*> encoders_ RTC_GUARDED_BY(crit_);
- int num_created_encoders_ RTC_GUARDED_BY(crit_);
+ std::vector<FakeWebRtcVideoEncoder*> encoders_ RTC_GUARDED_BY(mutex_);
+ int num_created_encoders_ RTC_GUARDED_BY(mutex_);
bool encoders_have_internal_sources_;
bool vp8_factory_mode_;
};
diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc
index 1d21fc5..ee30ec2 100644
--- a/media/engine/webrtc_video_engine.cc
+++ b/media/engine/webrtc_video_engine.cc
@@ -2953,7 +2953,7 @@
void WebRtcVideoChannel::WebRtcVideoReceiveStream::OnFrame(
const webrtc::VideoFrame& frame) {
- rtc::CritScope crit(&sink_lock_);
+ webrtc::MutexLock lock(&sink_lock_);
int64_t time_now_ms = rtc::TimeMillis();
if (first_frame_timestamp_ < 0)
@@ -2998,7 +2998,7 @@
void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetSink(
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) {
- rtc::CritScope crit(&sink_lock_);
+ webrtc::MutexLock lock(&sink_lock_);
sink_ = sink;
}
@@ -3038,7 +3038,7 @@
info.frame_height = stats.height;
{
- rtc::CritScope frame_cs(&sink_lock_);
+ webrtc::MutexLock frame_cs(&sink_lock_);
info.capture_start_ntp_time_ms = estimated_remote_start_ntp_time_ms_;
}
diff --git a/media/engine/webrtc_video_engine.h b/media/engine/webrtc_video_engine.h
index 126abfd..21033ff 100644
--- a/media/engine/webrtc_video_engine.h
+++ b/media/engine/webrtc_video_engine.h
@@ -32,8 +32,8 @@
#include "media/engine/constants.h"
#include "media/engine/unhandled_packets_buffer.h"
#include "rtc_base/async_invoker.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/network_route.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
@@ -516,7 +516,7 @@
webrtc::VideoDecoderFactory* const decoder_factory_;
- rtc::CriticalSection sink_lock_;
+ webrtc::Mutex sink_lock_;
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
RTC_GUARDED_BY(sink_lock_);
// Expands remote RTP timestamps to int64_t to be able to estimate how long
diff --git a/media/sctp/sctp_transport.cc b/media/sctp/sctp_transport.cc
index c399dfe..9bfc766 100644
--- a/media/sctp/sctp_transport.cc
+++ b/media/sctp/sctp_transport.cc
@@ -41,11 +41,11 @@
#include "p2p/base/dtls_transport_internal.h" // For PF_NORMAL
#include "rtc_base/arraysize.h"
#include "rtc_base/copy_on_write_buffer.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/helpers.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/string_utils.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
#include "rtc_base/trace_event.h"
@@ -89,7 +89,7 @@
// Assigns a new unused ID to the following transport.
uintptr_t Register(cricket::SctpTransport* transport) {
- rtc::CritScope cs(&lock_);
+ webrtc::MutexLock lock(&lock_);
// usrsctp_connect fails with a value of 0...
if (next_id_ == 0) {
++next_id_;
@@ -108,12 +108,12 @@
// Returns true if found.
bool Deregister(uintptr_t id) {
- rtc::CritScope cs(&lock_);
+ webrtc::MutexLock lock(&lock_);
return map_.erase(id) > 0;
}
cricket::SctpTransport* Retrieve(uintptr_t id) const {
- rtc::CritScope cs(&lock_);
+ webrtc::MutexLock lock(&lock_);
auto it = map_.find(id);
if (it == map_.end()) {
return nullptr;
@@ -122,7 +122,7 @@
}
private:
- rtc::CriticalSection lock_;
+ mutable webrtc::Mutex lock_;
uintptr_t next_id_ RTC_GUARDED_BY(lock_) = 0;
std::unordered_map<uintptr_t, cricket::SctpTransport*> map_
diff --git a/media/sctp/sctp_transport_reliability_unittest.cc b/media/sctp/sctp_transport_reliability_unittest.cc
index af9ddfe..e5dbf29 100644
--- a/media/sctp/sctp_transport_reliability_unittest.cc
+++ b/media/sctp/sctp_transport_reliability_unittest.cc
@@ -18,6 +18,7 @@
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/random.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h"
#include "test/gtest.h"
@@ -377,7 +378,7 @@
CreateTwoConnectedSctpTransportsWithAllStreams();
{
- rtc::CritScope cs(&lock_);
+ webrtc::MutexLock lock(&lock_);
if (!errors_list_.empty()) {
return false;
}
@@ -397,7 +398,7 @@
std::vector<std::string> GetErrorsList() const {
std::vector<std::string> result;
{
- rtc::CritScope cs(&lock_);
+ webrtc::MutexLock lock(&lock_);
result = errors_list_;
}
return result;
@@ -566,7 +567,7 @@
}
void ReportError(std::string error) {
- rtc::CritScope cs(&lock_);
+ webrtc::MutexLock lock(&lock_);
errors_list_.push_back(std::move(error));
}
@@ -578,7 +579,7 @@
std::unique_ptr<cricket::SctpTransport> sctp_transport2_;
std::unique_ptr<SctpDataSender> data_sender1_;
std::unique_ptr<SctpDataSender> data_sender2_;
- rtc::CriticalSection lock_;
+ mutable webrtc::Mutex lock_;
std::vector<std::string> errors_list_ RTC_GUARDED_BY(lock_);
const uint32_t id_;