aboutsummaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
authorMarkus Handell <handellm@webrtc.org>2020-07-07 15:39:14 +0200
committerCommit Bot <commit-bot@chromium.org>2020-07-07 18:01:44 +0000
commit0eba415fb40cc4e3958546a8ee53c698940df0a1 (patch)
treefa1ce5f37df8c0235164cd57f8e68cb1668ce0ed /video
parentedcb90755a65f35bd05b38565a6977b059e15f37 (diff)
downloadwebrtc-0eba415fb40cc4e3958546a8ee53c698940df0a1.tar.gz
Migrate video/ except video/end_to_end_tests and video/adaptation to webrtc::Mutex.
Also migrates test/ partly. Bug: webrtc:11567 Change-Id: I4203919615c087e5faca3b2fa1d54cba9f171e07 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178813 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Markus Handell <handellm@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31653}
Diffstat (limited to 'video')
-rw-r--r--video/BUILD.gn3
-rw-r--r--video/call_stats.cc4
-rw-r--r--video/call_stats.h4
-rw-r--r--video/encoder_rtcp_feedback.cc2
-rw-r--r--video/encoder_rtcp_feedback.h6
-rw-r--r--video/frame_encode_metadata_writer.cc10
-rw-r--r--video/frame_encode_metadata_writer.h4
-rw-r--r--video/picture_id_tests.cc27
-rw-r--r--video/receive_statistics_proxy.cc34
-rw-r--r--video/receive_statistics_proxy.h82
-rw-r--r--video/rtp_streams_synchronizer.cc6
-rw-r--r--video/rtp_streams_synchronizer.h12
-rw-r--r--video/rtp_video_stream_receiver.cc28
-rw-r--r--video/rtp_video_stream_receiver.h10
-rw-r--r--video/send_delay_stats.cc8
-rw-r--r--video/send_delay_stats.h18
-rw-r--r--video/send_statistics_proxy.cc54
-rw-r--r--video/send_statistics_proxy.h50
-rw-r--r--video/video_analyzer.cc62
-rw-r--r--video/video_analyzer.h37
-rw-r--r--video/video_receive_stream.cc10
-rw-r--r--video/video_receive_stream.h3
-rw-r--r--video/video_send_stream_impl.h4
-rw-r--r--video/video_send_stream_tests.cc184
-rw-r--r--video/video_source_sink_controller.cc26
-rw-r--r--video/video_source_sink_controller.h18
-rw-r--r--video/video_stream_decoder.h4
-rw-r--r--video/video_stream_encoder.cc9
-rw-r--r--video/video_stream_encoder_unittest.cc160
29 files changed, 443 insertions, 436 deletions
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 6eb753178f..12a316e69e 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -128,6 +128,7 @@ rtc_library("video") {
"../rtc_base/experiments:min_video_bitrate_experiment",
"../rtc_base/experiments:quality_scaling_experiment",
"../rtc_base/experiments:rate_control_settings",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker",
"../rtc_base/system:thread_registry",
"../rtc_base/task_utils:pending_task_safety_flag",
@@ -250,6 +251,7 @@ rtc_library("video_stream_encoder_impl") {
"../rtc_base/experiments:quality_scaler_settings",
"../rtc_base/experiments:quality_scaling_experiment",
"../rtc_base/experiments:rate_control_settings",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker",
"../rtc_base/task_utils:repeating_task",
"../system_wrappers",
@@ -326,6 +328,7 @@ if (rtc_include_tests) {
"../rtc_base:rtc_base_tests_utils",
"../rtc_base:rtc_numerics",
"../rtc_base:task_queue_for_test",
+ "../rtc_base/synchronization:mutex",
"../rtc_base/task_utils:repeating_task",
"../system_wrappers",
"../test:fake_video_codecs",
diff --git a/video/call_stats.cc b/video/call_stats.cc
index 27e00ee7ca..d575e114d8 100644
--- a/video/call_stats.cc
+++ b/video/call_stats.cc
@@ -129,7 +129,7 @@ void CallStats::Process() {
max_rtt_ms_ = GetMaxRttMs(reports_);
avg_rtt_ms = GetNewAvgRttMs(reports_, avg_rtt_ms);
{
- rtc::CritScope lock(&avg_rtt_ms_lock_);
+ MutexLock lock(&avg_rtt_ms_lock_);
avg_rtt_ms_ = avg_rtt_ms;
}
@@ -178,7 +178,7 @@ int64_t CallStats::LastProcessedRtt() const {
// allow only reading this from the process thread (or TQ once we get there)
// so that the lock isn't necessary.
- rtc::CritScope cs(&avg_rtt_ms_lock_);
+ MutexLock lock(&avg_rtt_ms_lock_);
return avg_rtt_ms_;
}
diff --git a/video/call_stats.h b/video/call_stats.h
index 80030012b6..3bfb632446 100644
--- a/video/call_stats.h
+++ b/video/call_stats.h
@@ -18,7 +18,7 @@
#include "modules/include/module_common_types.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h"
#include "system_wrappers/include/clock.h"
@@ -90,7 +90,7 @@ class CallStats : public Module, public RtcpRttStats {
int64_t avg_rtt_ms_;
// Protects |avg_rtt_ms_|.
- rtc::CriticalSection avg_rtt_ms_lock_;
+ mutable Mutex avg_rtt_ms_lock_;
// |sum_avg_rtt_ms_|, |num_avg_rtt_| and |time_of_first_rtt_ms_| are only used
// on the ProcessThread when running. When the Process Thread is not running,
diff --git a/video/encoder_rtcp_feedback.cc b/video/encoder_rtcp_feedback.cc
index a736d83b82..b81ff6120f 100644
--- a/video/encoder_rtcp_feedback.cc
+++ b/video/encoder_rtcp_feedback.cc
@@ -56,7 +56,7 @@ void EncoderRtcpFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) {
RTC_DCHECK(HasSsrc(ssrc));
{
int64_t now_ms = clock_->TimeInMilliseconds();
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (time_last_intra_request_ms_ + min_keyframe_send_interval_ms_ > now_ms) {
return;
}
diff --git a/video/encoder_rtcp_feedback.h b/video/encoder_rtcp_feedback.h
index b5dd0288f3..3bd1cb91f0 100644
--- a/video/encoder_rtcp_feedback.h
+++ b/video/encoder_rtcp_feedback.h
@@ -15,7 +15,7 @@
#include "api/video/video_stream_encoder_interface.h"
#include "call/rtp_video_sender_interface.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
@@ -50,8 +50,8 @@ class EncoderRtcpFeedback : public RtcpIntraFrameObserver,
const RtpVideoSenderInterface* rtp_video_sender_;
VideoStreamEncoderInterface* const video_stream_encoder_;
- rtc::CriticalSection crit_;
- int64_t time_last_intra_request_ms_ RTC_GUARDED_BY(crit_);
+ Mutex mutex_;
+ int64_t time_last_intra_request_ms_ RTC_GUARDED_BY(mutex_);
const int min_keyframe_send_interval_ms_;
};
diff --git a/video/frame_encode_metadata_writer.cc b/video/frame_encode_metadata_writer.cc
index e5f55575ec..8ffb3ae5ea 100644
--- a/video/frame_encode_metadata_writer.cc
+++ b/video/frame_encode_metadata_writer.cc
@@ -60,7 +60,7 @@ FrameEncodeMetadataWriter::~FrameEncodeMetadataWriter() {}
void FrameEncodeMetadataWriter::OnEncoderInit(const VideoCodec& codec,
bool internal_source) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
codec_settings_ = codec;
internal_source_ = internal_source;
}
@@ -68,7 +68,7 @@ void FrameEncodeMetadataWriter::OnEncoderInit(const VideoCodec& codec,
void FrameEncodeMetadataWriter::OnSetRates(
const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate_fps) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
framerate_fps_ = framerate_fps;
const size_t num_spatial_layers = NumSpatialLayers();
if (timing_frames_info_.size() < num_spatial_layers) {
@@ -81,7 +81,7 @@ void FrameEncodeMetadataWriter::OnSetRates(
}
void FrameEncodeMetadataWriter::OnEncodeStarted(const VideoFrame& frame) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
if (internal_source_) {
return;
}
@@ -128,7 +128,7 @@ void FrameEncodeMetadataWriter::OnEncodeStarted(const VideoFrame& frame) {
void FrameEncodeMetadataWriter::FillTimingInfo(size_t simulcast_svc_idx,
EncodedImage* encoded_image) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
absl::optional<size_t> outlier_frame_size;
absl::optional<int64_t> encode_start_ms;
uint8_t timing_flags = VideoSendTiming::kNotTriggered;
@@ -235,7 +235,7 @@ FrameEncodeMetadataWriter::UpdateBitstream(
}
void FrameEncodeMetadataWriter::Reset() {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
for (auto& info : timing_frames_info_) {
info.frames.clear();
}
diff --git a/video/frame_encode_metadata_writer.h b/video/frame_encode_metadata_writer.h
index 4ee2d7eec7..32b5872b27 100644
--- a/video/frame_encode_metadata_writer.h
+++ b/video/frame_encode_metadata_writer.h
@@ -20,7 +20,7 @@
#include "api/video_codecs/video_codec.h"
#include "api/video_codecs/video_encoder.h"
#include "modules/video_coding/include/video_codec_interface.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@@ -69,7 +69,7 @@ class FrameEncodeMetadataWriter {
std::list<FrameMetadata> frames;
};
- rtc::CriticalSection lock_;
+ Mutex lock_;
EncodedImageCallback* const frame_drop_callback_;
VideoCodec codec_settings_ RTC_GUARDED_BY(&lock_);
bool internal_source_ RTC_GUARDED_BY(&lock_);
diff --git a/video/picture_id_tests.cc b/video/picture_id_tests.cc
index 19c1141b0a..298919c096 100644
--- a/video/picture_id_tests.cc
+++ b/video/picture_id_tests.cc
@@ -22,6 +22,7 @@
#include "modules/video_coding/codecs/vp9/include/vp9.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "test/call_test.h"
@@ -49,12 +50,12 @@ class PictureIdObserver : public test::RtpRtcpObserver {
num_ssrcs_to_observe_(1) {}
void SetExpectedSsrcs(size_t num_expected_ssrcs) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
num_ssrcs_to_observe_ = num_expected_ssrcs;
}
void ResetObservedSsrcs() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// Do not clear the timestamp and picture_id, to ensure that we check
// consistency between reinits and recreations.
num_packets_sent_.clear();
@@ -62,7 +63,7 @@ class PictureIdObserver : public test::RtpRtcpObserver {
}
void SetMaxExpectedPictureIdGap(int max_expected_picture_id_gap) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
max_expected_picture_id_gap_ = max_expected_picture_id_gap;
// Expect smaller gap for |tl0_pic_idx| (running index for temporal_idx 0).
max_expected_tl0_idx_gap_ = max_expected_picture_id_gap_ / 2;
@@ -120,7 +121,7 @@ class PictureIdObserver : public test::RtpRtcpObserver {
// Verify continuity and monotonicity of picture_id sequence.
void VerifyPictureId(const ParsedPacket& current,
const ParsedPacket& last) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_) {
if (current.timestamp == last.timestamp) {
EXPECT_EQ(last.picture_id, current.picture_id);
return; // Same frame.
@@ -143,7 +144,7 @@ class PictureIdObserver : public test::RtpRtcpObserver {
}
void VerifyTl0Idx(const ParsedPacket& current, const ParsedPacket& last) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_) {
if (current.tl0_pic_idx == kNoTl0PicIdx ||
current.temporal_idx == kNoTemporalIdx) {
return; // No temporal layers.
@@ -169,7 +170,7 @@ class PictureIdObserver : public test::RtpRtcpObserver {
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
ParsedPacket parsed;
if (!ParsePayload(packet, length, &parsed))
@@ -196,14 +197,14 @@ class PictureIdObserver : public test::RtpRtcpObserver {
return SEND_PACKET;
}
- rtc::CriticalSection crit_;
+ Mutex mutex_;
const std::unique_ptr<VideoRtpDepacketizer> depacketizer_;
- std::map<uint32_t, ParsedPacket> last_observed_packet_ RTC_GUARDED_BY(crit_);
- std::map<uint32_t, size_t> num_packets_sent_ RTC_GUARDED_BY(crit_);
- int max_expected_picture_id_gap_ RTC_GUARDED_BY(crit_);
- int max_expected_tl0_idx_gap_ RTC_GUARDED_BY(crit_);
- size_t num_ssrcs_to_observe_ RTC_GUARDED_BY(crit_);
- std::set<uint32_t> observed_ssrcs_ RTC_GUARDED_BY(crit_);
+ std::map<uint32_t, ParsedPacket> last_observed_packet_ RTC_GUARDED_BY(mutex_);
+ std::map<uint32_t, size_t> num_packets_sent_ RTC_GUARDED_BY(mutex_);
+ int max_expected_picture_id_gap_ RTC_GUARDED_BY(mutex_);
+ int max_expected_tl0_idx_gap_ RTC_GUARDED_BY(mutex_);
+ size_t num_ssrcs_to_observe_ RTC_GUARDED_BY(mutex_);
+ std::set<uint32_t> observed_ssrcs_ RTC_GUARDED_BY(mutex_);
};
class PictureIdTest : public test::CallTest,
diff --git a/video/receive_statistics_proxy.cc b/video/receive_statistics_proxy.cc
index 82951c8a50..7aec685a1c 100644
--- a/video/receive_statistics_proxy.cc
+++ b/video/receive_statistics_proxy.cc
@@ -133,7 +133,7 @@ void ReceiveStatisticsProxy::UpdateHistograms(
// earlier.
RTC_DCHECK_RUN_ON(&decode_thread_);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
char log_stream_buf[8 * 1024];
rtc::SimpleStringBuilder log_stream(log_stream_buf);
@@ -623,7 +623,7 @@ ReceiveStatisticsProxy::GetCurrentEstimatedPlayoutNtpTimestampMs(
}
VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// Get current frame rates here, as only updating them on new frames prevents
// us from ever correctly displaying frame rate of 0.
int64_t now_ms = clock_->TimeInMilliseconds();
@@ -654,13 +654,13 @@ VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
}
void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
stats_.current_payload_type = payload_type;
}
void ReceiveStatisticsProxy::OnDecoderImplementationName(
const char* implementation_name) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
stats_.decoder_implementation_name = implementation_name;
}
@@ -671,7 +671,7 @@ void ReceiveStatisticsProxy::OnFrameBufferTimingsUpdated(
int jitter_buffer_ms,
int min_playout_delay_ms,
int render_delay_ms) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
stats_.max_decode_ms = max_decode_ms;
stats_.current_delay_ms = current_delay_ms;
stats_.target_delay_ms = target_delay_ms;
@@ -687,13 +687,13 @@ void ReceiveStatisticsProxy::OnFrameBufferTimingsUpdated(
}
void ReceiveStatisticsProxy::OnUniqueFramesCounted(int num_unique_frames) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
num_unique_frames_.emplace(num_unique_frames);
}
void ReceiveStatisticsProxy::OnTimingFrameInfoUpdated(
const TimingFrameInfo& info) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (info.flags != VideoSendTiming::kInvalid) {
int64_t now_ms = clock_->TimeInMilliseconds();
timing_frame_info_counter_.Add(info, now_ms);
@@ -714,14 +714,14 @@ void ReceiveStatisticsProxy::OnTimingFrameInfoUpdated(
void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
uint32_t ssrc,
const RtcpPacketTypeCounter& packet_counter) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (stats_.ssrc != ssrc)
return;
stats_.rtcp_packet_type_counts = packet_counter;
}
void ReceiveStatisticsProxy::OnCname(uint32_t ssrc, absl::string_view cname) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
// receive stats from one of them.
if (stats_.ssrc != ssrc)
@@ -733,7 +733,7 @@ void ReceiveStatisticsProxy::OnDecodedFrame(const VideoFrame& frame,
absl::optional<uint8_t> qp,
int32_t decode_time_ms,
VideoContentType content_type) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
uint64_t now_ms = clock_->TimeInMilliseconds();
@@ -799,7 +799,7 @@ void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0);
int64_t now_ms = clock_->TimeInMilliseconds();
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
video_quality_observer_->OnRenderedFrame(frame, now_ms);
@@ -833,7 +833,7 @@ void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t video_playout_ntp_ms,
int64_t sync_offset_ms,
double estimated_freq_khz) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
sync_offset_counter_.Add(std::abs(sync_offset_ms));
stats_.sync_offset_ms = sync_offset_ms;
last_estimated_playout_ntp_timestamp_ms_ = video_playout_ntp_ms;
@@ -851,7 +851,7 @@ void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t video_playout_ntp_ms,
void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe,
size_t size_bytes,
VideoContentType content_type) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (is_keyframe) {
++stats_.frame_counts.key_frames;
} else {
@@ -881,13 +881,13 @@ void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe,
}
void ReceiveStatisticsProxy::OnDroppedFrames(uint32_t frames_dropped) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
stats_.frames_dropped += frames_dropped;
}
void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) {
RTC_DCHECK_RUN_ON(&decode_thread_);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
last_codec_type_ = codec_type;
if (last_codec_type_ == kVideoCodecVP8 && qp != -1) {
qp_counters_.vp8.Add(qp);
@@ -898,7 +898,7 @@ void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) {
void ReceiveStatisticsProxy::OnStreamInactive() {
// TODO(sprang): Figure out any other state that should be reset.
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// Don't report inter-frame delay if stream was paused.
last_decoded_frame_time_ms_.reset();
video_quality_observer_->OnStreamInactive();
@@ -906,7 +906,7 @@ void ReceiveStatisticsProxy::OnStreamInactive() {
void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms,
int64_t max_rtt_ms) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
avg_rtt_ms_ = avg_rtt_ms;
}
diff --git a/video/receive_statistics_proxy.h b/video/receive_statistics_proxy.h
index 02043d6944..8b94c32b69 100644
--- a/video/receive_statistics_proxy.h
+++ b/video/receive_statistics_proxy.h
@@ -20,12 +20,12 @@
#include "call/video_receive_stream.h"
#include "modules/include/module_common_types.h"
#include "modules/video_coding/include/video_coding_defines.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/numerics/histogram_percentile_counter.h"
#include "rtc_base/numerics/moving_max_counter.h"
#include "rtc_base/numerics/sample_counter.h"
#include "rtc_base/rate_statistics.h"
#include "rtc_base/rate_tracker.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
#include "video/quality_threshold.h"
@@ -124,19 +124,19 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
rtc::HistogramPercentileCounter interframe_delay_percentiles;
};
- void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Removes info about old frames and then updates the framerate.
void UpdateFramerate(int64_t now_ms) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void UpdateDecodeTimeHistograms(int width,
int height,
int decode_time_ms) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
- int64_t now_ms) const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ int64_t now_ms) const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* const clock_;
// Ownership of this object lies with the owner of the ReceiveStatisticsProxy
@@ -150,52 +150,52 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
const int64_t start_ms_;
const bool enable_decode_time_histograms_;
- rtc::CriticalSection crit_;
- int64_t last_sample_time_ RTC_GUARDED_BY(crit_);
- QualityThreshold fps_threshold_ RTC_GUARDED_BY(crit_);
- QualityThreshold qp_threshold_ RTC_GUARDED_BY(crit_);
- QualityThreshold variance_threshold_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter qp_sample_ RTC_GUARDED_BY(crit_);
- int num_bad_states_ RTC_GUARDED_BY(crit_);
- int num_certain_states_ RTC_GUARDED_BY(crit_);
+ mutable Mutex mutex_;
+ int64_t last_sample_time_ RTC_GUARDED_BY(mutex_);
+ QualityThreshold fps_threshold_ RTC_GUARDED_BY(mutex_);
+ QualityThreshold qp_threshold_ RTC_GUARDED_BY(mutex_);
+ QualityThreshold variance_threshold_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter qp_sample_ RTC_GUARDED_BY(mutex_);
+ int num_bad_states_ RTC_GUARDED_BY(mutex_);
+ int num_certain_states_ RTC_GUARDED_BY(mutex_);
// Note: The |stats_.rtp_stats| member is not used or populated by this class.
- mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(crit_);
- RateStatistics decode_fps_estimator_ RTC_GUARDED_BY(crit_);
- RateStatistics renders_fps_estimator_ RTC_GUARDED_BY(crit_);
- rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(crit_);
- rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter sync_offset_counter_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter decode_time_counter_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter target_delay_counter_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter current_delay_counter_ RTC_GUARDED_BY(crit_);
- rtc::SampleCounter delay_counter_ RTC_GUARDED_BY(crit_);
+ mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(mutex_);
+ RateStatistics decode_fps_estimator_ RTC_GUARDED_BY(mutex_);
+ RateStatistics renders_fps_estimator_ RTC_GUARDED_BY(mutex_);
+ rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(mutex_);
+ rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter sync_offset_counter_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter decode_time_counter_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter target_delay_counter_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter current_delay_counter_ RTC_GUARDED_BY(mutex_);
+ rtc::SampleCounter delay_counter_ RTC_GUARDED_BY(mutex_);
std::unique_ptr<VideoQualityObserver> video_quality_observer_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
std::map<VideoContentType, ContentSpecificStats> content_specific_stats_
- RTC_GUARDED_BY(crit_);
- MaxCounter freq_offset_counter_ RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
+ MaxCounter freq_offset_counter_ RTC_GUARDED_BY(mutex_);
QpCounters qp_counters_ RTC_GUARDED_BY(decode_thread_);
- int64_t avg_rtt_ms_ RTC_GUARDED_BY(crit_);
- mutable std::map<int64_t, size_t> frame_window_ RTC_GUARDED_BY(&crit_);
- VideoContentType last_content_type_ RTC_GUARDED_BY(&crit_);
- VideoCodecType last_codec_type_ RTC_GUARDED_BY(&crit_);
- absl::optional<int64_t> first_frame_received_time_ms_ RTC_GUARDED_BY(&crit_);
- absl::optional<int64_t> first_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_);
- absl::optional<int64_t> last_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_);
- size_t num_delayed_frames_rendered_ RTC_GUARDED_BY(&crit_);
- int64_t sum_missed_render_deadline_ms_ RTC_GUARDED_BY(&crit_);
+ int64_t avg_rtt_ms_ RTC_GUARDED_BY(mutex_);
+ mutable std::map<int64_t, size_t> frame_window_ RTC_GUARDED_BY(&mutex_);
+ VideoContentType last_content_type_ RTC_GUARDED_BY(&mutex_);
+ VideoCodecType last_codec_type_ RTC_GUARDED_BY(&mutex_);
+ absl::optional<int64_t> first_frame_received_time_ms_ RTC_GUARDED_BY(&mutex_);
+ absl::optional<int64_t> first_decoded_frame_time_ms_ RTC_GUARDED_BY(&mutex_);
+ absl::optional<int64_t> last_decoded_frame_time_ms_ RTC_GUARDED_BY(&mutex_);
+ size_t num_delayed_frames_rendered_ RTC_GUARDED_BY(&mutex_);
+ int64_t sum_missed_render_deadline_ms_ RTC_GUARDED_BY(&mutex_);
// Mutable because calling Max() on MovingMaxCounter is not const. Yet it is
// called from const GetStats().
mutable rtc::MovingMaxCounter<TimingFrameInfo> timing_frame_info_counter_
- RTC_GUARDED_BY(&crit_);
- absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(&mutex_);
+ absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(mutex_);
absl::optional<int64_t> last_estimated_playout_ntp_timestamp_ms_
- RTC_GUARDED_BY(&crit_);
+ RTC_GUARDED_BY(&mutex_);
absl::optional<int64_t> last_estimated_playout_time_ms_
- RTC_GUARDED_BY(&crit_);
+ RTC_GUARDED_BY(&mutex_);
rtc::ThreadChecker decode_thread_;
rtc::ThreadChecker network_thread_;
rtc::ThreadChecker main_thread_;
diff --git a/video/rtp_streams_synchronizer.cc b/video/rtp_streams_synchronizer.cc
index 3dedc43eaa..28e9a0ba9d 100644
--- a/video/rtp_streams_synchronizer.cc
+++ b/video/rtp_streams_synchronizer.cc
@@ -51,7 +51,7 @@ RtpStreamsSynchronizer::RtpStreamsSynchronizer(Syncable* syncable_video)
RtpStreamsSynchronizer::~RtpStreamsSynchronizer() = default;
void RtpStreamsSynchronizer::ConfigureSync(Syncable* syncable_audio) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (syncable_audio == syncable_audio_) {
// This prevents expensive no-ops.
return;
@@ -76,7 +76,7 @@ void RtpStreamsSynchronizer::Process() {
RTC_DCHECK_RUN_ON(&process_thread_checker_);
last_sync_time_ = rtc::TimeNanos();
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!syncable_audio_) {
return;
}
@@ -157,7 +157,7 @@ bool RtpStreamsSynchronizer::GetStreamSyncOffsetInMs(
int64_t* video_playout_ntp_ms,
int64_t* stream_offset_ms,
double* estimated_freq_khz) const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!syncable_audio_) {
return false;
}
diff --git a/video/rtp_streams_synchronizer.h b/video/rtp_streams_synchronizer.h
index 6abf5bbe0e..732c9a7d77 100644
--- a/video/rtp_streams_synchronizer.h
+++ b/video/rtp_streams_synchronizer.h
@@ -17,7 +17,7 @@
#include <memory>
#include "modules/include/module.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h"
#include "video/stream_synchronization.h"
@@ -51,11 +51,11 @@ class RtpStreamsSynchronizer : public Module {
private:
Syncable* syncable_video_;
- rtc::CriticalSection crit_;
- Syncable* syncable_audio_ RTC_GUARDED_BY(crit_);
- std::unique_ptr<StreamSynchronization> sync_ RTC_GUARDED_BY(crit_);
- StreamSynchronization::Measurements audio_measurement_ RTC_GUARDED_BY(crit_);
- StreamSynchronization::Measurements video_measurement_ RTC_GUARDED_BY(crit_);
+ mutable Mutex mutex_;
+ Syncable* syncable_audio_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<StreamSynchronization> sync_ RTC_GUARDED_BY(mutex_);
+ StreamSynchronization::Measurements audio_measurement_ RTC_GUARDED_BY(mutex_);
+ StreamSynchronization::Measurements video_measurement_ RTC_GUARDED_BY(mutex_);
rtc::ThreadChecker process_thread_checker_;
int64_t last_sync_time_ RTC_GUARDED_BY(&process_thread_checker_);
diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc
index 8bbb5866a0..6289aba6b8 100644
--- a/video/rtp_video_stream_receiver.cc
+++ b/video/rtp_video_stream_receiver.cc
@@ -121,7 +121,7 @@ RtpVideoStreamReceiver::RtcpFeedbackBuffer::RtcpFeedbackBuffer(
}
void RtpVideoStreamReceiver::RtcpFeedbackBuffer::RequestKeyFrame() {
- rtc::CritScope lock(&cs_);
+ MutexLock lock(&cs_);
request_key_frame_ = true;
}
@@ -129,7 +129,7 @@ void RtpVideoStreamReceiver::RtcpFeedbackBuffer::SendNack(
const std::vector<uint16_t>& sequence_numbers,
bool buffering_allowed) {
RTC_DCHECK(!sequence_numbers.empty());
- rtc::CritScope lock(&cs_);
+ MutexLock lock(&cs_);
nack_sequence_numbers_.insert(nack_sequence_numbers_.end(),
sequence_numbers.cbegin(),
sequence_numbers.cend());
@@ -146,7 +146,7 @@ void RtpVideoStreamReceiver::RtcpFeedbackBuffer::SendLossNotification(
bool decodability_flag,
bool buffering_allowed) {
RTC_DCHECK(buffering_allowed);
- rtc::CritScope lock(&cs_);
+ MutexLock lock(&cs_);
RTC_DCHECK(!lntf_state_)
<< "SendLossNotification() called twice in a row with no call to "
"SendBufferedRtcpFeedback() in between.";
@@ -160,7 +160,7 @@ void RtpVideoStreamReceiver::RtcpFeedbackBuffer::SendBufferedRtcpFeedback() {
RtpVideoStreamReceiver::RtcpFeedbackBuffer::ConsumedRtcpFeedback
RtpVideoStreamReceiver::RtcpFeedbackBuffer::ConsumeRtcpFeedback() {
- rtc::CritScope lock(&cs_);
+ MutexLock lock(&cs_);
return ConsumeRtcpFeedbackLocked();
}
@@ -376,7 +376,7 @@ absl::optional<Syncable::Info> RtpVideoStreamReceiver::GetSyncInfo() const {
return absl::nullopt;
}
{
- rtc::CritScope lock(&sync_info_lock_);
+ MutexLock lock(&sync_info_lock_);
if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
return absl::nullopt;
}
@@ -667,7 +667,7 @@ void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) {
// TODO(nisse): Exclude out-of-order packets?
int64_t now_ms = clock_->TimeInMilliseconds();
{
- rtc::CritScope cs(&sync_info_lock_);
+ MutexLock lock(&sync_info_lock_);
last_received_rtp_timestamp_ = packet.Timestamp();
last_received_rtp_system_time_ms_ = now_ms;
}
@@ -844,7 +844,7 @@ void RtpVideoStreamReceiver::OnAssembledFrame(
has_received_frame_ = true;
}
- rtc::CritScope lock(&reference_finder_lock_);
+ MutexLock lock(&reference_finder_lock_);
// Reset |reference_finder_| if |frame| is new and the codec have changed.
if (current_codec_) {
bool frame_is_newer =
@@ -887,7 +887,7 @@ void RtpVideoStreamReceiver::OnAssembledFrame(
void RtpVideoStreamReceiver::OnCompleteFrame(
std::unique_ptr<video_coding::EncodedFrame> frame) {
{
- rtc::CritScope lock(&last_seq_num_cs_);
+ MutexLock lock(&last_seq_num_cs_);
video_coding::RtpFrameObject* rtp_frame =
static_cast<video_coding::RtpFrameObject*>(frame.get());
last_seq_num_for_pic_id_[rtp_frame->id.picture_id] =
@@ -900,7 +900,7 @@ void RtpVideoStreamReceiver::OnCompleteFrame(
void RtpVideoStreamReceiver::OnDecryptedFrame(
std::unique_ptr<video_coding::RtpFrameObject> frame) {
- rtc::CritScope lock(&reference_finder_lock_);
+ MutexLock lock(&reference_finder_lock_);
reference_finder_->ManageFrame(std::move(frame));
}
@@ -967,7 +967,7 @@ void RtpVideoStreamReceiver::RemoveSecondarySink(
void RtpVideoStreamReceiver::ManageFrame(
std::unique_ptr<video_coding::RtpFrameObject> frame) {
- rtc::CritScope lock(&reference_finder_lock_);
+ MutexLock lock(&reference_finder_lock_);
reference_finder_->ManageFrame(std::move(frame));
}
@@ -1022,7 +1022,7 @@ void RtpVideoStreamReceiver::ParseAndHandleEncapsulatingHeader(
// correctly calculate frame references.
void RtpVideoStreamReceiver::NotifyReceiverOfEmptyPacket(uint16_t seq_num) {
{
- rtc::CritScope lock(&reference_finder_lock_);
+ MutexLock lock(&reference_finder_lock_);
reference_finder_->PaddingReceived(seq_num);
}
OnInsertedPacket(packet_buffer_.InsertPadding(seq_num));
@@ -1086,7 +1086,7 @@ void RtpVideoStreamReceiver::FrameContinuous(int64_t picture_id) {
int seq_num = -1;
{
- rtc::CritScope lock(&last_seq_num_cs_);
+ MutexLock lock(&last_seq_num_cs_);
auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
if (seq_num_it != last_seq_num_for_pic_id_.end())
seq_num = seq_num_it->second;
@@ -1098,7 +1098,7 @@ void RtpVideoStreamReceiver::FrameContinuous(int64_t picture_id) {
void RtpVideoStreamReceiver::FrameDecoded(int64_t picture_id) {
int seq_num = -1;
{
- rtc::CritScope lock(&last_seq_num_cs_);
+ MutexLock lock(&last_seq_num_cs_);
auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
if (seq_num_it != last_seq_num_for_pic_id_.end()) {
seq_num = seq_num_it->second;
@@ -1108,7 +1108,7 @@ void RtpVideoStreamReceiver::FrameDecoded(int64_t picture_id) {
}
if (seq_num != -1) {
packet_buffer_.ClearTo(seq_num);
- rtc::CritScope lock(&reference_finder_lock_);
+ MutexLock lock(&reference_finder_lock_);
reference_finder_->ClearTo(seq_num);
}
}
diff --git a/video/rtp_video_stream_receiver.h b/video/rtp_video_stream_receiver.h
index 68e23eee53..b6a5a2f6a9 100644
--- a/video/rtp_video_stream_receiver.h
+++ b/video/rtp_video_stream_receiver.h
@@ -42,9 +42,9 @@
#include "modules/video_coding/rtp_frame_reference_finder.h"
#include "modules/video_coding/unique_timestamp_counter.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/experiments/field_trial_parser.h"
#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
@@ -275,7 +275,7 @@ class RtpVideoStreamReceiver : public LossNotificationSender,
LossNotificationSender* const loss_notification_sender_;
// NACKs are accessible from two threads due to nack_module_ being a module.
- rtc::CriticalSection cs_;
+ Mutex cs_;
// Key-frame-request-related state.
bool request_key_frame_ RTC_GUARDED_BY(cs_);
@@ -351,13 +351,13 @@ class RtpVideoStreamReceiver : public LossNotificationSender,
absl::optional<int64_t> video_structure_frame_id_
RTC_GUARDED_BY(worker_task_checker_);
- rtc::CriticalSection reference_finder_lock_;
+ Mutex reference_finder_lock_;
std::unique_ptr<video_coding::RtpFrameReferenceFinder> reference_finder_
RTC_GUARDED_BY(reference_finder_lock_);
absl::optional<VideoCodecType> current_codec_;
uint32_t last_assembled_frame_rtp_timestamp_;
- rtc::CriticalSection last_seq_num_cs_;
+ Mutex last_seq_num_cs_;
std::map<int64_t, uint16_t> last_seq_num_for_pic_id_
RTC_GUARDED_BY(last_seq_num_cs_);
video_coding::H264SpsPpsTracker tracker_;
@@ -378,7 +378,7 @@ class RtpVideoStreamReceiver : public LossNotificationSender,
// Info for GetSyncInfo is updated on network or worker thread, and queried on
// the worker thread.
- rtc::CriticalSection sync_info_lock_;
+ mutable Mutex sync_info_lock_;
absl::optional<uint32_t> last_received_rtp_timestamp_
RTC_GUARDED_BY(sync_info_lock_);
absl::optional<int64_t> last_received_rtp_system_time_ms_
diff --git a/video/send_delay_stats.cc b/video/send_delay_stats.cc
index a243eda292..56c4164424 100644
--- a/video/send_delay_stats.cc
+++ b/video/send_delay_stats.cc
@@ -41,7 +41,7 @@ SendDelayStats::~SendDelayStats() {
}
void SendDelayStats::UpdateHistograms() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
for (const auto& it : send_delay_counters_) {
AggregatedStats stats = it.second->GetStats();
if (stats.num_samples >= kMinRequiredPeriodicSamples) {
@@ -52,7 +52,7 @@ void SendDelayStats::UpdateHistograms() {
}
void SendDelayStats::AddSsrcs(const VideoSendStream::Config& config) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (ssrcs_.size() > kMaxSsrcMapSize)
return;
for (const auto& ssrc : config.rtp.ssrcs)
@@ -73,7 +73,7 @@ void SendDelayStats::OnSendPacket(uint16_t packet_id,
int64_t capture_time_ms,
uint32_t ssrc) {
// Packet sent to transport.
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (ssrcs_.find(ssrc) == ssrcs_.end())
return;
@@ -93,7 +93,7 @@ bool SendDelayStats::OnSentPacket(int packet_id, int64_t time_ms) {
if (packet_id == -1)
return false;
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
auto it = packets_.find(packet_id);
if (it == packets_.end())
return false;
diff --git a/video/send_delay_stats.h b/video/send_delay_stats.h
index d9fa16a126..20f9804d64 100644
--- a/video/send_delay_stats.h
+++ b/video/send_delay_stats.h
@@ -20,7 +20,7 @@
#include "call/video_send_stream.h"
#include "modules/include/module_common_types_public.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
#include "video/stats_counter.h"
@@ -66,22 +66,22 @@ class SendDelayStats : public SendPacketObserver {
void UpdateHistograms();
void RemoveOld(int64_t now, PacketMap* packets)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
AvgCounter* GetSendDelayCounter(uint32_t ssrc)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* const clock_;
- rtc::CriticalSection crit_;
+ Mutex mutex_;
- PacketMap packets_ RTC_GUARDED_BY(crit_);
- size_t num_old_packets_ RTC_GUARDED_BY(crit_);
- size_t num_skipped_packets_ RTC_GUARDED_BY(crit_);
+ PacketMap packets_ RTC_GUARDED_BY(mutex_);
+ size_t num_old_packets_ RTC_GUARDED_BY(mutex_);
+ size_t num_skipped_packets_ RTC_GUARDED_BY(mutex_);
- std::set<uint32_t> ssrcs_ RTC_GUARDED_BY(crit_);
+ std::set<uint32_t> ssrcs_ RTC_GUARDED_BY(mutex_);
// Mapped by SSRC.
std::map<uint32_t, std::unique_ptr<AvgCounter>> send_delay_counters_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
};
} // namespace webrtc
diff --git a/video/send_statistics_proxy.cc b/video/send_statistics_proxy.cc
index b5bcbe6bf1..ee32fd91c1 100644
--- a/video/send_statistics_proxy.cc
+++ b/video/send_statistics_proxy.cc
@@ -154,7 +154,7 @@ SendStatisticsProxy::SendStatisticsProxy(
}
SendStatisticsProxy::~SendStatisticsProxy() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
uma_container_->UpdateHistograms(rtp_config_, stats_);
int64_t elapsed_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000;
@@ -670,7 +670,7 @@ void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms(
void SendStatisticsProxy::OnEncoderReconfigured(
const VideoEncoderConfig& config,
const std::vector<VideoStream>& streams) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (content_type_ != config.content_type) {
uma_container_->UpdateHistograms(rtp_config_, stats_);
@@ -687,7 +687,7 @@ void SendStatisticsProxy::OnEncoderReconfigured(
void SendStatisticsProxy::OnEncodedFrameTimeMeasured(int encode_time_ms,
int encode_usage_percent) {
RTC_DCHECK_GE(encode_time_ms, 0);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
uma_container_->encode_time_counter_.Add(encode_time_ms);
encode_time_.Apply(1.0f, encode_time_ms);
stats_.avg_encode_time_ms = std::round(encode_time_.filtered());
@@ -697,7 +697,7 @@ void SendStatisticsProxy::OnEncodedFrameTimeMeasured(int encode_time_ms,
void SendStatisticsProxy::OnSuspendChange(bool is_suspended) {
int64_t now_ms = clock_->TimeInMilliseconds();
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
stats_.suspended = is_suspended;
if (is_suspended) {
// Pause framerate (add min pause time since there may be frames/packets
@@ -733,7 +733,7 @@ void SendStatisticsProxy::OnSuspendChange(bool is_suspended) {
}
VideoSendStream::Stats SendStatisticsProxy::GetStats() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
PurgeOldStats();
stats_.input_frame_rate =
round(uma_container_->input_frame_rate_tracker_.ComputeRate());
@@ -803,7 +803,7 @@ VideoSendStream::StreamStats* SendStatisticsProxy::GetStatsEntry(
}
void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -815,7 +815,7 @@ void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) {
}
void SendStatisticsProxy::OnSetEncoderTargetRate(uint32_t bitrate_bps) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (uma_container_->target_rate_updates_.last_ms == -1 && bitrate_bps == 0)
return; // Start on first non-zero bitrate, may initially be zero.
@@ -914,7 +914,7 @@ void SendStatisticsProxy::UpdateFallbackDisabledStats(
}
void SendStatisticsProxy::OnMinPixelLimitReached() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
uma_container_->fallback_info_disabled_.min_pixel_limit_reached = true;
}
@@ -929,7 +929,7 @@ void SendStatisticsProxy::OnSendEncodedImage(
? encoded_image.SpatialIndex().value_or(0)
: 0;
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
++stats_.frames_encoded;
// The current encode frame rate is based on previously encoded frames.
double encode_frame_rate = encoded_frame_rate_tracker_.ComputeRate();
@@ -1036,24 +1036,24 @@ void SendStatisticsProxy::OnSendEncodedImage(
void SendStatisticsProxy::OnEncoderImplementationChanged(
const std::string& implementation_name) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
encoder_changed_ = EncoderChangeEvent{stats_.encoder_implementation_name,
implementation_name};
stats_.encoder_implementation_name = implementation_name;
}
int SendStatisticsProxy::GetInputFrameRate() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return round(uma_container_->input_frame_rate_tracker_.ComputeRate());
}
int SendStatisticsProxy::GetSendFrameRate() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return round(encoded_frame_rate_tracker_.ComputeRate());
}
void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
uma_container_->input_frame_rate_tracker_.AddSamples(1);
uma_container_->input_fps_counter_.Add(1);
uma_container_->input_width_counter_.Add(width);
@@ -1071,7 +1071,7 @@ void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
}
void SendStatisticsProxy::OnFrameDropped(DropReason reason) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
switch (reason) {
case DropReason::kSource:
++stats_.frames_dropped_by_capturer;
@@ -1092,7 +1092,7 @@ void SendStatisticsProxy::OnFrameDropped(DropReason reason) {
}
void SendStatisticsProxy::ClearAdaptationStats() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
adaptation_limitations_.set_cpu_counts(VideoAdaptationCounters());
adaptation_limitations_.set_quality_counts(VideoAdaptationCounters());
UpdateAdaptationStats();
@@ -1101,7 +1101,7 @@ void SendStatisticsProxy::ClearAdaptationStats() {
void SendStatisticsProxy::UpdateAdaptationSettings(
VideoStreamEncoderObserver::AdaptationSettings cpu_settings,
VideoStreamEncoderObserver::AdaptationSettings quality_settings) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
adaptation_limitations_.UpdateMaskingSettings(cpu_settings, quality_settings);
SetAdaptTimer(adaptation_limitations_.MaskedCpuCounts(),
&uma_container_->cpu_adapt_timer_);
@@ -1114,7 +1114,7 @@ void SendStatisticsProxy::OnAdaptationChanged(
VideoAdaptationReason reason,
const VideoAdaptationCounters& cpu_counters,
const VideoAdaptationCounters& quality_counters) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
MaskedAdaptationCounts receiver =
adaptation_limitations_.MaskedQualityCounts();
@@ -1208,7 +1208,7 @@ void SendStatisticsProxy::OnBitrateAllocationUpdated(
spatial_layers[i] = (allocation.GetSpatialLayerSum(i) > 0);
}
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
bw_limited_layers_ = allocation.is_bw_limited();
UpdateAdaptationStats();
@@ -1231,14 +1231,14 @@ void SendStatisticsProxy::OnBitrateAllocationUpdated(
// resolution or not. |is_scaled| is a flag indicating if the video is scaled
// down.
void SendStatisticsProxy::OnEncoderInternalScalerUpdate(bool is_scaled) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
internal_encoder_scaler_ = is_scaled;
UpdateAdaptationStats();
}
// TODO(asapersson): Include fps changes.
void SendStatisticsProxy::OnInitialQualityResolutionAdaptDown() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
++uma_container_->initial_quality_changes_.down;
}
@@ -1274,7 +1274,7 @@ void SendStatisticsProxy::SetAdaptTimer(const MaskedAdaptationCounts& counts,
void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
uint32_t ssrc,
const RtcpPacketTypeCounter& packet_counter) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1286,7 +1286,7 @@ void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
uint32_t ssrc) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1297,7 +1297,7 @@ void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
void SendStatisticsProxy::OnReportBlockDataUpdated(
ReportBlockData report_block_data) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats =
GetStatsEntry(report_block_data.report_block().source_ssrc);
if (!stats)
@@ -1308,7 +1308,7 @@ void SendStatisticsProxy::OnReportBlockDataUpdated(
void SendStatisticsProxy::DataCountersUpdated(
const StreamDataCounters& counters,
uint32_t ssrc) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc " << ssrc;
@@ -1350,7 +1350,7 @@ void SendStatisticsProxy::DataCountersUpdated(
void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps,
uint32_t retransmit_bitrate_bps,
uint32_t ssrc) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1361,7 +1361,7 @@ void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps,
void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts,
uint32_t ssrc) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1373,7 +1373,7 @@ void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms,
int max_delay_ms,
uint64_t total_delay_ms,
uint32_t ssrc) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
diff --git a/video/send_statistics_proxy.h b/video/send_statistics_proxy.h
index ff3b786be9..0de7df290e 100644
--- a/video/send_statistics_proxy.h
+++ b/video/send_statistics_proxy.h
@@ -25,9 +25,9 @@
#include "modules/rtp_rtcp/include/report_block_data.h"
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/include/video_coding_defines.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/numerics/exp_filter.h"
#include "rtc_base/rate_tracker.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
#include "video/quality_limitation_reason_tracker.h"
@@ -223,9 +223,9 @@ class SendStatisticsProxy : public VideoStreamEncoderObserver,
};
typedef std::map<uint32_t, Frame, TimestampOlderThan> EncodedFrameMap;
- void PurgeOldStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void PurgeOldStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
struct MaskedAdaptationCounts {
absl::optional<int> resolution_adaptations = absl::nullopt;
@@ -257,52 +257,52 @@ class SendStatisticsProxy : public VideoStreamEncoderObserver,
};
void SetAdaptTimer(const MaskedAdaptationCounts& counts, StatsTimer* timer)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
- void UpdateAdaptationStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ void UpdateAdaptationStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void TryUpdateInitialQualityResolutionAdaptUp(
absl::optional<int> old_quality_downscales,
absl::optional<int> updated_quality_downscales)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void UpdateEncoderFallbackStats(const CodecSpecificInfo* codec_info,
int pixels,
int simulcast_index)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void UpdateFallbackDisabledStats(const CodecSpecificInfo* codec_info,
int pixels,
int simulcast_index)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* const clock_;
const std::string payload_name_;
const RtpConfig rtp_config_;
const absl::optional<int> fallback_max_pixels_;
const absl::optional<int> fallback_max_pixels_disabled_;
- rtc::CriticalSection crit_;
- VideoEncoderConfig::ContentType content_type_ RTC_GUARDED_BY(crit_);
+ mutable Mutex mutex_;
+ VideoEncoderConfig::ContentType content_type_ RTC_GUARDED_BY(mutex_);
const int64_t start_ms_;
- VideoSendStream::Stats stats_ RTC_GUARDED_BY(crit_);
- std::map<uint32_t, StatsUpdateTimes> update_times_ RTC_GUARDED_BY(crit_);
- rtc::ExpFilter encode_time_ RTC_GUARDED_BY(crit_);
+ VideoSendStream::Stats stats_ RTC_GUARDED_BY(mutex_);
+ std::map<uint32_t, StatsUpdateTimes> update_times_ RTC_GUARDED_BY(mutex_);
+ rtc::ExpFilter encode_time_ RTC_GUARDED_BY(mutex_);
QualityLimitationReasonTracker quality_limitation_reason_tracker_
- RTC_GUARDED_BY(crit_);
- rtc::RateTracker media_byte_rate_tracker_ RTC_GUARDED_BY(crit_);
- rtc::RateTracker encoded_frame_rate_tracker_ RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
+ rtc::RateTracker media_byte_rate_tracker_ RTC_GUARDED_BY(mutex_);
+ rtc::RateTracker encoded_frame_rate_tracker_ RTC_GUARDED_BY(mutex_);
std::map<uint32_t, std::unique_ptr<rtc::RateTracker>>
- encoded_frame_rate_trackers_ RTC_GUARDED_BY(crit_);
+ encoded_frame_rate_trackers_ RTC_GUARDED_BY(mutex_);
- absl::optional<int64_t> last_outlier_timestamp_ RTC_GUARDED_BY(crit_);
+ absl::optional<int64_t> last_outlier_timestamp_ RTC_GUARDED_BY(mutex_);
- int last_num_spatial_layers_ RTC_GUARDED_BY(crit_);
- int last_num_simulcast_streams_ RTC_GUARDED_BY(crit_);
+ int last_num_spatial_layers_ RTC_GUARDED_BY(mutex_);
+ int last_num_simulcast_streams_ RTC_GUARDED_BY(mutex_);
std::array<bool, kMaxSpatialLayers> last_spatial_layer_use_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
// Indicates if the latest bitrate allocation had layers disabled by low
// available bandwidth.
- bool bw_limited_layers_ RTC_GUARDED_BY(crit_);
+ bool bw_limited_layers_ RTC_GUARDED_BY(mutex_);
// Indicastes if the encoder internally downscales input image.
- bool internal_encoder_scaler_ RTC_GUARDED_BY(crit_);
- Adaptations adaptation_limitations_ RTC_GUARDED_BY(crit_);
+ bool internal_encoder_scaler_ RTC_GUARDED_BY(mutex_);
+ Adaptations adaptation_limitations_ RTC_GUARDED_BY(mutex_);
struct EncoderChangeEvent {
std::string previous_encoder_implementation;
@@ -374,7 +374,7 @@ class SendStatisticsProxy : public VideoStreamEncoderObserver,
qp_counters_; // QP counters mapped by spatial idx.
};
- std::unique_ptr<UmaSamplesContainer> uma_container_ RTC_GUARDED_BY(crit_);
+ std::unique_ptr<UmaSamplesContainer> uma_container_ RTC_GUARDED_BY(mutex_);
};
} // namespace webrtc
diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc
index f4a1c96d74..ecdf94b312 100644
--- a/video/video_analyzer.cc
+++ b/video/video_analyzer.cc
@@ -151,7 +151,7 @@ VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport,
VideoAnalyzer::~VideoAnalyzer() {
{
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
quit_ = true;
}
for (rtc::PlatformThread* thread : comparison_thread_pool_) {
@@ -174,25 +174,25 @@ void VideoAnalyzer::SetSource(
}
void VideoAnalyzer::SetCall(Call* call) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(!call_);
call_ = call;
}
void VideoAnalyzer::SetSendStream(VideoSendStream* stream) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(!send_stream_);
send_stream_ = stream;
}
void VideoAnalyzer::SetReceiveStream(VideoReceiveStream* stream) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(!receive_stream_);
receive_stream_ = stream;
}
void VideoAnalyzer::SetAudioReceiveStream(AudioReceiveStream* recv_stream) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_CHECK(!audio_receive_stream_);
audio_receive_stream_ = recv_stream;
}
@@ -234,7 +234,7 @@ PacketReceiver::DeliveryStatus VideoAnalyzer::DeliverPacket(
// (FlexFEC and media are sent on different SSRCs, which have different
// timestamps spaces.)
// Also ignore packets from wrong SSRC, but include retransmits.
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
int64_t timestamp =
wrap_handler_.Unwrap(rtp_packet.Timestamp() - rtp_timestamp_delta_);
recv_times_[timestamp] = clock_->CurrentNtpInMilliseconds();
@@ -245,7 +245,7 @@ PacketReceiver::DeliveryStatus VideoAnalyzer::DeliverPacket(
}
void VideoAnalyzer::PreEncodeOnFrame(const VideoFrame& video_frame) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!first_encoded_timestamp_) {
while (frames_.front().timestamp() != video_frame.timestamp()) {
++dropped_frames_before_first_encode_;
@@ -257,7 +257,7 @@ void VideoAnalyzer::PreEncodeOnFrame(const VideoFrame& video_frame) {
}
void VideoAnalyzer::PostEncodeOnFrame(size_t stream_id, uint32_t timestamp) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!first_sent_timestamp_ && stream_id == selected_stream_) {
first_sent_timestamp_ = timestamp;
}
@@ -273,7 +273,7 @@ bool VideoAnalyzer::SendRtp(const uint8_t* packet,
bool result = transport_->SendRtp(packet, length, options);
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (rtp_timestamp_delta_ == 0 && rtp_packet.Ssrc() == ssrc_to_analyze_) {
RTC_CHECK(static_cast<bool>(first_sent_timestamp_));
rtp_timestamp_delta_ = rtp_packet.Timestamp() - *first_sent_timestamp_;
@@ -304,7 +304,7 @@ bool VideoAnalyzer::SendRtcp(const uint8_t* packet, size_t length) {
void VideoAnalyzer::OnFrame(const VideoFrame& video_frame) {
int64_t render_time_ms = clock_->CurrentNtpInMilliseconds();
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
StartExcludingCpuThreadTime();
@@ -361,7 +361,7 @@ void VideoAnalyzer::Wait() {
int frames_processed;
int frames_captured;
{
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
frames_processed = frames_processed_;
frames_captured = captured_frames_;
}
@@ -401,29 +401,29 @@ void VideoAnalyzer::Wait() {
}
void VideoAnalyzer::StartMeasuringCpuProcessTime() {
- rtc::CritScope lock(&cpu_measurement_lock_);
+ MutexLock lock(&cpu_measurement_lock_);
cpu_time_ -= rtc::GetProcessCpuTimeNanos();
wallclock_time_ -= rtc::SystemTimeNanos();
}
void VideoAnalyzer::StopMeasuringCpuProcessTime() {
- rtc::CritScope lock(&cpu_measurement_lock_);
+ MutexLock lock(&cpu_measurement_lock_);
cpu_time_ += rtc::GetProcessCpuTimeNanos();
wallclock_time_ += rtc::SystemTimeNanos();
}
void VideoAnalyzer::StartExcludingCpuThreadTime() {
- rtc::CritScope lock(&cpu_measurement_lock_);
+ MutexLock lock(&cpu_measurement_lock_);
cpu_time_ += rtc::GetThreadCpuTimeNanos();
}
void VideoAnalyzer::StopExcludingCpuThreadTime() {
- rtc::CritScope lock(&cpu_measurement_lock_);
+ MutexLock lock(&cpu_measurement_lock_);
cpu_time_ -= rtc::GetThreadCpuTimeNanos();
}
double VideoAnalyzer::GetCpuUsagePercent() {
- rtc::CritScope lock(&cpu_measurement_lock_);
+ MutexLock lock(&cpu_measurement_lock_);
return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
}
@@ -456,7 +456,7 @@ bool VideoAnalyzer::IsInSelectedSpatialAndTemporalLayer(
}
void VideoAnalyzer::PollStats() {
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
Call::Stats call_stats = call_->GetStats();
send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps);
@@ -564,7 +564,7 @@ bool VideoAnalyzer::CompareFrames() {
}
bool VideoAnalyzer::PopComparison(VideoAnalyzer::FrameComparison* comparison) {
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
// If AllFramesRecorded() is true, it means we have already popped
// frames_to_process_ frames from comparisons_, so there is no more work
// for this thread to be done. frames_processed_ might still be lower if
@@ -581,19 +581,19 @@ bool VideoAnalyzer::PopComparison(VideoAnalyzer::FrameComparison* comparison) {
}
void VideoAnalyzer::FrameRecorded() {
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
++frames_recorded_;
}
bool VideoAnalyzer::AllFramesRecorded() {
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
RTC_DCHECK(frames_recorded_ <= frames_to_process_);
return frames_recorded_ == frames_to_process_ ||
(clock_->CurrentTime() > test_end_ && comparisons_.empty()) || quit_;
}
bool VideoAnalyzer::FrameProcessed() {
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
++frames_processed_;
assert(frames_processed_ <= frames_to_process_);
return frames_processed_ == frames_to_process_ ||
@@ -606,11 +606,11 @@ void VideoAnalyzer::PrintResults() {
StopMeasuringCpuProcessTime();
int dropped_frames_diff;
{
- rtc::CritScope crit(&crit_);
+ MutexLock lock(&mutex_);
dropped_frames_diff = dropped_frames_before_first_encode_ +
dropped_frames_before_rendering_ + frames_.size();
}
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
PrintResult("psnr", psnr_, "dB", ImproveDirection::kBiggerIsBetter);
PrintResult("ssim", ssim_, "unitless", ImproveDirection::kBiggerIsBetter);
PrintResult("sender_time", sender_time_, "ms",
@@ -753,7 +753,7 @@ void VideoAnalyzer::PerformFrameComparison(
ssim = I420SSIM(&*comparison.reference, &*comparison.render);
}
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
if (psnr >= 0.0 && (!worst_frame_ || worst_frame_->psnr > psnr)) {
worst_frame_.emplace(FrameWithPsnr{psnr, *comparison.render});
@@ -842,7 +842,7 @@ void VideoAnalyzer::PrintResultWithExternalMean(
void VideoAnalyzer::PrintSamplesToFile() {
FILE* out = graph_data_output_file_;
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
absl::c_sort(samples_, [](const Sample& A, const Sample& B) -> bool {
return A.input_time_ms < B.input_time_ms;
});
@@ -873,14 +873,14 @@ void VideoAnalyzer::AddCapturedFrameForComparison(
const VideoFrame& video_frame) {
bool must_capture = false;
{
- rtc::CritScope lock(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
must_capture = captured_frames_ < frames_to_process_;
if (must_capture) {
++captured_frames_;
}
}
if (must_capture) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
frames_.push_back(video_frame);
}
}
@@ -903,7 +903,7 @@ void VideoAnalyzer::AddFrameComparison(const VideoFrame& reference,
if (it != encoded_frame_sizes_.end())
encoded_frame_sizes_.erase(it);
- rtc::CritScope crit(&comparison_lock_);
+ MutexLock lock(&comparison_lock_);
if (comparisons_.size() < kMaxComparisons) {
comparisons_.push_back(FrameComparison(
reference, render, dropped, reference.ntp_time_ms(), send_time_ms,
@@ -999,7 +999,7 @@ void VideoAnalyzer::CapturedFrameForwarder::OnFrame(
copy.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
copy.set_timestamp(copy.ntp_time_ms() * 90);
analyzer_->AddCapturedFrameForComparison(copy);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
++captured_frames_;
if (send_stream_input_ && clock_->CurrentTime() <= test_end_ &&
captured_frames_ <= frames_to_capture_) {
@@ -1011,7 +1011,7 @@ void VideoAnalyzer::CapturedFrameForwarder::AddOrUpdateSink(
rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants) {
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
send_stream_input_ = sink;
}
@@ -1022,7 +1022,7 @@ void VideoAnalyzer::CapturedFrameForwarder::AddOrUpdateSink(
void VideoAnalyzer::CapturedFrameForwarder::RemoveSink(
rtc::VideoSinkInterface<VideoFrame>* sink) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RTC_DCHECK(sink == send_stream_input_);
send_stream_input_ = nullptr;
}
diff --git a/video/video_analyzer.h b/video/video_analyzer.h
index 14f77ac53c..190321f539 100644
--- a/video/video_analyzer.h
+++ b/video/video_analyzer.h
@@ -23,6 +23,7 @@
#include "rtc_base/event.h"
#include "rtc_base/numerics/running_statistics.h"
#include "rtc_base/platform_thread.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
#include "test/layer_filtering_transport.h"
#include "test/rtp_file_writer.h"
@@ -163,12 +164,12 @@ class VideoAnalyzer : public PacketReceiver,
void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
VideoAnalyzer* const analyzer_;
- rtc::CriticalSection crit_;
+ Mutex mutex_;
rtc::VideoSinkInterface<VideoFrame>* send_stream_input_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
VideoSourceInterface<VideoFrame>* video_source_;
Clock* clock_;
- int captured_frames_ RTC_GUARDED_BY(crit_);
+ int captured_frames_ RTC_GUARDED_BY(mutex_);
const int frames_to_capture_;
const Timestamp test_end_;
};
@@ -184,7 +185,7 @@ class VideoAnalyzer : public PacketReceiver,
const VideoFrame& render,
bool dropped,
int64_t render_time_ms)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void PollStats();
static void FrameComparisonThread(void* obj);
@@ -226,7 +227,7 @@ class VideoAnalyzer : public PacketReceiver,
const int selected_sl_;
const int selected_tl_;
- rtc::CriticalSection comparison_lock_;
+ Mutex comparison_lock_;
std::vector<Sample> samples_ RTC_GUARDED_BY(comparison_lock_);
Statistics sender_time_ RTC_GUARDED_BY(comparison_lock_);
Statistics receiver_time_ RTC_GUARDED_BY(comparison_lock_);
@@ -264,32 +265,32 @@ class VideoAnalyzer : public PacketReceiver,
size_t last_fec_bytes_;
- rtc::CriticalSection crit_;
+ Mutex mutex_;
const int frames_to_process_;
const Timestamp test_end_;
int frames_recorded_ RTC_GUARDED_BY(comparison_lock_);
int frames_processed_ RTC_GUARDED_BY(comparison_lock_);
int captured_frames_ RTC_GUARDED_BY(comparison_lock_);
int dropped_frames_ RTC_GUARDED_BY(comparison_lock_);
- int dropped_frames_before_first_encode_ RTC_GUARDED_BY(crit_);
- int dropped_frames_before_rendering_ RTC_GUARDED_BY(crit_);
+ int dropped_frames_before_first_encode_ RTC_GUARDED_BY(mutex_);
+ int dropped_frames_before_rendering_ RTC_GUARDED_BY(mutex_);
int64_t last_render_time_ RTC_GUARDED_BY(comparison_lock_);
int64_t last_render_delta_ms_ RTC_GUARDED_BY(comparison_lock_);
int64_t last_unfreeze_time_ms_ RTC_GUARDED_BY(comparison_lock_);
- uint32_t rtp_timestamp_delta_ RTC_GUARDED_BY(crit_);
+ uint32_t rtp_timestamp_delta_ RTC_GUARDED_BY(mutex_);
- rtc::CriticalSection cpu_measurement_lock_;
+ Mutex cpu_measurement_lock_;
int64_t cpu_time_ RTC_GUARDED_BY(cpu_measurement_lock_);
int64_t wallclock_time_ RTC_GUARDED_BY(cpu_measurement_lock_);
- std::deque<VideoFrame> frames_ RTC_GUARDED_BY(crit_);
- absl::optional<VideoFrame> last_rendered_frame_ RTC_GUARDED_BY(crit_);
- rtc::TimestampWrapAroundHandler wrap_handler_ RTC_GUARDED_BY(crit_);
- std::map<int64_t, int64_t> send_times_ RTC_GUARDED_BY(crit_);
- std::map<int64_t, int64_t> recv_times_ RTC_GUARDED_BY(crit_);
- std::map<int64_t, size_t> encoded_frame_sizes_ RTC_GUARDED_BY(crit_);
- absl::optional<uint32_t> first_encoded_timestamp_ RTC_GUARDED_BY(crit_);
- absl::optional<uint32_t> first_sent_timestamp_ RTC_GUARDED_BY(crit_);
+ std::deque<VideoFrame> frames_ RTC_GUARDED_BY(mutex_);
+ absl::optional<VideoFrame> last_rendered_frame_ RTC_GUARDED_BY(mutex_);
+ rtc::TimestampWrapAroundHandler wrap_handler_ RTC_GUARDED_BY(mutex_);
+ std::map<int64_t, int64_t> send_times_ RTC_GUARDED_BY(mutex_);
+ std::map<int64_t, int64_t> recv_times_ RTC_GUARDED_BY(mutex_);
+ std::map<int64_t, size_t> encoded_frame_sizes_ RTC_GUARDED_BY(mutex_);
+ absl::optional<uint32_t> first_encoded_timestamp_ RTC_GUARDED_BY(mutex_);
+ absl::optional<uint32_t> first_sent_timestamp_ RTC_GUARDED_BY(mutex_);
const double avg_psnr_threshold_;
const double avg_ssim_threshold_;
bool is_quick_test_enabled_;
diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc
index f1b3fc7b5b..b4c6ddf10f 100644
--- a/video/video_receive_stream.cc
+++ b/video/video_receive_stream.cc
@@ -494,7 +494,7 @@ bool VideoReceiveStream::SetBaseMinimumPlayoutDelayMs(int delay_ms) {
return false;
}
- rtc::CritScope cs(&playout_delay_lock_);
+ MutexLock lock(&playout_delay_lock_);
base_minimum_playout_delay_ms_ = delay_ms;
UpdatePlayoutDelays();
return true;
@@ -503,7 +503,7 @@ bool VideoReceiveStream::SetBaseMinimumPlayoutDelayMs(int delay_ms) {
int VideoReceiveStream::GetBaseMinimumPlayoutDelayMs() const {
RTC_DCHECK_RUN_ON(&worker_sequence_checker_);
- rtc::CritScope cs(&playout_delay_lock_);
+ MutexLock lock(&playout_delay_lock_);
return base_minimum_playout_delay_ms_;
}
@@ -566,13 +566,13 @@ void VideoReceiveStream::OnCompleteFrame(
const PlayoutDelay& playout_delay = frame->EncodedImage().playout_delay_;
if (playout_delay.min_ms >= 0) {
- rtc::CritScope cs(&playout_delay_lock_);
+ MutexLock lock(&playout_delay_lock_);
frame_minimum_playout_delay_ms_ = playout_delay.min_ms;
UpdatePlayoutDelays();
}
if (playout_delay.max_ms >= 0) {
- rtc::CritScope cs(&playout_delay_lock_);
+ MutexLock lock(&playout_delay_lock_);
frame_maximum_playout_delay_ms_ = playout_delay.max_ms;
UpdatePlayoutDelays();
}
@@ -619,7 +619,7 @@ void VideoReceiveStream::SetEstimatedPlayoutNtpTimestampMs(
void VideoReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
RTC_DCHECK_RUN_ON(&module_process_sequence_checker_);
- rtc::CritScope cs(&playout_delay_lock_);
+ MutexLock lock(&playout_delay_lock_);
syncable_minimum_playout_delay_ms_ = delay_ms;
UpdatePlayoutDelays();
}
diff --git a/video/video_receive_stream.h b/video/video_receive_stream.h
index 8a5136a4b1..57329f4927 100644
--- a/video/video_receive_stream.h
+++ b/video/video_receive_stream.h
@@ -23,6 +23,7 @@
#include "modules/rtp_rtcp/source/source_tracker.h"
#include "modules/video_coding/frame_buffer2.h"
#include "modules/video_coding/video_receiver2.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/task_queue.h"
#include "system_wrappers/include/clock.h"
@@ -205,7 +206,7 @@ class VideoReceiveStream : public webrtc::VideoReceiveStream,
const int max_wait_for_keyframe_ms_;
const int max_wait_for_frame_ms_;
- rtc::CriticalSection playout_delay_lock_;
+ mutable Mutex playout_delay_lock_;
// All of them tries to change current min_playout_delay on |timing_| but
// source of the change request is different in each case. Among them the
diff --git a/video/video_send_stream_impl.h b/video/video_send_stream_impl.h
index 8f30b630be..834fed4693 100644
--- a/video/video_send_stream_impl.h
+++ b/video/video_send_stream_impl.h
@@ -35,8 +35,8 @@
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/utility/include/process_thread.h"
#include "modules/video_coding/include/video_codec_interface.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/experiments/field_trial_parser.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/task_utils/repeating_task.h"
#include "rtc_base/thread_annotations.h"
@@ -164,7 +164,7 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
RtpTransportControllerSendInterface* const transport_;
BitrateAllocatorInterface* const bitrate_allocator_;
- rtc::CriticalSection ivf_writers_crit_;
+ Mutex ivf_writers_mutex_;
bool disable_padding_;
int max_padding_bitrate_;
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc
index 09d7abc062..efbcef7278 100644
--- a/video/video_send_stream_tests.cc
+++ b/video/video_send_stream_tests.cc
@@ -33,12 +33,12 @@
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "modules/video_coding/codecs/vp9/include/vp9.h"
#include "rtc_base/checks.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/experiments/alr_experiment.h"
#include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/rate_limiter.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/task_utils/to_queued_task.h"
@@ -1140,7 +1140,7 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
fec_packet_received_ = false;
++current_size_rtp_;
- rtc::CritScope lock(&mutex_);
+ MutexLock lock(&mutex_);
++current_size_frame_;
}
}
@@ -1182,7 +1182,7 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
}
void UpdateConfiguration() {
- rtc::CritScope lock(&mutex_);
+ MutexLock lock(&mutex_);
// Increase frame size for next encoded frame, in the context of the
// encoder thread.
if (!use_fec_ && current_size_frame_ < static_cast<int32_t>(stop_size_)) {
@@ -1247,7 +1247,7 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
bool fec_packet_received_;
size_t current_size_rtp_;
- rtc::CriticalSection mutex_;
+ Mutex mutex_;
int current_size_frame_ RTC_GUARDED_BY(mutex_);
};
@@ -1296,7 +1296,7 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
: remb_observer_(remb_observer) {}
void OnFrame(const VideoFrame&) {
- rtc::CritScope lock(&remb_observer_->crit_);
+ MutexLock lock(&remb_observer_->mutex_);
if (remb_observer_->test_state_ == kDuringSuspend &&
++remb_observer_->suspended_frame_count_ > kSuspendTimeFrames) {
VideoSendStream::Stats stats = remb_observer_->stream_->GetStats();
@@ -1324,7 +1324,7 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
++rtp_count_;
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@@ -1361,12 +1361,12 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
}
void set_low_remb_bps(int value) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
low_remb_bps_ = value;
}
void set_high_remb_bps(int value) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
high_remb_bps_ = value;
}
@@ -1413,7 +1413,7 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
};
virtual void SendRtcpFeedback(int remb_value)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
FakeReceiveStatistics receive_stats(kVideoSendSsrcs[0],
last_sequence_number_, rtp_count_, 0);
RtpRtcpInterface::Configuration config;
@@ -1438,13 +1438,13 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
CaptureObserver capture_observer_;
VideoSendStream* stream_;
- rtc::CriticalSection crit_;
- TestState test_state_ RTC_GUARDED_BY(crit_);
- int rtp_count_ RTC_GUARDED_BY(crit_);
- int last_sequence_number_ RTC_GUARDED_BY(crit_);
- int suspended_frame_count_ RTC_GUARDED_BY(crit_);
- int low_remb_bps_ RTC_GUARDED_BY(crit_);
- int high_remb_bps_ RTC_GUARDED_BY(crit_);
+ Mutex mutex_;
+ TestState test_state_ RTC_GUARDED_BY(mutex_);
+ int rtp_count_ RTC_GUARDED_BY(mutex_);
+ int last_sequence_number_ RTC_GUARDED_BY(mutex_);
+ int suspended_frame_count_ RTC_GUARDED_BY(mutex_);
+ int low_remb_bps_ RTC_GUARDED_BY(mutex_);
+ int high_remb_bps_ RTC_GUARDED_BY(mutex_);
} test;
RunBaseTest(&test);
@@ -1462,7 +1462,7 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
last_packet_time_ms_ = clock_->TimeInMilliseconds();
RtpPacket rtp_packet;
@@ -1490,7 +1490,7 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
const int kNoPacketsThresholdMs = 2000;
if (test_state_ == kWaitingForNoPackets &&
(last_packet_time_ms_ &&
@@ -1513,7 +1513,7 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
void OnFrameGeneratorCapturerCreated(
test::FrameGeneratorCapturer* frame_generator_capturer) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
capturer_ = frame_generator_capturer;
}
@@ -1532,9 +1532,9 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
TestState test_state_ = kBeforeStopCapture;
Clock* const clock_;
- rtc::CriticalSection crit_;
- absl::optional<int64_t> last_packet_time_ms_ RTC_GUARDED_BY(crit_);
- test::FrameGeneratorCapturer* capturer_ RTC_GUARDED_BY(crit_);
+ Mutex mutex_;
+ absl::optional<int64_t> last_packet_time_ms_ RTC_GUARDED_BY(mutex_);
+ test::FrameGeneratorCapturer* capturer_ RTC_GUARDED_BY(mutex_);
} test;
RunBaseTest(&test);
@@ -1557,7 +1557,7 @@ TEST_F(VideoSendStreamTest, PaddingIsPrimarilyRetransmissions) {
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RtpPacket rtp_packet;
rtp_packet.Parse(packet, length);
@@ -1597,16 +1597,16 @@ TEST_F(VideoSendStreamTest, PaddingIsPrimarilyRetransmissions) {
// rid of this.
SleepMs(5000);
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// Expect padding to be a small percentage of total bytes sent.
EXPECT_LT(padding_length_, .1 * total_length_);
}
}
- rtc::CriticalSection crit_;
+ Mutex mutex_;
Clock* const clock_;
- size_t padding_length_ RTC_GUARDED_BY(crit_);
- size_t total_length_ RTC_GUARDED_BY(crit_);
+ size_t padding_length_ RTC_GUARDED_BY(mutex_);
+ size_t total_length_ RTC_GUARDED_BY(mutex_);
Call* call_;
} test;
@@ -1946,7 +1946,7 @@ TEST_F(VideoSendStreamTest, ChangingTransportOverhead) {
Action OnSendRtp(const uint8_t* packet, size_t length) override {
EXPECT_LE(length, kMaxRtpPacketSize);
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
if (++packets_sent_ < 100)
return SEND_PACKET;
observation_complete_.Set();
@@ -1970,7 +1970,7 @@ TEST_F(VideoSendStreamTest, ChangingTransportOverhead) {
EXPECT_TRUE(Wait());
{
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
packets_sent_ = 0;
}
@@ -1986,7 +1986,7 @@ TEST_F(VideoSendStreamTest, ChangingTransportOverhead) {
private:
TaskQueueBase* const task_queue_;
Call* call_;
- rtc::CriticalSection lock_;
+ Mutex lock_;
int packets_sent_ RTC_GUARDED_BY(lock_);
int transport_overhead_;
const size_t kMaxRtpPacketSize = 1000;
@@ -2162,7 +2162,7 @@ TEST_F(VideoSendStreamTest,
void WaitForResolution(int width, int height) {
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (last_initialized_frame_width_ == width &&
last_initialized_frame_height_ == height) {
return;
@@ -2171,7 +2171,7 @@ TEST_F(VideoSendStreamTest,
EXPECT_TRUE(
init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
EXPECT_EQ(width, last_initialized_frame_width_);
EXPECT_EQ(height, last_initialized_frame_height_);
}
@@ -2180,7 +2180,7 @@ TEST_F(VideoSendStreamTest,
private:
int32_t InitEncode(const VideoCodec* config,
const Settings& settings) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
last_initialized_frame_width_ = config->width;
last_initialized_frame_height_ = config->height;
++number_of_initializations_;
@@ -2195,11 +2195,11 @@ TEST_F(VideoSendStreamTest,
return 0;
}
- rtc::CriticalSection crit_;
+ Mutex mutex_;
rtc::Event init_encode_called_;
- size_t number_of_initializations_ RTC_GUARDED_BY(&crit_);
- int last_initialized_frame_width_ RTC_GUARDED_BY(&crit_);
- int last_initialized_frame_height_ RTC_GUARDED_BY(&crit_);
+ size_t number_of_initializations_ RTC_GUARDED_BY(&mutex_);
+ int last_initialized_frame_width_ RTC_GUARDED_BY(&mutex_);
+ int last_initialized_frame_height_ RTC_GUARDED_BY(&mutex_);
};
test::NullTransport transport;
@@ -2238,21 +2238,21 @@ TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) {
: FakeEncoder(Clock::GetRealTimeClock()), start_bitrate_kbps_(0) {}
int32_t InitEncode(const VideoCodec* config,
const Settings& settings) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
start_bitrate_kbps_ = config->startBitrate;
start_bitrate_changed_.Set();
return FakeEncoder::InitEncode(config, settings);
}
void SetRates(const RateControlParameters& parameters) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
start_bitrate_kbps_ = parameters.bitrate.get_sum_kbps();
start_bitrate_changed_.Set();
FakeEncoder::SetRates(parameters);
}
int GetStartBitrateKbps() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return start_bitrate_kbps_;
}
@@ -2262,9 +2262,9 @@ TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) {
}
private:
- rtc::CriticalSection crit_;
+ mutable Mutex mutex_;
rtc::Event start_bitrate_changed_;
- int start_bitrate_kbps_ RTC_GUARDED_BY(crit_);
+ int start_bitrate_kbps_ RTC_GUARDED_BY(mutex_);
};
CreateSenderCall();
@@ -2311,13 +2311,13 @@ class StartStopBitrateObserver : public test::FakeEncoder {
StartStopBitrateObserver() : FakeEncoder(Clock::GetRealTimeClock()) {}
int32_t InitEncode(const VideoCodec* config,
const Settings& settings) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
encoder_init_.Set();
return FakeEncoder::InitEncode(config, settings);
}
void SetRates(const RateControlParameters& parameters) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
bitrate_kbps_ = parameters.bitrate.get_sum_kbps();
bitrate_changed_.Set();
FakeEncoder::SetRates(parameters);
@@ -2331,7 +2331,7 @@ class StartStopBitrateObserver : public test::FakeEncoder {
do {
absl::optional<int> bitrate_kbps;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
bitrate_kbps = bitrate_kbps_;
}
if (!bitrate_kbps)
@@ -2346,10 +2346,10 @@ class StartStopBitrateObserver : public test::FakeEncoder {
}
private:
- rtc::CriticalSection crit_;
+ Mutex mutex_;
rtc::Event encoder_init_;
rtc::Event bitrate_changed_;
- absl::optional<int> bitrate_kbps_ RTC_GUARDED_BY(crit_);
+ absl::optional<int> bitrate_kbps_ RTC_GUARDED_BY(mutex_);
};
// This test that if the encoder use an internal source, VideoEncoder::SetRates
@@ -2483,23 +2483,23 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
released_(false),
encoder_factory_(this) {}
- bool IsReleased() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope lock(&crit_);
+ bool IsReleased() RTC_LOCKS_EXCLUDED(mutex_) {
+ MutexLock lock(&mutex_);
return released_;
}
- bool IsReadyForEncode() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope lock(&crit_);
+ bool IsReadyForEncode() RTC_LOCKS_EXCLUDED(mutex_) {
+ MutexLock lock(&mutex_);
return IsReadyForEncodeLocked();
}
- size_t num_releases() RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope lock(&crit_);
+ size_t num_releases() RTC_LOCKS_EXCLUDED(mutex_) {
+ MutexLock lock(&mutex_);
return num_releases_;
}
private:
- bool IsReadyForEncodeLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
+ bool IsReadyForEncodeLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return initialized_ && callback_registered_;
}
@@ -2510,8 +2510,8 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
int32_t InitEncode(const VideoCodec* codecSettings,
const Settings& settings) override
- RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope lock(&crit_);
+ RTC_LOCKS_EXCLUDED(mutex_) {
+ MutexLock lock(&mutex_);
EXPECT_FALSE(initialized_);
initialized_ = true;
released_ = false;
@@ -2527,15 +2527,15 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
}
int32_t RegisterEncodeCompleteCallback(
- EncodedImageCallback* callback) override RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope lock(&crit_);
+ EncodedImageCallback* callback) override RTC_LOCKS_EXCLUDED(mutex_) {
+ MutexLock lock(&mutex_);
EXPECT_TRUE(initialized_);
callback_registered_ = true;
return 0;
}
- int32_t Release() override RTC_LOCKS_EXCLUDED(crit_) {
- rtc::CritScope lock(&crit_);
+ int32_t Release() override RTC_LOCKS_EXCLUDED(mutex_) {
+ MutexLock lock(&mutex_);
EXPECT_TRUE(IsReadyForEncodeLocked());
EXPECT_FALSE(released_);
initialized_ = false;
@@ -2582,12 +2582,12 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
}
TaskQueueBase* const task_queue_;
- rtc::CriticalSection crit_;
+ Mutex mutex_;
VideoSendStream* stream_;
- bool initialized_ RTC_GUARDED_BY(crit_);
- bool callback_registered_ RTC_GUARDED_BY(crit_);
- size_t num_releases_ RTC_GUARDED_BY(crit_);
- bool released_ RTC_GUARDED_BY(crit_);
+ bool initialized_ RTC_GUARDED_BY(mutex_);
+ bool callback_registered_ RTC_GUARDED_BY(mutex_);
+ size_t num_releases_ RTC_GUARDED_BY(mutex_);
+ bool released_ RTC_GUARDED_BY(mutex_);
test::VideoEncoderProxyFactory encoder_factory_;
VideoEncoderConfig encoder_config_;
} test_encoder(task_queue());
@@ -2817,7 +2817,7 @@ TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
++rtp_packets_sent_;
@@ -2826,7 +2826,7 @@ TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) {
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
@@ -2850,9 +2850,9 @@ TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) {
EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP sender report.";
}
- rtc::CriticalSection crit_;
- size_t rtp_packets_sent_ RTC_GUARDED_BY(&crit_);
- size_t media_bytes_sent_ RTC_GUARDED_BY(&crit_);
+ Mutex mutex_;
+ size_t rtp_packets_sent_ RTC_GUARDED_BY(&mutex_);
+ size_t media_bytes_sent_ RTC_GUARDED_BY(&mutex_);
} test;
RunBaseTest(&test);
@@ -3006,7 +3006,7 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
void SetRates(const RateControlParameters& parameters) override {
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (target_bitrate_ == parameters.bitrate.get_sum_kbps()) {
FakeEncoder::SetRates(parameters);
return;
@@ -3023,14 +3023,14 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
// until the correct value has been observed.
const int64_t start_time = rtc::TimeMillis();
do {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (target_bitrate_ == expected_bitrate) {
return;
}
} while (bitrate_changed_event_.Wait(
std::max(int64_t{1}, VideoSendStreamTest::kDefaultTimeoutMs -
(rtc::TimeMillis() - start_time))));
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
EXPECT_EQ(target_bitrate_, expected_bitrate)
<< "Timed out while waiting encoder rate to be set.";
}
@@ -3111,8 +3111,8 @@ TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
rtc::Event create_rate_allocator_event_;
rtc::Event init_encode_event_;
rtc::Event bitrate_changed_event_;
- rtc::CriticalSection crit_;
- uint32_t target_bitrate_ RTC_GUARDED_BY(&crit_);
+ Mutex mutex_;
+ uint32_t target_bitrate_ RTC_GUARDED_BY(&mutex_);
int num_rate_allocator_creations_;
int num_encoder_initializations_;
@@ -3160,7 +3160,7 @@ TEST_F(VideoSendStreamTest, ReportsSentResolution) {
encoded.SetSpatialIndex(i);
EncodedImageCallback* callback;
{
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
callback = callback_;
}
RTC_DCHECK(callback);
@@ -3263,7 +3263,7 @@ class Vp9HeaderObserver : public test::SendTest {
bool wait = Wait();
{
// In case of time out, OnSendRtp might still access frames_sent_;
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
EXPECT_TRUE(wait) << "Test timed out waiting for VP9 packet, num frames "
<< frames_sent_;
}
@@ -3295,7 +3295,7 @@ class Vp9HeaderObserver : public test::SendTest {
++packets_sent_;
if (rtp_packet.Marker()) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
++frames_sent_;
}
last_packet_marker_ = rtp_packet.Marker();
@@ -3522,7 +3522,7 @@ class Vp9HeaderObserver : public test::SendTest {
uint32_t last_packet_timestamp_ = 0;
RTPVideoHeaderVP9 last_vp9_;
size_t packets_sent_;
- rtc::CriticalSection crit_;
+ Mutex mutex_;
size_t frames_sent_;
int expected_width_;
int expected_height_;
@@ -3813,7 +3813,7 @@ TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) {
first_packet_sent_(false) {}
void SetRates(const RateControlParameters& parameters) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// Wait for the first sent packet so that videosendstream knows
// rtp_overhead.
if (first_packet_sent_) {
@@ -3837,7 +3837,7 @@ TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) {
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
first_packet_sent_ = true;
return SEND_PACKET;
}
@@ -3862,7 +3862,7 @@ TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) {
EXPECT_TRUE(
bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
EXPECT_LE(max_bitrate_bps_, 57760u);
}
}
@@ -3871,9 +3871,9 @@ TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) {
TaskQueueBase* const task_queue_;
test::VideoEncoderProxyFactory encoder_factory_;
Call* call_;
- rtc::CriticalSection crit_;
- uint32_t max_bitrate_bps_ RTC_GUARDED_BY(&crit_);
- bool first_packet_sent_ RTC_GUARDED_BY(&crit_);
+ Mutex mutex_;
+ uint32_t max_bitrate_bps_ RTC_GUARDED_BY(&mutex_);
+ bool first_packet_sent_ RTC_GUARDED_BY(&mutex_);
rtc::Event bitrate_changed_event_;
} test(task_queue());
RunBaseTest(&test);
@@ -3992,7 +3992,7 @@ class ContentSwitchTest : public test::SendTest {
void OnVideoStreamsCreated(
VideoSendStream* send_stream,
const std::vector<VideoReceiveStream*>& receive_streams) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
send_stream_ = send_stream;
}
@@ -4013,7 +4013,7 @@ class ContentSwitchTest : public test::SendTest {
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
auto internal_send_peer = test::VideoSendStreamPeer(send_stream_);
float pacing_factor =
@@ -4075,18 +4075,18 @@ class ContentSwitchTest : public test::SendTest {
private:
StreamState GetStreamState() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return state_;
}
- rtc::CriticalSection crit_;
+ Mutex mutex_;
rtc::Event content_switch_event_;
Call* call_;
- StreamState state_ RTC_GUARDED_BY(crit_);
- VideoSendStream* send_stream_ RTC_GUARDED_BY(crit_);
+ StreamState state_ RTC_GUARDED_BY(mutex_);
+ VideoSendStream* send_stream_ RTC_GUARDED_BY(mutex_);
VideoSendStream::Config send_stream_config_;
VideoEncoderConfig encoder_config_;
- uint32_t packets_sent_ RTC_GUARDED_BY(crit_);
+ uint32_t packets_sent_ RTC_GUARDED_BY(mutex_);
T* stream_resetter_;
};
diff --git a/video/video_source_sink_controller.cc b/video/video_source_sink_controller.cc
index 7c24eadef5..a5c0941e02 100644
--- a/video/video_source_sink_controller.cc
+++ b/video/video_source_sink_controller.cc
@@ -48,7 +48,7 @@ void VideoSourceSinkController::SetSource(
rtc::VideoSourceInterface<VideoFrame>* old_source;
rtc::VideoSinkWants wants;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
old_source = source_;
source_ = source;
wants = CurrentSettingsToSinkWants();
@@ -61,7 +61,7 @@ void VideoSourceSinkController::SetSource(
}
void VideoSourceSinkController::PushSourceSinkSettings() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!source_)
return;
rtc::VideoSinkWants wants = CurrentSettingsToSinkWants();
@@ -70,62 +70,62 @@ void VideoSourceSinkController::PushSourceSinkSettings() {
}
VideoSourceRestrictions VideoSourceSinkController::restrictions() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return restrictions_;
}
absl::optional<size_t> VideoSourceSinkController::pixels_per_frame_upper_limit()
const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return pixels_per_frame_upper_limit_;
}
absl::optional<double> VideoSourceSinkController::frame_rate_upper_limit()
const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return frame_rate_upper_limit_;
}
bool VideoSourceSinkController::rotation_applied() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return rotation_applied_;
}
int VideoSourceSinkController::resolution_alignment() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return resolution_alignment_;
}
void VideoSourceSinkController::SetRestrictions(
VideoSourceRestrictions restrictions) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
restrictions_ = std::move(restrictions);
}
void VideoSourceSinkController::SetPixelsPerFrameUpperLimit(
absl::optional<size_t> pixels_per_frame_upper_limit) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
pixels_per_frame_upper_limit_ = std::move(pixels_per_frame_upper_limit);
}
void VideoSourceSinkController::SetFrameRateUpperLimit(
absl::optional<double> frame_rate_upper_limit) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
frame_rate_upper_limit_ = std::move(frame_rate_upper_limit);
}
void VideoSourceSinkController::SetRotationApplied(bool rotation_applied) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
rotation_applied_ = rotation_applied;
}
void VideoSourceSinkController::SetResolutionAlignment(
int resolution_alignment) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
resolution_alignment_ = resolution_alignment;
}
-// RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_)
+// RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_)
rtc::VideoSinkWants VideoSourceSinkController::CurrentSettingsToSinkWants()
const {
rtc::VideoSinkWants wants;
diff --git a/video/video_source_sink_controller.h b/video/video_source_sink_controller.h
index 665493aa3d..877cf85901 100644
--- a/video/video_source_sink_controller.h
+++ b/video/video_source_sink_controller.h
@@ -18,7 +18,7 @@
#include "api/video/video_sink_interface.h"
#include "api/video/video_source_interface.h"
#include "call/adaptation/video_source_restrictions.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@@ -53,20 +53,20 @@ class VideoSourceSinkController {
private:
rtc::VideoSinkWants CurrentSettingsToSinkWants() const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- mutable rtc::CriticalSection crit_;
+ mutable Mutex mutex_;
rtc::VideoSinkInterface<VideoFrame>* const sink_;
- rtc::VideoSourceInterface<VideoFrame>* source_ RTC_GUARDED_BY(&crit_);
+ rtc::VideoSourceInterface<VideoFrame>* source_ RTC_GUARDED_BY(&mutex_);
// Pixel and frame rate restrictions.
- VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&crit_);
+ VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&mutex_);
// Ensures that even if we are not restricted, the sink is never configured
// above this limit. Example: We are not CPU limited (no |restrictions_|) but
// our encoder is capped at 30 fps (= |frame_rate_upper_limit_|).
- absl::optional<size_t> pixels_per_frame_upper_limit_ RTC_GUARDED_BY(&crit_);
- absl::optional<double> frame_rate_upper_limit_ RTC_GUARDED_BY(&crit_);
- bool rotation_applied_ RTC_GUARDED_BY(&crit_) = false;
- int resolution_alignment_ RTC_GUARDED_BY(&crit_) = 1;
+ absl::optional<size_t> pixels_per_frame_upper_limit_ RTC_GUARDED_BY(&mutex_);
+ absl::optional<double> frame_rate_upper_limit_ RTC_GUARDED_BY(&mutex_);
+ bool rotation_applied_ RTC_GUARDED_BY(&mutex_) = false;
+ int resolution_alignment_ RTC_GUARDED_BY(&mutex_) = 1;
};
} // namespace webrtc
diff --git a/video/video_stream_decoder.h b/video/video_stream_decoder.h
index 6b040c6a6f..bfe9252976 100644
--- a/video/video_stream_decoder.h
+++ b/video/video_stream_decoder.h
@@ -20,8 +20,8 @@
#include "api/video/video_sink_interface.h"
#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "modules/video_coding/include/video_coding_defines.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/platform_thread.h"
+#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@@ -50,7 +50,7 @@ class VideoStreamDecoder : public VCMReceiveCallback {
private:
// Used for all registered callbacks except rendering.
- rtc::CriticalSection crit_;
+ Mutex mutex_;
VideoReceiver2* const video_receiver_;
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 2e9f5da366..84b5aa327c 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -39,6 +39,7 @@
#include "rtc_base/location.h"
#include "rtc_base/logging.h"
#include "rtc_base/strings/string_builder.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/time_utils.h"
@@ -220,18 +221,18 @@ class VideoStreamEncoder::DegradationPreferenceManager
}
DegradationPreference degradation_preference() const override {
- rtc::CritScope crit(&lock_);
+ MutexLock lock(&lock_);
return effective_degradation_preference_;
}
void SetDegradationPreference(DegradationPreference degradation_preference) {
- rtc::CritScope crit(&lock_);
+ MutexLock lock(&lock_);
degradation_preference_ = degradation_preference;
MaybeUpdateEffectiveDegradationPreference();
}
void SetIsScreenshare(bool is_screenshare) {
- rtc::CritScope crit(&lock_);
+ MutexLock lock(&lock_);
is_screenshare_ = is_screenshare;
MaybeUpdateEffectiveDegradationPreference();
}
@@ -273,7 +274,7 @@ class VideoStreamEncoder::DegradationPreferenceManager
}
}
- rtc::CriticalSection lock_;
+ mutable Mutex lock_;
DegradationPreference degradation_preference_ RTC_GUARDED_BY(&lock_);
bool is_screenshare_ RTC_GUARDED_BY(&lock_);
DegradationPreference effective_degradation_preference_
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc
index 138c47569b..6bdcbd09c5 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -39,6 +39,7 @@
#include "rtc_base/gunit.h"
#include "rtc_base/logging.h"
#include "rtc_base/ref_counted_object.h"
+#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/metrics.h"
#include "system_wrappers/include/sleep.h"
@@ -139,14 +140,14 @@ class CpuOveruseDetectorProxy : public OveruseFrameDetector {
virtual ~CpuOveruseDetectorProxy() {}
void OnTargetFramerateUpdated(int framerate_fps) override {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
last_target_framerate_fps_ = framerate_fps;
OveruseFrameDetector::OnTargetFramerateUpdated(framerate_fps);
framerate_updated_event_.Set();
}
int GetLastTargetFramerate() {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
return last_target_framerate_fps_;
}
@@ -155,7 +156,7 @@ class CpuOveruseDetectorProxy : public OveruseFrameDetector {
rtc::Event* framerate_updated_event() { return &framerate_updated_event_; }
private:
- rtc::CriticalSection lock_;
+ Mutex lock_;
int last_target_framerate_fps_ RTC_GUARDED_BY(lock_);
rtc::Event framerate_updated_event_;
};
@@ -499,17 +500,17 @@ class AdaptingFrameForwarder : public test::FrameForwarder {
~AdaptingFrameForwarder() override {}
void set_adaptation_enabled(bool enabled) {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
adaptation_enabled_ = enabled;
}
bool adaption_enabled() const {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return adaptation_enabled_;
}
rtc::VideoSinkWants last_wants() const {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
return last_wants_;
}
@@ -558,14 +559,14 @@ class AdaptingFrameForwarder : public test::FrameForwarder {
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants) override {
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
last_wants_ = sink_wants_locked();
adapter_.OnSinkWants(wants);
test::FrameForwarder::AddOrUpdateSinkLocked(sink, wants);
}
cricket::VideoAdapter adapter_;
- bool adaptation_enabled_ RTC_GUARDED_BY(crit_);
- rtc::VideoSinkWants last_wants_ RTC_GUARDED_BY(crit_);
+ bool adaptation_enabled_ RTC_GUARDED_BY(mutex_);
+ rtc::VideoSinkWants last_wants_ RTC_GUARDED_BY(mutex_);
absl::optional<int> last_width_;
absl::optional<int> last_height_;
};
@@ -579,30 +580,30 @@ class MockableSendStatisticsProxy : public SendStatisticsProxy {
: SendStatisticsProxy(clock, config, content_type) {}
VideoSendStream::Stats GetStats() override {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
if (mock_stats_)
return *mock_stats_;
return SendStatisticsProxy::GetStats();
}
int GetInputFrameRate() const override {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
if (mock_stats_)
return mock_stats_->input_frame_rate;
return SendStatisticsProxy::GetInputFrameRate();
}
void SetMockStats(const VideoSendStream::Stats& stats) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
mock_stats_.emplace(stats);
}
void ResetMockStats() {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
mock_stats_.reset();
}
private:
- rtc::CriticalSection lock_;
+ mutable Mutex lock_;
absl::optional<VideoSendStream::Stats> mock_stats_ RTC_GUARDED_BY(lock_);
};
@@ -830,17 +831,17 @@ class VideoStreamEncoderTest : public ::testing::Test {
TestEncoder() : FakeEncoder(Clock::GetRealTimeClock()) {}
VideoCodec codec_config() const {
- rtc::CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
return config_;
}
void BlockNextEncode() {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
block_next_encode_ = true;
}
VideoEncoder::EncoderInfo GetEncoderInfo() const override {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
EncoderInfo info;
if (initialized_ == EncoderState::kInitialized) {
if (quality_scaling_) {
@@ -863,7 +864,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
int32_t RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) override {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
encoded_image_callback_ = callback;
return FakeEncoder::RegisterEncodeCompleteCallback(callback);
}
@@ -872,60 +873,60 @@ class VideoStreamEncoderTest : public ::testing::Test {
void CheckLastTimeStampsMatch(int64_t ntp_time_ms,
uint32_t timestamp) const {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
EXPECT_EQ(timestamp_, timestamp);
EXPECT_EQ(ntp_time_ms_, ntp_time_ms);
}
void SetQualityScaling(bool b) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
quality_scaling_ = b;
}
void SetRequestedResolutionAlignment(int requested_resolution_alignment) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
requested_resolution_alignment_ = requested_resolution_alignment;
}
void SetIsHardwareAccelerated(bool is_hardware_accelerated) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
is_hardware_accelerated_ = is_hardware_accelerated;
}
void SetTemporalLayersSupported(size_t spatial_idx, bool supported) {
RTC_DCHECK_LT(spatial_idx, kMaxSpatialLayers);
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
temporal_layers_supported_[spatial_idx] = supported;
}
void SetResolutionBitrateLimits(
std::vector<ResolutionBitrateLimits> thresholds) {
- rtc::CritScope cs(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
resolution_bitrate_limits_ = thresholds;
}
void ForceInitEncodeFailure(bool force_failure) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
force_init_encode_failed_ = force_failure;
}
void SimulateOvershoot(double rate_factor) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
rate_factor_ = rate_factor;
}
uint32_t GetLastFramerate() const {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
return last_framerate_;
}
VideoFrame::UpdateRect GetLastUpdateRect() const {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
return last_update_rect_;
}
const std::vector<VideoFrameType>& LastFrameTypes() const {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
return last_frame_types_;
}
@@ -934,27 +935,27 @@ class VideoStreamEncoderTest : public ::testing::Test {
keyframe ? VideoFrameType::kVideoFrameKey
: VideoFrameType::kVideoFrameDelta};
{
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
last_frame_types_ = frame_type;
}
FakeEncoder::Encode(input_image, &frame_type);
}
void InjectEncodedImage(const EncodedImage& image) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
encoded_image_callback_->OnEncodedImage(image, nullptr, nullptr);
}
void InjectEncodedImage(const EncodedImage& image,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
encoded_image_callback_->OnEncodedImage(image, codec_specific_info,
fragmentation);
}
void ExpectNullFrame() {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
expect_null_frame_ = true;
}
@@ -966,12 +967,12 @@ class VideoStreamEncoderTest : public ::testing::Test {
}
int GetNumEncoderInitializations() const {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
return num_encoder_initializations_;
}
int GetNumSetRates() const {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
return num_set_rates_;
}
@@ -980,7 +981,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
const std::vector<VideoFrameType>* frame_types) override {
bool block_encode;
{
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
if (expect_null_frame_) {
EXPECT_EQ(input_image.timestamp(), 0u);
EXPECT_EQ(input_image.width(), 1);
@@ -1011,7 +1012,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
const Settings& settings) override {
int res = FakeEncoder::InitEncode(config, settings);
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
EXPECT_EQ(initialized_, EncoderState::kUninitialized);
++num_encoder_initializations_;
@@ -1033,14 +1034,14 @@ class VideoStreamEncoderTest : public ::testing::Test {
}
int32_t Release() override {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
EXPECT_NE(initialized_, EncoderState::kUninitialized);
initialized_ = EncoderState::kUninitialized;
return FakeEncoder::Release();
}
void SetRates(const RateControlParameters& parameters) {
- rtc::CritScope lock(&local_crit_sect_);
+ MutexLock lock(&local_mutex_);
num_set_rates_++;
VideoBitrateAllocation adjusted_rate_allocation;
for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
@@ -1060,43 +1061,42 @@ class VideoStreamEncoderTest : public ::testing::Test {
FakeEncoder::SetRates(adjusted_paramters);
}
- rtc::CriticalSection local_crit_sect_;
+ mutable Mutex local_mutex_;
enum class EncoderState {
kUninitialized,
kInitializationFailed,
kInitialized
- } initialized_ RTC_GUARDED_BY(local_crit_sect_) =
- EncoderState::kUninitialized;
- bool block_next_encode_ RTC_GUARDED_BY(local_crit_sect_) = false;
+ } initialized_ RTC_GUARDED_BY(local_mutex_) = EncoderState::kUninitialized;
+ bool block_next_encode_ RTC_GUARDED_BY(local_mutex_) = false;
rtc::Event continue_encode_event_;
- uint32_t timestamp_ RTC_GUARDED_BY(local_crit_sect_) = 0;
- int64_t ntp_time_ms_ RTC_GUARDED_BY(local_crit_sect_) = 0;
- int last_input_width_ RTC_GUARDED_BY(local_crit_sect_) = 0;
- int last_input_height_ RTC_GUARDED_BY(local_crit_sect_) = 0;
- bool quality_scaling_ RTC_GUARDED_BY(local_crit_sect_) = true;
- int requested_resolution_alignment_ RTC_GUARDED_BY(local_crit_sect_) = 1;
- bool is_hardware_accelerated_ RTC_GUARDED_BY(local_crit_sect_) = false;
+ uint32_t timestamp_ RTC_GUARDED_BY(local_mutex_) = 0;
+ int64_t ntp_time_ms_ RTC_GUARDED_BY(local_mutex_) = 0;
+ int last_input_width_ RTC_GUARDED_BY(local_mutex_) = 0;
+ int last_input_height_ RTC_GUARDED_BY(local_mutex_) = 0;
+ bool quality_scaling_ RTC_GUARDED_BY(local_mutex_) = true;
+ int requested_resolution_alignment_ RTC_GUARDED_BY(local_mutex_) = 1;
+ bool is_hardware_accelerated_ RTC_GUARDED_BY(local_mutex_) = false;
std::unique_ptr<Vp8FrameBufferController> frame_buffer_controller_
- RTC_GUARDED_BY(local_crit_sect_);
+ RTC_GUARDED_BY(local_mutex_);
absl::optional<bool>
temporal_layers_supported_[kMaxSpatialLayers] RTC_GUARDED_BY(
- local_crit_sect_);
- bool force_init_encode_failed_ RTC_GUARDED_BY(local_crit_sect_) = false;
- double rate_factor_ RTC_GUARDED_BY(local_crit_sect_) = 1.0;
- uint32_t last_framerate_ RTC_GUARDED_BY(local_crit_sect_) = 0;
+ local_mutex_);
+ bool force_init_encode_failed_ RTC_GUARDED_BY(local_mutex_) = false;
+ double rate_factor_ RTC_GUARDED_BY(local_mutex_) = 1.0;
+ uint32_t last_framerate_ RTC_GUARDED_BY(local_mutex_) = 0;
absl::optional<VideoEncoder::RateControlParameters>
last_rate_control_settings_;
- VideoFrame::UpdateRect last_update_rect_
- RTC_GUARDED_BY(local_crit_sect_) = {0, 0, 0, 0};
+ VideoFrame::UpdateRect last_update_rect_ RTC_GUARDED_BY(local_mutex_) = {
+ 0, 0, 0, 0};
std::vector<VideoFrameType> last_frame_types_;
bool expect_null_frame_ = false;
- EncodedImageCallback* encoded_image_callback_
- RTC_GUARDED_BY(local_crit_sect_) = nullptr;
+ EncodedImageCallback* encoded_image_callback_ RTC_GUARDED_BY(local_mutex_) =
+ nullptr;
NiceMock<MockFecControllerOverride> fec_controller_override_;
- int num_encoder_initializations_ RTC_GUARDED_BY(local_crit_sect_) = 0;
+ int num_encoder_initializations_ RTC_GUARDED_BY(local_mutex_) = 0;
std::vector<ResolutionBitrateLimits> resolution_bitrate_limits_
- RTC_GUARDED_BY(local_crit_sect_);
- int num_set_rates_ RTC_GUARDED_BY(local_crit_sect_) = 0;
+ RTC_GUARDED_BY(local_mutex_);
+ int num_set_rates_ RTC_GUARDED_BY(local_mutex_) = 0;
};
class TestSink : public VideoStreamEncoder::EncoderSink {
@@ -1115,7 +1115,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
if (!encoded_frame_event_.Wait(timeout_ms))
return false;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
timestamp = last_timestamp_;
}
test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp);
@@ -1133,7 +1133,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
uint32_t width = 0;
uint32_t height = 0;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
width = last_width_;
height = last_height_;
}
@@ -1145,7 +1145,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
int width = 0;
int height = 0;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
width = last_width_;
height = last_height_;
}
@@ -1156,7 +1156,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
void CheckLastFrameRotationMatches(VideoRotation expected_rotation) {
VideoRotation rotation;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
rotation = last_rotation_;
}
EXPECT_EQ(expected_rotation, rotation);
@@ -1169,37 +1169,37 @@ class VideoStreamEncoderTest : public ::testing::Test {
}
void SetExpectNoFrames() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
expect_frames_ = false;
}
int number_of_reconfigurations() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return number_of_reconfigurations_;
}
int last_min_transmit_bitrate() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return min_transmit_bitrate_bps_;
}
void SetNumExpectedLayers(size_t num_layers) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
num_expected_layers_ = num_layers;
}
int64_t GetLastCaptureTimeMs() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return last_capture_time_ms_;
}
std::vector<uint8_t> GetLastEncodedImageData() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return std::move(last_encoded_image_data_);
}
RTPFragmentationHeader GetLastFragmentation() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return std::move(last_fragmentation_);
}
@@ -1208,7 +1208,7 @@ class VideoStreamEncoderTest : public ::testing::Test {
const EncodedImage& encoded_image,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
EXPECT_TRUE(expect_frames_);
last_encoded_image_data_ = std::vector<uint8_t>(
encoded_image.data(), encoded_image.data() + encoded_image.size());
@@ -1237,12 +1237,12 @@ class VideoStreamEncoderTest : public ::testing::Test {
bool is_svc,
VideoEncoderConfig::ContentType content_type,
int min_transmit_bitrate_bps) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
++number_of_reconfigurations_;
min_transmit_bitrate_bps_ = min_transmit_bitrate_bps;
}
- rtc::CriticalSection crit_;
+ mutable Mutex mutex_;
TestEncoder* test_encoder_;
rtc::Event encoded_frame_event_;
std::vector<uint8_t> last_encoded_image_data_;
@@ -1268,21 +1268,21 @@ class VideoStreamEncoderTest : public ::testing::Test {
std::unique_ptr<VideoBitrateAllocator> CreateVideoBitrateAllocator(
const VideoCodec& codec) override {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
codec_config_ = codec;
return bitrate_allocator_factory_->CreateVideoBitrateAllocator(codec);
}
VideoCodec codec_config() const {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
return codec_config_;
}
private:
std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
- rtc::CriticalSection crit_;
- VideoCodec codec_config_ RTC_GUARDED_BY(crit_);
+ mutable Mutex mutex_;
+ VideoCodec codec_config_ RTC_GUARDED_BY(mutex_);
};
VideoSendStream::Config video_send_config_;