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}
This commit is contained in:
Markus Handell 2020-07-07 15:43:11 +02:00 committed by Commit Bot
parent 06d034fe40
commit 1e257cacbf
16 changed files with 100 additions and 94 deletions

View File

@ -115,6 +115,7 @@ rtc_library("rtc_media_base") {
"../rtc_base:rtc_task_queue", "../rtc_base:rtc_task_queue",
"../rtc_base:sanitizer", "../rtc_base:sanitizer",
"../rtc_base:stringutils", "../rtc_base:stringutils",
"../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker", "../rtc_base/synchronization:sequence_checker",
"../rtc_base/system:file_wrapper", "../rtc_base/system:file_wrapper",
"../rtc_base/system:rtc_export", "../rtc_base/system:rtc_export",
@ -324,6 +325,7 @@ rtc_library("rtc_audio_video") {
"../rtc_base/experiments:min_video_bitrate_experiment", "../rtc_base/experiments:min_video_bitrate_experiment",
"../rtc_base/experiments:normalize_simulcast_size_experiment", "../rtc_base/experiments:normalize_simulcast_size_experiment",
"../rtc_base/experiments:rate_control_settings", "../rtc_base/experiments:rate_control_settings",
"../rtc_base/synchronization:mutex",
"../rtc_base/system:rtc_export", "../rtc_base/system:rtc_export",
"../rtc_base/third_party/base64", "../rtc_base/third_party/base64",
"../system_wrappers", "../system_wrappers",
@ -408,6 +410,7 @@ rtc_library("rtc_data") {
"../p2p:rtc_p2p", "../p2p:rtc_p2p",
"../rtc_base", "../rtc_base",
"../rtc_base:rtc_base_approved", "../rtc_base:rtc_base_approved",
"../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot", "../rtc_base/third_party/sigslot",
"../system_wrappers", "../system_wrappers",
] ]
@ -478,6 +481,7 @@ if (rtc_include_tests) {
"../rtc_base:rtc_base_approved", "../rtc_base:rtc_base_approved",
"../rtc_base:rtc_task_queue", "../rtc_base:rtc_task_queue",
"../rtc_base:stringutils", "../rtc_base:stringutils",
"../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot", "../rtc_base/third_party/sigslot",
"../test:test_support", "../test:test_support",
"//testing/gtest", "//testing/gtest",
@ -589,6 +593,7 @@ if (rtc_include_tests) {
"../rtc_base:rtc_task_queue", "../rtc_base:rtc_task_queue",
"../rtc_base:stringutils", "../rtc_base:stringutils",
"../rtc_base/experiments:min_video_bitrate_experiment", "../rtc_base/experiments:min_video_bitrate_experiment",
"../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot", "../rtc_base/third_party/sigslot",
"../test:audio_codec_mocks", "../test:audio_codec_mocks",
"../test:fake_video_codecs", "../test:fake_video_codecs",

View File

@ -27,7 +27,7 @@ AdaptedVideoTrackSource::AdaptedVideoTrackSource(int required_alignment)
AdaptedVideoTrackSource::~AdaptedVideoTrackSource() = default; AdaptedVideoTrackSource::~AdaptedVideoTrackSource() = default;
bool AdaptedVideoTrackSource::GetStats(Stats* stats) { bool AdaptedVideoTrackSource::GetStats(Stats* stats) {
rtc::CritScope lock(&stats_crit_); webrtc::MutexLock lock(&stats_mutex_);
if (!stats_) { if (!stats_) {
return false; return false;
@ -93,7 +93,7 @@ bool AdaptedVideoTrackSource::AdaptFrame(int width,
int* crop_x, int* crop_x,
int* crop_y) { int* crop_y) {
{ {
rtc::CritScope lock(&stats_crit_); webrtc::MutexLock lock(&stats_mutex_);
stats_ = Stats{width, height}; stats_ = Stats{width, height};
} }

View File

@ -21,7 +21,7 @@
#include "api/video/video_source_interface.h" #include "api/video/video_source_interface.h"
#include "media/base/video_adapter.h" #include "media/base/video_adapter.h"
#include "media/base/video_broadcaster.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/system/rtc_export.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
@ -89,8 +89,8 @@ class RTC_EXPORT AdaptedVideoTrackSource
cricket::VideoAdapter video_adapter_; cricket::VideoAdapter video_adapter_;
rtc::CriticalSection stats_crit_; webrtc::Mutex stats_mutex_;
absl::optional<Stats> stats_ RTC_GUARDED_BY(stats_crit_); absl::optional<Stats> stats_ RTC_GUARDED_BY(stats_mutex_);
VideoBroadcaster broadcaster_; VideoBroadcaster broadcaster_;
}; };

View File

@ -19,9 +19,9 @@
#include "media/base/rtp_utils.h" #include "media/base/rtp_utils.h"
#include "rtc_base/byte_order.h" #include "rtc_base/byte_order.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/dscp.h" #include "rtc_base/dscp.h"
#include "rtc_base/message_handler.h" #include "rtc_base/message_handler.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
namespace cricket { namespace cricket {
@ -44,14 +44,14 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
// the transport will send multiple copies of the packet with the specified // the transport will send multiple copies of the packet with the specified
// SSRCs. This allows us to simulate receiving media from multiple sources. // SSRCs. This allows us to simulate receiving media from multiple sources.
void SetConferenceMode(bool conf, const std::vector<uint32_t>& ssrcs) void SetConferenceMode(bool conf, const std::vector<uint32_t>& ssrcs)
RTC_LOCKS_EXCLUDED(crit_) { RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
conf_ = conf; conf_ = conf;
conf_sent_ssrcs_ = ssrcs; conf_sent_ssrcs_ = ssrcs;
} }
int NumRtpBytes() RTC_LOCKS_EXCLUDED(crit_) { int NumRtpBytes() RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
int bytes = 0; int bytes = 0;
for (size_t i = 0; i < rtp_packets_.size(); ++i) { for (size_t i = 0; i < rtp_packets_.size(); ++i) {
bytes += static_cast<int>(rtp_packets_[i].size()); bytes += static_cast<int>(rtp_packets_[i].size());
@ -59,49 +59,49 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
return bytes; return bytes;
} }
int NumRtpBytes(uint32_t ssrc) RTC_LOCKS_EXCLUDED(crit_) { int NumRtpBytes(uint32_t ssrc) RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
int bytes = 0; int bytes = 0;
GetNumRtpBytesAndPackets(ssrc, &bytes, NULL); GetNumRtpBytesAndPackets(ssrc, &bytes, NULL);
return bytes; return bytes;
} }
int NumRtpPackets() RTC_LOCKS_EXCLUDED(crit_) { int NumRtpPackets() RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return static_cast<int>(rtp_packets_.size()); return static_cast<int>(rtp_packets_.size());
} }
int NumRtpPackets(uint32_t ssrc) RTC_LOCKS_EXCLUDED(crit_) { int NumRtpPackets(uint32_t ssrc) RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
int packets = 0; int packets = 0;
GetNumRtpBytesAndPackets(ssrc, NULL, &packets); GetNumRtpBytesAndPackets(ssrc, NULL, &packets);
return packets; return packets;
} }
int NumSentSsrcs() RTC_LOCKS_EXCLUDED(crit_) { int NumSentSsrcs() RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return static_cast<int>(sent_ssrcs_.size()); return static_cast<int>(sent_ssrcs_.size());
} }
// Note: callers are responsible for deleting the returned buffer. // Note: callers are responsible for deleting the returned buffer.
const rtc::CopyOnWriteBuffer* GetRtpPacket(int index) const rtc::CopyOnWriteBuffer* GetRtpPacket(int index)
RTC_LOCKS_EXCLUDED(crit_) { RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (index >= static_cast<int>(rtp_packets_.size())) { if (index >= static_cast<int>(rtp_packets_.size())) {
return NULL; return NULL;
} }
return new rtc::CopyOnWriteBuffer(rtp_packets_[index]); return new rtc::CopyOnWriteBuffer(rtp_packets_[index]);
} }
int NumRtcpPackets() RTC_LOCKS_EXCLUDED(crit_) { int NumRtcpPackets() RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return static_cast<int>(rtcp_packets_.size()); return static_cast<int>(rtcp_packets_.size());
} }
// Note: callers are responsible for deleting the returned buffer. // Note: callers are responsible for deleting the returned buffer.
const rtc::CopyOnWriteBuffer* GetRtcpPacket(int index) const rtc::CopyOnWriteBuffer* GetRtcpPacket(int index)
RTC_LOCKS_EXCLUDED(crit_) { RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (index >= static_cast<int>(rtcp_packets_.size())) { if (index >= static_cast<int>(rtcp_packets_.size())) {
return NULL; return NULL;
} }
@ -116,8 +116,8 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
protected: protected:
virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet, virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options) const rtc::PacketOptions& options)
RTC_LOCKS_EXCLUDED(crit_) { RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
uint32_t cur_ssrc = 0; uint32_t cur_ssrc = 0;
if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) { if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) {
@ -142,8 +142,8 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet, virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options) const rtc::PacketOptions& options)
RTC_LOCKS_EXCLUDED(crit_) { RTC_LOCKS_EXCLUDED(mutex_) {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
rtcp_packets_.push_back(*packet); rtcp_packets_.push_back(*packet);
options_ = options; options_ = options;
if (!conf_) { if (!conf_) {
@ -217,7 +217,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
std::map<uint32_t, uint32_t> sent_ssrcs_; std::map<uint32_t, uint32_t> sent_ssrcs_;
// Map to track packet-number that needs to be dropped per ssrc. // Map to track packet-number that needs to be dropped per ssrc.
std::map<uint32_t, std::set<uint32_t> > drop_map_; 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> rtp_packets_;
std::vector<rtc::CopyOnWriteBuffer> rtcp_packets_; std::vector<rtc::CopyOnWriteBuffer> rtcp_packets_;
int sendbuf_size_; int sendbuf_size_;

View File

@ -15,7 +15,7 @@ namespace cricket {
FakeVideoRenderer::FakeVideoRenderer() = default; FakeVideoRenderer::FakeVideoRenderer() = default;
void FakeVideoRenderer::OnFrame(const webrtc::VideoFrame& frame) { 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 // TODO(zhurunz) Check with VP8 team to see if we can remove this
// tolerance on Y values. Some unit tests produce Y values close // tolerance on Y values. Some unit tests produce Y values close
// to 16 rather than close to zero, for supposedly black frames. // to 16 rather than close to zero, for supposedly black frames.

View File

@ -18,8 +18,8 @@
#include "api/video/video_frame_buffer.h" #include "api/video/video_frame_buffer.h"
#include "api/video/video_rotation.h" #include "api/video/video_rotation.h"
#include "api/video/video_sink_interface.h" #include "api/video/video_sink_interface.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/synchronization/mutex.h"
namespace cricket { namespace cricket {
@ -33,46 +33,46 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
int errors() const { return errors_; } int errors() const { return errors_; }
int width() const { int width() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return width_; return width_;
} }
int height() const { int height() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return height_; return height_;
} }
webrtc::VideoRotation rotation() const { webrtc::VideoRotation rotation() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return rotation_; return rotation_;
} }
int64_t timestamp_us() const { int64_t timestamp_us() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return timestamp_us_; return timestamp_us_;
} }
int num_rendered_frames() const { int num_rendered_frames() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return num_rendered_frames_; return num_rendered_frames_;
} }
bool black_frame() const { bool black_frame() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return black_frame_; return black_frame_;
} }
int64_t ntp_time_ms() const { int64_t ntp_time_ms() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return ntp_timestamp_ms_; return ntp_timestamp_ms_;
} }
absl::optional<webrtc::ColorSpace> color_space() const { absl::optional<webrtc::ColorSpace> color_space() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return color_space_; return color_space_;
} }
webrtc::RtpPacketInfos packet_infos() const { webrtc::RtpPacketInfos packet_infos() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return packet_infos_; return packet_infos_;
} }
@ -140,7 +140,7 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
int num_rendered_frames_ = 0; int num_rendered_frames_ = 0;
int64_t ntp_timestamp_ms_ = 0; int64_t ntp_timestamp_ms_ = 0;
bool black_frame_ = false; bool black_frame_ = false;
rtc::CriticalSection crit_; mutable webrtc::Mutex mutex_;
rtc::Event frame_rendered_event_; rtc::Event frame_rendered_event_;
absl::optional<webrtc::ColorSpace> color_space_; absl::optional<webrtc::ColorSpace> color_space_;
webrtc::RtpPacketInfos packet_infos_; webrtc::RtpPacketInfos packet_infos_;

View File

@ -24,7 +24,7 @@ MediaChannel::MediaChannel() : enable_dscp_(false) {}
MediaChannel::~MediaChannel() {} MediaChannel::~MediaChannel() {}
void MediaChannel::SetInterface(NetworkInterface* iface) { void MediaChannel::SetInterface(NetworkInterface* iface) {
rtc::CritScope cs(&network_interface_crit_); webrtc::MutexLock lock(&network_interface_mutex_);
network_interface_ = iface; network_interface_ = iface;
UpdateDscp(); UpdateDscp();
} }

View File

@ -45,13 +45,13 @@
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/callback.h" #include "rtc_base/callback.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/dscp.h" #include "rtc_base/dscp.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/network_route.h" #include "rtc_base/network_route.h"
#include "rtc_base/socket.h" #include "rtc_base/socket.h"
#include "rtc_base/string_encode.h" #include "rtc_base/string_encode.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/third_party/sigslot/sigslot.h"
namespace rtc { namespace rtc {
@ -196,7 +196,7 @@ class MediaChannel : public sigslot::has_slots<> {
// Sets the abstract interface class for sending RTP/RTCP data. // Sets the abstract interface class for sending RTP/RTCP data.
virtual void SetInterface(NetworkInterface* iface) virtual void SetInterface(NetworkInterface* iface)
RTC_LOCKS_EXCLUDED(network_interface_crit_); RTC_LOCKS_EXCLUDED(network_interface_mutex_);
// Called when a RTP packet is received. // Called when a RTP packet is received.
virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet, virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us) = 0; int64_t packet_time_us) = 0;
@ -257,8 +257,8 @@ class MediaChannel : public sigslot::has_slots<> {
int SetOption(NetworkInterface::SocketType type, int SetOption(NetworkInterface::SocketType type,
rtc::Socket::Option opt, rtc::Socket::Option opt,
int option) RTC_LOCKS_EXCLUDED(network_interface_crit_) { int option) RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
rtc::CritScope cs(&network_interface_crit_); webrtc::MutexLock lock(&network_interface_mutex_);
return SetOptionLocked(type, opt, option); return SetOptionLocked(type, opt, option);
} }
@ -287,7 +287,7 @@ class MediaChannel : public sigslot::has_slots<> {
int SetOptionLocked(NetworkInterface::SocketType type, int SetOptionLocked(NetworkInterface::SocketType type,
rtc::Socket::Option opt, rtc::Socket::Option opt,
int option) int option)
RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) { RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_mutex_) {
if (!network_interface_) if (!network_interface_)
return -1; return -1;
return network_interface_->SetOption(type, opt, option); 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 // 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|. // enabled. It can be changed at any time via |SetPreferredDscp|.
rtc::DiffServCodePoint PreferredDscp() const rtc::DiffServCodePoint PreferredDscp() const
RTC_LOCKS_EXCLUDED(network_interface_crit_) { RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
rtc::CritScope cs(&network_interface_crit_); webrtc::MutexLock lock(&network_interface_mutex_);
return preferred_dscp_; return preferred_dscp_;
} }
int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp)
RTC_LOCKS_EXCLUDED(network_interface_crit_) { RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
rtc::CritScope cs(&network_interface_crit_); webrtc::MutexLock lock(&network_interface_mutex_);
if (preferred_dscp == preferred_dscp_) { if (preferred_dscp == preferred_dscp_) {
return 0; return 0;
} }
@ -316,7 +316,7 @@ class MediaChannel : public sigslot::has_slots<> {
private: private:
// Apply the preferred DSCP setting to the underlying network interface RTP // Apply the preferred DSCP setting to the underlying network interface RTP
// and RTCP channels. If DSCP is disabled, then apply the default DSCP value. // 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 = rtc::DiffServCodePoint value =
enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT; enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
int ret = int ret =
@ -331,8 +331,8 @@ class MediaChannel : public sigslot::has_slots<> {
bool DoSendPacket(rtc::CopyOnWriteBuffer* packet, bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
bool rtcp, bool rtcp,
const rtc::PacketOptions& options) const rtc::PacketOptions& options)
RTC_LOCKS_EXCLUDED(network_interface_crit_) { RTC_LOCKS_EXCLUDED(network_interface_mutex_) {
rtc::CritScope cs(&network_interface_crit_); webrtc::MutexLock lock(&network_interface_mutex_);
if (!network_interface_) if (!network_interface_)
return false; return false;
@ -344,11 +344,11 @@ class MediaChannel : public sigslot::has_slots<> {
// |network_interface_| can be accessed from the worker_thread and // |network_interface_| can be accessed from the worker_thread and
// from any MediaEngine threads. This critical section is to protect accessing // from any MediaEngine threads. This critical section is to protect accessing
// of network_interface_ object. // of network_interface_ object.
rtc::CriticalSection network_interface_crit_; mutable webrtc::Mutex network_interface_mutex_;
NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) = NetworkInterface* network_interface_
nullptr; RTC_GUARDED_BY(network_interface_mutex_) = nullptr;
rtc::DiffServCodePoint preferred_dscp_ 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; bool extmap_allow_mixed_ = false;
}; };

View File

@ -28,7 +28,7 @@ void VideoBroadcaster::AddOrUpdateSink(
VideoSinkInterface<webrtc::VideoFrame>* sink, VideoSinkInterface<webrtc::VideoFrame>* sink,
const VideoSinkWants& wants) { const VideoSinkWants& wants) {
RTC_DCHECK(sink != nullptr); RTC_DCHECK(sink != nullptr);
rtc::CritScope cs(&sinks_and_wants_lock_); webrtc::MutexLock lock(&sinks_and_wants_lock_);
if (!FindSinkPair(sink)) { if (!FindSinkPair(sink)) {
// |Sink| is a new sink, which didn't receive previous frame. // |Sink| is a new sink, which didn't receive previous frame.
previous_frame_sent_to_all_sinks_ = false; previous_frame_sent_to_all_sinks_ = false;
@ -40,23 +40,23 @@ void VideoBroadcaster::AddOrUpdateSink(
void VideoBroadcaster::RemoveSink( void VideoBroadcaster::RemoveSink(
VideoSinkInterface<webrtc::VideoFrame>* sink) { VideoSinkInterface<webrtc::VideoFrame>* sink) {
RTC_DCHECK(sink != nullptr); RTC_DCHECK(sink != nullptr);
rtc::CritScope cs(&sinks_and_wants_lock_); webrtc::MutexLock lock(&sinks_and_wants_lock_);
VideoSourceBase::RemoveSink(sink); VideoSourceBase::RemoveSink(sink);
UpdateWants(); UpdateWants();
} }
bool VideoBroadcaster::frame_wanted() const { bool VideoBroadcaster::frame_wanted() const {
rtc::CritScope cs(&sinks_and_wants_lock_); webrtc::MutexLock lock(&sinks_and_wants_lock_);
return !sink_pairs().empty(); return !sink_pairs().empty();
} }
VideoSinkWants VideoBroadcaster::wants() const { VideoSinkWants VideoBroadcaster::wants() const {
rtc::CritScope cs(&sinks_and_wants_lock_); webrtc::MutexLock lock(&sinks_and_wants_lock_);
return current_wants_; return current_wants_;
} }
void VideoBroadcaster::OnFrame(const webrtc::VideoFrame& frame) { 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; bool current_frame_was_discarded = false;
for (auto& sink_pair : sink_pairs()) { for (auto& sink_pair : sink_pairs()) {
if (sink_pair.wants.rotation_applied && if (sink_pair.wants.rotation_applied &&

View File

@ -15,7 +15,7 @@
#include "api/video/video_frame_buffer.h" #include "api/video/video_frame_buffer.h"
#include "api/video/video_source_interface.h" #include "api/video/video_source_interface.h"
#include "media/base/video_source_base.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_annotations.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
@ -56,7 +56,7 @@ class VideoBroadcaster : public VideoSourceBase,
int width, int width,
int height) RTC_EXCLUSIVE_LOCKS_REQUIRED(sinks_and_wants_lock_); 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_); VideoSinkWants current_wants_ RTC_GUARDED_BY(sinks_and_wants_lock_);
rtc::scoped_refptr<webrtc::VideoFrameBuffer> black_frame_buffer_; rtc::scoped_refptr<webrtc::VideoFrameBuffer> black_frame_buffer_;

View File

@ -148,7 +148,7 @@ void FakeWebRtcVideoEncoder::SetFecControllerOverride(
int32_t FakeWebRtcVideoEncoder::InitEncode( int32_t FakeWebRtcVideoEncoder::InitEncode(
const webrtc::VideoCodec* codecSettings, const webrtc::VideoCodec* codecSettings,
const VideoEncoder::Settings& settings) { const VideoEncoder::Settings& settings) {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
codec_settings_ = *codecSettings; codec_settings_ = *codecSettings;
init_encode_event_.Set(); init_encode_event_.Set();
return WEBRTC_VIDEO_CODEC_OK; return WEBRTC_VIDEO_CODEC_OK;
@ -157,7 +157,7 @@ int32_t FakeWebRtcVideoEncoder::InitEncode(
int32_t FakeWebRtcVideoEncoder::Encode( int32_t FakeWebRtcVideoEncoder::Encode(
const webrtc::VideoFrame& inputImage, const webrtc::VideoFrame& inputImage,
const std::vector<webrtc::VideoFrameType>* frame_types) { const std::vector<webrtc::VideoFrameType>* frame_types) {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
++num_frames_encoded_; ++num_frames_encoded_;
init_encode_event_.Set(); init_encode_event_.Set();
return WEBRTC_VIDEO_CODEC_OK; return WEBRTC_VIDEO_CODEC_OK;
@ -188,12 +188,12 @@ bool FakeWebRtcVideoEncoder::WaitForInitEncode() {
} }
webrtc::VideoCodec FakeWebRtcVideoEncoder::GetCodecSettings() { webrtc::VideoCodec FakeWebRtcVideoEncoder::GetCodecSettings() {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
return codec_settings_; return codec_settings_;
} }
int FakeWebRtcVideoEncoder::GetNumEncodedFrames() { int FakeWebRtcVideoEncoder::GetNumEncodedFrames() {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
return num_frames_encoded_; return num_frames_encoded_;
} }
@ -219,7 +219,7 @@ FakeWebRtcVideoEncoderFactory::GetSupportedFormats() const {
std::unique_ptr<webrtc::VideoEncoder> std::unique_ptr<webrtc::VideoEncoder>
FakeWebRtcVideoEncoderFactory::CreateVideoEncoder( FakeWebRtcVideoEncoderFactory::CreateVideoEncoder(
const webrtc::SdpVideoFormat& format) { const webrtc::SdpVideoFormat& format) {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
std::unique_ptr<webrtc::VideoEncoder> encoder; std::unique_ptr<webrtc::VideoEncoder> encoder;
if (IsFormatSupported(formats_, format)) { if (IsFormatSupported(formats_, format)) {
if (absl::EqualsIgnoreCase(format.name, kVp8CodecName) && if (absl::EqualsIgnoreCase(format.name, kVp8CodecName) &&
@ -262,7 +262,7 @@ bool FakeWebRtcVideoEncoderFactory::WaitForCreatedVideoEncoders(
void FakeWebRtcVideoEncoderFactory::EncoderDestroyed( void FakeWebRtcVideoEncoderFactory::EncoderDestroyed(
FakeWebRtcVideoEncoder* encoder) { FakeWebRtcVideoEncoder* encoder) {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
encoders_.erase(std::remove(encoders_.begin(), encoders_.end(), encoder), encoders_.erase(std::remove(encoders_.begin(), encoders_.end(), encoder),
encoders_.end()); encoders_.end());
} }
@ -286,13 +286,13 @@ void FakeWebRtcVideoEncoderFactory::AddSupportedVideoCodecType(
} }
int FakeWebRtcVideoEncoderFactory::GetNumCreatedEncoders() { int FakeWebRtcVideoEncoderFactory::GetNumCreatedEncoders() {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
return num_created_encoders_; return num_created_encoders_;
} }
const std::vector<FakeWebRtcVideoEncoder*> const std::vector<FakeWebRtcVideoEncoder*>
FakeWebRtcVideoEncoderFactory::encoders() { FakeWebRtcVideoEncoderFactory::encoders() {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
return encoders_; return encoders_;
} }

View File

@ -29,8 +29,8 @@
#include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder.h"
#include "api/video_codecs/video_encoder_factory.h" #include "api/video_codecs/video_encoder_factory.h"
#include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
namespace cricket { namespace cricket {
@ -101,10 +101,10 @@ class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder {
int GetNumEncodedFrames(); int GetNumEncodedFrames();
private: private:
rtc::CriticalSection crit_; webrtc::Mutex mutex_;
rtc::Event init_encode_event_; rtc::Event init_encode_event_;
int num_frames_encoded_ RTC_GUARDED_BY(crit_); int num_frames_encoded_ RTC_GUARDED_BY(mutex_);
webrtc::VideoCodec codec_settings_ RTC_GUARDED_BY(crit_); webrtc::VideoCodec codec_settings_ RTC_GUARDED_BY(mutex_);
FakeWebRtcVideoEncoderFactory* factory_; FakeWebRtcVideoEncoderFactory* factory_;
}; };
@ -128,11 +128,11 @@ class FakeWebRtcVideoEncoderFactory : public webrtc::VideoEncoderFactory {
const std::vector<FakeWebRtcVideoEncoder*> encoders(); const std::vector<FakeWebRtcVideoEncoder*> encoders();
private: private:
rtc::CriticalSection crit_; webrtc::Mutex mutex_;
rtc::Event created_video_encoder_event_; rtc::Event created_video_encoder_event_;
std::vector<webrtc::SdpVideoFormat> formats_; std::vector<webrtc::SdpVideoFormat> formats_;
std::vector<FakeWebRtcVideoEncoder*> encoders_ RTC_GUARDED_BY(crit_); std::vector<FakeWebRtcVideoEncoder*> encoders_ RTC_GUARDED_BY(mutex_);
int num_created_encoders_ RTC_GUARDED_BY(crit_); int num_created_encoders_ RTC_GUARDED_BY(mutex_);
bool encoders_have_internal_sources_; bool encoders_have_internal_sources_;
bool vp8_factory_mode_; bool vp8_factory_mode_;
}; };

View File

@ -2953,7 +2953,7 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::
void WebRtcVideoChannel::WebRtcVideoReceiveStream::OnFrame( void WebRtcVideoChannel::WebRtcVideoReceiveStream::OnFrame(
const webrtc::VideoFrame& frame) { const webrtc::VideoFrame& frame) {
rtc::CritScope crit(&sink_lock_); webrtc::MutexLock lock(&sink_lock_);
int64_t time_now_ms = rtc::TimeMillis(); int64_t time_now_ms = rtc::TimeMillis();
if (first_frame_timestamp_ < 0) if (first_frame_timestamp_ < 0)
@ -2998,7 +2998,7 @@ int WebRtcVideoChannel::WebRtcVideoReceiveStream::GetBaseMinimumPlayoutDelayMs()
void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetSink( void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetSink(
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) { rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) {
rtc::CritScope crit(&sink_lock_); webrtc::MutexLock lock(&sink_lock_);
sink_ = sink; sink_ = sink;
} }
@ -3038,7 +3038,7 @@ WebRtcVideoChannel::WebRtcVideoReceiveStream::GetVideoReceiverInfo(
info.frame_height = stats.height; 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_; info.capture_start_ntp_time_ms = estimated_remote_start_ntp_time_ms_;
} }

View File

@ -32,8 +32,8 @@
#include "media/engine/constants.h" #include "media/engine/constants.h"
#include "media/engine/unhandled_packets_buffer.h" #include "media/engine/unhandled_packets_buffer.h"
#include "rtc_base/async_invoker.h" #include "rtc_base/async_invoker.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/network_route.h" #include "rtc_base/network_route.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
@ -516,7 +516,7 @@ class WebRtcVideoChannel : public VideoMediaChannel,
webrtc::VideoDecoderFactory* const decoder_factory_; webrtc::VideoDecoderFactory* const decoder_factory_;
rtc::CriticalSection sink_lock_; webrtc::Mutex sink_lock_;
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_ rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
RTC_GUARDED_BY(sink_lock_); RTC_GUARDED_BY(sink_lock_);
// Expands remote RTP timestamps to int64_t to be able to estimate how long // Expands remote RTP timestamps to int64_t to be able to estimate how long

View File

@ -41,11 +41,11 @@ constexpr int kSctpSuccessReturn = 1;
#include "p2p/base/dtls_transport_internal.h" // For PF_NORMAL #include "p2p/base/dtls_transport_internal.h" // For PF_NORMAL
#include "rtc_base/arraysize.h" #include "rtc_base/arraysize.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/helpers.h" #include "rtc_base/helpers.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/string_utils.h" #include "rtc_base/string_utils.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "rtc_base/trace_event.h" #include "rtc_base/trace_event.h"
@ -89,7 +89,7 @@ class SctpTransportMap {
// Assigns a new unused ID to the following transport. // Assigns a new unused ID to the following transport.
uintptr_t Register(cricket::SctpTransport* transport) { uintptr_t Register(cricket::SctpTransport* transport) {
rtc::CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
// usrsctp_connect fails with a value of 0... // usrsctp_connect fails with a value of 0...
if (next_id_ == 0) { if (next_id_ == 0) {
++next_id_; ++next_id_;
@ -108,12 +108,12 @@ class SctpTransportMap {
// Returns true if found. // Returns true if found.
bool Deregister(uintptr_t id) { bool Deregister(uintptr_t id) {
rtc::CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
return map_.erase(id) > 0; return map_.erase(id) > 0;
} }
cricket::SctpTransport* Retrieve(uintptr_t id) const { cricket::SctpTransport* Retrieve(uintptr_t id) const {
rtc::CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
auto it = map_.find(id); auto it = map_.find(id);
if (it == map_.end()) { if (it == map_.end()) {
return nullptr; return nullptr;
@ -122,7 +122,7 @@ class SctpTransportMap {
} }
private: private:
rtc::CriticalSection lock_; mutable webrtc::Mutex lock_;
uintptr_t next_id_ RTC_GUARDED_BY(lock_) = 0; uintptr_t next_id_ RTC_GUARDED_BY(lock_) = 0;
std::unordered_map<uintptr_t, cricket::SctpTransport*> map_ std::unordered_map<uintptr_t, cricket::SctpTransport*> map_

View File

@ -18,6 +18,7 @@
#include "rtc_base/gunit.h" #include "rtc_base/gunit.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/random.h" #include "rtc_base/random.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -377,7 +378,7 @@ class SctpPingPong final {
CreateTwoConnectedSctpTransportsWithAllStreams(); CreateTwoConnectedSctpTransportsWithAllStreams();
{ {
rtc::CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
if (!errors_list_.empty()) { if (!errors_list_.empty()) {
return false; return false;
} }
@ -397,7 +398,7 @@ class SctpPingPong final {
std::vector<std::string> GetErrorsList() const { std::vector<std::string> GetErrorsList() const {
std::vector<std::string> result; std::vector<std::string> result;
{ {
rtc::CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
result = errors_list_; result = errors_list_;
} }
return result; return result;
@ -566,7 +567,7 @@ class SctpPingPong final {
} }
void ReportError(std::string error) { void ReportError(std::string error) {
rtc::CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
errors_list_.push_back(std::move(error)); errors_list_.push_back(std::move(error));
} }
@ -578,7 +579,7 @@ class SctpPingPong final {
std::unique_ptr<cricket::SctpTransport> sctp_transport2_; std::unique_ptr<cricket::SctpTransport> sctp_transport2_;
std::unique_ptr<SctpDataSender> data_sender1_; std::unique_ptr<SctpDataSender> data_sender1_;
std::unique_ptr<SctpDataSender> data_sender2_; std::unique_ptr<SctpDataSender> data_sender2_;
rtc::CriticalSection lock_; mutable webrtc::Mutex lock_;
std::vector<std::string> errors_list_ RTC_GUARDED_BY(lock_); std::vector<std::string> errors_list_ RTC_GUARDED_BY(lock_);
const uint32_t id_; const uint32_t id_;