Revert "Migrate video/ except video/end_to_end_tests and video/adaptation to webrtc::Mutex."
This reverts commit 0eba415fb40cc4e3958546a8ee53c698940df0a1.
Reason for revert: previously unknown lock recursion occurring downstream.
Original change's description:
> 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}
TBR=sprang@webrtc.org,handellm@webrtc.org
Change-Id: I13f337e0de5b8f0eb19deb57cb5623444460ec4d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:11567
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178842
Reviewed-by: Markus Handell <handellm@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31656}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 15e86e4..856b73e 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -125,7 +125,6 @@
"../rtc_base:rtc_base_approved",
"../rtc_base:rtc_task_queue",
"../rtc_base:timeutils",
- "../rtc_base/synchronization:mutex",
"../rtc_base/task_utils:repeating_task",
"../system_wrappers",
]
@@ -764,7 +763,6 @@
"../rtc_base:macromagic",
"../rtc_base:rtc_task_queue",
"../rtc_base:timeutils",
- "../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker",
"../system_wrappers",
]
diff --git a/test/fake_encoder.cc b/test/fake_encoder.cc
index 84a4afd..2959559 100644
--- a/test/fake_encoder.cc
+++ b/test/fake_encoder.cc
@@ -67,19 +67,19 @@
void FakeEncoder::SetMaxBitrate(int max_kbps) {
RTC_DCHECK_GE(max_kbps, -1); // max_kbps == -1 disables it.
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
max_target_bitrate_kbps_ = max_kbps;
SetRatesLocked(current_rate_settings_);
}
void FakeEncoder::SetQp(int qp) {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
qp_ = qp;
}
int32_t FakeEncoder::InitEncode(const VideoCodec* config,
const Settings& settings) {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
config_ = *config;
current_rate_settings_.bitrate.SetBitrate(0, 0, config_.startBitrate * 1000);
current_rate_settings_.framerate_fps = config_.maxFramerate;
@@ -100,7 +100,7 @@
uint32_t counter;
absl::optional<int> qp;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
max_framerate = config_.maxFramerate;
num_simulcast_streams = config_.numberOfSimulcastStreams;
for (int i = 0; i < num_simulcast_streams; ++i) {
@@ -182,7 +182,7 @@
}
}
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
for (uint8_t i = 0; i < num_simulcast_streams; ++i) {
if (target_bitrate.GetBitrate(i, 0) > 0) {
int temporal_id = last_frame_info_.layers.size() > i
@@ -232,7 +232,7 @@
int32_t FakeEncoder::RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
callback_ = callback;
return 0;
}
@@ -242,7 +242,7 @@
}
void FakeEncoder::SetRates(const RateControlParameters& parameters) {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
SetRatesLocked(parameters);
}
@@ -280,7 +280,7 @@
}
int FakeEncoder::GetConfiguredInputFramerate() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
return static_cast<int>(current_rate_settings_.framerate_fps + 0.5);
}
@@ -295,7 +295,7 @@
const int kIdrFrequency = 10;
int current_idr_counter;
{
- MutexLock lock(&local_mutex_);
+ rtc::CritScope cs(&local_crit_sect_);
current_idr_counter = idr_counter_;
++idr_counter_;
}
diff --git a/test/fake_encoder.h b/test/fake_encoder.h
index 22c7723..ade0e35 100644
--- a/test/fake_encoder.h
+++ b/test/fake_encoder.h
@@ -26,7 +26,7 @@
#include "api/video_codecs/video_encoder.h"
#include "modules/include/module_common_types.h"
#include "modules/video_coding/include/video_codec_interface.h"
-#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
@@ -40,23 +40,23 @@
virtual ~FakeEncoder() = default;
// Sets max bitrate. Not thread-safe, call before registering the encoder.
- void SetMaxBitrate(int max_kbps) RTC_LOCKS_EXCLUDED(mutex_);
- void SetQp(int qp) RTC_LOCKS_EXCLUDED(mutex_);
+ void SetMaxBitrate(int max_kbps) RTC_LOCKS_EXCLUDED(crit_sect_);
+ void SetQp(int qp) RTC_LOCKS_EXCLUDED(crit_sect_);
void SetFecControllerOverride(
FecControllerOverride* fec_controller_override) override;
int32_t InitEncode(const VideoCodec* config, const Settings& settings)
- RTC_LOCKS_EXCLUDED(mutex_) override;
+ RTC_LOCKS_EXCLUDED(crit_sect_) override;
int32_t Encode(const VideoFrame& input_image,
const std::vector<VideoFrameType>* frame_types)
- RTC_LOCKS_EXCLUDED(mutex_) override;
+ RTC_LOCKS_EXCLUDED(crit_sect_) override;
int32_t RegisterEncodeCompleteCallback(EncodedImageCallback* callback)
- RTC_LOCKS_EXCLUDED(mutex_) override;
+ RTC_LOCKS_EXCLUDED(crit_sect_) override;
int32_t Release() override;
void SetRates(const RateControlParameters& parameters)
- RTC_LOCKS_EXCLUDED(mutex_) override;
- int GetConfiguredInputFramerate() const RTC_LOCKS_EXCLUDED(mutex_);
+ RTC_LOCKS_EXCLUDED(crit_sect_) override;
+ int GetConfiguredInputFramerate() const RTC_LOCKS_EXCLUDED(crit_sect_);
EncoderInfo GetEncoderInfo() const override;
static const char* kImplementationName;
@@ -81,7 +81,7 @@
uint8_t num_simulcast_streams,
const VideoBitrateAllocation& target_bitrate,
SimulcastStream simulcast_streams[kMaxSimulcastStreams],
- int framerate) RTC_LOCKS_EXCLUDED(mutex_);
+ int framerate) RTC_LOCKS_EXCLUDED(crit_sect_);
// Called before the frame is passed to callback_->OnEncodedImage, to let
// subclasses fill out codec_specific, possibly modify encodedImage.
@@ -91,20 +91,20 @@
CodecSpecificInfo* codec_specific);
void SetRatesLocked(const RateControlParameters& parameters)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
- FrameInfo last_frame_info_ RTC_GUARDED_BY(mutex_);
+ FrameInfo last_frame_info_ RTC_GUARDED_BY(crit_sect_);
Clock* const clock_;
- VideoCodec config_ RTC_GUARDED_BY(mutex_);
- EncodedImageCallback* callback_ RTC_GUARDED_BY(mutex_);
- RateControlParameters current_rate_settings_ RTC_GUARDED_BY(mutex_);
- int max_target_bitrate_kbps_ RTC_GUARDED_BY(mutex_);
- bool pending_keyframe_ RTC_GUARDED_BY(mutex_);
- uint32_t counter_ RTC_GUARDED_BY(mutex_);
- mutable Mutex mutex_;
+ VideoCodec config_ RTC_GUARDED_BY(crit_sect_);
+ EncodedImageCallback* callback_ RTC_GUARDED_BY(crit_sect_);
+ RateControlParameters current_rate_settings_ RTC_GUARDED_BY(crit_sect_);
+ int max_target_bitrate_kbps_ RTC_GUARDED_BY(crit_sect_);
+ bool pending_keyframe_ RTC_GUARDED_BY(crit_sect_);
+ uint32_t counter_ RTC_GUARDED_BY(crit_sect_);
+ rtc::CriticalSection crit_sect_;
bool used_layers_[kMaxSimulcastStreams];
- absl::optional<int> qp_ RTC_GUARDED_BY(mutex_);
+ absl::optional<int> qp_ RTC_GUARDED_BY(crit_sect_);
// Current byte debt to be payed over a number of frames.
// The debt is acquired by keyframes overshooting the bitrate target.
@@ -121,8 +121,8 @@
EncodedImage* encoded_image,
CodecSpecificInfo* codec_specific) override;
- int idr_counter_ RTC_GUARDED_BY(local_mutex_);
- Mutex local_mutex_;
+ int idr_counter_ RTC_GUARDED_BY(local_crit_sect_);
+ rtc::CriticalSection local_crit_sect_;
};
class DelayedEncoder : public test::FakeEncoder {
diff --git a/test/frame_forwarder.cc b/test/frame_forwarder.cc
index e89f753..d8ec4b5 100644
--- a/test/frame_forwarder.cc
+++ b/test/frame_forwarder.cc
@@ -18,14 +18,14 @@
FrameForwarder::~FrameForwarder() {}
void FrameForwarder::IncomingCapturedFrame(const VideoFrame& video_frame) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (sink_)
sink_->OnFrame(video_frame);
}
void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
AddOrUpdateSinkLocked(sink, wants);
}
@@ -38,13 +38,13 @@
}
void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_DCHECK_EQ(sink, sink_);
sink_ = nullptr;
}
rtc::VideoSinkWants FrameForwarder::sink_wants() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return sink_wants_;
}
@@ -53,7 +53,7 @@
}
bool FrameForwarder::has_sinks() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return sink_ != nullptr;
}
diff --git a/test/frame_forwarder.h b/test/frame_forwarder.h
index bbf11cc..d391160 100644
--- a/test/frame_forwarder.h
+++ b/test/frame_forwarder.h
@@ -12,7 +12,7 @@
#include "api/video/video_frame.h"
#include "api/video/video_source_interface.h"
-#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
namespace webrtc {
namespace test {
@@ -27,25 +27,25 @@
~FrameForwarder() override;
// Forwards |video_frame| to the registered |sink_|.
virtual void IncomingCapturedFrame(const VideoFrame& video_frame)
- RTC_LOCKS_EXCLUDED(mutex_);
- rtc::VideoSinkWants sink_wants() const RTC_LOCKS_EXCLUDED(mutex_);
- bool has_sinks() const RTC_LOCKS_EXCLUDED(mutex_);
+ RTC_LOCKS_EXCLUDED(crit_);
+ rtc::VideoSinkWants sink_wants() const RTC_LOCKS_EXCLUDED(crit_);
+ bool has_sinks() const RTC_LOCKS_EXCLUDED(crit_);
protected:
rtc::VideoSinkWants sink_wants_locked() const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants)
- RTC_LOCKS_EXCLUDED(mutex_) override;
+ RTC_LOCKS_EXCLUDED(crit_) override;
void AddOrUpdateSinkLocked(rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink)
- RTC_LOCKS_EXCLUDED(mutex_) override;
+ RTC_LOCKS_EXCLUDED(crit_) override;
- mutable Mutex mutex_;
- rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(mutex_);
- rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(mutex_);
+ rtc::CriticalSection crit_;
+ rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
+ rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_);
};
} // namespace test
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 12a316e..6eb7531 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -128,7 +128,6 @@
"../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",
@@ -251,7 +250,6 @@
"../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",
@@ -328,7 +326,6 @@
"../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 d575e11..27e00ee 100644
--- a/video/call_stats.cc
+++ b/video/call_stats.cc
@@ -129,7 +129,7 @@
max_rtt_ms_ = GetMaxRttMs(reports_);
avg_rtt_ms = GetNewAvgRttMs(reports_, avg_rtt_ms);
{
- MutexLock lock(&avg_rtt_ms_lock_);
+ rtc::CritScope lock(&avg_rtt_ms_lock_);
avg_rtt_ms_ = avg_rtt_ms;
}
@@ -178,7 +178,7 @@
// allow only reading this from the process thread (or TQ once we get there)
// so that the lock isn't necessary.
- MutexLock lock(&avg_rtt_ms_lock_);
+ rtc::CritScope cs(&avg_rtt_ms_lock_);
return avg_rtt_ms_;
}
diff --git a/video/call_stats.h b/video/call_stats.h
index 3bfb632..8003001 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/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
#include "rtc_base/thread_checker.h"
#include "system_wrappers/include/clock.h"
@@ -90,7 +90,7 @@
int64_t avg_rtt_ms_;
// Protects |avg_rtt_ms_|.
- mutable Mutex avg_rtt_ms_lock_;
+ rtc::CriticalSection 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 b81ff61..a736d83 100644
--- a/video/encoder_rtcp_feedback.cc
+++ b/video/encoder_rtcp_feedback.cc
@@ -56,7 +56,7 @@
RTC_DCHECK(HasSsrc(ssrc));
{
int64_t now_ms = clock_->TimeInMilliseconds();
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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 3bd1cb9..b5dd028 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/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
@@ -50,8 +50,8 @@
const RtpVideoSenderInterface* rtp_video_sender_;
VideoStreamEncoderInterface* const video_stream_encoder_;
- Mutex mutex_;
- int64_t time_last_intra_request_ms_ RTC_GUARDED_BY(mutex_);
+ rtc::CriticalSection crit_;
+ int64_t time_last_intra_request_ms_ RTC_GUARDED_BY(crit_);
const int min_keyframe_send_interval_ms_;
};
diff --git a/video/frame_encode_metadata_writer.cc b/video/frame_encode_metadata_writer.cc
index 8ffb3ae..e5f5557 100644
--- a/video/frame_encode_metadata_writer.cc
+++ b/video/frame_encode_metadata_writer.cc
@@ -60,7 +60,7 @@
void FrameEncodeMetadataWriter::OnEncoderInit(const VideoCodec& codec,
bool internal_source) {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
codec_settings_ = codec;
internal_source_ = internal_source;
}
@@ -68,7 +68,7 @@
void FrameEncodeMetadataWriter::OnSetRates(
const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate_fps) {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&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::OnEncodeStarted(const VideoFrame& frame) {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
if (internal_source_) {
return;
}
@@ -128,7 +128,7 @@
void FrameEncodeMetadataWriter::FillTimingInfo(size_t simulcast_svc_idx,
EncodedImage* encoded_image) {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&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 @@
}
void FrameEncodeMetadataWriter::Reset() {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&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 32b5872..4ee2d7e 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/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
namespace webrtc {
@@ -69,7 +69,7 @@
std::list<FrameMetadata> frames;
};
- Mutex lock_;
+ rtc::CriticalSection 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 298919c..19c1141 100644
--- a/video/picture_id_tests.cc
+++ b/video/picture_id_tests.cc
@@ -22,7 +22,6 @@
#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"
@@ -50,12 +49,12 @@
num_ssrcs_to_observe_(1) {}
void SetExpectedSsrcs(size_t num_expected_ssrcs) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
num_ssrcs_to_observe_ = num_expected_ssrcs;
}
void ResetObservedSsrcs() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
// Do not clear the timestamp and picture_id, to ensure that we check
// consistency between reinits and recreations.
num_packets_sent_.clear();
@@ -63,7 +62,7 @@
}
void SetMaxExpectedPictureIdGap(int max_expected_picture_id_gap) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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;
@@ -121,7 +120,7 @@
// Verify continuity and monotonicity of picture_id sequence.
void VerifyPictureId(const ParsedPacket& current,
const ParsedPacket& last) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
if (current.timestamp == last.timestamp) {
EXPECT_EQ(last.picture_id, current.picture_id);
return; // Same frame.
@@ -144,7 +143,7 @@
}
void VerifyTl0Idx(const ParsedPacket& current, const ParsedPacket& last) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
if (current.tl0_pic_idx == kNoTl0PicIdx ||
current.temporal_idx == kNoTemporalIdx) {
return; // No temporal layers.
@@ -170,7 +169,7 @@
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
ParsedPacket parsed;
if (!ParsePayload(packet, length, &parsed))
@@ -197,14 +196,14 @@
return SEND_PACKET;
}
- Mutex mutex_;
+ rtc::CriticalSection crit_;
const std::unique_ptr<VideoRtpDepacketizer> depacketizer_;
- 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_);
+ 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_);
};
class PictureIdTest : public test::CallTest,
diff --git a/video/receive_statistics_proxy.cc b/video/receive_statistics_proxy.cc
index 7aec685..82951c8 100644
--- a/video/receive_statistics_proxy.cc
+++ b/video/receive_statistics_proxy.cc
@@ -133,7 +133,7 @@
// earlier.
RTC_DCHECK_RUN_ON(&decode_thread_);
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
char log_stream_buf[8 * 1024];
rtc::SimpleStringBuilder log_stream(log_stream_buf);
@@ -623,7 +623,7 @@
}
VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
// 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 @@
}
void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
stats_.current_payload_type = payload_type;
}
void ReceiveStatisticsProxy::OnDecoderImplementationName(
const char* implementation_name) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
stats_.decoder_implementation_name = implementation_name;
}
@@ -671,7 +671,7 @@
int jitter_buffer_ms,
int min_playout_delay_ms,
int render_delay_ms) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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::OnUniqueFramesCounted(int num_unique_frames) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
num_unique_frames_.emplace(num_unique_frames);
}
void ReceiveStatisticsProxy::OnTimingFrameInfoUpdated(
const TimingFrameInfo& info) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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::RtcpPacketTypesCounterUpdated(
uint32_t ssrc,
const RtcpPacketTypeCounter& packet_counter) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (stats_.ssrc != ssrc)
return;
stats_.rtcp_packet_type_counts = packet_counter;
}
void ReceiveStatisticsProxy::OnCname(uint32_t ssrc, absl::string_view cname) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
// 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 @@
absl::optional<uint8_t> qp,
int32_t decode_time_ms,
VideoContentType content_type) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
uint64_t now_ms = clock_->TimeInMilliseconds();
@@ -799,7 +799,7 @@
RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0);
int64_t now_ms = clock_->TimeInMilliseconds();
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
video_quality_observer_->OnRenderedFrame(frame, now_ms);
@@ -833,7 +833,7 @@
void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t video_playout_ntp_ms,
int64_t sync_offset_ms,
double estimated_freq_khz) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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::OnCompleteFrame(bool is_keyframe,
size_t size_bytes,
VideoContentType content_type) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (is_keyframe) {
++stats_.frame_counts.key_frames;
} else {
@@ -881,13 +881,13 @@
}
void ReceiveStatisticsProxy::OnDroppedFrames(uint32_t frames_dropped) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
stats_.frames_dropped += frames_dropped;
}
void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) {
RTC_DCHECK_RUN_ON(&decode_thread_);
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
last_codec_type_ = codec_type;
if (last_codec_type_ == kVideoCodecVP8 && qp != -1) {
qp_counters_.vp8.Add(qp);
@@ -898,7 +898,7 @@
void ReceiveStatisticsProxy::OnStreamInactive() {
// TODO(sprang): Figure out any other state that should be reset.
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
// 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::OnRttUpdate(int64_t avg_rtt_ms,
int64_t max_rtt_ms) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
avg_rtt_ms_ = avg_rtt_ms;
}
diff --git a/video/receive_statistics_proxy.h b/video/receive_statistics_proxy.h
index 8b94c32..02043d69 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 @@
rtc::HistogramPercentileCounter interframe_delay_percentiles;
};
- void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
// Removes info about old frames and then updates the framerate.
void UpdateFramerate(int64_t now_ms) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void UpdateDecodeTimeHistograms(int width,
int height,
int decode_time_ms) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
- int64_t now_ms) const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ int64_t now_ms) const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Clock* const clock_;
// Ownership of this object lies with the owner of the ReceiveStatisticsProxy
@@ -150,52 +150,52 @@
const int64_t start_ms_;
const bool enable_decode_time_histograms_;
- 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_);
+ 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_);
// Note: The |stats_.rtp_stats| member is not used or populated by this class.
- 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_);
+ 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_);
std::unique_ptr<VideoQualityObserver> video_quality_observer_
- RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_
- RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
std::map<VideoContentType, ContentSpecificStats> content_specific_stats_
- RTC_GUARDED_BY(mutex_);
- MaxCounter freq_offset_counter_ RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
+ MaxCounter freq_offset_counter_ RTC_GUARDED_BY(crit_);
QpCounters qp_counters_ RTC_GUARDED_BY(decode_thread_);
- 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_);
+ 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_);
// 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(&mutex_);
- absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(&crit_);
+ absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(crit_);
absl::optional<int64_t> last_estimated_playout_ntp_timestamp_ms_
- RTC_GUARDED_BY(&mutex_);
+ RTC_GUARDED_BY(&crit_);
absl::optional<int64_t> last_estimated_playout_time_ms_
- RTC_GUARDED_BY(&mutex_);
+ RTC_GUARDED_BY(&crit_);
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 28e9a0b..3dedc43 100644
--- a/video/rtp_streams_synchronizer.cc
+++ b/video/rtp_streams_synchronizer.cc
@@ -51,7 +51,7 @@
RtpStreamsSynchronizer::~RtpStreamsSynchronizer() = default;
void RtpStreamsSynchronizer::ConfigureSync(Syncable* syncable_audio) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (syncable_audio == syncable_audio_) {
// This prevents expensive no-ops.
return;
@@ -76,7 +76,7 @@
RTC_DCHECK_RUN_ON(&process_thread_checker_);
last_sync_time_ = rtc::TimeNanos();
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (!syncable_audio_) {
return;
}
@@ -157,7 +157,7 @@
int64_t* video_playout_ntp_ms,
int64_t* stream_offset_ms,
double* estimated_freq_khz) const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (!syncable_audio_) {
return false;
}
diff --git a/video/rtp_streams_synchronizer.h b/video/rtp_streams_synchronizer.h
index 732c9a7..6abf5bb 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/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
#include "rtc_base/thread_checker.h"
#include "video/stream_synchronization.h"
@@ -51,11 +51,11 @@
private:
Syncable* syncable_video_;
- 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::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_);
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 6289aba..8bbb586 100644
--- a/video/rtp_video_stream_receiver.cc
+++ b/video/rtp_video_stream_receiver.cc
@@ -121,7 +121,7 @@
}
void RtpVideoStreamReceiver::RtcpFeedbackBuffer::RequestKeyFrame() {
- MutexLock lock(&cs_);
+ rtc::CritScope lock(&cs_);
request_key_frame_ = true;
}
@@ -129,7 +129,7 @@
const std::vector<uint16_t>& sequence_numbers,
bool buffering_allowed) {
RTC_DCHECK(!sequence_numbers.empty());
- MutexLock lock(&cs_);
+ rtc::CritScope lock(&cs_);
nack_sequence_numbers_.insert(nack_sequence_numbers_.end(),
sequence_numbers.cbegin(),
sequence_numbers.cend());
@@ -146,7 +146,7 @@
bool decodability_flag,
bool buffering_allowed) {
RTC_DCHECK(buffering_allowed);
- MutexLock lock(&cs_);
+ rtc::CritScope lock(&cs_);
RTC_DCHECK(!lntf_state_)
<< "SendLossNotification() called twice in a row with no call to "
"SendBufferedRtcpFeedback() in between.";
@@ -160,7 +160,7 @@
RtpVideoStreamReceiver::RtcpFeedbackBuffer::ConsumedRtcpFeedback
RtpVideoStreamReceiver::RtcpFeedbackBuffer::ConsumeRtcpFeedback() {
- MutexLock lock(&cs_);
+ rtc::CritScope lock(&cs_);
return ConsumeRtcpFeedbackLocked();
}
@@ -376,7 +376,7 @@
return absl::nullopt;
}
{
- MutexLock lock(&sync_info_lock_);
+ rtc::CritScope lock(&sync_info_lock_);
if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
return absl::nullopt;
}
@@ -667,7 +667,7 @@
// TODO(nisse): Exclude out-of-order packets?
int64_t now_ms = clock_->TimeInMilliseconds();
{
- MutexLock lock(&sync_info_lock_);
+ rtc::CritScope cs(&sync_info_lock_);
last_received_rtp_timestamp_ = packet.Timestamp();
last_received_rtp_system_time_ms_ = now_ms;
}
@@ -844,7 +844,7 @@
has_received_frame_ = true;
}
- MutexLock lock(&reference_finder_lock_);
+ rtc::CritScope 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::OnCompleteFrame(
std::unique_ptr<video_coding::EncodedFrame> frame) {
{
- MutexLock lock(&last_seq_num_cs_);
+ rtc::CritScope 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::OnDecryptedFrame(
std::unique_ptr<video_coding::RtpFrameObject> frame) {
- MutexLock lock(&reference_finder_lock_);
+ rtc::CritScope lock(&reference_finder_lock_);
reference_finder_->ManageFrame(std::move(frame));
}
@@ -967,7 +967,7 @@
void RtpVideoStreamReceiver::ManageFrame(
std::unique_ptr<video_coding::RtpFrameObject> frame) {
- MutexLock lock(&reference_finder_lock_);
+ rtc::CritScope lock(&reference_finder_lock_);
reference_finder_->ManageFrame(std::move(frame));
}
@@ -1022,7 +1022,7 @@
// correctly calculate frame references.
void RtpVideoStreamReceiver::NotifyReceiverOfEmptyPacket(uint16_t seq_num) {
{
- MutexLock lock(&reference_finder_lock_);
+ rtc::CritScope lock(&reference_finder_lock_);
reference_finder_->PaddingReceived(seq_num);
}
OnInsertedPacket(packet_buffer_.InsertPadding(seq_num));
@@ -1086,7 +1086,7 @@
int seq_num = -1;
{
- MutexLock lock(&last_seq_num_cs_);
+ rtc::CritScope 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::FrameDecoded(int64_t picture_id) {
int seq_num = -1;
{
- MutexLock lock(&last_seq_num_cs_);
+ rtc::CritScope 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 @@
}
if (seq_num != -1) {
packet_buffer_.ClearTo(seq_num);
- MutexLock lock(&reference_finder_lock_);
+ rtc::CritScope 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 b6a5a2f..68e23ee 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 @@
LossNotificationSender* const loss_notification_sender_;
// NACKs are accessible from two threads due to nack_module_ being a module.
- Mutex cs_;
+ rtc::CriticalSection cs_;
// Key-frame-request-related state.
bool request_key_frame_ RTC_GUARDED_BY(cs_);
@@ -351,13 +351,13 @@
absl::optional<int64_t> video_structure_frame_id_
RTC_GUARDED_BY(worker_task_checker_);
- Mutex reference_finder_lock_;
+ rtc::CriticalSection 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_;
- Mutex last_seq_num_cs_;
+ rtc::CriticalSection 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 @@
// Info for GetSyncInfo is updated on network or worker thread, and queried on
// the worker thread.
- mutable Mutex sync_info_lock_;
+ rtc::CriticalSection 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 56c4164..a243eda 100644
--- a/video/send_delay_stats.cc
+++ b/video/send_delay_stats.cc
@@ -41,7 +41,7 @@
}
void SendDelayStats::UpdateHistograms() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
for (const auto& it : send_delay_counters_) {
AggregatedStats stats = it.second->GetStats();
if (stats.num_samples >= kMinRequiredPeriodicSamples) {
@@ -52,7 +52,7 @@
}
void SendDelayStats::AddSsrcs(const VideoSendStream::Config& config) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (ssrcs_.size() > kMaxSsrcMapSize)
return;
for (const auto& ssrc : config.rtp.ssrcs)
@@ -73,7 +73,7 @@
int64_t capture_time_ms,
uint32_t ssrc) {
// Packet sent to transport.
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (ssrcs_.find(ssrc) == ssrcs_.end())
return;
@@ -93,7 +93,7 @@
if (packet_id == -1)
return false;
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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 20f9804..d9fa16a 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/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
#include "video/stats_counter.h"
@@ -66,22 +66,22 @@
void UpdateHistograms();
void RemoveOld(int64_t now, PacketMap* packets)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
AvgCounter* GetSendDelayCounter(uint32_t ssrc)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Clock* const clock_;
- Mutex mutex_;
+ rtc::CriticalSection 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_);
+ PacketMap packets_ RTC_GUARDED_BY(crit_);
+ size_t num_old_packets_ RTC_GUARDED_BY(crit_);
+ size_t num_skipped_packets_ RTC_GUARDED_BY(crit_);
- std::set<uint32_t> ssrcs_ RTC_GUARDED_BY(mutex_);
+ std::set<uint32_t> ssrcs_ RTC_GUARDED_BY(crit_);
// Mapped by SSRC.
std::map<uint32_t, std::unique_ptr<AvgCounter>> send_delay_counters_
- RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
};
} // namespace webrtc
diff --git a/video/send_statistics_proxy.cc b/video/send_statistics_proxy.cc
index ee32fd9..b5bcbe6 100644
--- a/video/send_statistics_proxy.cc
+++ b/video/send_statistics_proxy.cc
@@ -154,7 +154,7 @@
}
SendStatisticsProxy::~SendStatisticsProxy() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
uma_container_->UpdateHistograms(rtp_config_, stats_);
int64_t elapsed_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000;
@@ -670,7 +670,7 @@
void SendStatisticsProxy::OnEncoderReconfigured(
const VideoEncoderConfig& config,
const std::vector<VideoStream>& streams) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (content_type_ != config.content_type) {
uma_container_->UpdateHistograms(rtp_config_, stats_);
@@ -687,7 +687,7 @@
void SendStatisticsProxy::OnEncodedFrameTimeMeasured(int encode_time_ms,
int encode_usage_percent) {
RTC_DCHECK_GE(encode_time_ms, 0);
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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::OnSuspendChange(bool is_suspended) {
int64_t now_ms = clock_->TimeInMilliseconds();
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
stats_.suspended = is_suspended;
if (is_suspended) {
// Pause framerate (add min pause time since there may be frames/packets
@@ -733,7 +733,7 @@
}
VideoSendStream::Stats SendStatisticsProxy::GetStats() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
PurgeOldStats();
stats_.input_frame_rate =
round(uma_container_->input_frame_rate_tracker_.ComputeRate());
@@ -803,7 +803,7 @@
}
void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -815,7 +815,7 @@
}
void SendStatisticsProxy::OnSetEncoderTargetRate(uint32_t bitrate_bps) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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::OnMinPixelLimitReached() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
uma_container_->fallback_info_disabled_.min_pixel_limit_reached = true;
}
@@ -929,7 +929,7 @@
? encoded_image.SpatialIndex().value_or(0)
: 0;
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
++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::OnEncoderImplementationChanged(
const std::string& implementation_name) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
encoder_changed_ = EncoderChangeEvent{stats_.encoder_implementation_name,
implementation_name};
stats_.encoder_implementation_name = implementation_name;
}
int SendStatisticsProxy::GetInputFrameRate() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return round(uma_container_->input_frame_rate_tracker_.ComputeRate());
}
int SendStatisticsProxy::GetSendFrameRate() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return round(encoded_frame_rate_tracker_.ComputeRate());
}
void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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::OnFrameDropped(DropReason reason) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
switch (reason) {
case DropReason::kSource:
++stats_.frames_dropped_by_capturer;
@@ -1092,7 +1092,7 @@
}
void SendStatisticsProxy::ClearAdaptationStats() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
adaptation_limitations_.set_cpu_counts(VideoAdaptationCounters());
adaptation_limitations_.set_quality_counts(VideoAdaptationCounters());
UpdateAdaptationStats();
@@ -1101,7 +1101,7 @@
void SendStatisticsProxy::UpdateAdaptationSettings(
VideoStreamEncoderObserver::AdaptationSettings cpu_settings,
VideoStreamEncoderObserver::AdaptationSettings quality_settings) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
adaptation_limitations_.UpdateMaskingSettings(cpu_settings, quality_settings);
SetAdaptTimer(adaptation_limitations_.MaskedCpuCounts(),
&uma_container_->cpu_adapt_timer_);
@@ -1114,7 +1114,7 @@
VideoAdaptationReason reason,
const VideoAdaptationCounters& cpu_counters,
const VideoAdaptationCounters& quality_counters) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
MaskedAdaptationCounts receiver =
adaptation_limitations_.MaskedQualityCounts();
@@ -1208,7 +1208,7 @@
spatial_layers[i] = (allocation.GetSpatialLayerSum(i) > 0);
}
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
bw_limited_layers_ = allocation.is_bw_limited();
UpdateAdaptationStats();
@@ -1231,14 +1231,14 @@
// resolution or not. |is_scaled| is a flag indicating if the video is scaled
// down.
void SendStatisticsProxy::OnEncoderInternalScalerUpdate(bool is_scaled) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
internal_encoder_scaler_ = is_scaled;
UpdateAdaptationStats();
}
// TODO(asapersson): Include fps changes.
void SendStatisticsProxy::OnInitialQualityResolutionAdaptDown() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
++uma_container_->initial_quality_changes_.down;
}
@@ -1274,7 +1274,7 @@
void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
uint32_t ssrc,
const RtcpPacketTypeCounter& packet_counter) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1286,7 +1286,7 @@
void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
uint32_t ssrc) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1297,7 +1297,7 @@
void SendStatisticsProxy::OnReportBlockDataUpdated(
ReportBlockData report_block_data) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats =
GetStatsEntry(report_block_data.report_block().source_ssrc);
if (!stats)
@@ -1308,7 +1308,7 @@
void SendStatisticsProxy::DataCountersUpdated(
const StreamDataCounters& counters,
uint32_t ssrc) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc " << ssrc;
@@ -1350,7 +1350,7 @@
void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps,
uint32_t retransmit_bitrate_bps,
uint32_t ssrc) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1361,7 +1361,7 @@
void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts,
uint32_t ssrc) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
@@ -1373,7 +1373,7 @@
int max_delay_ms,
uint64_t total_delay_ms,
uint32_t ssrc) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (!stats)
return;
diff --git a/video/send_statistics_proxy.h b/video/send_statistics_proxy.h
index 0de7df2..ff3b786 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 @@
};
typedef std::map<uint32_t, Frame, TimestampOlderThan> EncodedFrameMap;
- void PurgeOldStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ void PurgeOldStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
struct MaskedAdaptationCounts {
absl::optional<int> resolution_adaptations = absl::nullopt;
@@ -257,52 +257,52 @@
};
void SetAdaptTimer(const MaskedAdaptationCounts& counts, StatsTimer* timer)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- void UpdateAdaptationStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void UpdateAdaptationStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void TryUpdateInitialQualityResolutionAdaptUp(
absl::optional<int> old_quality_downscales,
absl::optional<int> updated_quality_downscales)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void UpdateEncoderFallbackStats(const CodecSpecificInfo* codec_info,
int pixels,
int simulcast_index)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void UpdateFallbackDisabledStats(const CodecSpecificInfo* codec_info,
int pixels,
int simulcast_index)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
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_;
- mutable Mutex mutex_;
- VideoEncoderConfig::ContentType content_type_ RTC_GUARDED_BY(mutex_);
+ rtc::CriticalSection crit_;
+ VideoEncoderConfig::ContentType content_type_ RTC_GUARDED_BY(crit_);
const int64_t start_ms_;
- 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_);
+ 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_);
QualityLimitationReasonTracker quality_limitation_reason_tracker_
- RTC_GUARDED_BY(mutex_);
- rtc::RateTracker media_byte_rate_tracker_ RTC_GUARDED_BY(mutex_);
- rtc::RateTracker encoded_frame_rate_tracker_ RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
+ rtc::RateTracker media_byte_rate_tracker_ RTC_GUARDED_BY(crit_);
+ rtc::RateTracker encoded_frame_rate_tracker_ RTC_GUARDED_BY(crit_);
std::map<uint32_t, std::unique_ptr<rtc::RateTracker>>
- encoded_frame_rate_trackers_ RTC_GUARDED_BY(mutex_);
+ encoded_frame_rate_trackers_ RTC_GUARDED_BY(crit_);
- absl::optional<int64_t> last_outlier_timestamp_ RTC_GUARDED_BY(mutex_);
+ absl::optional<int64_t> last_outlier_timestamp_ RTC_GUARDED_BY(crit_);
- int last_num_spatial_layers_ RTC_GUARDED_BY(mutex_);
- int last_num_simulcast_streams_ RTC_GUARDED_BY(mutex_);
+ int last_num_spatial_layers_ RTC_GUARDED_BY(crit_);
+ int last_num_simulcast_streams_ RTC_GUARDED_BY(crit_);
std::array<bool, kMaxSpatialLayers> last_spatial_layer_use_
- RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
// Indicates if the latest bitrate allocation had layers disabled by low
// available bandwidth.
- bool bw_limited_layers_ RTC_GUARDED_BY(mutex_);
+ bool bw_limited_layers_ RTC_GUARDED_BY(crit_);
// Indicastes if the encoder internally downscales input image.
- bool internal_encoder_scaler_ RTC_GUARDED_BY(mutex_);
- Adaptations adaptation_limitations_ RTC_GUARDED_BY(mutex_);
+ bool internal_encoder_scaler_ RTC_GUARDED_BY(crit_);
+ Adaptations adaptation_limitations_ RTC_GUARDED_BY(crit_);
struct EncoderChangeEvent {
std::string previous_encoder_implementation;
@@ -374,7 +374,7 @@
qp_counters_; // QP counters mapped by spatial idx.
};
- std::unique_ptr<UmaSamplesContainer> uma_container_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<UmaSamplesContainer> uma_container_ RTC_GUARDED_BY(crit_);
};
} // namespace webrtc
diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc
index ecdf94b..f4a1c96 100644
--- a/video/video_analyzer.cc
+++ b/video/video_analyzer.cc
@@ -151,7 +151,7 @@
VideoAnalyzer::~VideoAnalyzer() {
{
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
quit_ = true;
}
for (rtc::PlatformThread* thread : comparison_thread_pool_) {
@@ -174,25 +174,25 @@
}
void VideoAnalyzer::SetCall(Call* call) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_DCHECK(!call_);
call_ = call;
}
void VideoAnalyzer::SetSendStream(VideoSendStream* stream) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_DCHECK(!send_stream_);
send_stream_ = stream;
}
void VideoAnalyzer::SetReceiveStream(VideoReceiveStream* stream) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_DCHECK(!receive_stream_);
receive_stream_ = stream;
}
void VideoAnalyzer::SetAudioReceiveStream(AudioReceiveStream* recv_stream) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_CHECK(!audio_receive_stream_);
audio_receive_stream_ = recv_stream;
}
@@ -234,7 +234,7 @@
// (FlexFEC and media are sent on different SSRCs, which have different
// timestamps spaces.)
// Also ignore packets from wrong SSRC, but include retransmits.
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
int64_t timestamp =
wrap_handler_.Unwrap(rtp_packet.Timestamp() - rtp_timestamp_delta_);
recv_times_[timestamp] = clock_->CurrentNtpInMilliseconds();
@@ -245,7 +245,7 @@
}
void VideoAnalyzer::PreEncodeOnFrame(const VideoFrame& video_frame) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (!first_encoded_timestamp_) {
while (frames_.front().timestamp() != video_frame.timestamp()) {
++dropped_frames_before_first_encode_;
@@ -257,7 +257,7 @@
}
void VideoAnalyzer::PostEncodeOnFrame(size_t stream_id, uint32_t timestamp) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (!first_sent_timestamp_ && stream_id == selected_stream_) {
first_sent_timestamp_ = timestamp;
}
@@ -273,7 +273,7 @@
bool result = transport_->SendRtp(packet, length, options);
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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 @@
void VideoAnalyzer::OnFrame(const VideoFrame& video_frame) {
int64_t render_time_ms = clock_->CurrentNtpInMilliseconds();
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
StartExcludingCpuThreadTime();
@@ -361,7 +361,7 @@
int frames_processed;
int frames_captured;
{
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
frames_processed = frames_processed_;
frames_captured = captured_frames_;
}
@@ -401,29 +401,29 @@
}
void VideoAnalyzer::StartMeasuringCpuProcessTime() {
- MutexLock lock(&cpu_measurement_lock_);
+ rtc::CritScope lock(&cpu_measurement_lock_);
cpu_time_ -= rtc::GetProcessCpuTimeNanos();
wallclock_time_ -= rtc::SystemTimeNanos();
}
void VideoAnalyzer::StopMeasuringCpuProcessTime() {
- MutexLock lock(&cpu_measurement_lock_);
+ rtc::CritScope lock(&cpu_measurement_lock_);
cpu_time_ += rtc::GetProcessCpuTimeNanos();
wallclock_time_ += rtc::SystemTimeNanos();
}
void VideoAnalyzer::StartExcludingCpuThreadTime() {
- MutexLock lock(&cpu_measurement_lock_);
+ rtc::CritScope lock(&cpu_measurement_lock_);
cpu_time_ += rtc::GetThreadCpuTimeNanos();
}
void VideoAnalyzer::StopExcludingCpuThreadTime() {
- MutexLock lock(&cpu_measurement_lock_);
+ rtc::CritScope lock(&cpu_measurement_lock_);
cpu_time_ -= rtc::GetThreadCpuTimeNanos();
}
double VideoAnalyzer::GetCpuUsagePercent() {
- MutexLock lock(&cpu_measurement_lock_);
+ rtc::CritScope lock(&cpu_measurement_lock_);
return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
}
@@ -456,7 +456,7 @@
}
void VideoAnalyzer::PollStats() {
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
Call::Stats call_stats = call_->GetStats();
send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps);
@@ -564,7 +564,7 @@
}
bool VideoAnalyzer::PopComparison(VideoAnalyzer::FrameComparison* comparison) {
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&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 @@
}
void VideoAnalyzer::FrameRecorded() {
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
++frames_recorded_;
}
bool VideoAnalyzer::AllFramesRecorded() {
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&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() {
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
++frames_processed_;
assert(frames_processed_ <= frames_to_process_);
return frames_processed_ == frames_to_process_ ||
@@ -606,11 +606,11 @@
StopMeasuringCpuProcessTime();
int dropped_frames_diff;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope crit(&crit_);
dropped_frames_diff = dropped_frames_before_first_encode_ +
dropped_frames_before_rendering_ + frames_.size();
}
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
PrintResult("psnr", psnr_, "dB", ImproveDirection::kBiggerIsBetter);
PrintResult("ssim", ssim_, "unitless", ImproveDirection::kBiggerIsBetter);
PrintResult("sender_time", sender_time_, "ms",
@@ -753,7 +753,7 @@
ssim = I420SSIM(&*comparison.reference, &*comparison.render);
}
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&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::PrintSamplesToFile() {
FILE* out = graph_data_output_file_;
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&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 @@
const VideoFrame& video_frame) {
bool must_capture = false;
{
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope lock(&comparison_lock_);
must_capture = captured_frames_ < frames_to_process_;
if (must_capture) {
++captured_frames_;
}
}
if (must_capture) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
frames_.push_back(video_frame);
}
}
@@ -903,7 +903,7 @@
if (it != encoded_frame_sizes_.end())
encoded_frame_sizes_.erase(it);
- MutexLock lock(&comparison_lock_);
+ rtc::CritScope crit(&comparison_lock_);
if (comparisons_.size() < kMaxComparisons) {
comparisons_.push_back(FrameComparison(
reference, render, dropped, reference.ntp_time_ms(), send_time_ms,
@@ -999,7 +999,7 @@
copy.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
copy.set_timestamp(copy.ntp_time_ms() * 90);
analyzer_->AddCapturedFrameForComparison(copy);
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
++captured_frames_;
if (send_stream_input_ && clock_->CurrentTime() <= test_end_ &&
captured_frames_ <= frames_to_capture_) {
@@ -1011,7 +1011,7 @@
rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants) {
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
send_stream_input_ = sink;
}
@@ -1022,7 +1022,7 @@
void VideoAnalyzer::CapturedFrameForwarder::RemoveSink(
rtc::VideoSinkInterface<VideoFrame>* sink) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RTC_DCHECK(sink == send_stream_input_);
send_stream_input_ = nullptr;
}
diff --git a/video/video_analyzer.h b/video/video_analyzer.h
index 190321f..14f77ac 100644
--- a/video/video_analyzer.h
+++ b/video/video_analyzer.h
@@ -23,7 +23,6 @@
#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"
@@ -164,12 +163,12 @@
void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
VideoAnalyzer* const analyzer_;
- Mutex mutex_;
+ rtc::CriticalSection crit_;
rtc::VideoSinkInterface<VideoFrame>* send_stream_input_
- RTC_GUARDED_BY(mutex_);
+ RTC_GUARDED_BY(crit_);
VideoSourceInterface<VideoFrame>* video_source_;
Clock* clock_;
- int captured_frames_ RTC_GUARDED_BY(mutex_);
+ int captured_frames_ RTC_GUARDED_BY(crit_);
const int frames_to_capture_;
const Timestamp test_end_;
};
@@ -185,7 +184,7 @@
const VideoFrame& render,
bool dropped,
int64_t render_time_ms)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
void PollStats();
static void FrameComparisonThread(void* obj);
@@ -227,7 +226,7 @@
const int selected_sl_;
const int selected_tl_;
- Mutex comparison_lock_;
+ rtc::CriticalSection 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_);
@@ -265,32 +264,32 @@
size_t last_fec_bytes_;
- Mutex mutex_;
+ rtc::CriticalSection crit_;
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(mutex_);
- int dropped_frames_before_rendering_ RTC_GUARDED_BY(mutex_);
+ int dropped_frames_before_first_encode_ RTC_GUARDED_BY(crit_);
+ int dropped_frames_before_rendering_ RTC_GUARDED_BY(crit_);
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(mutex_);
+ uint32_t rtp_timestamp_delta_ RTC_GUARDED_BY(crit_);
- Mutex cpu_measurement_lock_;
+ rtc::CriticalSection 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(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_);
+ 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_);
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 b4c6ddf..f1b3fc7 100644
--- a/video/video_receive_stream.cc
+++ b/video/video_receive_stream.cc
@@ -494,7 +494,7 @@
return false;
}
- MutexLock lock(&playout_delay_lock_);
+ rtc::CritScope cs(&playout_delay_lock_);
base_minimum_playout_delay_ms_ = delay_ms;
UpdatePlayoutDelays();
return true;
@@ -503,7 +503,7 @@
int VideoReceiveStream::GetBaseMinimumPlayoutDelayMs() const {
RTC_DCHECK_RUN_ON(&worker_sequence_checker_);
- MutexLock lock(&playout_delay_lock_);
+ rtc::CritScope cs(&playout_delay_lock_);
return base_minimum_playout_delay_ms_;
}
@@ -566,13 +566,13 @@
const PlayoutDelay& playout_delay = frame->EncodedImage().playout_delay_;
if (playout_delay.min_ms >= 0) {
- MutexLock lock(&playout_delay_lock_);
+ rtc::CritScope cs(&playout_delay_lock_);
frame_minimum_playout_delay_ms_ = playout_delay.min_ms;
UpdatePlayoutDelays();
}
if (playout_delay.max_ms >= 0) {
- MutexLock lock(&playout_delay_lock_);
+ rtc::CritScope cs(&playout_delay_lock_);
frame_maximum_playout_delay_ms_ = playout_delay.max_ms;
UpdatePlayoutDelays();
}
@@ -619,7 +619,7 @@
void VideoReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
RTC_DCHECK_RUN_ON(&module_process_sequence_checker_);
- MutexLock lock(&playout_delay_lock_);
+ rtc::CritScope cs(&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 57329f4..8a5136a 100644
--- a/video/video_receive_stream.h
+++ b/video/video_receive_stream.h
@@ -23,7 +23,6 @@
#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"
@@ -206,7 +205,7 @@
const int max_wait_for_keyframe_ms_;
const int max_wait_for_frame_ms_;
- mutable Mutex playout_delay_lock_;
+ rtc::CriticalSection 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 834fed4..8f30b63 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 @@
RtpTransportControllerSendInterface* const transport_;
BitrateAllocatorInterface* const bitrate_allocator_;
- Mutex ivf_writers_mutex_;
+ rtc::CriticalSection ivf_writers_crit_;
bool disable_padding_;
int max_padding_bitrate_;
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc
index efbcef7..09d7abc 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 @@
fec_packet_received_ = false;
++current_size_rtp_;
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&mutex_);
++current_size_frame_;
}
}
@@ -1182,7 +1182,7 @@
}
void UpdateConfiguration() {
- MutexLock lock(&mutex_);
+ rtc::CritScope 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 @@
bool fec_packet_received_;
size_t current_size_rtp_;
- Mutex mutex_;
+ rtc::CriticalSection mutex_;
int current_size_frame_ RTC_GUARDED_BY(mutex_);
};
@@ -1296,7 +1296,7 @@
: remb_observer_(remb_observer) {}
void OnFrame(const VideoFrame&) {
- MutexLock lock(&remb_observer_->mutex_);
+ rtc::CritScope lock(&remb_observer_->crit_);
if (remb_observer_->test_state_ == kDuringSuspend &&
++remb_observer_->suspended_frame_count_ > kSuspendTimeFrames) {
VideoSendStream::Stats stats = remb_observer_->stream_->GetStats();
@@ -1324,7 +1324,7 @@
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
++rtp_count_;
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@@ -1361,12 +1361,12 @@
}
void set_low_remb_bps(int value) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
low_remb_bps_ = value;
}
void set_high_remb_bps(int value) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
high_remb_bps_ = value;
}
@@ -1413,7 +1413,7 @@
};
virtual void SendRtcpFeedback(int remb_value)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
FakeReceiveStatistics receive_stats(kVideoSendSsrcs[0],
last_sequence_number_, rtp_count_, 0);
RtpRtcpInterface::Configuration config;
@@ -1438,13 +1438,13 @@
CaptureObserver capture_observer_;
VideoSendStream* stream_;
- 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_);
+ 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_);
} test;
RunBaseTest(&test);
@@ -1462,7 +1462,7 @@
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
last_packet_time_ms_ = clock_->TimeInMilliseconds();
RtpPacket rtp_packet;
@@ -1490,7 +1490,7 @@
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
const int kNoPacketsThresholdMs = 2000;
if (test_state_ == kWaitingForNoPackets &&
(last_packet_time_ms_ &&
@@ -1513,7 +1513,7 @@
void OnFrameGeneratorCapturerCreated(
test::FrameGeneratorCapturer* frame_generator_capturer) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
capturer_ = frame_generator_capturer;
}
@@ -1532,9 +1532,9 @@
TestState test_state_ = kBeforeStopCapture;
Clock* const clock_;
- Mutex mutex_;
- absl::optional<int64_t> last_packet_time_ms_ RTC_GUARDED_BY(mutex_);
- test::FrameGeneratorCapturer* capturer_ RTC_GUARDED_BY(mutex_);
+ rtc::CriticalSection crit_;
+ absl::optional<int64_t> last_packet_time_ms_ RTC_GUARDED_BY(crit_);
+ test::FrameGeneratorCapturer* capturer_ RTC_GUARDED_BY(crit_);
} test;
RunBaseTest(&test);
@@ -1557,7 +1557,7 @@
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RtpPacket rtp_packet;
rtp_packet.Parse(packet, length);
@@ -1597,16 +1597,16 @@
// rid of this.
SleepMs(5000);
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
// Expect padding to be a small percentage of total bytes sent.
EXPECT_LT(padding_length_, .1 * total_length_);
}
}
- Mutex mutex_;
+ rtc::CriticalSection crit_;
Clock* const clock_;
- size_t padding_length_ RTC_GUARDED_BY(mutex_);
- size_t total_length_ RTC_GUARDED_BY(mutex_);
+ size_t padding_length_ RTC_GUARDED_BY(crit_);
+ size_t total_length_ RTC_GUARDED_BY(crit_);
Call* call_;
} test;
@@ -1946,7 +1946,7 @@
Action OnSendRtp(const uint8_t* packet, size_t length) override {
EXPECT_LE(length, kMaxRtpPacketSize);
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
if (++packets_sent_ < 100)
return SEND_PACKET;
observation_complete_.Set();
@@ -1970,7 +1970,7 @@
EXPECT_TRUE(Wait());
{
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
packets_sent_ = 0;
}
@@ -1986,7 +1986,7 @@
private:
TaskQueueBase* const task_queue_;
Call* call_;
- Mutex lock_;
+ rtc::CriticalSection lock_;
int packets_sent_ RTC_GUARDED_BY(lock_);
int transport_overhead_;
const size_t kMaxRtpPacketSize = 1000;
@@ -2162,7 +2162,7 @@
void WaitForResolution(int width, int height) {
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (last_initialized_frame_width_ == width &&
last_initialized_frame_height_ == height) {
return;
@@ -2171,7 +2171,7 @@
EXPECT_TRUE(
init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
EXPECT_EQ(width, last_initialized_frame_width_);
EXPECT_EQ(height, last_initialized_frame_height_);
}
@@ -2180,7 +2180,7 @@
private:
int32_t InitEncode(const VideoCodec* config,
const Settings& settings) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
last_initialized_frame_width_ = config->width;
last_initialized_frame_height_ = config->height;
++number_of_initializations_;
@@ -2195,11 +2195,11 @@
return 0;
}
- Mutex mutex_;
+ rtc::CriticalSection crit_;
rtc::Event init_encode_called_;
- 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_);
+ 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_);
};
test::NullTransport transport;
@@ -2238,21 +2238,21 @@
: FakeEncoder(Clock::GetRealTimeClock()), start_bitrate_kbps_(0) {}
int32_t InitEncode(const VideoCodec* config,
const Settings& settings) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
start_bitrate_kbps_ = config->startBitrate;
start_bitrate_changed_.Set();
return FakeEncoder::InitEncode(config, settings);
}
void SetRates(const RateControlParameters& parameters) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
start_bitrate_kbps_ = parameters.bitrate.get_sum_kbps();
start_bitrate_changed_.Set();
FakeEncoder::SetRates(parameters);
}
int GetStartBitrateKbps() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return start_bitrate_kbps_;
}
@@ -2262,9 +2262,9 @@
}
private:
- mutable Mutex mutex_;
+ rtc::CriticalSection crit_;
rtc::Event start_bitrate_changed_;
- int start_bitrate_kbps_ RTC_GUARDED_BY(mutex_);
+ int start_bitrate_kbps_ RTC_GUARDED_BY(crit_);
};
CreateSenderCall();
@@ -2311,13 +2311,13 @@
StartStopBitrateObserver() : FakeEncoder(Clock::GetRealTimeClock()) {}
int32_t InitEncode(const VideoCodec* config,
const Settings& settings) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
encoder_init_.Set();
return FakeEncoder::InitEncode(config, settings);
}
void SetRates(const RateControlParameters& parameters) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
bitrate_kbps_ = parameters.bitrate.get_sum_kbps();
bitrate_changed_.Set();
FakeEncoder::SetRates(parameters);
@@ -2331,7 +2331,7 @@
do {
absl::optional<int> bitrate_kbps;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
bitrate_kbps = bitrate_kbps_;
}
if (!bitrate_kbps)
@@ -2346,10 +2346,10 @@
}
private:
- Mutex mutex_;
+ rtc::CriticalSection crit_;
rtc::Event encoder_init_;
rtc::Event bitrate_changed_;
- absl::optional<int> bitrate_kbps_ RTC_GUARDED_BY(mutex_);
+ absl::optional<int> bitrate_kbps_ RTC_GUARDED_BY(crit_);
};
// This test that if the encoder use an internal source, VideoEncoder::SetRates
@@ -2483,23 +2483,23 @@
released_(false),
encoder_factory_(this) {}
- bool IsReleased() RTC_LOCKS_EXCLUDED(mutex_) {
- MutexLock lock(&mutex_);
+ bool IsReleased() RTC_LOCKS_EXCLUDED(crit_) {
+ rtc::CritScope lock(&crit_);
return released_;
}
- bool IsReadyForEncode() RTC_LOCKS_EXCLUDED(mutex_) {
- MutexLock lock(&mutex_);
+ bool IsReadyForEncode() RTC_LOCKS_EXCLUDED(crit_) {
+ rtc::CritScope lock(&crit_);
return IsReadyForEncodeLocked();
}
- size_t num_releases() RTC_LOCKS_EXCLUDED(mutex_) {
- MutexLock lock(&mutex_);
+ size_t num_releases() RTC_LOCKS_EXCLUDED(crit_) {
+ rtc::CritScope lock(&crit_);
return num_releases_;
}
private:
- bool IsReadyForEncodeLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
+ bool IsReadyForEncodeLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
return initialized_ && callback_registered_;
}
@@ -2510,8 +2510,8 @@
int32_t InitEncode(const VideoCodec* codecSettings,
const Settings& settings) override
- RTC_LOCKS_EXCLUDED(mutex_) {
- MutexLock lock(&mutex_);
+ RTC_LOCKS_EXCLUDED(crit_) {
+ rtc::CritScope lock(&crit_);
EXPECT_FALSE(initialized_);
initialized_ = true;
released_ = false;
@@ -2527,15 +2527,15 @@
}
int32_t RegisterEncodeCompleteCallback(
- EncodedImageCallback* callback) override RTC_LOCKS_EXCLUDED(mutex_) {
- MutexLock lock(&mutex_);
+ EncodedImageCallback* callback) override RTC_LOCKS_EXCLUDED(crit_) {
+ rtc::CritScope lock(&crit_);
EXPECT_TRUE(initialized_);
callback_registered_ = true;
return 0;
}
- int32_t Release() override RTC_LOCKS_EXCLUDED(mutex_) {
- MutexLock lock(&mutex_);
+ int32_t Release() override RTC_LOCKS_EXCLUDED(crit_) {
+ rtc::CritScope lock(&crit_);
EXPECT_TRUE(IsReadyForEncodeLocked());
EXPECT_FALSE(released_);
initialized_ = false;
@@ -2582,12 +2582,12 @@
}
TaskQueueBase* const task_queue_;
- Mutex mutex_;
+ rtc::CriticalSection crit_;
VideoSendStream* stream_;
- 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_);
+ 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_);
test::VideoEncoderProxyFactory encoder_factory_;
VideoEncoderConfig encoder_config_;
} test_encoder(task_queue());
@@ -2817,7 +2817,7 @@
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
++rtp_packets_sent_;
@@ -2826,7 +2826,7 @@
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
@@ -2850,9 +2850,9 @@
EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP sender report.";
}
- Mutex mutex_;
- size_t rtp_packets_sent_ RTC_GUARDED_BY(&mutex_);
- size_t media_bytes_sent_ RTC_GUARDED_BY(&mutex_);
+ rtc::CriticalSection crit_;
+ size_t rtp_packets_sent_ RTC_GUARDED_BY(&crit_);
+ size_t media_bytes_sent_ RTC_GUARDED_BY(&crit_);
} test;
RunBaseTest(&test);
@@ -3006,7 +3006,7 @@
void SetRates(const RateControlParameters& parameters) override {
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (target_bitrate_ == parameters.bitrate.get_sum_kbps()) {
FakeEncoder::SetRates(parameters);
return;
@@ -3023,14 +3023,14 @@
// until the correct value has been observed.
const int64_t start_time = rtc::TimeMillis();
do {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (target_bitrate_ == expected_bitrate) {
return;
}
} while (bitrate_changed_event_.Wait(
std::max(int64_t{1}, VideoSendStreamTest::kDefaultTimeoutMs -
(rtc::TimeMillis() - start_time))));
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
EXPECT_EQ(target_bitrate_, expected_bitrate)
<< "Timed out while waiting encoder rate to be set.";
}
@@ -3111,8 +3111,8 @@
rtc::Event create_rate_allocator_event_;
rtc::Event init_encode_event_;
rtc::Event bitrate_changed_event_;
- Mutex mutex_;
- uint32_t target_bitrate_ RTC_GUARDED_BY(&mutex_);
+ rtc::CriticalSection crit_;
+ uint32_t target_bitrate_ RTC_GUARDED_BY(&crit_);
int num_rate_allocator_creations_;
int num_encoder_initializations_;
@@ -3160,7 +3160,7 @@
encoded.SetSpatialIndex(i);
EncodedImageCallback* callback;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_sect_);
callback = callback_;
}
RTC_DCHECK(callback);
@@ -3263,7 +3263,7 @@
bool wait = Wait();
{
// In case of time out, OnSendRtp might still access frames_sent_;
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
EXPECT_TRUE(wait) << "Test timed out waiting for VP9 packet, num frames "
<< frames_sent_;
}
@@ -3295,7 +3295,7 @@
++packets_sent_;
if (rtp_packet.Marker()) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
++frames_sent_;
}
last_packet_marker_ = rtp_packet.Marker();
@@ -3522,7 +3522,7 @@
uint32_t last_packet_timestamp_ = 0;
RTPVideoHeaderVP9 last_vp9_;
size_t packets_sent_;
- Mutex mutex_;
+ rtc::CriticalSection crit_;
size_t frames_sent_;
int expected_width_;
int expected_height_;
@@ -3813,7 +3813,7 @@
first_packet_sent_(false) {}
void SetRates(const RateControlParameters& parameters) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
// Wait for the first sent packet so that videosendstream knows
// rtp_overhead.
if (first_packet_sent_) {
@@ -3837,7 +3837,7 @@
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
first_packet_sent_ = true;
return SEND_PACKET;
}
@@ -3862,7 +3862,7 @@
EXPECT_TRUE(
bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
EXPECT_LE(max_bitrate_bps_, 57760u);
}
}
@@ -3871,9 +3871,9 @@
TaskQueueBase* const task_queue_;
test::VideoEncoderProxyFactory encoder_factory_;
Call* call_;
- Mutex mutex_;
- uint32_t max_bitrate_bps_ RTC_GUARDED_BY(&mutex_);
- bool first_packet_sent_ RTC_GUARDED_BY(&mutex_);
+ rtc::CriticalSection crit_;
+ uint32_t max_bitrate_bps_ RTC_GUARDED_BY(&crit_);
+ bool first_packet_sent_ RTC_GUARDED_BY(&crit_);
rtc::Event bitrate_changed_event_;
} test(task_queue());
RunBaseTest(&test);
@@ -3992,7 +3992,7 @@
void OnVideoStreamsCreated(
VideoSendStream* send_stream,
const std::vector<VideoReceiveStream*>& receive_streams) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
send_stream_ = send_stream;
}
@@ -4013,7 +4013,7 @@
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
auto internal_send_peer = test::VideoSendStreamPeer(send_stream_);
float pacing_factor =
@@ -4075,18 +4075,18 @@
private:
StreamState GetStreamState() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return state_;
}
- Mutex mutex_;
+ rtc::CriticalSection crit_;
rtc::Event content_switch_event_;
Call* call_;
- StreamState state_ RTC_GUARDED_BY(mutex_);
- VideoSendStream* send_stream_ RTC_GUARDED_BY(mutex_);
+ StreamState state_ RTC_GUARDED_BY(crit_);
+ VideoSendStream* send_stream_ RTC_GUARDED_BY(crit_);
VideoSendStream::Config send_stream_config_;
VideoEncoderConfig encoder_config_;
- uint32_t packets_sent_ RTC_GUARDED_BY(mutex_);
+ uint32_t packets_sent_ RTC_GUARDED_BY(crit_);
T* stream_resetter_;
};
diff --git a/video/video_source_sink_controller.cc b/video/video_source_sink_controller.cc
index a5c0941..7c24ead 100644
--- a/video/video_source_sink_controller.cc
+++ b/video/video_source_sink_controller.cc
@@ -48,7 +48,7 @@
rtc::VideoSourceInterface<VideoFrame>* old_source;
rtc::VideoSinkWants wants;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
old_source = source_;
source_ = source;
wants = CurrentSettingsToSinkWants();
@@ -61,7 +61,7 @@
}
void VideoSourceSinkController::PushSourceSinkSettings() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
if (!source_)
return;
rtc::VideoSinkWants wants = CurrentSettingsToSinkWants();
@@ -70,62 +70,62 @@
}
VideoSourceRestrictions VideoSourceSinkController::restrictions() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return restrictions_;
}
absl::optional<size_t> VideoSourceSinkController::pixels_per_frame_upper_limit()
const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return pixels_per_frame_upper_limit_;
}
absl::optional<double> VideoSourceSinkController::frame_rate_upper_limit()
const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return frame_rate_upper_limit_;
}
bool VideoSourceSinkController::rotation_applied() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return rotation_applied_;
}
int VideoSourceSinkController::resolution_alignment() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return resolution_alignment_;
}
void VideoSourceSinkController::SetRestrictions(
VideoSourceRestrictions restrictions) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
restrictions_ = std::move(restrictions);
}
void VideoSourceSinkController::SetPixelsPerFrameUpperLimit(
absl::optional<size_t> pixels_per_frame_upper_limit) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
pixels_per_frame_upper_limit_ = std::move(pixels_per_frame_upper_limit);
}
void VideoSourceSinkController::SetFrameRateUpperLimit(
absl::optional<double> frame_rate_upper_limit) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
frame_rate_upper_limit_ = std::move(frame_rate_upper_limit);
}
void VideoSourceSinkController::SetRotationApplied(bool rotation_applied) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
rotation_applied_ = rotation_applied;
}
void VideoSourceSinkController::SetResolutionAlignment(
int resolution_alignment) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
resolution_alignment_ = resolution_alignment;
}
-// RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_)
+// RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_)
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 877cf85..665493a 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/synchronization/mutex.h"
+#include "rtc_base/critical_section.h"
namespace webrtc {
@@ -53,20 +53,20 @@
private:
rtc::VideoSinkWants CurrentSettingsToSinkWants() const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
- mutable Mutex mutex_;
+ mutable rtc::CriticalSection crit_;
rtc::VideoSinkInterface<VideoFrame>* const sink_;
- rtc::VideoSourceInterface<VideoFrame>* source_ RTC_GUARDED_BY(&mutex_);
+ rtc::VideoSourceInterface<VideoFrame>* source_ RTC_GUARDED_BY(&crit_);
// Pixel and frame rate restrictions.
- VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&mutex_);
+ VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&crit_);
// 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(&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;
+ 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;
};
} // namespace webrtc
diff --git a/video/video_stream_decoder.h b/video/video_stream_decoder.h
index bfe9252..6b040c6 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 @@
private:
// Used for all registered callbacks except rendering.
- Mutex mutex_;
+ rtc::CriticalSection crit_;
VideoReceiver2* const video_receiver_;
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 84b5aa3..2e9f5da 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -39,7 +39,6 @@
#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"
@@ -221,18 +220,18 @@
}
DegradationPreference degradation_preference() const override {
- MutexLock lock(&lock_);
+ rtc::CritScope crit(&lock_);
return effective_degradation_preference_;
}
void SetDegradationPreference(DegradationPreference degradation_preference) {
- MutexLock lock(&lock_);
+ rtc::CritScope crit(&lock_);
degradation_preference_ = degradation_preference;
MaybeUpdateEffectiveDegradationPreference();
}
void SetIsScreenshare(bool is_screenshare) {
- MutexLock lock(&lock_);
+ rtc::CritScope crit(&lock_);
is_screenshare_ = is_screenshare;
MaybeUpdateEffectiveDegradationPreference();
}
@@ -274,7 +273,7 @@
}
}
- mutable Mutex lock_;
+ rtc::CriticalSection 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 6bdcbd0..138c475 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -39,7 +39,6 @@
#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"
@@ -140,14 +139,14 @@
virtual ~CpuOveruseDetectorProxy() {}
void OnTargetFramerateUpdated(int framerate_fps) override {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
last_target_framerate_fps_ = framerate_fps;
OveruseFrameDetector::OnTargetFramerateUpdated(framerate_fps);
framerate_updated_event_.Set();
}
int GetLastTargetFramerate() {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
return last_target_framerate_fps_;
}
@@ -156,7 +155,7 @@
rtc::Event* framerate_updated_event() { return &framerate_updated_event_; }
private:
- Mutex lock_;
+ rtc::CriticalSection lock_;
int last_target_framerate_fps_ RTC_GUARDED_BY(lock_);
rtc::Event framerate_updated_event_;
};
@@ -500,17 +499,17 @@
~AdaptingFrameForwarder() override {}
void set_adaptation_enabled(bool enabled) {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_);
adaptation_enabled_ = enabled;
}
bool adaption_enabled() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_);
return adaptation_enabled_;
}
rtc::VideoSinkWants last_wants() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_);
return last_wants_;
}
@@ -559,14 +558,14 @@
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
const rtc::VideoSinkWants& wants) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope cs(&crit_);
last_wants_ = sink_wants_locked();
adapter_.OnSinkWants(wants);
test::FrameForwarder::AddOrUpdateSinkLocked(sink, wants);
}
cricket::VideoAdapter adapter_;
- bool adaptation_enabled_ RTC_GUARDED_BY(mutex_);
- rtc::VideoSinkWants last_wants_ RTC_GUARDED_BY(mutex_);
+ bool adaptation_enabled_ RTC_GUARDED_BY(crit_);
+ rtc::VideoSinkWants last_wants_ RTC_GUARDED_BY(crit_);
absl::optional<int> last_width_;
absl::optional<int> last_height_;
};
@@ -580,30 +579,30 @@
: SendStatisticsProxy(clock, config, content_type) {}
VideoSendStream::Stats GetStats() override {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
if (mock_stats_)
return *mock_stats_;
return SendStatisticsProxy::GetStats();
}
int GetInputFrameRate() const override {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
if (mock_stats_)
return mock_stats_->input_frame_rate;
return SendStatisticsProxy::GetInputFrameRate();
}
void SetMockStats(const VideoSendStream::Stats& stats) {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
mock_stats_.emplace(stats);
}
void ResetMockStats() {
- MutexLock lock(&lock_);
+ rtc::CritScope cs(&lock_);
mock_stats_.reset();
}
private:
- mutable Mutex lock_;
+ rtc::CriticalSection lock_;
absl::optional<VideoSendStream::Stats> mock_stats_ RTC_GUARDED_BY(lock_);
};
@@ -831,17 +830,17 @@
TestEncoder() : FakeEncoder(Clock::GetRealTimeClock()) {}
VideoCodec codec_config() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_sect_);
return config_;
}
void BlockNextEncode() {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
block_next_encode_ = true;
}
VideoEncoder::EncoderInfo GetEncoderInfo() const override {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
EncoderInfo info;
if (initialized_ == EncoderState::kInitialized) {
if (quality_scaling_) {
@@ -864,7 +863,7 @@
int32_t RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) override {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
encoded_image_callback_ = callback;
return FakeEncoder::RegisterEncodeCompleteCallback(callback);
}
@@ -873,60 +872,60 @@
void CheckLastTimeStampsMatch(int64_t ntp_time_ms,
uint32_t timestamp) const {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
EXPECT_EQ(timestamp_, timestamp);
EXPECT_EQ(ntp_time_ms_, ntp_time_ms);
}
void SetQualityScaling(bool b) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
quality_scaling_ = b;
}
void SetRequestedResolutionAlignment(int requested_resolution_alignment) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
requested_resolution_alignment_ = requested_resolution_alignment;
}
void SetIsHardwareAccelerated(bool is_hardware_accelerated) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
is_hardware_accelerated_ = is_hardware_accelerated;
}
void SetTemporalLayersSupported(size_t spatial_idx, bool supported) {
RTC_DCHECK_LT(spatial_idx, kMaxSpatialLayers);
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
temporal_layers_supported_[spatial_idx] = supported;
}
void SetResolutionBitrateLimits(
std::vector<ResolutionBitrateLimits> thresholds) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope cs(&local_crit_sect_);
resolution_bitrate_limits_ = thresholds;
}
void ForceInitEncodeFailure(bool force_failure) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
force_init_encode_failed_ = force_failure;
}
void SimulateOvershoot(double rate_factor) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
rate_factor_ = rate_factor;
}
uint32_t GetLastFramerate() const {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
return last_framerate_;
}
VideoFrame::UpdateRect GetLastUpdateRect() const {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
return last_update_rect_;
}
const std::vector<VideoFrameType>& LastFrameTypes() const {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
return last_frame_types_;
}
@@ -935,27 +934,27 @@
keyframe ? VideoFrameType::kVideoFrameKey
: VideoFrameType::kVideoFrameDelta};
{
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
last_frame_types_ = frame_type;
}
FakeEncoder::Encode(input_image, &frame_type);
}
void InjectEncodedImage(const EncodedImage& image) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
encoded_image_callback_->OnEncodedImage(image, nullptr, nullptr);
}
void InjectEncodedImage(const EncodedImage& image,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
encoded_image_callback_->OnEncodedImage(image, codec_specific_info,
fragmentation);
}
void ExpectNullFrame() {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
expect_null_frame_ = true;
}
@@ -967,12 +966,12 @@
}
int GetNumEncoderInitializations() const {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
return num_encoder_initializations_;
}
int GetNumSetRates() const {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
return num_set_rates_;
}
@@ -981,7 +980,7 @@
const std::vector<VideoFrameType>* frame_types) override {
bool block_encode;
{
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
if (expect_null_frame_) {
EXPECT_EQ(input_image.timestamp(), 0u);
EXPECT_EQ(input_image.width(), 1);
@@ -1012,7 +1011,7 @@
const Settings& settings) override {
int res = FakeEncoder::InitEncode(config, settings);
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
EXPECT_EQ(initialized_, EncoderState::kUninitialized);
++num_encoder_initializations_;
@@ -1034,14 +1033,14 @@
}
int32_t Release() override {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
EXPECT_NE(initialized_, EncoderState::kUninitialized);
initialized_ = EncoderState::kUninitialized;
return FakeEncoder::Release();
}
void SetRates(const RateControlParameters& parameters) {
- MutexLock lock(&local_mutex_);
+ rtc::CritScope lock(&local_crit_sect_);
num_set_rates_++;
VideoBitrateAllocation adjusted_rate_allocation;
for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
@@ -1061,42 +1060,43 @@
FakeEncoder::SetRates(adjusted_paramters);
}
- mutable Mutex local_mutex_;
+ rtc::CriticalSection local_crit_sect_;
enum class EncoderState {
kUninitialized,
kInitializationFailed,
kInitialized
- } initialized_ RTC_GUARDED_BY(local_mutex_) = EncoderState::kUninitialized;
- bool block_next_encode_ RTC_GUARDED_BY(local_mutex_) = false;
+ } initialized_ RTC_GUARDED_BY(local_crit_sect_) =
+ EncoderState::kUninitialized;
+ bool block_next_encode_ RTC_GUARDED_BY(local_crit_sect_) = false;
rtc::Event continue_encode_event_;
- 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;
+ 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;
std::unique_ptr<Vp8FrameBufferController> frame_buffer_controller_
- RTC_GUARDED_BY(local_mutex_);
+ RTC_GUARDED_BY(local_crit_sect_);
absl::optional<bool>
temporal_layers_supported_[kMaxSpatialLayers] RTC_GUARDED_BY(
- 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;
+ 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;
absl::optional<VideoEncoder::RateControlParameters>
last_rate_control_settings_;
- VideoFrame::UpdateRect last_update_rect_ RTC_GUARDED_BY(local_mutex_) = {
- 0, 0, 0, 0};
+ VideoFrame::UpdateRect last_update_rect_
+ RTC_GUARDED_BY(local_crit_sect_) = {0, 0, 0, 0};
std::vector<VideoFrameType> last_frame_types_;
bool expect_null_frame_ = false;
- EncodedImageCallback* encoded_image_callback_ RTC_GUARDED_BY(local_mutex_) =
- nullptr;
+ EncodedImageCallback* encoded_image_callback_
+ RTC_GUARDED_BY(local_crit_sect_) = nullptr;
NiceMock<MockFecControllerOverride> fec_controller_override_;
- int num_encoder_initializations_ RTC_GUARDED_BY(local_mutex_) = 0;
+ int num_encoder_initializations_ RTC_GUARDED_BY(local_crit_sect_) = 0;
std::vector<ResolutionBitrateLimits> resolution_bitrate_limits_
- RTC_GUARDED_BY(local_mutex_);
- int num_set_rates_ RTC_GUARDED_BY(local_mutex_) = 0;
+ RTC_GUARDED_BY(local_crit_sect_);
+ int num_set_rates_ RTC_GUARDED_BY(local_crit_sect_) = 0;
};
class TestSink : public VideoStreamEncoder::EncoderSink {
@@ -1115,7 +1115,7 @@
if (!encoded_frame_event_.Wait(timeout_ms))
return false;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
timestamp = last_timestamp_;
}
test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp);
@@ -1133,7 +1133,7 @@
uint32_t width = 0;
uint32_t height = 0;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
width = last_width_;
height = last_height_;
}
@@ -1145,7 +1145,7 @@
int width = 0;
int height = 0;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
width = last_width_;
height = last_height_;
}
@@ -1156,7 +1156,7 @@
void CheckLastFrameRotationMatches(VideoRotation expected_rotation) {
VideoRotation rotation;
{
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
rotation = last_rotation_;
}
EXPECT_EQ(expected_rotation, rotation);
@@ -1169,37 +1169,37 @@
}
void SetExpectNoFrames() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
expect_frames_ = false;
}
int number_of_reconfigurations() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return number_of_reconfigurations_;
}
int last_min_transmit_bitrate() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return min_transmit_bitrate_bps_;
}
void SetNumExpectedLayers(size_t num_layers) {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
num_expected_layers_ = num_layers;
}
int64_t GetLastCaptureTimeMs() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return last_capture_time_ms_;
}
std::vector<uint8_t> GetLastEncodedImageData() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return std::move(last_encoded_image_data_);
}
RTPFragmentationHeader GetLastFragmentation() {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return std::move(last_fragmentation_);
}
@@ -1208,7 +1208,7 @@
const EncodedImage& encoded_image,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
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 @@
bool is_svc,
VideoEncoderConfig::ContentType content_type,
int min_transmit_bitrate_bps) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
++number_of_reconfigurations_;
min_transmit_bitrate_bps_ = min_transmit_bitrate_bps;
}
- mutable Mutex mutex_;
+ rtc::CriticalSection crit_;
TestEncoder* test_encoder_;
rtc::Event encoded_frame_event_;
std::vector<uint8_t> last_encoded_image_data_;
@@ -1268,21 +1268,21 @@
std::unique_ptr<VideoBitrateAllocator> CreateVideoBitrateAllocator(
const VideoCodec& codec) override {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
codec_config_ = codec;
return bitrate_allocator_factory_->CreateVideoBitrateAllocator(codec);
}
VideoCodec codec_config() const {
- MutexLock lock(&mutex_);
+ rtc::CritScope lock(&crit_);
return codec_config_;
}
private:
std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
- mutable Mutex mutex_;
- VideoCodec codec_config_ RTC_GUARDED_BY(mutex_);
+ rtc::CriticalSection crit_;
+ VideoCodec codec_config_ RTC_GUARDED_BY(crit_);
};
VideoSendStream::Config video_send_config_;