diff --git a/media/BUILD.gn b/media/BUILD.gn index f1ead11e30..72bec31d2f 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -115,6 +115,7 @@ rtc_library("rtc_media_base") { "../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_library("rtc_audio_video") { "../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 @@ rtc_library("rtc_data") { "../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 @@ if (rtc_include_tests) { "../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 @@ if (rtc_include_tests) { "../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 c4918725d2..2fce973f68 100644 --- a/media/base/adapted_video_track_source.cc +++ b/media/base/adapted_video_track_source.cc @@ -27,7 +27,7 @@ AdaptedVideoTrackSource::AdaptedVideoTrackSource(int required_alignment) 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 @@ bool AdaptedVideoTrackSource::AdaptFrame(int width, 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 7dbab540ed..59ae036ff6 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 @@ class RTC_EXPORT AdaptedVideoTrackSource cricket::VideoAdapter video_adapter_; - rtc::CriticalSection stats_crit_; - absl::optional stats_ RTC_GUARDED_BY(stats_crit_); + webrtc::Mutex stats_mutex_; + absl::optional 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 28fbb31a4e..eb08f69b5f 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 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface, // 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& 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(rtp_packets_[i].size()); @@ -59,49 +59,49 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface, 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(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(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(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(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(rtcp_packets_.size())) { return NULL; } @@ -116,8 +116,8 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface, 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 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface, 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 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface, std::map sent_ssrcs_; // Map to track packet-number that needs to be dropped per ssrc. std::map > drop_map_; - rtc::CriticalSection crit_; + webrtc::Mutex mutex_; std::vector rtp_packets_; std::vector rtcp_packets_; int sendbuf_size_; diff --git a/media/base/fake_video_renderer.cc b/media/base/fake_video_renderer.cc index 801f81dec4..b3ceb352f0 100644 --- a/media/base/fake_video_renderer.cc +++ b/media/base/fake_video_renderer.cc @@ -15,7 +15,7 @@ namespace cricket { 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 ba67bf0332..9f3c87c379 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 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface { 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 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 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface { 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 color_space_; webrtc::RtpPacketInfos packet_infos_; diff --git a/media/base/media_channel.cc b/media/base/media_channel.cc index 5b0ed26f8b..0cef36e2b9 100644 --- a/media/base/media_channel.cc +++ b/media/base/media_channel.cc @@ -24,7 +24,7 @@ MediaChannel::MediaChannel() : enable_dscp_(false) {} 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 07be28cafa..416f5e9c2f 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 @@ class MediaChannel : public sigslot::has_slots<> { // 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 @@ class MediaChannel : public sigslot::has_slots<> { 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 @@ class MediaChannel : public sigslot::has_slots<> { 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 @@ class MediaChannel : public sigslot::has_slots<> { // 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 @@ class MediaChannel : public sigslot::has_slots<> { 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 @@ class MediaChannel : public sigslot::has_slots<> { 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 @@ class MediaChannel : public sigslot::has_slots<> { // |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 700478d4e1..e6a91368fc 100644 --- a/media/base/video_broadcaster.cc +++ b/media/base/video_broadcaster.cc @@ -28,7 +28,7 @@ void VideoBroadcaster::AddOrUpdateSink( VideoSinkInterface* 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::AddOrUpdateSink( void VideoBroadcaster::RemoveSink( VideoSinkInterface* 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 898ef2ac9a..0703862c4f 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 @@ class VideoBroadcaster : public VideoSourceBase, 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 black_frame_buffer_; diff --git a/media/engine/fake_webrtc_video_engine.cc b/media/engine/fake_webrtc_video_engine.cc index 91f7e53956..d7675228cf 100644 --- a/media/engine/fake_webrtc_video_engine.cc +++ b/media/engine/fake_webrtc_video_engine.cc @@ -148,7 +148,7 @@ void FakeWebRtcVideoEncoder::SetFecControllerOverride( 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::InitEncode( int32_t FakeWebRtcVideoEncoder::Encode( const webrtc::VideoFrame& inputImage, const std::vector* 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 @@ bool FakeWebRtcVideoEncoder::WaitForInitEncode() { } 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 @@ FakeWebRtcVideoEncoderFactory::GetSupportedFormats() const { std::unique_ptr FakeWebRtcVideoEncoderFactory::CreateVideoEncoder( const webrtc::SdpVideoFormat& format) { - rtc::CritScope lock(&crit_); + webrtc::MutexLock lock(&mutex_); std::unique_ptr encoder; if (IsFormatSupported(formats_, format)) { if (absl::EqualsIgnoreCase(format.name, kVp8CodecName) && @@ -262,7 +262,7 @@ bool FakeWebRtcVideoEncoderFactory::WaitForCreatedVideoEncoders( 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 @@ void FakeWebRtcVideoEncoderFactory::AddSupportedVideoCodecType( } int FakeWebRtcVideoEncoderFactory::GetNumCreatedEncoders() { - rtc::CritScope lock(&crit_); + webrtc::MutexLock lock(&mutex_); return num_created_encoders_; } const std::vector 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 28dc4fe99b..9adb5a41ef 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 @@ class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { 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 @@ class FakeWebRtcVideoEncoderFactory : public webrtc::VideoEncoderFactory { const std::vector encoders(); private: - rtc::CriticalSection crit_; + webrtc::Mutex mutex_; rtc::Event created_video_encoder_event_; std::vector formats_; - std::vector encoders_ RTC_GUARDED_BY(crit_); - int num_created_encoders_ RTC_GUARDED_BY(crit_); + std::vector 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 1d21fc5991..ee30ec290f 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -2953,7 +2953,7 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream:: 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 @@ int WebRtcVideoChannel::WebRtcVideoReceiveStream::GetBaseMinimumPlayoutDelayMs() void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetSink( rtc::VideoSinkInterface* sink) { - rtc::CritScope crit(&sink_lock_); + webrtc::MutexLock lock(&sink_lock_); sink_ = sink; } @@ -3038,7 +3038,7 @@ WebRtcVideoChannel::WebRtcVideoReceiveStream::GetVideoReceiverInfo( 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 126abfd290..21033ffae7 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 @@ class WebRtcVideoChannel : public VideoMediaChannel, webrtc::VideoDecoderFactory* const decoder_factory_; - rtc::CriticalSection sink_lock_; + webrtc::Mutex sink_lock_; rtc::VideoSinkInterface* 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 c399dfe98d..9bfc766152 100644 --- a/media/sctp/sctp_transport.cc +++ b/media/sctp/sctp_transport.cc @@ -41,11 +41,11 @@ constexpr int kSctpSuccessReturn = 1; #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 @@ class SctpTransportMap { // 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 @@ class SctpTransportMap { // 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 @@ class SctpTransportMap { } private: - rtc::CriticalSection lock_; + mutable webrtc::Mutex lock_; uintptr_t next_id_ RTC_GUARDED_BY(lock_) = 0; std::unordered_map map_ diff --git a/media/sctp/sctp_transport_reliability_unittest.cc b/media/sctp/sctp_transport_reliability_unittest.cc index af9ddfeba7..e5dbf2933d 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 @@ class SctpPingPong final { CreateTwoConnectedSctpTransportsWithAllStreams(); { - rtc::CritScope cs(&lock_); + webrtc::MutexLock lock(&lock_); if (!errors_list_.empty()) { return false; } @@ -397,7 +398,7 @@ class SctpPingPong final { std::vector GetErrorsList() const { std::vector result; { - rtc::CritScope cs(&lock_); + webrtc::MutexLock lock(&lock_); result = errors_list_; } return result; @@ -566,7 +567,7 @@ class SctpPingPong final { } void ReportError(std::string error) { - rtc::CritScope cs(&lock_); + webrtc::MutexLock lock(&lock_); errors_list_.push_back(std::move(error)); } @@ -578,7 +579,7 @@ class SctpPingPong final { std::unique_ptr sctp_transport2_; std::unique_ptr data_sender1_; std::unique_ptr data_sender2_; - rtc::CriticalSection lock_; + mutable webrtc::Mutex lock_; std::vector errors_list_ RTC_GUARDED_BY(lock_); const uint32_t id_;