diff --git a/media/base/video_adapter.cc b/media/base/video_adapter.cc index 8ba91d7189..73e77cc37e 100644 --- a/media/base/video_adapter.cc +++ b/media/base/video_adapter.cc @@ -190,7 +190,7 @@ bool VideoAdapter::AdaptFrameResolution(int in_width, int* cropped_height, int* out_width, int* out_height) { - rtc::CritScope cs(&critical_section_); + webrtc::MutexLock lock(&mutex_); ++frames_in_; // The max output pixel count is the minimum of the requests from @@ -329,7 +329,7 @@ void VideoAdapter::OnOutputFormatRequest( const absl::optional>& target_portrait_aspect_ratio, const absl::optional& max_portrait_pixel_count, const absl::optional& max_fps) { - rtc::CritScope cs(&critical_section_); + webrtc::MutexLock lock(&mutex_); target_landscape_aspect_ratio_ = target_landscape_aspect_ratio; max_landscape_pixel_count_ = max_landscape_pixel_count; target_portrait_aspect_ratio_ = target_portrait_aspect_ratio; @@ -339,7 +339,7 @@ void VideoAdapter::OnOutputFormatRequest( } void VideoAdapter::OnSinkWants(const rtc::VideoSinkWants& sink_wants) { - rtc::CritScope cs(&critical_section_); + webrtc::MutexLock lock(&mutex_); resolution_request_max_pixel_count_ = sink_wants.max_pixel_count; resolution_request_target_pixel_count_ = sink_wants.target_pixel_count.value_or( diff --git a/media/base/video_adapter.h b/media/base/video_adapter.h index b7acf0e67c..2c42632762 100644 --- a/media/base/video_adapter.h +++ b/media/base/video_adapter.h @@ -19,7 +19,7 @@ #include "api/video/video_source_interface.h" #include "media/base/video_common.h" #include "rtc_base/constructor_magic.h" -#include "rtc_base/critical_section.h" +#include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" namespace cricket { @@ -46,8 +46,7 @@ class VideoAdapter { int* cropped_width, int* cropped_height, int* out_width, - int* out_height) - RTC_LOCKS_EXCLUDED(critical_section_); + int* out_height) RTC_LOCKS_EXCLUDED(mutex_); // DEPRECATED. Please use OnOutputFormatRequest below. // TODO(asapersson): Remove this once it is no longer used. @@ -59,7 +58,7 @@ class VideoAdapter { // 720x1280 is requested. // Note: Should be called from the source only. void OnOutputFormatRequest(const absl::optional& format) - RTC_LOCKS_EXCLUDED(critical_section_); + RTC_LOCKS_EXCLUDED(mutex_); // Requests output frame size and frame interval from |AdaptFrameResolution|. // |target_aspect_ratio|: The input frame size will be cropped to match the @@ -72,7 +71,7 @@ class VideoAdapter { void OnOutputFormatRequest( const absl::optional>& target_aspect_ratio, const absl::optional& max_pixel_count, - const absl::optional& max_fps) RTC_LOCKS_EXCLUDED(critical_section_); + const absl::optional& max_fps) RTC_LOCKS_EXCLUDED(mutex_); // Same as above, but allows setting two different target aspect ratios // depending on incoming frame orientation. This gives more fine-grained @@ -83,7 +82,7 @@ class VideoAdapter { const absl::optional& max_landscape_pixel_count, const absl::optional>& target_portrait_aspect_ratio, const absl::optional& max_portrait_pixel_count, - const absl::optional& max_fps) RTC_LOCKS_EXCLUDED(critical_section_); + const absl::optional& max_fps) RTC_LOCKS_EXCLUDED(mutex_); // Requests the output frame size from |AdaptFrameResolution| to have as close // as possible to |sink_wants.target_pixel_count| pixels (if set) @@ -96,24 +95,20 @@ class VideoAdapter { // |sink_wants.resolution_alignment|. // Note: Should be called from the sink only. void OnSinkWants(const rtc::VideoSinkWants& sink_wants) - RTC_LOCKS_EXCLUDED(critical_section_); + RTC_LOCKS_EXCLUDED(mutex_); private: // Determine if frame should be dropped based on input fps and requested fps. - bool KeepFrame(int64_t in_timestamp_ns) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_); + bool KeepFrame(int64_t in_timestamp_ns) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); - int frames_in_ RTC_GUARDED_BY(critical_section_); // Number of input frames. - int frames_out_ - RTC_GUARDED_BY(critical_section_); // Number of output frames. - int frames_scaled_ - RTC_GUARDED_BY(critical_section_); // Number of frames scaled. + int frames_in_ RTC_GUARDED_BY(mutex_); // Number of input frames. + int frames_out_ RTC_GUARDED_BY(mutex_); // Number of output frames. + int frames_scaled_ RTC_GUARDED_BY(mutex_); // Number of frames scaled. int adaption_changes_ - RTC_GUARDED_BY(critical_section_); // Number of changes in scale factor. - int previous_width_ - RTC_GUARDED_BY(critical_section_); // Previous adapter output width. + RTC_GUARDED_BY(mutex_); // Number of changes in scale factor. + int previous_width_ RTC_GUARDED_BY(mutex_); // Previous adapter output width. int previous_height_ - RTC_GUARDED_BY(critical_section_); // Previous adapter output height. + RTC_GUARDED_BY(mutex_); // Previous adapter output height. const bool variable_start_scale_factor_; // The fixed source resolution alignment requirement. @@ -121,30 +116,27 @@ class VideoAdapter { // The currently applied resolution alignment, as given by the requirements: // - the fixed |source_resolution_alignment_|; and // - the latest |sink_wants.resolution_alignment|. - int resolution_alignment_ RTC_GUARDED_BY(critical_section_); + int resolution_alignment_ RTC_GUARDED_BY(mutex_); // The target timestamp for the next frame based on requested format. - absl::optional next_frame_timestamp_ns_ - RTC_GUARDED_BY(critical_section_); + absl::optional next_frame_timestamp_ns_ RTC_GUARDED_BY(mutex_); // Max number of pixels/fps requested via calls to OnOutputFormatRequest, // OnResolutionFramerateRequest respectively. // The adapted output format is the minimum of these. absl::optional> target_landscape_aspect_ratio_ - RTC_GUARDED_BY(critical_section_); - absl::optional max_landscape_pixel_count_ - RTC_GUARDED_BY(critical_section_); + RTC_GUARDED_BY(mutex_); + absl::optional max_landscape_pixel_count_ RTC_GUARDED_BY(mutex_); absl::optional> target_portrait_aspect_ratio_ - RTC_GUARDED_BY(critical_section_); - absl::optional max_portrait_pixel_count_ - RTC_GUARDED_BY(critical_section_); - absl::optional max_fps_ RTC_GUARDED_BY(critical_section_); - int resolution_request_target_pixel_count_ RTC_GUARDED_BY(critical_section_); - int resolution_request_max_pixel_count_ RTC_GUARDED_BY(critical_section_); - int max_framerate_request_ RTC_GUARDED_BY(critical_section_); + RTC_GUARDED_BY(mutex_); + absl::optional max_portrait_pixel_count_ RTC_GUARDED_BY(mutex_); + absl::optional max_fps_ RTC_GUARDED_BY(mutex_); + int resolution_request_target_pixel_count_ RTC_GUARDED_BY(mutex_); + int resolution_request_max_pixel_count_ RTC_GUARDED_BY(mutex_); + int max_framerate_request_ RTC_GUARDED_BY(mutex_); // The critical section to protect the above variables. - rtc::CriticalSection critical_section_; + webrtc::Mutex mutex_; RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter); }; diff --git a/modules/rtp_rtcp/source/rtcp_sender.cc b/modules/rtp_rtcp/source/rtcp_sender.cc index f3e04b17f3..fae635e1bc 100644 --- a/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/modules/rtp_rtcp/source/rtcp_sender.cc @@ -199,12 +199,12 @@ RTCPSender::RTCPSender(const RtpRtcpInterface::Configuration& config) RTCPSender::~RTCPSender() {} RtcpMode RTCPSender::Status() const { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); return method_; } void RTCPSender::SetRTCPStatus(RtcpMode new_method) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); if (method_ == RtcpMode::kOff && new_method != RtcpMode::kOff) { // When switching on, reschedule the next packet @@ -215,7 +215,7 @@ void RTCPSender::SetRTCPStatus(RtcpMode new_method) { } bool RTCPSender::Sending() const { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); return sending_; } @@ -223,7 +223,7 @@ int32_t RTCPSender::SetSendingStatus(const FeedbackState& feedback_state, bool sending) { bool sendRTCPBye = false; { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); if (method_ != RtcpMode::kOff) { if (sending == false && sending_ == true) { @@ -243,7 +243,7 @@ int32_t RTCPSender::SendLossNotification(const FeedbackState& feedback_state, uint16_t last_received_seq_num, bool decodability_flag, bool buffering_allowed) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); loss_notification_state_.last_decoded_seq_num = last_decoded_seq_num; loss_notification_state_.last_received_seq_num = last_received_seq_num; @@ -262,7 +262,7 @@ int32_t RTCPSender::SendLossNotification(const FeedbackState& feedback_state, void RTCPSender::SetRemb(int64_t bitrate_bps, std::vector ssrcs) { RTC_CHECK_GE(bitrate_bps, 0); - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); remb_bitrate_ = bitrate_bps; remb_ssrcs_ = std::move(ssrcs); @@ -273,18 +273,18 @@ void RTCPSender::SetRemb(int64_t bitrate_bps, std::vector ssrcs) { } void RTCPSender::UnsetRemb() { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); // Stop sending REMB each report until it is reenabled and REMB data set. ConsumeFlag(kRtcpRemb, /*forced=*/true); } bool RTCPSender::TMMBR() const { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); return IsFlagPresent(RTCPPacketType::kRtcpTmmbr); } void RTCPSender::SetTMMBRStatus(bool enable) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); if (enable) { SetFlag(RTCPPacketType::kRtcpTmmbr, false); } else { @@ -293,19 +293,19 @@ void RTCPSender::SetTMMBRStatus(bool enable) { } void RTCPSender::SetMaxRtpPacketSize(size_t max_packet_size) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); max_packet_size_ = max_packet_size; } void RTCPSender::SetTimestampOffset(uint32_t timestamp_offset) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); timestamp_offset_ = timestamp_offset; } void RTCPSender::SetLastRtpTime(uint32_t rtp_timestamp, int64_t capture_time_ms, int8_t payload_type) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); // For compatibility with clients who don't set payload type correctly on all // calls. if (payload_type != -1) { @@ -321,12 +321,12 @@ void RTCPSender::SetLastRtpTime(uint32_t rtp_timestamp, } void RTCPSender::SetRtpClockRate(int8_t payload_type, int rtp_clock_rate_hz) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); rtp_clock_rates_khz_[payload_type] = rtp_clock_rate_hz / 1000; } void RTCPSender::SetRemoteSSRC(uint32_t ssrc) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); remote_ssrc_ = ssrc; } @@ -335,7 +335,7 @@ int32_t RTCPSender::SetCNAME(const char* c_name) { return -1; RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE); - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); cname_ = c_name; return 0; } @@ -343,7 +343,7 @@ int32_t RTCPSender::SetCNAME(const char* c_name) { int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, const char* c_name) { RTC_DCHECK(c_name); RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE); - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); // One spot is reserved for ssrc_/cname_. // TODO(danilchap): Add support for more than 30 contributes by sending // several sdes packets. @@ -355,7 +355,7 @@ int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, const char* c_name) { } int32_t RTCPSender::RemoveMixedCNAME(uint32_t SSRC) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); auto it = csrc_cnames_.find(SSRC); if (it == csrc_cnames_.end()) @@ -426,7 +426,7 @@ bool RTCPSender::TimeToSendRTCPReport(bool sendKeyframeBeforeRTP) const { int64_t now = clock_->TimeInMilliseconds(); - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); if (method_ == RtcpMode::kOff) return false; @@ -532,7 +532,7 @@ std::unique_ptr RTCPSender::BuildREMB( } void RTCPSender::SetTargetBitrate(unsigned int target_bitrate) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); tmmbr_send_bps_ = target_bitrate; } @@ -548,7 +548,7 @@ std::unique_ptr RTCPSender::BuildTMMBR( // get current bounding set from RTCP receiver bool tmmbr_owner = false; - // holding critical_section_rtcp_sender_ while calling RTCPreceiver which + // holding mutex_rtcp_sender_ while calling RTCPreceiver which // will accuire criticalSectionRTCPReceiver_ is a potental deadlock but // since RTCPreceiver is not doing the reverse we should be fine std::vector candidates = @@ -702,7 +702,7 @@ int32_t RTCPSender::SendCompoundRTCP( size_t max_packet_size; { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); auto result = ComputeCompoundRTCPPacket(feedback_state, packet_types, nack_size, nack_list, &container); if (result) { @@ -895,22 +895,22 @@ std::vector RTCPSender::CreateReportBlocks( void RTCPSender::SetCsrcs(const std::vector& csrcs) { RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize); - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); csrcs_ = csrcs; } void RTCPSender::SendRtcpXrReceiverReferenceTime(bool enable) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); xr_send_receiver_reference_time_enabled_ = enable; } bool RTCPSender::RtcpXrReceiverReferenceTime() const { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); return xr_send_receiver_reference_time_enabled_; } void RTCPSender::SetTmmbn(std::vector bounding_set) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); tmmbn_to_send_ = std::move(bounding_set); SetFlag(kRtcpTmmbn, true); } @@ -952,7 +952,7 @@ bool RTCPSender::AllVolatileFlagsConsumed() const { void RTCPSender::SetVideoBitrateAllocation( const VideoBitrateAllocation& bitrate) { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); // Check if this allocation is first ever, or has a different set of // spatial/temporal layers signaled and enabled, if so trigger an rtcp report // as soon as possible. @@ -1000,7 +1000,7 @@ void RTCPSender::SendCombinedRtcpPacket( size_t max_packet_size; uint32_t ssrc; { - rtc::CritScope lock(&critical_section_rtcp_sender_); + MutexLock lock(&mutex_rtcp_sender_); if (method_ == RtcpMode::kOff) { RTC_LOG(LS_WARNING) << "Can't send rtcp if it is disabled."; return; diff --git a/modules/rtp_rtcp/source/rtcp_sender.h b/modules/rtp_rtcp/source/rtcp_sender.h index d9422ebe8e..bcdf15edab 100644 --- a/modules/rtp_rtcp/source/rtcp_sender.h +++ b/modules/rtp_rtcp/source/rtcp_sender.h @@ -32,8 +32,8 @@ #include "modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h" #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" #include "rtc_base/constructor_magic.h" -#include "rtc_base/critical_section.h" #include "rtc_base/random.h" +#include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" namespace webrtc { @@ -67,100 +67,94 @@ class RTCPSender final { explicit RTCPSender(const RtpRtcpInterface::Configuration& config); virtual ~RTCPSender(); - RtcpMode Status() const RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); - void SetRTCPStatus(RtcpMode method) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RtcpMode Status() const RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); + void SetRTCPStatus(RtcpMode method) RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); - bool Sending() const RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + bool Sending() const RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); int32_t SetSendingStatus(const FeedbackState& feedback_state, bool enabled) - RTC_LOCKS_EXCLUDED( - critical_section_rtcp_sender_); // combine the functions + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); // combine the functions - int32_t SetNackStatus(bool enable) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + int32_t SetNackStatus(bool enable) RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetTimestampOffset(uint32_t timestamp_offset) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); // TODO(bugs.webrtc.org/6458): Remove default parameter value when all the // depending projects are updated to correctly set payload type. void SetLastRtpTime(uint32_t rtp_timestamp, int64_t capture_time_ms, int8_t payload_type = -1) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetRtpClockRate(int8_t payload_type, int rtp_clock_rate_hz) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); uint32_t SSRC() const { return ssrc_; } - void SetRemoteSSRC(uint32_t ssrc) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + void SetRemoteSSRC(uint32_t ssrc) RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); - int32_t SetCNAME(const char* cName) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + int32_t SetCNAME(const char* cName) RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); int32_t AddMixedCNAME(uint32_t SSRC, const char* c_name) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); int32_t RemoveMixedCNAME(uint32_t SSRC) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); bool TimeToSendRTCPReport(bool sendKeyframeBeforeRTP = false) const - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); int32_t SendRTCP(const FeedbackState& feedback_state, RTCPPacketType packetType, int32_t nackSize = 0, const uint16_t* nackList = 0) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); int32_t SendCompoundRTCP(const FeedbackState& feedback_state, const std::set& packetTypes, int32_t nackSize = 0, const uint16_t* nackList = nullptr) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); int32_t SendLossNotification(const FeedbackState& feedback_state, uint16_t last_decoded_seq_num, uint16_t last_received_seq_num, bool decodability_flag, bool buffering_allowed) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetRemb(int64_t bitrate_bps, std::vector ssrcs) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); - void UnsetRemb() RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + void UnsetRemb() RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); - bool TMMBR() const RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + bool TMMBR() const RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); - void SetTMMBRStatus(bool enable) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + void SetTMMBRStatus(bool enable) RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetMaxRtpPacketSize(size_t max_packet_size) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetTmmbn(std::vector bounding_set) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SendRtcpXrReceiverReferenceTime(bool enable) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); bool RtcpXrReceiverReferenceTime() const - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetCsrcs(const std::vector& csrcs) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetTargetBitrate(unsigned int target_bitrate) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SetVideoBitrateAllocation(const VideoBitrateAllocation& bitrate) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); void SendCombinedRtcpPacket( std::vector> rtcp_packets) - RTC_LOCKS_EXCLUDED(critical_section_rtcp_sender_); + RTC_LOCKS_EXCLUDED(mutex_rtcp_sender_); private: class RtcpContext; @@ -169,7 +163,7 @@ class RTCPSender final { const std::set& packet_types, int32_t nack_size, const uint16_t* nack_list) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); absl::optional ComputeCompoundRTCPPacket( const FeedbackState& feedback_state, @@ -177,80 +171,79 @@ class RTCPSender final { int32_t nack_size, const uint16_t* nack_list, rtcp::CompoundPacket* out_packet) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); // Determine which RTCP messages should be sent and setup flags. void PrepareReport(const FeedbackState& feedback_state) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::vector CreateReportBlocks( const FeedbackState& feedback_state) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildSR(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildRR(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildSDES(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildPLI(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildREMB(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildTMMBR(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildTMMBN(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildAPP(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildLossNotification( const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildExtendedReports( const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildBYE(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildFIR(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); std::unique_ptr BuildNACK(const RtcpContext& context) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); private: const bool audio_; const uint32_t ssrc_; Clock* const clock_; - Random random_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - RtcpMode method_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + Random random_ RTC_GUARDED_BY(mutex_rtcp_sender_); + RtcpMode method_ RTC_GUARDED_BY(mutex_rtcp_sender_); RtcEventLog* const event_log_; Transport* const transport_; const int report_interval_ms_; - rtc::CriticalSection critical_section_rtcp_sender_; - bool sending_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + mutable Mutex mutex_rtcp_sender_; + bool sending_ RTC_GUARDED_BY(mutex_rtcp_sender_); - int64_t next_time_to_send_rtcp_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + int64_t next_time_to_send_rtcp_ RTC_GUARDED_BY(mutex_rtcp_sender_); - uint32_t timestamp_offset_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - int64_t last_frame_capture_time_ms_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + uint32_t timestamp_offset_ RTC_GUARDED_BY(mutex_rtcp_sender_); + uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(mutex_rtcp_sender_); + int64_t last_frame_capture_time_ms_ RTC_GUARDED_BY(mutex_rtcp_sender_); // SSRC that we receive on our RTP channel - uint32_t remote_ssrc_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - std::string cname_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + uint32_t remote_ssrc_ RTC_GUARDED_BY(mutex_rtcp_sender_); + std::string cname_ RTC_GUARDED_BY(mutex_rtcp_sender_); ReceiveStatisticsProvider* receive_statistics_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + RTC_GUARDED_BY(mutex_rtcp_sender_); std::map csrc_cnames_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + RTC_GUARDED_BY(mutex_rtcp_sender_); // send CSRCs - std::vector csrcs_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + std::vector csrcs_ RTC_GUARDED_BY(mutex_rtcp_sender_); // Full intra request - uint8_t sequence_number_fir_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + uint8_t sequence_number_fir_ RTC_GUARDED_BY(mutex_rtcp_sender_); // Loss Notification struct LossNotificationState { @@ -259,52 +252,47 @@ class RTCPSender final { bool decodability_flag; }; LossNotificationState loss_notification_state_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + RTC_GUARDED_BY(mutex_rtcp_sender_); // REMB - int64_t remb_bitrate_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - std::vector remb_ssrcs_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + int64_t remb_bitrate_ RTC_GUARDED_BY(mutex_rtcp_sender_); + std::vector remb_ssrcs_ RTC_GUARDED_BY(mutex_rtcp_sender_); - std::vector tmmbn_to_send_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); - uint32_t tmmbr_send_bps_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - uint32_t packet_oh_send_ RTC_GUARDED_BY(critical_section_rtcp_sender_); - size_t max_packet_size_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + std::vector tmmbn_to_send_ RTC_GUARDED_BY(mutex_rtcp_sender_); + uint32_t tmmbr_send_bps_ RTC_GUARDED_BY(mutex_rtcp_sender_); + uint32_t packet_oh_send_ RTC_GUARDED_BY(mutex_rtcp_sender_); + size_t max_packet_size_ RTC_GUARDED_BY(mutex_rtcp_sender_); // True if sending of XR Receiver reference time report is enabled. bool xr_send_receiver_reference_time_enabled_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + RTC_GUARDED_BY(mutex_rtcp_sender_); RtcpPacketTypeCounterObserver* const packet_type_counter_observer_; - RtcpPacketTypeCounter packet_type_counter_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + RtcpPacketTypeCounter packet_type_counter_ RTC_GUARDED_BY(mutex_rtcp_sender_); - RtcpNackStats nack_stats_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + RtcpNackStats nack_stats_ RTC_GUARDED_BY(mutex_rtcp_sender_); VideoBitrateAllocation video_bitrate_allocation_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); - bool send_video_bitrate_allocation_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + RTC_GUARDED_BY(mutex_rtcp_sender_); + bool send_video_bitrate_allocation_ RTC_GUARDED_BY(mutex_rtcp_sender_); - std::map rtp_clock_rates_khz_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); - int8_t last_payload_type_ RTC_GUARDED_BY(critical_section_rtcp_sender_); + std::map rtp_clock_rates_khz_ RTC_GUARDED_BY(mutex_rtcp_sender_); + int8_t last_payload_type_ RTC_GUARDED_BY(mutex_rtcp_sender_); absl::optional CheckAndUpdateLayerStructure( const VideoBitrateAllocation& bitrate) const - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); void SetFlag(uint32_t type, bool is_volatile) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); void SetFlags(const std::set& types, bool is_volatile) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); bool IsFlagPresent(uint32_t type) const - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); bool ConsumeFlag(uint32_t type, bool forced = false) - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); bool AllVolatileFlagsConsumed() const - RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_rtcp_sender_); + RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_rtcp_sender_); struct ReportFlag { ReportFlag(uint32_t type, bool is_volatile) : type(type), is_volatile(is_volatile) {} @@ -314,8 +302,7 @@ class RTCPSender final { const bool is_volatile; }; - std::set report_flags_ - RTC_GUARDED_BY(critical_section_rtcp_sender_); + std::set report_flags_ RTC_GUARDED_BY(mutex_rtcp_sender_); typedef std::unique_ptr (RTCPSender::*BuilderFunc)( const RtcpContext&); diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 9f8bac54f4..92abd9be6f 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -804,7 +804,7 @@ bool ModuleRtpRtcpImpl::LastReceivedNTP( void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) { { - rtc::CritScope cs(&critical_section_rtt_); + MutexLock lock(&mutex_rtt_); rtt_ms_ = rtt_ms; } if (rtp_sender_) { @@ -813,7 +813,7 @@ void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) { } int64_t ModuleRtpRtcpImpl::rtt_ms() const { - rtc::CritScope cs(&critical_section_rtt_); + MutexLock lock(&mutex_rtt_); return rtt_ms_; } diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/modules/rtp_rtcp/source/rtp_rtcp_impl.h index 1fa57db372..c413efe13a 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -33,8 +33,8 @@ #include "modules/rtp_rtcp/source/rtp_packet_history.h" #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" #include "modules/rtp_rtcp/source/rtp_sender.h" -#include "rtc_base/critical_section.h" #include "rtc_base/gtest_prod_util.h" +#include "rtc_base/synchronization/mutex.h" namespace webrtc { @@ -352,7 +352,7 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { RtcpRttStats* const rtt_stats_; // The processed RTT from RtcpRttStats. - rtc::CriticalSection critical_section_rtt_; + mutable Mutex mutex_rtt_; int64_t rtt_ms_; }; diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc index 67cb70e1cb..31e4854839 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc @@ -712,7 +712,7 @@ bool ModuleRtpRtcpImpl2::LastReceivedNTP( void ModuleRtpRtcpImpl2::set_rtt_ms(int64_t rtt_ms) { RTC_DCHECK_RUN_ON(worker_queue_); { - rtc::CritScope cs(&critical_section_rtt_); + MutexLock lock(&mutex_rtt_); rtt_ms_ = rtt_ms; } if (rtp_sender_) { @@ -721,7 +721,7 @@ void ModuleRtpRtcpImpl2::set_rtt_ms(int64_t rtt_ms) { } int64_t ModuleRtpRtcpImpl2::rtt_ms() const { - rtc::CritScope cs(&critical_section_rtt_); + MutexLock lock(&mutex_rtt_); return rtt_ms_; } diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl2.h b/modules/rtp_rtcp/source/rtp_rtcp_impl2.h index 932c43656d..9611ace910 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl2.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl2.h @@ -34,8 +34,8 @@ #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h" #include "modules/rtp_rtcp/source/rtp_sender.h" #include "modules/rtp_rtcp/source/rtp_sender_egress.h" -#include "rtc_base/critical_section.h" #include "rtc_base/gtest_prod_util.h" +#include "rtc_base/synchronization/mutex.h" #include "rtc_base/synchronization/sequence_checker.h" #include "rtc_base/task_utils/pending_task_safety_flag.h" #include "rtc_base/task_utils/repeating_task.h" @@ -320,7 +320,7 @@ class ModuleRtpRtcpImpl2 final : public RtpRtcpInterface, RepeatingTaskHandle rtt_update_task_ RTC_GUARDED_BY(worker_queue_); // The processed RTT from RtcpRttStats. - rtc::CriticalSection critical_section_rtt_; + mutable Mutex mutex_rtt_; int64_t rtt_ms_; };