aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMarkus Handell <handellm@webrtc.org>2020-07-07 12:17:12 +0200
committerCommit Bot <commit-bot@chromium.org>2020-07-07 11:41:21 +0000
commit6deec38edef45e7505330eb892f9c75b7e6f6ba4 (patch)
tree595dd2286799a8de82bfe79d6b23867447735da4 /modules
parentfb6f975401972635a644c0db06c135b4c0aaef4a (diff)
downloadwebrtc-6deec38edef45e7505330eb892f9c75b7e6f6ba4.tar.gz
Migrate modules/video_coding to webrtc::Mutex.
Bug: webrtc:11567 Change-Id: I8023fbe7595f7ba8ae7c7db3583fc2e560ec3df2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178803 Commit-Queue: Markus Handell <handellm@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31644}
Diffstat (limited to 'modules')
-rw-r--r--modules/video_coding/BUILD.gn5
-rw-r--r--modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h6
-rw-r--r--modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc6
-rw-r--r--modules/video_coding/codecs/test/video_codec_unittest.cc12
-rw-r--r--modules/video_coding/codecs/test/video_codec_unittest.h6
-rw-r--r--modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.cc8
-rw-r--r--modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h4
-rw-r--r--modules/video_coding/deprecated/BUILD.gn1
-rw-r--r--modules/video_coding/deprecated/nack_module.cc10
-rw-r--r--modules/video_coding/deprecated/nack_module.h28
-rw-r--r--modules/video_coding/fec_controller_default.cc9
-rw-r--r--modules/video_coding/fec_controller_default.h8
-rw-r--r--modules/video_coding/frame_buffer2.cc18
-rw-r--r--modules/video_coding/frame_buffer2.h58
-rw-r--r--modules/video_coding/generic_decoder.cc6
-rw-r--r--modules/video_coding/generic_decoder.h4
-rw-r--r--modules/video_coding/generic_decoder_unittest.cc10
-rw-r--r--modules/video_coding/jitter_buffer.cc49
-rw-r--r--modules/video_coding/jitter_buffer.h49
-rw-r--r--modules/video_coding/timing.cc34
-rw-r--r--modules/video_coding/timing.h32
-rw-r--r--modules/video_coding/video_coding_impl.h7
-rw-r--r--modules/video_coding/video_receiver.cc11
23 files changed, 190 insertions, 191 deletions
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index e92649d4e6..8cb4e7be40 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -280,6 +280,7 @@ rtc_library("video_coding_legacy") {
"../../rtc_base:logging",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_event",
+ "../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:sequence_checker",
"../../system_wrappers",
"../rtp_rtcp:rtp_rtcp_format",
@@ -437,6 +438,7 @@ rtc_library("webrtc_multiplex") {
"../../media:rtc_media_base",
"../../rtc_base",
"../../rtc_base:checks",
+ "../../rtc_base/synchronization:mutex",
"../rtp_rtcp:rtp_rtcp_format",
]
}
@@ -572,6 +574,7 @@ rtc_library("webrtc_vp9") {
"../../rtc_base",
"../../rtc_base:checks",
"../../rtc_base/experiments:rate_control_settings",
+ "../../rtc_base/synchronization:mutex",
"../../system_wrappers:field_trial",
"../rtp_rtcp:rtp_rtcp_format",
]
@@ -707,6 +710,7 @@ if (rtc_include_tests) {
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_task_queue",
+ "../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:sequence_checker",
"../../rtc_base/task_utils:to_queued_task",
"../../test:test_support",
@@ -1001,6 +1005,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_task_queue",
"../../rtc_base:task_queue_for_test",
"../../rtc_base/experiments:jitter_upper_bound_experiment",
+ "../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../system_wrappers:field_trial",
"../../system_wrappers:metrics",
diff --git a/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h b/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h
index 9e718303b7..92a4c88cef 100644
--- a/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h
+++ b/modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h
@@ -21,7 +21,7 @@
#include "api/video_codecs/video_encoder_factory.h"
#include "modules/video_coding/codecs/multiplex/multiplex_encoded_image_packer.h"
#include "modules/video_coding/include/video_codec_interface.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@@ -71,7 +71,7 @@ class MultiplexEncoderAdapter : public VideoEncoder {
EncodedImageCallback* encoded_complete_callback_;
std::map<uint32_t /* timestamp */, MultiplexImage> stashed_images_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
uint16_t picture_index_ = 0;
std::vector<uint8_t> multiplex_dummy_planes_;
@@ -79,7 +79,7 @@ class MultiplexEncoderAdapter : public VideoEncoder {
int key_frame_interval_;
EncodedImage combined_image_;
- rtc::CriticalSection crit_;
+ Mutex mutex_;
const bool supports_augmented_data_;
int augmenting_data_size_ = 0;
diff --git a/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc b/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc
index 492ff19ffa..13f177cdad 100644
--- a/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc
+++ b/modules/video_coding/codecs/multiplex/multiplex_encoder_adapter.cc
@@ -180,7 +180,7 @@ int MultiplexEncoderAdapter::Encode(
}
{
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
stashed_images_.emplace(
std::piecewise_construct,
std::forward_as_tuple(input_image.timestamp()),
@@ -273,7 +273,7 @@ int MultiplexEncoderAdapter::Release() {
}
encoders_.clear();
adapter_callbacks_.clear();
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
stashed_images_.clear();
return WEBRTC_VIDEO_CODEC_OK;
@@ -298,7 +298,7 @@ EncodedImageCallback::Result MultiplexEncoderAdapter::OnEncodedImage(
// If we don't already own the buffer, make a copy.
image_component.encoded_image.Retain();
- rtc::CritScope cs(&crit_);
+ MutexLock lock(&mutex_);
const auto& stashed_image_itr =
stashed_images_.find(encodedImage.Timestamp());
const auto& stashed_image_next_itr = std::next(stashed_image_itr, 1);
diff --git a/modules/video_coding/codecs/test/video_codec_unittest.cc b/modules/video_coding/codecs/test/video_codec_unittest.cc
index c6cf1add94..94806b844e 100644
--- a/modules/video_coding/codecs/test/video_codec_unittest.cc
+++ b/modules/video_coding/codecs/test/video_codec_unittest.cc
@@ -37,7 +37,7 @@ VideoCodecUnitTest::FakeEncodeCompleteCallback::OnEncodedImage(
const EncodedImage& frame,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) {
- rtc::CritScope lock(&test_->encoded_frame_section_);
+ MutexLock lock(&test_->encoded_frame_section_);
test_->encoded_frames_.push_back(frame);
RTC_DCHECK(codec_specific_info);
test_->codec_specific_infos_.push_back(*codec_specific_info);
@@ -58,7 +58,7 @@ void VideoCodecUnitTest::FakeDecodeCompleteCallback::Decoded(
VideoFrame& frame,
absl::optional<int32_t> decode_time_ms,
absl::optional<uint8_t> qp) {
- rtc::CritScope lock(&test_->decoded_frame_section_);
+ MutexLock lock(&test_->decoded_frame_section_);
test_->decoded_frame_.emplace(frame);
test_->decoded_qp_ = qp;
test_->decoded_frame_event_.Set();
@@ -126,7 +126,7 @@ bool VideoCodecUnitTest::WaitForEncodedFrame(
}
void VideoCodecUnitTest::SetWaitForEncodedFramesThreshold(size_t num_frames) {
- rtc::CritScope lock(&encoded_frame_section_);
+ MutexLock lock(&encoded_frame_section_);
wait_for_encoded_frames_threshold_ = num_frames;
}
@@ -136,7 +136,7 @@ bool VideoCodecUnitTest::WaitForEncodedFrames(
EXPECT_TRUE(encoded_frame_event_.Wait(kEncodeTimeoutMs))
<< "Timed out while waiting for encoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames.
- rtc::CritScope lock(&encoded_frame_section_);
+ MutexLock lock(&encoded_frame_section_);
EXPECT_FALSE(encoded_frames_.empty());
EXPECT_FALSE(codec_specific_infos_.empty());
EXPECT_EQ(encoded_frames_.size(), codec_specific_infos_.size());
@@ -157,7 +157,7 @@ bool VideoCodecUnitTest::WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame,
bool ret = decoded_frame_event_.Wait(kDecodeTimeoutMs);
EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames.
- rtc::CritScope lock(&decoded_frame_section_);
+ MutexLock lock(&decoded_frame_section_);
EXPECT_TRUE(decoded_frame_);
if (decoded_frame_) {
frame->reset(new VideoFrame(std::move(*decoded_frame_)));
@@ -170,7 +170,7 @@ bool VideoCodecUnitTest::WaitForDecodedFrame(std::unique_ptr<VideoFrame>* frame,
}
size_t VideoCodecUnitTest::GetNumEncodedFrames() {
- rtc::CritScope lock(&encoded_frame_section_);
+ MutexLock lock(&encoded_frame_section_);
return encoded_frames_.size();
}
diff --git a/modules/video_coding/codecs/test/video_codec_unittest.h b/modules/video_coding/codecs/test/video_codec_unittest.h
index 1ce37a7ed5..c10eec4cb4 100644
--- a/modules/video_coding/codecs/test/video_codec_unittest.h
+++ b/modules/video_coding/codecs/test/video_codec_unittest.h
@@ -20,8 +20,8 @@
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/utility/vp8_header_parser.h"
#include "modules/video_coding/utility/vp9_uncompressed_header_parser.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "test/gtest.h"
@@ -108,7 +108,7 @@ class VideoCodecUnitTest : public ::testing::Test {
FakeDecodeCompleteCallback decode_complete_callback_;
rtc::Event encoded_frame_event_;
- rtc::CriticalSection encoded_frame_section_;
+ Mutex encoded_frame_section_;
size_t wait_for_encoded_frames_threshold_;
std::vector<EncodedImage> encoded_frames_
RTC_GUARDED_BY(encoded_frame_section_);
@@ -116,7 +116,7 @@ class VideoCodecUnitTest : public ::testing::Test {
RTC_GUARDED_BY(encoded_frame_section_);
rtc::Event decoded_frame_event_;
- rtc::CriticalSection decoded_frame_section_;
+ Mutex decoded_frame_section_;
absl::optional<VideoFrame> decoded_frame_
RTC_GUARDED_BY(decoded_frame_section_);
absl::optional<uint8_t> decoded_qp_ RTC_GUARDED_BY(decoded_frame_section_);
diff --git a/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.cc b/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.cc
index 551ace22a2..4d0a6983ac 100644
--- a/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.cc
+++ b/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.cc
@@ -58,7 +58,7 @@ Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) {
RTC_DCHECK_GT(min_size, 0);
rtc::scoped_refptr<Vp9FrameBuffer> available_buffer = nullptr;
{
- rtc::CritScope cs(&buffers_lock_);
+ MutexLock lock(&buffers_lock_);
// Do we have a buffer we can recycle?
for (const auto& buffer : allocated_buffers_) {
if (buffer->HasOneRef()) {
@@ -91,7 +91,7 @@ Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) {
int Vp9FrameBufferPool::GetNumBuffersInUse() const {
int num_buffers_in_use = 0;
- rtc::CritScope cs(&buffers_lock_);
+ MutexLock lock(&buffers_lock_);
for (const auto& buffer : allocated_buffers_) {
if (!buffer->HasOneRef())
++num_buffers_in_use;
@@ -100,7 +100,7 @@ int Vp9FrameBufferPool::GetNumBuffersInUse() const {
}
bool Vp9FrameBufferPool::Resize(size_t max_number_of_buffers) {
- rtc::CritScope cs(&buffers_lock_);
+ MutexLock lock(&buffers_lock_);
size_t used_buffers_count = 0;
for (const auto& buffer : allocated_buffers_) {
// If the buffer is in use, the ref count will be >= 2, one from the list we
@@ -130,7 +130,7 @@ bool Vp9FrameBufferPool::Resize(size_t max_number_of_buffers) {
}
void Vp9FrameBufferPool::ClearPool() {
- rtc::CritScope cs(&buffers_lock_);
+ MutexLock lock(&buffers_lock_);
allocated_buffers_.clear();
}
diff --git a/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h b/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h
index 02d2b26273..d37a9fc0e2 100644
--- a/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h
+++ b/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h
@@ -18,8 +18,8 @@
#include "api/scoped_refptr.h"
#include "rtc_base/buffer.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/ref_count.h"
+#include "rtc_base/synchronization/mutex.h"
struct vpx_codec_ctx;
struct vpx_codec_frame_buffer;
@@ -119,7 +119,7 @@ class Vp9FrameBufferPool {
private:
// Protects |allocated_buffers_|.
- rtc::CriticalSection buffers_lock_;
+ mutable Mutex buffers_lock_;
// All buffers, in use or ready to be recycled.
std::vector<rtc::scoped_refptr<Vp9FrameBuffer>> allocated_buffers_
RTC_GUARDED_BY(buffers_lock_);
diff --git a/modules/video_coding/deprecated/BUILD.gn b/modules/video_coding/deprecated/BUILD.gn
index f333b3f5e2..fd3a5fa5fc 100644
--- a/modules/video_coding/deprecated/BUILD.gn
+++ b/modules/video_coding/deprecated/BUILD.gn
@@ -26,6 +26,7 @@ rtc_library("nack_module") {
"../../../rtc_base:macromagic",
"../../../rtc_base:rtc_numerics",
"../../../rtc_base/experiments:field_trial_parser",
+ "../../../rtc_base/synchronization:mutex",
"../../../system_wrappers",
"../../../system_wrappers:field_trial",
"../../utility",
diff --git a/modules/video_coding/deprecated/nack_module.cc b/modules/video_coding/deprecated/nack_module.cc
index 8658729e99..f8cfd3440b 100644
--- a/modules/video_coding/deprecated/nack_module.cc
+++ b/modules/video_coding/deprecated/nack_module.cc
@@ -115,7 +115,7 @@ int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num,
int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num,
bool is_keyframe,
bool is_recovered) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
// TODO(philipel): When the packet includes information whether it is
// retransmitted or not, use that value instead. For
// now set it to true, which will cause the reordering
@@ -184,7 +184,7 @@ int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num,
}
void DEPRECATED_NackModule::ClearUpTo(uint16_t seq_num) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
nack_list_.erase(nack_list_.begin(), nack_list_.lower_bound(seq_num));
keyframe_list_.erase(keyframe_list_.begin(),
keyframe_list_.lower_bound(seq_num));
@@ -193,12 +193,12 @@ void DEPRECATED_NackModule::ClearUpTo(uint16_t seq_num) {
}
void DEPRECATED_NackModule::UpdateRtt(int64_t rtt_ms) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
rtt_ms_ = rtt_ms;
}
void DEPRECATED_NackModule::Clear() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
nack_list_.clear();
keyframe_list_.clear();
recovered_list_.clear();
@@ -213,7 +213,7 @@ void DEPRECATED_NackModule::Process() {
if (nack_sender_) {
std::vector<uint16_t> nack_batch;
{
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
nack_batch = GetNackBatch(kTimeOnly);
}
diff --git a/modules/video_coding/deprecated/nack_module.h b/modules/video_coding/deprecated/nack_module.h
index d704a05c11..f9580ae80c 100644
--- a/modules/video_coding/deprecated/nack_module.h
+++ b/modules/video_coding/deprecated/nack_module.h
@@ -21,9 +21,9 @@
#include "modules/include/module.h"
#include "modules/include/module_common_types.h"
#include "modules/video_coding/histogram.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/deprecation.h"
#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
@@ -80,24 +80,24 @@ class DEPRECATED_NackModule : public Module {
};
void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Removes packets from the nack list until the next keyframe. Returns true
// if packets were removed.
- bool RemovePacketsUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ bool RemovePacketsUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
std::vector<uint16_t> GetNackBatch(NackFilterOptions options)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Update the reordering distribution.
void UpdateReorderingStatistics(uint16_t seq_num)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns how many packets we have to wait in order to receive the packet
// with probability |probabilty| or higher.
int WaitNumberOfPackets(float probability) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- rtc::CriticalSection crit_;
+ Mutex mutex_;
Clock* const clock_;
NackSender* const nack_sender_;
KeyFrameRequestSender* const keyframe_request_sender_;
@@ -106,15 +106,15 @@ class DEPRECATED_NackModule : public Module {
// known thread (e.g. see |initialized_|). Those probably do not need
// synchronized access.
std::map<uint16_t, NackInfo, DescendingSeqNumComp<uint16_t>> nack_list_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
std::set<uint16_t, DescendingSeqNumComp<uint16_t>> keyframe_list_
- RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
std::set<uint16_t, DescendingSeqNumComp<uint16_t>> recovered_list_
- RTC_GUARDED_BY(crit_);
- video_coding::Histogram reordering_histogram_ RTC_GUARDED_BY(crit_);
- bool initialized_ RTC_GUARDED_BY(crit_);
- int64_t rtt_ms_ RTC_GUARDED_BY(crit_);
- uint16_t newest_seq_num_ RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
+ video_coding::Histogram reordering_histogram_ RTC_GUARDED_BY(mutex_);
+ bool initialized_ RTC_GUARDED_BY(mutex_);
+ int64_t rtt_ms_ RTC_GUARDED_BY(mutex_);
+ uint16_t newest_seq_num_ RTC_GUARDED_BY(mutex_);
// Only touched on the process thread.
int64_t next_process_time_ms_;
diff --git a/modules/video_coding/fec_controller_default.cc b/modules/video_coding/fec_controller_default.cc
index 97919f5315..827c853541 100644
--- a/modules/video_coding/fec_controller_default.cc
+++ b/modules/video_coding/fec_controller_default.cc
@@ -20,7 +20,6 @@
#include "system_wrappers/include/field_trial.h"
namespace webrtc {
-using rtc::CritScope;
const float kProtectionOverheadRateThreshold = 0.5;
@@ -54,7 +53,7 @@ void FecControllerDefault::SetEncodingData(size_t width,
size_t height,
size_t num_temporal_layers,
size_t max_payload_size) {
- CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
loss_prot_logic_->UpdateFrameSize(width, height);
loss_prot_logic_->UpdateNumLayers(num_temporal_layers);
max_payload_size_ = max_payload_size;
@@ -94,7 +93,7 @@ uint32_t FecControllerDefault::UpdateFecRates(
FecProtectionParams delta_fec_params;
FecProtectionParams key_fec_params;
{
- CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
loss_prot_logic_->UpdateBitRate(target_bitrate_kbps);
loss_prot_logic_->UpdateRtt(round_trip_time_ms);
// Update frame rate for the loss protection logic class: frame rate should
@@ -175,7 +174,7 @@ void FecControllerDefault::SetProtectionMethod(bool enable_fec,
} else if (enable_fec) {
method = media_optimization::kFec;
}
- CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
loss_prot_logic_->SetMethod(method);
}
@@ -183,7 +182,7 @@ void FecControllerDefault::UpdateWithEncodedData(
const size_t encoded_image_length,
const VideoFrameType encoded_image_frametype) {
const size_t encoded_length = encoded_image_length;
- CritScope lock(&crit_sect_);
+ MutexLock lock(&mutex_);
if (encoded_length > 0) {
const bool delta_frame =
encoded_image_frametype != VideoFrameType::kVideoFrameKey;
diff --git a/modules/video_coding/fec_controller_default.h b/modules/video_coding/fec_controller_default.h
index 02c0ec0d37..6b9e8eb8e5 100644
--- a/modules/video_coding/fec_controller_default.h
+++ b/modules/video_coding/fec_controller_default.h
@@ -20,7 +20,7 @@
#include "api/fec_controller.h"
#include "modules/video_coding/media_opt_util.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
@@ -54,10 +54,10 @@ class FecControllerDefault : public FecController {
enum { kBitrateAverageWinMs = 1000 };
Clock* const clock_;
VCMProtectionCallback* protection_callback_;
- rtc::CriticalSection crit_sect_;
+ Mutex mutex_;
std::unique_ptr<media_optimization::VCMLossProtectionLogic> loss_prot_logic_
- RTC_GUARDED_BY(crit_sect_);
- size_t max_payload_size_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ size_t max_payload_size_ RTC_GUARDED_BY(mutex_);
RTC_DISALLOW_COPY_AND_ASSIGN(FecControllerDefault);
const float overhead_threshold_;
};
diff --git a/modules/video_coding/frame_buffer2.cc b/modules/video_coding/frame_buffer2.cc
index 64d3699e01..88ac09c496 100644
--- a/modules/video_coding/frame_buffer2.cc
+++ b/modules/video_coding/frame_buffer2.cc
@@ -82,7 +82,7 @@ void FrameBuffer::NextFrame(
int64_t latest_return_time_ms =
clock_->TimeInMilliseconds() + max_wait_time_ms;
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (stopped_) {
return;
}
@@ -102,7 +102,7 @@ void FrameBuffer::StartWaitForNextFrameOnQueue() {
RTC_DCHECK_RUN_ON(&callback_checker_);
// If this task has not been cancelled, we did not get any new frames
// while waiting. Continue with frame delivery.
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!frames_to_decode_.empty()) {
// We have frames, deliver!
frame_handler_(absl::WrapUnique(GetNextFrame()), kFrameFound);
@@ -329,19 +329,19 @@ bool FrameBuffer::HasBadRenderTiming(const EncodedFrame& frame,
void FrameBuffer::SetProtectionMode(VCMVideoProtection mode) {
TRACE_EVENT0("webrtc", "FrameBuffer::SetProtectionMode");
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
protection_mode_ = mode;
}
void FrameBuffer::Start() {
TRACE_EVENT0("webrtc", "FrameBuffer::Start");
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
stopped_ = false;
}
void FrameBuffer::Stop() {
TRACE_EVENT0("webrtc", "FrameBuffer::Stop");
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (stopped_)
return;
stopped_ = true;
@@ -350,12 +350,12 @@ void FrameBuffer::Stop() {
}
void FrameBuffer::Clear() {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
ClearFramesAndHistory();
}
void FrameBuffer::UpdateRtt(int64_t rtt_ms) {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
jitter_estimator_.UpdateRtt(rtt_ms);
}
@@ -431,7 +431,7 @@ int64_t FrameBuffer::InsertFrame(std::unique_ptr<EncodedFrame> frame) {
TRACE_EVENT0("webrtc", "FrameBuffer::InsertFrame");
RTC_DCHECK(frame);
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
const VideoLayerFrameId& id = frame->id;
int64_t last_continuous_picture_id =
@@ -529,7 +529,7 @@ int64_t FrameBuffer::InsertFrame(std::unique_ptr<EncodedFrame> frame) {
// to return from NextFrame.
if (callback_queue_) {
callback_queue_->PostTask([this] {
- rtc::CritScope lock(&crit_);
+ MutexLock lock(&mutex_);
if (!callback_task_.Running())
return;
RTC_CHECK(frame_handler_);
diff --git a/modules/video_coding/frame_buffer2.h b/modules/video_coding/frame_buffer2.h
index d824ddf4d0..7909000a22 100644
--- a/modules/video_coding/frame_buffer2.h
+++ b/modules/video_coding/frame_buffer2.h
@@ -24,10 +24,10 @@
#include "modules/video_coding/jitter_estimator.h"
#include "modules/video_coding/utility/decoded_frames_history.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/experiments/rtt_mult_experiment.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/task_queue.h"
#include "rtc_base/task_utils/repeating_task.h"
@@ -118,40 +118,40 @@ class FrameBuffer {
// Check that the references of |frame| are valid.
bool ValidReferences(const EncodedFrame& frame) const;
- int64_t FindNextFrame(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
- EncodedFrame* GetNextFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ int64_t FindNextFrame(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ EncodedFrame* GetNextFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- void StartWaitForNextFrameOnQueue() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
- void CancelCallback() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void StartWaitForNextFrameOnQueue() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ void CancelCallback() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Update all directly dependent and indirectly dependent frames and mark
// them as continuous if all their references has been fulfilled.
void PropagateContinuity(FrameMap::iterator start)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Marks the frame as decoded and updates all directly dependent frames.
void PropagateDecodability(const FrameInfo& info)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Update the corresponding FrameInfo of |frame| and all FrameInfos that
// |frame| references.
// Return false if |frame| will never be decodable, true otherwise.
bool UpdateFrameInfoWithIncomingFrame(const EncodedFrame& frame,
FrameMap::iterator info)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- void UpdateJitterDelay() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void UpdateJitterDelay() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- void UpdateTimingFrameInfo() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void UpdateTimingFrameInfo() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- void ClearFramesAndHistory() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ void ClearFramesAndHistory() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Checks if the superframe, which current frame belongs to, is complete.
bool IsCompleteSuperFrame(const EncodedFrame& frame)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool HasBadRenderTiming(const EncodedFrame& frame, int64_t now_ms)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// The cleaner solution would be to have the NextFrame function return a
// vector of frames, but until the decoding pipeline can support decoding
@@ -164,29 +164,29 @@ class FrameBuffer {
SequenceChecker callback_checker_;
// Stores only undecoded frames.
- FrameMap frames_ RTC_GUARDED_BY(crit_);
- DecodedFramesHistory decoded_frames_history_ RTC_GUARDED_BY(crit_);
+ FrameMap frames_ RTC_GUARDED_BY(mutex_);
+ DecodedFramesHistory decoded_frames_history_ RTC_GUARDED_BY(mutex_);
- rtc::CriticalSection crit_;
+ Mutex mutex_;
Clock* const clock_;
- rtc::TaskQueue* callback_queue_ RTC_GUARDED_BY(crit_);
- RepeatingTaskHandle callback_task_ RTC_GUARDED_BY(crit_);
+ rtc::TaskQueue* callback_queue_ RTC_GUARDED_BY(mutex_);
+ RepeatingTaskHandle callback_task_ RTC_GUARDED_BY(mutex_);
std::function<void(std::unique_ptr<EncodedFrame>, ReturnReason)>
- frame_handler_ RTC_GUARDED_BY(crit_);
- int64_t latest_return_time_ms_ RTC_GUARDED_BY(crit_);
- bool keyframe_required_ RTC_GUARDED_BY(crit_);
+ frame_handler_ RTC_GUARDED_BY(mutex_);
+ int64_t latest_return_time_ms_ RTC_GUARDED_BY(mutex_);
+ bool keyframe_required_ RTC_GUARDED_BY(mutex_);
- VCMJitterEstimator jitter_estimator_ RTC_GUARDED_BY(crit_);
- VCMTiming* const timing_ RTC_GUARDED_BY(crit_);
- VCMInterFrameDelay inter_frame_delay_ RTC_GUARDED_BY(crit_);
+ VCMJitterEstimator jitter_estimator_ RTC_GUARDED_BY(mutex_);
+ VCMTiming* const timing_ RTC_GUARDED_BY(mutex_);
+ VCMInterFrameDelay inter_frame_delay_ RTC_GUARDED_BY(mutex_);
absl::optional<VideoLayerFrameId> last_continuous_frame_
- RTC_GUARDED_BY(crit_);
- std::vector<FrameMap::iterator> frames_to_decode_ RTC_GUARDED_BY(crit_);
- bool stopped_ RTC_GUARDED_BY(crit_);
- VCMVideoProtection protection_mode_ RTC_GUARDED_BY(crit_);
+ RTC_GUARDED_BY(mutex_);
+ std::vector<FrameMap::iterator> frames_to_decode_ RTC_GUARDED_BY(mutex_);
+ bool stopped_ RTC_GUARDED_BY(mutex_);
+ VCMVideoProtection protection_mode_ RTC_GUARDED_BY(mutex_);
VCMReceiveStatisticsCallback* const stats_callback_;
- int64_t last_log_non_decoded_ms_ RTC_GUARDED_BY(crit_);
+ int64_t last_log_non_decoded_ms_ RTC_GUARDED_BY(mutex_);
const bool add_rtt_to_playout_delay_;
diff --git a/modules/video_coding/generic_decoder.cc b/modules/video_coding/generic_decoder.cc
index cfe16ed3f1..50ecd8da8d 100644
--- a/modules/video_coding/generic_decoder.cc
+++ b/modules/video_coding/generic_decoder.cc
@@ -86,7 +86,7 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
// callbacks from one call to Decode().
VCMFrameInformation* frameInfo;
{
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
frameInfo = _timestampMap.Pop(decodedImage.timestamp());
}
@@ -172,12 +172,12 @@ void VCMDecodedFrameCallback::OnDecoderImplementationName(
void VCMDecodedFrameCallback::Map(uint32_t timestamp,
VCMFrameInformation* frameInfo) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
_timestampMap.Add(timestamp, frameInfo);
}
int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
if (_timestampMap.Pop(timestamp) == NULL) {
return VCM_GENERAL_ERROR;
}
diff --git a/modules/video_coding/generic_decoder.h b/modules/video_coding/generic_decoder.h
index 40fe667d65..b89d3f4368 100644
--- a/modules/video_coding/generic_decoder.h
+++ b/modules/video_coding/generic_decoder.h
@@ -19,8 +19,8 @@
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/timestamp_map.h"
#include "modules/video_coding/timing.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/experiments/field_trial_parser.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h"
namespace webrtc {
@@ -70,7 +70,7 @@ class VCMDecodedFrameCallback : public DecodedImageCallback {
// from the same thread, and therfore a lock is not required to access it.
VCMReceiveCallback* _receiveCallback = nullptr;
VCMTiming* _timing;
- rtc::CriticalSection lock_;
+ Mutex lock_;
VCMTimestampMap _timestampMap RTC_GUARDED_BY(lock_);
int64_t ntp_offset_;
// Set by the field trial WebRTC-SlowDownDecoder to simulate a slow decoder.
diff --git a/modules/video_coding/generic_decoder_unittest.cc b/modules/video_coding/generic_decoder_unittest.cc
index 3e07a2a81c..dbceb187be 100644
--- a/modules/video_coding/generic_decoder_unittest.cc
+++ b/modules/video_coding/generic_decoder_unittest.cc
@@ -16,8 +16,8 @@
#include "api/task_queue/default_task_queue_factory.h"
#include "common_video/test/utilities.h"
#include "modules/video_coding/timing.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
+#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/clock.h"
#include "test/fake_decoder.h"
#include "test/gmock.h"
@@ -33,7 +33,7 @@ class ReceiveCallback : public VCMReceiveCallback {
int32_t decode_time_ms,
VideoContentType content_type) override {
{
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
last_frame_ = videoFrame;
}
received_frame_event_.Set();
@@ -41,13 +41,13 @@ class ReceiveCallback : public VCMReceiveCallback {
}
absl::optional<VideoFrame> GetLastFrame() {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
return last_frame_;
}
absl::optional<VideoFrame> WaitForFrame(int64_t wait_ms) {
if (received_frame_event_.Wait(wait_ms)) {
- rtc::CritScope cs(&lock_);
+ MutexLock lock(&lock_);
return last_frame_;
} else {
return absl::nullopt;
@@ -55,7 +55,7 @@ class ReceiveCallback : public VCMReceiveCallback {
}
private:
- rtc::CriticalSection lock_;
+ Mutex lock_;
rtc::Event received_frame_event_;
absl::optional<VideoFrame> last_frame_ RTC_GUARDED_BY(lock_);
};
diff --git a/modules/video_coding/jitter_buffer.cc b/modules/video_coding/jitter_buffer.cc
index 0873285f39..9d2d3a2d1d 100644
--- a/modules/video_coding/jitter_buffer.cc
+++ b/modules/video_coding/jitter_buffer.cc
@@ -153,7 +153,7 @@ VCMJitterBuffer::~VCMJitterBuffer() {
}
void VCMJitterBuffer::Start() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
running_ = true;
num_consecutive_old_packets_ = 0;
@@ -172,7 +172,7 @@ void VCMJitterBuffer::Start() {
}
void VCMJitterBuffer::Stop() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
running_ = false;
last_decoded_state_.Reset();
@@ -181,12 +181,12 @@ void VCMJitterBuffer::Stop() {
}
bool VCMJitterBuffer::Running() const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return running_;
}
void VCMJitterBuffer::Flush() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
decodable_frames_.Reset(&free_frames_);
incomplete_frames_.Reset(&free_frames_);
last_decoded_state_.Reset(); // TODO(mikhal): sync reset.
@@ -202,21 +202,20 @@ void VCMJitterBuffer::Flush() {
}
int VCMJitterBuffer::num_packets() const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return num_packets_;
}
int VCMJitterBuffer::num_duplicated_packets() const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return num_duplicated_packets_;
}
// Returns immediately or a |max_wait_time_ms| ms event hang waiting for a
// complete frame, |max_wait_time_ms| decided by caller.
VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
- crit_sect_.Enter();
+ MutexLock lock(&mutex_);
if (!running_) {
- crit_sect_.Leave();
return nullptr;
}
CleanUpOldOrEmptyFrames();
@@ -227,14 +226,13 @@ VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
clock_->TimeInMilliseconds() + max_wait_time_ms;
int64_t wait_time_ms = max_wait_time_ms;
while (wait_time_ms > 0) {
- crit_sect_.Leave();
+ mutex_.Unlock();
const EventTypeWrapper ret =
frame_event_->Wait(static_cast<uint32_t>(wait_time_ms));
- crit_sect_.Enter();
+ mutex_.Lock();
if (ret == kEventSignaled) {
// Are we shutting down the jitter buffer?
if (!running_) {
- crit_sect_.Leave();
return nullptr;
}
// Finding oldest frame ready for decoder.
@@ -252,16 +250,13 @@ VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
}
if (decodable_frames_.empty() ||
decodable_frames_.Front()->GetState() != kStateComplete) {
- crit_sect_.Leave();
return nullptr;
}
- VCMEncodedFrame* encoded_frame = decodable_frames_.Front();
- crit_sect_.Leave();
- return encoded_frame;
+ return decodable_frames_.Front();
}
VCMEncodedFrame* VCMJitterBuffer::ExtractAndSetDecode(uint32_t timestamp) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
if (!running_) {
return NULL;
}
@@ -313,7 +308,7 @@ VCMEncodedFrame* VCMJitterBuffer::ExtractAndSetDecode(uint32_t timestamp) {
// frames from within the jitter buffer.
void VCMJitterBuffer::ReleaseFrame(VCMEncodedFrame* frame) {
RTC_CHECK(frame != nullptr);
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
VCMFrameBuffer* frame_buffer = static_cast<VCMFrameBuffer*>(frame);
RecycleFrameBuffer(frame_buffer);
}
@@ -354,7 +349,7 @@ VCMFrameBufferEnum VCMJitterBuffer::GetFrame(const VCMPacket& packet,
int64_t VCMJitterBuffer::LastPacketTime(const VCMEncodedFrame* frame,
bool* retransmitted) const {
assert(retransmitted);
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
const VCMFrameBuffer* frame_buffer =
static_cast<const VCMFrameBuffer*>(frame);
*retransmitted = (frame_buffer->GetNackCount() > 0);
@@ -363,7 +358,7 @@ int64_t VCMJitterBuffer::LastPacketTime(const VCMEncodedFrame* frame,
VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet,
bool* retransmitted) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
++num_packets_;
// Does this packet belong to an old frame?
@@ -577,7 +572,7 @@ void VCMJitterBuffer::FindAndInsertContinuousFramesWithState(
}
uint32_t VCMJitterBuffer::EstimatedJitterMs() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
const double rtt_mult = 1.0f;
return jitter_estimate_.GetJitterEstimate(rtt_mult, absl::nullopt);
}
@@ -585,7 +580,7 @@ uint32_t VCMJitterBuffer::EstimatedJitterMs() {
void VCMJitterBuffer::SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack,
int max_incomplete_time_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
assert(max_packet_age_to_nack >= 0);
assert(max_incomplete_time_ms_ >= 0);
max_nack_list_size_ = max_nack_list_size;
@@ -616,7 +611,7 @@ uint16_t VCMJitterBuffer::EstimatedLowSequenceNumber(
}
std::vector<uint16_t> VCMJitterBuffer::GetNackList(bool* request_key_frame) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
*request_key_frame = false;
if (last_decoded_state_.in_initial_state()) {
VCMFrameBuffer* next_frame = NextFrame();
@@ -827,7 +822,7 @@ void VCMJitterBuffer::UpdateAveragePacketsPerFrame(int current_number_packets) {
}
}
-// Must be called under the critical section |crit_sect_|.
+// Must be called under the critical section |mutex_|.
void VCMJitterBuffer::CleanUpOldOrEmptyFrames() {
decodable_frames_.CleanUpOldOrEmptyFrames(&last_decoded_state_,
&free_frames_);
@@ -838,13 +833,13 @@ void VCMJitterBuffer::CleanUpOldOrEmptyFrames() {
}
}
-// Must be called from within |crit_sect_|.
+// Must be called from within |mutex_|.
bool VCMJitterBuffer::IsPacketRetransmitted(const VCMPacket& packet) const {
return missing_sequence_numbers_.find(packet.seqNum) !=
missing_sequence_numbers_.end();
}
-// Must be called under the critical section |crit_sect_|. Should never be
+// Must be called under the critical section |mutex_|. Should never be
// called with retransmitted frames, they must be filtered out before this
// function is called.
void VCMJitterBuffer::UpdateJitterEstimate(const VCMJitterSample& sample,
@@ -856,7 +851,7 @@ void VCMJitterBuffer::UpdateJitterEstimate(const VCMJitterSample& sample,
sample.frame_size, incomplete_frame);
}
-// Must be called under the critical section crit_sect_. Should never be
+// Must be called under the critical section mutex_. Should never be
// called with retransmitted frames, they must be filtered out before this
// function is called.
void VCMJitterBuffer::UpdateJitterEstimate(const VCMFrameBuffer& frame,
@@ -870,7 +865,7 @@ void VCMJitterBuffer::UpdateJitterEstimate(const VCMFrameBuffer& frame,
frame.size(), incomplete_frame);
}
-// Must be called under the critical section |crit_sect_|. Should never be
+// Must be called under the critical section |mutex_|. Should never be
// called with retransmitted frames, they must be filtered out before this
// function is called.
void VCMJitterBuffer::UpdateJitterEstimate(int64_t latest_packet_time_ms,
diff --git a/modules/video_coding/jitter_buffer.h b/modules/video_coding/jitter_buffer.h
index 2505845d4f..b15ca75ffa 100644
--- a/modules/video_coding/jitter_buffer.h
+++ b/modules/video_coding/jitter_buffer.h
@@ -28,7 +28,7 @@
#include "modules/video_coding/jitter_buffer_common.h"
#include "modules/video_coding/jitter_estimator.h"
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@@ -143,66 +143,66 @@ class VCMJitterBuffer {
VCMFrameBufferEnum GetFrame(const VCMPacket& packet,
VCMFrameBuffer** frame,
FrameList** frame_list)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if |frame| is continuous in |decoding_state|, not taking
// decodable frames into account.
bool IsContinuousInState(const VCMFrameBuffer& frame,
const VCMDecodingState& decoding_state) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if |frame| is continuous in the |last_decoded_state_|, taking
// all decodable frames into account.
bool IsContinuous(const VCMFrameBuffer& frame) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Looks for frames in |incomplete_frames_| which are continuous in the
// provided |decoded_state|. Starts the search from the timestamp of
// |decoded_state|.
void FindAndInsertContinuousFramesWithState(
const VCMDecodingState& decoded_state)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Looks for frames in |incomplete_frames_| which are continuous in
// |last_decoded_state_| taking all decodable frames into account. Starts
// the search from |new_frame|.
void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
- VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if the NACK list was updated to cover sequence numbers up to
// |sequence_number|. If false a key frame is needed to get into a state where
// we can continue decoding.
bool UpdateNackList(uint16_t sequence_number)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool TooLargeNackList() const;
// Returns true if the NACK list was reduced without problem. If false a key
// frame is needed to get into a state where we can continue decoding.
- bool HandleTooLargeNackList() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool HandleTooLargeNackList() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool MissingTooOldPacket(uint16_t latest_sequence_number) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if the too old packets was successfully removed from the NACK
// list. If false, a key frame is needed to get into a state where we can
// continue decoding.
bool HandleTooOldPackets(uint16_t latest_sequence_number)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Drops all packets in the NACK list up until |last_decoded_sequence_number|.
void DropPacketsFromNackList(uint16_t last_decoded_sequence_number);
// Gets an empty frame, creating a new frame if necessary (i.e. increases
// jitter buffer size).
- VCMFrameBuffer* GetEmptyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ VCMFrameBuffer* GetEmptyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Attempts to increase the size of the jitter buffer. Returns true on
// success, false otherwise.
- bool TryToIncreaseJitterBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool TryToIncreaseJitterBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Recycles oldest frames until a key frame is found. Used if jitter buffer is
// completely full. Returns true if a key frame was found.
- bool RecycleFramesUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool RecycleFramesUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Update rolling average of packets per frame.
void UpdateAveragePacketsPerFrame(int current_number_packets_);
// Cleans the frame list in the JB from old/empty frames.
// Should only be called prior to actual use.
- void CleanUpOldOrEmptyFrames() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ void CleanUpOldOrEmptyFrames() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if |packet| is likely to have been retransmitted.
bool IsPacketRetransmitted(const VCMPacket& packet) const;
@@ -217,35 +217,34 @@ class VCMJitterBuffer {
unsigned int frame_size,
bool incomplete_frame);
- int NonContinuousOrIncompleteDuration()
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ int NonContinuousOrIncompleteDuration() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const;
// Reset frame buffer and return it to free_frames_.
void RecycleFrameBuffer(VCMFrameBuffer* frame)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* clock_;
// If we are running (have started) or not.
bool running_;
- rtc::CriticalSection crit_sect_;
+ mutable Mutex mutex_;
// Event to signal when we have a frame ready for decoder.
std::unique_ptr<EventWrapper> frame_event_;
// Number of allocated frames.
int max_number_of_frames_;
- UnorderedFrameList free_frames_ RTC_GUARDED_BY(crit_sect_);
- FrameList decodable_frames_ RTC_GUARDED_BY(crit_sect_);
- FrameList incomplete_frames_ RTC_GUARDED_BY(crit_sect_);
- VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(crit_sect_);
+ UnorderedFrameList free_frames_ RTC_GUARDED_BY(mutex_);
+ FrameList decodable_frames_ RTC_GUARDED_BY(mutex_);
+ FrameList incomplete_frames_ RTC_GUARDED_BY(mutex_);
+ VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(mutex_);
bool first_packet_since_reset_;
// Number of packets in a row that have been too old.
int num_consecutive_old_packets_;
// Number of packets received.
- int num_packets_ RTC_GUARDED_BY(crit_sect_);
+ int num_packets_ RTC_GUARDED_BY(mutex_);
// Number of duplicated packets received.
- int num_duplicated_packets_ RTC_GUARDED_BY(crit_sect_);
+ int num_duplicated_packets_ RTC_GUARDED_BY(mutex_);
// Jitter estimation.
// Filter for estimating jitter.
diff --git a/modules/video_coding/timing.cc b/modules/video_coding/timing.cc
index c62c848c09..f046edf497 100644
--- a/modules/video_coding/timing.cc
+++ b/modules/video_coding/timing.cc
@@ -47,7 +47,7 @@ VCMTiming::~VCMTiming() {
}
void VCMTiming::Reset() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
ts_extrapolator_->Reset(clock_->TimeInMilliseconds());
codec_timer_.reset(new VCMCodecTimer());
render_delay_ms_ = kDefaultRenderDelayMs;
@@ -58,32 +58,32 @@ void VCMTiming::Reset() {
}
void VCMTiming::set_render_delay(int render_delay_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
render_delay_ms_ = render_delay_ms;
}
void VCMTiming::set_min_playout_delay(int min_playout_delay_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
min_playout_delay_ms_ = min_playout_delay_ms;
}
int VCMTiming::min_playout_delay() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return min_playout_delay_ms_;
}
void VCMTiming::set_max_playout_delay(int max_playout_delay_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
max_playout_delay_ms_ = max_playout_delay_ms;
}
int VCMTiming::max_playout_delay() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return max_playout_delay_ms_;
}
void VCMTiming::SetJitterDelay(int jitter_delay_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
if (jitter_delay_ms != jitter_delay_ms_) {
jitter_delay_ms_ = jitter_delay_ms;
// When in initial state, set current delay to minimum delay.
@@ -94,7 +94,7 @@ void VCMTiming::SetJitterDelay(int jitter_delay_ms) {
}
void VCMTiming::UpdateCurrentDelay(uint32_t frame_timestamp) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
int target_delay_ms = TargetDelayInternal();
if (current_delay_ms_ == 0) {
@@ -135,7 +135,7 @@ void VCMTiming::UpdateCurrentDelay(uint32_t frame_timestamp) {
void VCMTiming::UpdateCurrentDelay(int64_t render_time_ms,
int64_t actual_decode_time_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
uint32_t target_delay_ms = TargetDelayInternal();
int64_t delayed_ms =
actual_decode_time_ms -
@@ -158,20 +158,20 @@ void VCMTiming::StopDecodeTimer(uint32_t /*time_stamp*/,
}
void VCMTiming::StopDecodeTimer(int32_t decode_time_ms, int64_t now_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
codec_timer_->AddTiming(decode_time_ms, now_ms);
assert(decode_time_ms >= 0);
++num_decoded_frames_;
}
void VCMTiming::IncomingTimestamp(uint32_t time_stamp, int64_t now_ms) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
ts_extrapolator_->Update(now_ms, time_stamp);
}
int64_t VCMTiming::RenderTimeMs(uint32_t frame_timestamp,
int64_t now_ms) const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return RenderTimeMsInternal(frame_timestamp, now_ms);
}
@@ -202,7 +202,7 @@ int VCMTiming::RequiredDecodeTimeMs() const {
int64_t VCMTiming::MaxWaitingTime(int64_t render_time_ms,
int64_t now_ms) const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
const int64_t max_wait_time_ms =
render_time_ms - now_ms - RequiredDecodeTimeMs() - render_delay_ms_;
@@ -211,7 +211,7 @@ int64_t VCMTiming::MaxWaitingTime(int64_t render_time_ms,
}
int VCMTiming::TargetVideoDelay() const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return TargetDelayInternal();
}
@@ -226,7 +226,7 @@ bool VCMTiming::GetTimings(int* max_decode_ms,
int* jitter_buffer_ms,
int* min_playout_delay_ms,
int* render_delay_ms) const {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
*max_decode_ms = RequiredDecodeTimeMs();
*current_delay_ms = current_delay_ms_;
*target_delay_ms = TargetDelayInternal();
@@ -237,12 +237,12 @@ bool VCMTiming::GetTimings(int* max_decode_ms,
}
void VCMTiming::SetTimingFrameInfo(const TimingFrameInfo& info) {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
timing_frame_info_.emplace(info);
}
absl::optional<TimingFrameInfo> VCMTiming::GetTimingFrameInfo() {
- rtc::CritScope cs(&crit_sect_);
+ MutexLock lock(&mutex_);
return timing_frame_info_;
}
diff --git a/modules/video_coding/timing.h b/modules/video_coding/timing.h
index c9efcb13b0..75b8e7d99d 100644
--- a/modules/video_coding/timing.h
+++ b/modules/video_coding/timing.h
@@ -16,7 +16,7 @@
#include "absl/types/optional.h"
#include "api/video/video_timing.h"
#include "modules/video_coding/codec_timer.h"
-#include "rtc_base/critical_section.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@@ -104,30 +104,30 @@ class VCMTiming {
enum { kDelayMaxChangeMsPerS = 100 };
protected:
- int RequiredDecodeTimeMs() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ int RequiredDecodeTimeMs() const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
int64_t RenderTimeMsInternal(uint32_t frame_timestamp, int64_t now_ms) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
- int TargetDelayInternal() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ int TargetDelayInternal() const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
private:
- rtc::CriticalSection crit_sect_;
+ mutable Mutex mutex_;
Clock* const clock_;
- bool master_ RTC_GUARDED_BY(crit_sect_);
- TimestampExtrapolator* ts_extrapolator_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<VCMCodecTimer> codec_timer_ RTC_GUARDED_BY(crit_sect_);
- int render_delay_ms_ RTC_GUARDED_BY(crit_sect_);
+ bool master_ RTC_GUARDED_BY(mutex_);
+ TimestampExtrapolator* ts_extrapolator_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<VCMCodecTimer> codec_timer_ RTC_GUARDED_BY(mutex_);
+ int render_delay_ms_ RTC_GUARDED_BY(mutex_);
// Best-effort playout delay range for frames from capture to render.
// The receiver tries to keep the delay between |min_playout_delay_ms_|
// and |max_playout_delay_ms_| taking the network jitter into account.
// A special case is where min_playout_delay_ms_ = max_playout_delay_ms_ = 0,
// in which case the receiver tries to play the frames as they arrive.
- int min_playout_delay_ms_ RTC_GUARDED_BY(crit_sect_);
- int max_playout_delay_ms_ RTC_GUARDED_BY(crit_sect_);
- int jitter_delay_ms_ RTC_GUARDED_BY(crit_sect_);
- int current_delay_ms_ RTC_GUARDED_BY(crit_sect_);
- uint32_t prev_frame_timestamp_ RTC_GUARDED_BY(crit_sect_);
- absl::optional<TimingFrameInfo> timing_frame_info_ RTC_GUARDED_BY(crit_sect_);
- size_t num_decoded_frames_ RTC_GUARDED_BY(crit_sect_);
+ int min_playout_delay_ms_ RTC_GUARDED_BY(mutex_);
+ int max_playout_delay_ms_ RTC_GUARDED_BY(mutex_);
+ int jitter_delay_ms_ RTC_GUARDED_BY(mutex_);
+ int current_delay_ms_ RTC_GUARDED_BY(mutex_);
+ uint32_t prev_frame_timestamp_ RTC_GUARDED_BY(mutex_);
+ absl::optional<TimingFrameInfo> timing_frame_info_ RTC_GUARDED_BY(mutex_);
+ size_t num_decoded_frames_ RTC_GUARDED_BY(mutex_);
};
} // namespace webrtc
diff --git a/modules/video_coding/video_coding_impl.h b/modules/video_coding/video_coding_impl.h
index eaab639dbf..440d1998bc 100644
--- a/modules/video_coding/video_coding_impl.h
+++ b/modules/video_coding/video_coding_impl.h
@@ -24,6 +24,7 @@
#include "modules/video_coding/receiver.h"
#include "modules/video_coding/timing.h"
#include "rtc_base/one_time_event.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"
@@ -100,7 +101,7 @@ class VideoReceiver : public Module {
rtc::ThreadChecker decoder_thread_checker_;
rtc::ThreadChecker module_thread_checker_;
Clock* const clock_;
- rtc::CriticalSection process_crit_;
+ Mutex process_mutex_;
VCMTiming* _timing;
VCMReceiver _receiver;
VCMDecodedFrameCallback _decodedFrameCallback;
@@ -111,8 +112,8 @@ class VideoReceiver : public Module {
VCMPacketRequestCallback* _packetRequestCallback;
// Used on both the module and decoder thread.
- bool _scheduleKeyRequest RTC_GUARDED_BY(process_crit_);
- bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_crit_);
+ bool _scheduleKeyRequest RTC_GUARDED_BY(process_mutex_);
+ bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_mutex_);
// Modified on the construction thread while not attached to the process
// thread. Once attached to the process thread, its value is only read
diff --git a/modules/video_coding/video_receiver.cc b/modules/video_coding/video_receiver.cc
index a817293f2f..a227a8c337 100644
--- a/modules/video_coding/video_receiver.cc
+++ b/modules/video_coding/video_receiver.cc
@@ -31,7 +31,6 @@
#include "modules/video_coding/timing.h"
#include "modules/video_coding/video_coding_impl.h"
#include "rtc_base/checks.h"
-#include "rtc_base/critical_section.h"
#include "rtc_base/location.h"
#include "rtc_base/logging.h"
#include "rtc_base/one_time_event.h"
@@ -71,7 +70,7 @@ void VideoReceiver::Process() {
_keyRequestTimer.Processed();
bool request_key_frame = _frameTypeCallback != nullptr;
if (request_key_frame) {
- rtc::CritScope cs(&process_crit_);
+ MutexLock lock(&process_mutex_);
request_key_frame = _scheduleKeyRequest;
}
if (request_key_frame)
@@ -94,7 +93,7 @@ void VideoReceiver::Process() {
ret = RequestKeyFrame();
}
if (ret == VCM_OK && !nackList.empty()) {
- rtc::CritScope cs(&process_crit_);
+ MutexLock lock(&process_mutex_);
if (_packetRequestCallback != nullptr) {
_packetRequestCallback->ResendPackets(&nackList[0], nackList.size());
}
@@ -183,7 +182,7 @@ int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
bool drop_frame = false;
{
- rtc::CritScope cs(&process_crit_);
+ MutexLock lock(&process_mutex_);
if (drop_frames_until_keyframe_) {
// Still getting delta frames, schedule another keyframe request as if
// decode failed.
@@ -229,7 +228,7 @@ int32_t VideoReceiver::RequestKeyFrame() {
if (ret < 0) {
return ret;
}
- rtc::CritScope cs(&process_crit_);
+ MutexLock lock(&process_mutex_);
_scheduleKeyRequest = false;
} else {
return VCM_MISSING_CALLBACK;
@@ -291,7 +290,7 @@ int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
// request scheduling to throttle the requests.
if (ret == VCM_FLUSH_INDICATOR) {
{
- rtc::CritScope cs(&process_crit_);
+ MutexLock lock(&process_mutex_);
drop_frames_until_keyframe_ = true;
}
RequestKeyFrame();