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}
This commit is contained in:
Markus Handell
2020-07-07 12:17:12 +02:00
committed by Commit Bot
parent fb6f975401
commit 6deec38ede
23 changed files with 190 additions and 191 deletions

View File

@ -280,6 +280,7 @@ rtc_library("video_coding_legacy") {
"../../rtc_base:logging", "../../rtc_base:logging",
"../../rtc_base:rtc_base_approved", "../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_event", "../../rtc_base:rtc_event",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:sequence_checker", "../../rtc_base/synchronization:sequence_checker",
"../../system_wrappers", "../../system_wrappers",
"../rtp_rtcp:rtp_rtcp_format", "../rtp_rtcp:rtp_rtcp_format",
@ -437,6 +438,7 @@ rtc_library("webrtc_multiplex") {
"../../media:rtc_media_base", "../../media:rtc_media_base",
"../../rtc_base", "../../rtc_base",
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base/synchronization:mutex",
"../rtp_rtcp:rtp_rtcp_format", "../rtp_rtcp:rtp_rtcp_format",
] ]
} }
@ -572,6 +574,7 @@ rtc_library("webrtc_vp9") {
"../../rtc_base", "../../rtc_base",
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base/experiments:rate_control_settings", "../../rtc_base/experiments:rate_control_settings",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers:field_trial", "../../system_wrappers:field_trial",
"../rtp_rtcp:rtp_rtcp_format", "../rtp_rtcp:rtp_rtcp_format",
] ]
@ -707,6 +710,7 @@ if (rtc_include_tests) {
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base:rtc_base_approved", "../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_task_queue", "../../rtc_base:rtc_task_queue",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:sequence_checker", "../../rtc_base/synchronization:sequence_checker",
"../../rtc_base/task_utils:to_queued_task", "../../rtc_base/task_utils:to_queued_task",
"../../test:test_support", "../../test:test_support",
@ -1001,6 +1005,7 @@ if (rtc_include_tests) {
"../../rtc_base:rtc_task_queue", "../../rtc_base:rtc_task_queue",
"../../rtc_base:task_queue_for_test", "../../rtc_base:task_queue_for_test",
"../../rtc_base/experiments:jitter_upper_bound_experiment", "../../rtc_base/experiments:jitter_upper_bound_experiment",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers", "../../system_wrappers",
"../../system_wrappers:field_trial", "../../system_wrappers:field_trial",
"../../system_wrappers:metrics", "../../system_wrappers:metrics",

View File

@ -21,7 +21,7 @@
#include "api/video_codecs/video_encoder_factory.h" #include "api/video_codecs/video_encoder_factory.h"
#include "modules/video_coding/codecs/multiplex/multiplex_encoded_image_packer.h" #include "modules/video_coding/codecs/multiplex/multiplex_encoded_image_packer.h"
#include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
namespace webrtc { namespace webrtc {
@ -71,7 +71,7 @@ class MultiplexEncoderAdapter : public VideoEncoder {
EncodedImageCallback* encoded_complete_callback_; EncodedImageCallback* encoded_complete_callback_;
std::map<uint32_t /* timestamp */, MultiplexImage> stashed_images_ std::map<uint32_t /* timestamp */, MultiplexImage> stashed_images_
RTC_GUARDED_BY(crit_); RTC_GUARDED_BY(mutex_);
uint16_t picture_index_ = 0; uint16_t picture_index_ = 0;
std::vector<uint8_t> multiplex_dummy_planes_; std::vector<uint8_t> multiplex_dummy_planes_;
@ -79,7 +79,7 @@ class MultiplexEncoderAdapter : public VideoEncoder {
int key_frame_interval_; int key_frame_interval_;
EncodedImage combined_image_; EncodedImage combined_image_;
rtc::CriticalSection crit_; Mutex mutex_;
const bool supports_augmented_data_; const bool supports_augmented_data_;
int augmenting_data_size_ = 0; int augmenting_data_size_ = 0;

View File

@ -180,7 +180,7 @@ int MultiplexEncoderAdapter::Encode(
} }
{ {
rtc::CritScope cs(&crit_); MutexLock lock(&mutex_);
stashed_images_.emplace( stashed_images_.emplace(
std::piecewise_construct, std::piecewise_construct,
std::forward_as_tuple(input_image.timestamp()), std::forward_as_tuple(input_image.timestamp()),
@ -273,7 +273,7 @@ int MultiplexEncoderAdapter::Release() {
} }
encoders_.clear(); encoders_.clear();
adapter_callbacks_.clear(); adapter_callbacks_.clear();
rtc::CritScope cs(&crit_); MutexLock lock(&mutex_);
stashed_images_.clear(); stashed_images_.clear();
return WEBRTC_VIDEO_CODEC_OK; return WEBRTC_VIDEO_CODEC_OK;
@ -298,7 +298,7 @@ EncodedImageCallback::Result MultiplexEncoderAdapter::OnEncodedImage(
// If we don't already own the buffer, make a copy. // If we don't already own the buffer, make a copy.
image_component.encoded_image.Retain(); image_component.encoded_image.Retain();
rtc::CritScope cs(&crit_); MutexLock lock(&mutex_);
const auto& stashed_image_itr = const auto& stashed_image_itr =
stashed_images_.find(encodedImage.Timestamp()); stashed_images_.find(encodedImage.Timestamp());
const auto& stashed_image_next_itr = std::next(stashed_image_itr, 1); const auto& stashed_image_next_itr = std::next(stashed_image_itr, 1);

View File

@ -37,7 +37,7 @@ VideoCodecUnitTest::FakeEncodeCompleteCallback::OnEncodedImage(
const EncodedImage& frame, const EncodedImage& frame,
const CodecSpecificInfo* codec_specific_info, const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) { const RTPFragmentationHeader* fragmentation) {
rtc::CritScope lock(&test_->encoded_frame_section_); MutexLock lock(&test_->encoded_frame_section_);
test_->encoded_frames_.push_back(frame); test_->encoded_frames_.push_back(frame);
RTC_DCHECK(codec_specific_info); RTC_DCHECK(codec_specific_info);
test_->codec_specific_infos_.push_back(*codec_specific_info); test_->codec_specific_infos_.push_back(*codec_specific_info);
@ -58,7 +58,7 @@ void VideoCodecUnitTest::FakeDecodeCompleteCallback::Decoded(
VideoFrame& frame, VideoFrame& frame,
absl::optional<int32_t> decode_time_ms, absl::optional<int32_t> decode_time_ms,
absl::optional<uint8_t> qp) { 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_frame_.emplace(frame);
test_->decoded_qp_ = qp; test_->decoded_qp_ = qp;
test_->decoded_frame_event_.Set(); test_->decoded_frame_event_.Set();
@ -126,7 +126,7 @@ bool VideoCodecUnitTest::WaitForEncodedFrame(
} }
void VideoCodecUnitTest::SetWaitForEncodedFramesThreshold(size_t num_frames) { 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; wait_for_encoded_frames_threshold_ = num_frames;
} }
@ -136,7 +136,7 @@ bool VideoCodecUnitTest::WaitForEncodedFrames(
EXPECT_TRUE(encoded_frame_event_.Wait(kEncodeTimeoutMs)) EXPECT_TRUE(encoded_frame_event_.Wait(kEncodeTimeoutMs))
<< "Timed out while waiting for encoded frame."; << "Timed out while waiting for encoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames. // 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(encoded_frames_.empty());
EXPECT_FALSE(codec_specific_infos_.empty()); EXPECT_FALSE(codec_specific_infos_.empty());
EXPECT_EQ(encoded_frames_.size(), codec_specific_infos_.size()); 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); bool ret = decoded_frame_event_.Wait(kDecodeTimeoutMs);
EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame."; EXPECT_TRUE(ret) << "Timed out while waiting for a decoded frame.";
// This becomes unsafe if there are multiple threads waiting for frames. // 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_); EXPECT_TRUE(decoded_frame_);
if (decoded_frame_) { if (decoded_frame_) {
frame->reset(new VideoFrame(std::move(*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() { size_t VideoCodecUnitTest::GetNumEncodedFrames() {
rtc::CritScope lock(&encoded_frame_section_); MutexLock lock(&encoded_frame_section_);
return encoded_frames_.size(); return encoded_frames_.size();
} }

View File

@ -20,8 +20,8 @@
#include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/utility/vp8_header_parser.h" #include "modules/video_coding/utility/vp8_header_parser.h"
#include "modules/video_coding/utility/vp9_uncompressed_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/event.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -108,7 +108,7 @@ class VideoCodecUnitTest : public ::testing::Test {
FakeDecodeCompleteCallback decode_complete_callback_; FakeDecodeCompleteCallback decode_complete_callback_;
rtc::Event encoded_frame_event_; rtc::Event encoded_frame_event_;
rtc::CriticalSection encoded_frame_section_; Mutex encoded_frame_section_;
size_t wait_for_encoded_frames_threshold_; size_t wait_for_encoded_frames_threshold_;
std::vector<EncodedImage> encoded_frames_ std::vector<EncodedImage> encoded_frames_
RTC_GUARDED_BY(encoded_frame_section_); RTC_GUARDED_BY(encoded_frame_section_);
@ -116,7 +116,7 @@ class VideoCodecUnitTest : public ::testing::Test {
RTC_GUARDED_BY(encoded_frame_section_); RTC_GUARDED_BY(encoded_frame_section_);
rtc::Event decoded_frame_event_; rtc::Event decoded_frame_event_;
rtc::CriticalSection decoded_frame_section_; Mutex decoded_frame_section_;
absl::optional<VideoFrame> decoded_frame_ absl::optional<VideoFrame> decoded_frame_
RTC_GUARDED_BY(decoded_frame_section_); RTC_GUARDED_BY(decoded_frame_section_);
absl::optional<uint8_t> decoded_qp_ RTC_GUARDED_BY(decoded_frame_section_); absl::optional<uint8_t> decoded_qp_ RTC_GUARDED_BY(decoded_frame_section_);

View File

@ -58,7 +58,7 @@ Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) {
RTC_DCHECK_GT(min_size, 0); RTC_DCHECK_GT(min_size, 0);
rtc::scoped_refptr<Vp9FrameBuffer> available_buffer = nullptr; rtc::scoped_refptr<Vp9FrameBuffer> available_buffer = nullptr;
{ {
rtc::CritScope cs(&buffers_lock_); MutexLock lock(&buffers_lock_);
// Do we have a buffer we can recycle? // Do we have a buffer we can recycle?
for (const auto& buffer : allocated_buffers_) { for (const auto& buffer : allocated_buffers_) {
if (buffer->HasOneRef()) { if (buffer->HasOneRef()) {
@ -91,7 +91,7 @@ Vp9FrameBufferPool::GetFrameBuffer(size_t min_size) {
int Vp9FrameBufferPool::GetNumBuffersInUse() const { int Vp9FrameBufferPool::GetNumBuffersInUse() const {
int num_buffers_in_use = 0; int num_buffers_in_use = 0;
rtc::CritScope cs(&buffers_lock_); MutexLock lock(&buffers_lock_);
for (const auto& buffer : allocated_buffers_) { for (const auto& buffer : allocated_buffers_) {
if (!buffer->HasOneRef()) if (!buffer->HasOneRef())
++num_buffers_in_use; ++num_buffers_in_use;
@ -100,7 +100,7 @@ int Vp9FrameBufferPool::GetNumBuffersInUse() const {
} }
bool Vp9FrameBufferPool::Resize(size_t max_number_of_buffers) { bool Vp9FrameBufferPool::Resize(size_t max_number_of_buffers) {
rtc::CritScope cs(&buffers_lock_); MutexLock lock(&buffers_lock_);
size_t used_buffers_count = 0; size_t used_buffers_count = 0;
for (const auto& buffer : allocated_buffers_) { for (const auto& buffer : allocated_buffers_) {
// If the buffer is in use, the ref count will be >= 2, one from the list we // 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() { void Vp9FrameBufferPool::ClearPool() {
rtc::CritScope cs(&buffers_lock_); MutexLock lock(&buffers_lock_);
allocated_buffers_.clear(); allocated_buffers_.clear();
} }

View File

@ -18,8 +18,8 @@
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/ref_count.h" #include "rtc_base/ref_count.h"
#include "rtc_base/synchronization/mutex.h"
struct vpx_codec_ctx; struct vpx_codec_ctx;
struct vpx_codec_frame_buffer; struct vpx_codec_frame_buffer;
@ -119,7 +119,7 @@ class Vp9FrameBufferPool {
private: private:
// Protects |allocated_buffers_|. // Protects |allocated_buffers_|.
rtc::CriticalSection buffers_lock_; mutable Mutex buffers_lock_;
// All buffers, in use or ready to be recycled. // All buffers, in use or ready to be recycled.
std::vector<rtc::scoped_refptr<Vp9FrameBuffer>> allocated_buffers_ std::vector<rtc::scoped_refptr<Vp9FrameBuffer>> allocated_buffers_
RTC_GUARDED_BY(buffers_lock_); RTC_GUARDED_BY(buffers_lock_);

View File

@ -26,6 +26,7 @@ rtc_library("nack_module") {
"../../../rtc_base:macromagic", "../../../rtc_base:macromagic",
"../../../rtc_base:rtc_numerics", "../../../rtc_base:rtc_numerics",
"../../../rtc_base/experiments:field_trial_parser", "../../../rtc_base/experiments:field_trial_parser",
"../../../rtc_base/synchronization:mutex",
"../../../system_wrappers", "../../../system_wrappers",
"../../../system_wrappers:field_trial", "../../../system_wrappers:field_trial",
"../../utility", "../../utility",

View File

@ -115,7 +115,7 @@ int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num,
int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num, int DEPRECATED_NackModule::OnReceivedPacket(uint16_t seq_num,
bool is_keyframe, bool is_keyframe,
bool is_recovered) { bool is_recovered) {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
// TODO(philipel): When the packet includes information whether it is // TODO(philipel): When the packet includes information whether it is
// retransmitted or not, use that value instead. For // retransmitted or not, use that value instead. For
// now set it to true, which will cause the reordering // 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) { 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)); nack_list_.erase(nack_list_.begin(), nack_list_.lower_bound(seq_num));
keyframe_list_.erase(keyframe_list_.begin(), keyframe_list_.erase(keyframe_list_.begin(),
keyframe_list_.lower_bound(seq_num)); 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) { void DEPRECATED_NackModule::UpdateRtt(int64_t rtt_ms) {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
rtt_ms_ = rtt_ms; rtt_ms_ = rtt_ms;
} }
void DEPRECATED_NackModule::Clear() { void DEPRECATED_NackModule::Clear() {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
nack_list_.clear(); nack_list_.clear();
keyframe_list_.clear(); keyframe_list_.clear();
recovered_list_.clear(); recovered_list_.clear();
@ -213,7 +213,7 @@ void DEPRECATED_NackModule::Process() {
if (nack_sender_) { if (nack_sender_) {
std::vector<uint16_t> nack_batch; std::vector<uint16_t> nack_batch;
{ {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
nack_batch = GetNackBatch(kTimeOnly); nack_batch = GetNackBatch(kTimeOnly);
} }

View File

@ -21,9 +21,9 @@
#include "modules/include/module.h" #include "modules/include/module.h"
#include "modules/include/module_common_types.h" #include "modules/include/module_common_types.h"
#include "modules/video_coding/histogram.h" #include "modules/video_coding/histogram.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecation.h" #include "rtc_base/deprecation.h"
#include "rtc_base/numerics/sequence_number_util.h" #include "rtc_base/numerics/sequence_number_util.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.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) 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 // Removes packets from the nack list until the next keyframe. Returns true
// if packets were removed. // 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) std::vector<uint16_t> GetNackBatch(NackFilterOptions options)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Update the reordering distribution. // Update the reordering distribution.
void UpdateReorderingStatistics(uint16_t seq_num) 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 // Returns how many packets we have to wait in order to receive the packet
// with probability |probabilty| or higher. // with probability |probabilty| or higher.
int WaitNumberOfPackets(float probability) const int WaitNumberOfPackets(float probability) const
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
rtc::CriticalSection crit_; Mutex mutex_;
Clock* const clock_; Clock* const clock_;
NackSender* const nack_sender_; NackSender* const nack_sender_;
KeyFrameRequestSender* const keyframe_request_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 // known thread (e.g. see |initialized_|). Those probably do not need
// synchronized access. // synchronized access.
std::map<uint16_t, NackInfo, DescendingSeqNumComp<uint16_t>> nack_list_ 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_ 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_ std::set<uint16_t, DescendingSeqNumComp<uint16_t>> recovered_list_
RTC_GUARDED_BY(crit_); RTC_GUARDED_BY(mutex_);
video_coding::Histogram reordering_histogram_ RTC_GUARDED_BY(crit_); video_coding::Histogram reordering_histogram_ RTC_GUARDED_BY(mutex_);
bool initialized_ RTC_GUARDED_BY(crit_); bool initialized_ RTC_GUARDED_BY(mutex_);
int64_t rtt_ms_ RTC_GUARDED_BY(crit_); int64_t rtt_ms_ RTC_GUARDED_BY(mutex_);
uint16_t newest_seq_num_ RTC_GUARDED_BY(crit_); uint16_t newest_seq_num_ RTC_GUARDED_BY(mutex_);
// Only touched on the process thread. // Only touched on the process thread.
int64_t next_process_time_ms_; int64_t next_process_time_ms_;

View File

@ -20,7 +20,6 @@
#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/field_trial.h"
namespace webrtc { namespace webrtc {
using rtc::CritScope;
const float kProtectionOverheadRateThreshold = 0.5; const float kProtectionOverheadRateThreshold = 0.5;
@ -54,7 +53,7 @@ void FecControllerDefault::SetEncodingData(size_t width,
size_t height, size_t height,
size_t num_temporal_layers, size_t num_temporal_layers,
size_t max_payload_size) { size_t max_payload_size) {
CritScope lock(&crit_sect_); MutexLock lock(&mutex_);
loss_prot_logic_->UpdateFrameSize(width, height); loss_prot_logic_->UpdateFrameSize(width, height);
loss_prot_logic_->UpdateNumLayers(num_temporal_layers); loss_prot_logic_->UpdateNumLayers(num_temporal_layers);
max_payload_size_ = max_payload_size; max_payload_size_ = max_payload_size;
@ -94,7 +93,7 @@ uint32_t FecControllerDefault::UpdateFecRates(
FecProtectionParams delta_fec_params; FecProtectionParams delta_fec_params;
FecProtectionParams key_fec_params; FecProtectionParams key_fec_params;
{ {
CritScope lock(&crit_sect_); MutexLock lock(&mutex_);
loss_prot_logic_->UpdateBitRate(target_bitrate_kbps); loss_prot_logic_->UpdateBitRate(target_bitrate_kbps);
loss_prot_logic_->UpdateRtt(round_trip_time_ms); loss_prot_logic_->UpdateRtt(round_trip_time_ms);
// Update frame rate for the loss protection logic class: frame rate should // 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) { } else if (enable_fec) {
method = media_optimization::kFec; method = media_optimization::kFec;
} }
CritScope lock(&crit_sect_); MutexLock lock(&mutex_);
loss_prot_logic_->SetMethod(method); loss_prot_logic_->SetMethod(method);
} }
@ -183,7 +182,7 @@ void FecControllerDefault::UpdateWithEncodedData(
const size_t encoded_image_length, const size_t encoded_image_length,
const VideoFrameType encoded_image_frametype) { const VideoFrameType encoded_image_frametype) {
const size_t encoded_length = encoded_image_length; const size_t encoded_length = encoded_image_length;
CritScope lock(&crit_sect_); MutexLock lock(&mutex_);
if (encoded_length > 0) { if (encoded_length > 0) {
const bool delta_frame = const bool delta_frame =
encoded_image_frametype != VideoFrameType::kVideoFrameKey; encoded_image_frametype != VideoFrameType::kVideoFrameKey;

View File

@ -20,7 +20,7 @@
#include "api/fec_controller.h" #include "api/fec_controller.h"
#include "modules/video_coding/media_opt_util.h" #include "modules/video_coding/media_opt_util.h"
#include "rtc_base/constructor_magic.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 "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
@ -54,10 +54,10 @@ class FecControllerDefault : public FecController {
enum { kBitrateAverageWinMs = 1000 }; enum { kBitrateAverageWinMs = 1000 };
Clock* const clock_; Clock* const clock_;
VCMProtectionCallback* protection_callback_; VCMProtectionCallback* protection_callback_;
rtc::CriticalSection crit_sect_; Mutex mutex_;
std::unique_ptr<media_optimization::VCMLossProtectionLogic> loss_prot_logic_ std::unique_ptr<media_optimization::VCMLossProtectionLogic> loss_prot_logic_
RTC_GUARDED_BY(crit_sect_); RTC_GUARDED_BY(mutex_);
size_t max_payload_size_ RTC_GUARDED_BY(crit_sect_); size_t max_payload_size_ RTC_GUARDED_BY(mutex_);
RTC_DISALLOW_COPY_AND_ASSIGN(FecControllerDefault); RTC_DISALLOW_COPY_AND_ASSIGN(FecControllerDefault);
const float overhead_threshold_; const float overhead_threshold_;
}; };

View File

@ -82,7 +82,7 @@ void FrameBuffer::NextFrame(
int64_t latest_return_time_ms = int64_t latest_return_time_ms =
clock_->TimeInMilliseconds() + max_wait_time_ms; clock_->TimeInMilliseconds() + max_wait_time_ms;
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
if (stopped_) { if (stopped_) {
return; return;
} }
@ -102,7 +102,7 @@ void FrameBuffer::StartWaitForNextFrameOnQueue() {
RTC_DCHECK_RUN_ON(&callback_checker_); RTC_DCHECK_RUN_ON(&callback_checker_);
// If this task has not been cancelled, we did not get any new frames // If this task has not been cancelled, we did not get any new frames
// while waiting. Continue with frame delivery. // while waiting. Continue with frame delivery.
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
if (!frames_to_decode_.empty()) { if (!frames_to_decode_.empty()) {
// We have frames, deliver! // We have frames, deliver!
frame_handler_(absl::WrapUnique(GetNextFrame()), kFrameFound); frame_handler_(absl::WrapUnique(GetNextFrame()), kFrameFound);
@ -329,19 +329,19 @@ bool FrameBuffer::HasBadRenderTiming(const EncodedFrame& frame,
void FrameBuffer::SetProtectionMode(VCMVideoProtection mode) { void FrameBuffer::SetProtectionMode(VCMVideoProtection mode) {
TRACE_EVENT0("webrtc", "FrameBuffer::SetProtectionMode"); TRACE_EVENT0("webrtc", "FrameBuffer::SetProtectionMode");
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
protection_mode_ = mode; protection_mode_ = mode;
} }
void FrameBuffer::Start() { void FrameBuffer::Start() {
TRACE_EVENT0("webrtc", "FrameBuffer::Start"); TRACE_EVENT0("webrtc", "FrameBuffer::Start");
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
stopped_ = false; stopped_ = false;
} }
void FrameBuffer::Stop() { void FrameBuffer::Stop() {
TRACE_EVENT0("webrtc", "FrameBuffer::Stop"); TRACE_EVENT0("webrtc", "FrameBuffer::Stop");
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
if (stopped_) if (stopped_)
return; return;
stopped_ = true; stopped_ = true;
@ -350,12 +350,12 @@ void FrameBuffer::Stop() {
} }
void FrameBuffer::Clear() { void FrameBuffer::Clear() {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
ClearFramesAndHistory(); ClearFramesAndHistory();
} }
void FrameBuffer::UpdateRtt(int64_t rtt_ms) { void FrameBuffer::UpdateRtt(int64_t rtt_ms) {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
jitter_estimator_.UpdateRtt(rtt_ms); jitter_estimator_.UpdateRtt(rtt_ms);
} }
@ -431,7 +431,7 @@ int64_t FrameBuffer::InsertFrame(std::unique_ptr<EncodedFrame> frame) {
TRACE_EVENT0("webrtc", "FrameBuffer::InsertFrame"); TRACE_EVENT0("webrtc", "FrameBuffer::InsertFrame");
RTC_DCHECK(frame); RTC_DCHECK(frame);
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
const VideoLayerFrameId& id = frame->id; const VideoLayerFrameId& id = frame->id;
int64_t last_continuous_picture_id = int64_t last_continuous_picture_id =
@ -529,7 +529,7 @@ int64_t FrameBuffer::InsertFrame(std::unique_ptr<EncodedFrame> frame) {
// to return from NextFrame. // to return from NextFrame.
if (callback_queue_) { if (callback_queue_) {
callback_queue_->PostTask([this] { callback_queue_->PostTask([this] {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
if (!callback_task_.Running()) if (!callback_task_.Running())
return; return;
RTC_CHECK(frame_handler_); RTC_CHECK(frame_handler_);

View File

@ -24,10 +24,10 @@
#include "modules/video_coding/jitter_estimator.h" #include "modules/video_coding/jitter_estimator.h"
#include "modules/video_coding/utility/decoded_frames_history.h" #include "modules/video_coding/utility/decoded_frames_history.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/experiments/rtt_mult_experiment.h" #include "rtc_base/experiments/rtt_mult_experiment.h"
#include "rtc_base/numerics/sequence_number_util.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/synchronization/sequence_checker.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/task_utils/repeating_task.h" #include "rtc_base/task_utils/repeating_task.h"
@ -118,40 +118,40 @@ class FrameBuffer {
// Check that the references of |frame| are valid. // Check that the references of |frame| are valid.
bool ValidReferences(const EncodedFrame& frame) const; bool ValidReferences(const EncodedFrame& frame) const;
int64_t FindNextFrame(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); int64_t FindNextFrame(int64_t now_ms) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
EncodedFrame* GetNextFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); EncodedFrame* GetNextFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void StartWaitForNextFrameOnQueue() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); void StartWaitForNextFrameOnQueue() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void CancelCallback() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); void CancelCallback() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Update all directly dependent and indirectly dependent frames and mark // Update all directly dependent and indirectly dependent frames and mark
// them as continuous if all their references has been fulfilled. // them as continuous if all their references has been fulfilled.
void PropagateContinuity(FrameMap::iterator start) 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. // Marks the frame as decoded and updates all directly dependent frames.
void PropagateDecodability(const FrameInfo& info) 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 // Update the corresponding FrameInfo of |frame| and all FrameInfos that
// |frame| references. // |frame| references.
// Return false if |frame| will never be decodable, true otherwise. // Return false if |frame| will never be decodable, true otherwise.
bool UpdateFrameInfoWithIncomingFrame(const EncodedFrame& frame, bool UpdateFrameInfoWithIncomingFrame(const EncodedFrame& frame,
FrameMap::iterator info) 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. // Checks if the superframe, which current frame belongs to, is complete.
bool IsCompleteSuperFrame(const EncodedFrame& frame) bool IsCompleteSuperFrame(const EncodedFrame& frame)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool HasBadRenderTiming(const EncodedFrame& frame, int64_t now_ms) 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 // The cleaner solution would be to have the NextFrame function return a
// vector of frames, but until the decoding pipeline can support decoding // vector of frames, but until the decoding pipeline can support decoding
@ -164,29 +164,29 @@ class FrameBuffer {
SequenceChecker callback_checker_; SequenceChecker callback_checker_;
// Stores only undecoded frames. // Stores only undecoded frames.
FrameMap frames_ RTC_GUARDED_BY(crit_); FrameMap frames_ RTC_GUARDED_BY(mutex_);
DecodedFramesHistory decoded_frames_history_ RTC_GUARDED_BY(crit_); DecodedFramesHistory decoded_frames_history_ RTC_GUARDED_BY(mutex_);
rtc::CriticalSection crit_; Mutex mutex_;
Clock* const clock_; Clock* const clock_;
rtc::TaskQueue* callback_queue_ RTC_GUARDED_BY(crit_); rtc::TaskQueue* callback_queue_ RTC_GUARDED_BY(mutex_);
RepeatingTaskHandle callback_task_ RTC_GUARDED_BY(crit_); RepeatingTaskHandle callback_task_ RTC_GUARDED_BY(mutex_);
std::function<void(std::unique_ptr<EncodedFrame>, ReturnReason)> std::function<void(std::unique_ptr<EncodedFrame>, ReturnReason)>
frame_handler_ RTC_GUARDED_BY(crit_); frame_handler_ RTC_GUARDED_BY(mutex_);
int64_t latest_return_time_ms_ RTC_GUARDED_BY(crit_); int64_t latest_return_time_ms_ RTC_GUARDED_BY(mutex_);
bool keyframe_required_ RTC_GUARDED_BY(crit_); bool keyframe_required_ RTC_GUARDED_BY(mutex_);
VCMJitterEstimator jitter_estimator_ RTC_GUARDED_BY(crit_); VCMJitterEstimator jitter_estimator_ RTC_GUARDED_BY(mutex_);
VCMTiming* const timing_ RTC_GUARDED_BY(crit_); VCMTiming* const timing_ RTC_GUARDED_BY(mutex_);
VCMInterFrameDelay inter_frame_delay_ RTC_GUARDED_BY(crit_); VCMInterFrameDelay inter_frame_delay_ RTC_GUARDED_BY(mutex_);
absl::optional<VideoLayerFrameId> last_continuous_frame_ absl::optional<VideoLayerFrameId> last_continuous_frame_
RTC_GUARDED_BY(crit_); RTC_GUARDED_BY(mutex_);
std::vector<FrameMap::iterator> frames_to_decode_ RTC_GUARDED_BY(crit_); std::vector<FrameMap::iterator> frames_to_decode_ RTC_GUARDED_BY(mutex_);
bool stopped_ RTC_GUARDED_BY(crit_); bool stopped_ RTC_GUARDED_BY(mutex_);
VCMVideoProtection protection_mode_ RTC_GUARDED_BY(crit_); VCMVideoProtection protection_mode_ RTC_GUARDED_BY(mutex_);
VCMReceiveStatisticsCallback* const stats_callback_; 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_; const bool add_rtt_to_playout_delay_;

View File

@ -86,7 +86,7 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
// callbacks from one call to Decode(). // callbacks from one call to Decode().
VCMFrameInformation* frameInfo; VCMFrameInformation* frameInfo;
{ {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
frameInfo = _timestampMap.Pop(decodedImage.timestamp()); frameInfo = _timestampMap.Pop(decodedImage.timestamp());
} }
@ -172,12 +172,12 @@ void VCMDecodedFrameCallback::OnDecoderImplementationName(
void VCMDecodedFrameCallback::Map(uint32_t timestamp, void VCMDecodedFrameCallback::Map(uint32_t timestamp,
VCMFrameInformation* frameInfo) { VCMFrameInformation* frameInfo) {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
_timestampMap.Add(timestamp, frameInfo); _timestampMap.Add(timestamp, frameInfo);
} }
int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) { int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
if (_timestampMap.Pop(timestamp) == NULL) { if (_timestampMap.Pop(timestamp) == NULL) {
return VCM_GENERAL_ERROR; return VCM_GENERAL_ERROR;
} }

View File

@ -19,8 +19,8 @@
#include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/timestamp_map.h" #include "modules/video_coding/timestamp_map.h"
#include "modules/video_coding/timing.h" #include "modules/video_coding/timing.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/experiments/field_trial_parser.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
namespace webrtc { namespace webrtc {
@ -70,7 +70,7 @@ class VCMDecodedFrameCallback : public DecodedImageCallback {
// from the same thread, and therfore a lock is not required to access it. // from the same thread, and therfore a lock is not required to access it.
VCMReceiveCallback* _receiveCallback = nullptr; VCMReceiveCallback* _receiveCallback = nullptr;
VCMTiming* _timing; VCMTiming* _timing;
rtc::CriticalSection lock_; Mutex lock_;
VCMTimestampMap _timestampMap RTC_GUARDED_BY(lock_); VCMTimestampMap _timestampMap RTC_GUARDED_BY(lock_);
int64_t ntp_offset_; int64_t ntp_offset_;
// Set by the field trial WebRTC-SlowDownDecoder to simulate a slow decoder. // Set by the field trial WebRTC-SlowDownDecoder to simulate a slow decoder.

View File

@ -16,8 +16,8 @@
#include "api/task_queue/default_task_queue_factory.h" #include "api/task_queue/default_task_queue_factory.h"
#include "common_video/test/utilities.h" #include "common_video/test/utilities.h"
#include "modules/video_coding/timing.h" #include "modules/video_coding/timing.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "test/fake_decoder.h" #include "test/fake_decoder.h"
#include "test/gmock.h" #include "test/gmock.h"
@ -33,7 +33,7 @@ class ReceiveCallback : public VCMReceiveCallback {
int32_t decode_time_ms, int32_t decode_time_ms,
VideoContentType content_type) override { VideoContentType content_type) override {
{ {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
last_frame_ = videoFrame; last_frame_ = videoFrame;
} }
received_frame_event_.Set(); received_frame_event_.Set();
@ -41,13 +41,13 @@ class ReceiveCallback : public VCMReceiveCallback {
} }
absl::optional<VideoFrame> GetLastFrame() { absl::optional<VideoFrame> GetLastFrame() {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
return last_frame_; return last_frame_;
} }
absl::optional<VideoFrame> WaitForFrame(int64_t wait_ms) { absl::optional<VideoFrame> WaitForFrame(int64_t wait_ms) {
if (received_frame_event_.Wait(wait_ms)) { if (received_frame_event_.Wait(wait_ms)) {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
return last_frame_; return last_frame_;
} else { } else {
return absl::nullopt; return absl::nullopt;
@ -55,7 +55,7 @@ class ReceiveCallback : public VCMReceiveCallback {
} }
private: private:
rtc::CriticalSection lock_; Mutex lock_;
rtc::Event received_frame_event_; rtc::Event received_frame_event_;
absl::optional<VideoFrame> last_frame_ RTC_GUARDED_BY(lock_); absl::optional<VideoFrame> last_frame_ RTC_GUARDED_BY(lock_);
}; };

View File

@ -153,7 +153,7 @@ VCMJitterBuffer::~VCMJitterBuffer() {
} }
void VCMJitterBuffer::Start() { void VCMJitterBuffer::Start() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
running_ = true; running_ = true;
num_consecutive_old_packets_ = 0; num_consecutive_old_packets_ = 0;
@ -172,7 +172,7 @@ void VCMJitterBuffer::Start() {
} }
void VCMJitterBuffer::Stop() { void VCMJitterBuffer::Stop() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
running_ = false; running_ = false;
last_decoded_state_.Reset(); last_decoded_state_.Reset();
@ -181,12 +181,12 @@ void VCMJitterBuffer::Stop() {
} }
bool VCMJitterBuffer::Running() const { bool VCMJitterBuffer::Running() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return running_; return running_;
} }
void VCMJitterBuffer::Flush() { void VCMJitterBuffer::Flush() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
decodable_frames_.Reset(&free_frames_); decodable_frames_.Reset(&free_frames_);
incomplete_frames_.Reset(&free_frames_); incomplete_frames_.Reset(&free_frames_);
last_decoded_state_.Reset(); // TODO(mikhal): sync reset. last_decoded_state_.Reset(); // TODO(mikhal): sync reset.
@ -202,21 +202,20 @@ void VCMJitterBuffer::Flush() {
} }
int VCMJitterBuffer::num_packets() const { int VCMJitterBuffer::num_packets() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return num_packets_; return num_packets_;
} }
int VCMJitterBuffer::num_duplicated_packets() const { int VCMJitterBuffer::num_duplicated_packets() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return num_duplicated_packets_; return num_duplicated_packets_;
} }
// Returns immediately or a |max_wait_time_ms| ms event hang waiting for a // Returns immediately or a |max_wait_time_ms| ms event hang waiting for a
// complete frame, |max_wait_time_ms| decided by caller. // complete frame, |max_wait_time_ms| decided by caller.
VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) { VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
crit_sect_.Enter(); MutexLock lock(&mutex_);
if (!running_) { if (!running_) {
crit_sect_.Leave();
return nullptr; return nullptr;
} }
CleanUpOldOrEmptyFrames(); CleanUpOldOrEmptyFrames();
@ -227,14 +226,13 @@ VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
clock_->TimeInMilliseconds() + max_wait_time_ms; clock_->TimeInMilliseconds() + max_wait_time_ms;
int64_t wait_time_ms = max_wait_time_ms; int64_t wait_time_ms = max_wait_time_ms;
while (wait_time_ms > 0) { while (wait_time_ms > 0) {
crit_sect_.Leave(); mutex_.Unlock();
const EventTypeWrapper ret = const EventTypeWrapper ret =
frame_event_->Wait(static_cast<uint32_t>(wait_time_ms)); frame_event_->Wait(static_cast<uint32_t>(wait_time_ms));
crit_sect_.Enter(); mutex_.Lock();
if (ret == kEventSignaled) { if (ret == kEventSignaled) {
// Are we shutting down the jitter buffer? // Are we shutting down the jitter buffer?
if (!running_) { if (!running_) {
crit_sect_.Leave();
return nullptr; return nullptr;
} }
// Finding oldest frame ready for decoder. // Finding oldest frame ready for decoder.
@ -252,16 +250,13 @@ VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
} }
if (decodable_frames_.empty() || if (decodable_frames_.empty() ||
decodable_frames_.Front()->GetState() != kStateComplete) { decodable_frames_.Front()->GetState() != kStateComplete) {
crit_sect_.Leave();
return nullptr; return nullptr;
} }
VCMEncodedFrame* encoded_frame = decodable_frames_.Front(); return decodable_frames_.Front();
crit_sect_.Leave();
return encoded_frame;
} }
VCMEncodedFrame* VCMJitterBuffer::ExtractAndSetDecode(uint32_t timestamp) { VCMEncodedFrame* VCMJitterBuffer::ExtractAndSetDecode(uint32_t timestamp) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
if (!running_) { if (!running_) {
return NULL; return NULL;
} }
@ -313,7 +308,7 @@ VCMEncodedFrame* VCMJitterBuffer::ExtractAndSetDecode(uint32_t timestamp) {
// frames from within the jitter buffer. // frames from within the jitter buffer.
void VCMJitterBuffer::ReleaseFrame(VCMEncodedFrame* frame) { void VCMJitterBuffer::ReleaseFrame(VCMEncodedFrame* frame) {
RTC_CHECK(frame != nullptr); RTC_CHECK(frame != nullptr);
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
VCMFrameBuffer* frame_buffer = static_cast<VCMFrameBuffer*>(frame); VCMFrameBuffer* frame_buffer = static_cast<VCMFrameBuffer*>(frame);
RecycleFrameBuffer(frame_buffer); RecycleFrameBuffer(frame_buffer);
} }
@ -354,7 +349,7 @@ VCMFrameBufferEnum VCMJitterBuffer::GetFrame(const VCMPacket& packet,
int64_t VCMJitterBuffer::LastPacketTime(const VCMEncodedFrame* frame, int64_t VCMJitterBuffer::LastPacketTime(const VCMEncodedFrame* frame,
bool* retransmitted) const { bool* retransmitted) const {
assert(retransmitted); assert(retransmitted);
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
const VCMFrameBuffer* frame_buffer = const VCMFrameBuffer* frame_buffer =
static_cast<const VCMFrameBuffer*>(frame); static_cast<const VCMFrameBuffer*>(frame);
*retransmitted = (frame_buffer->GetNackCount() > 0); *retransmitted = (frame_buffer->GetNackCount() > 0);
@ -363,7 +358,7 @@ int64_t VCMJitterBuffer::LastPacketTime(const VCMEncodedFrame* frame,
VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet, VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet,
bool* retransmitted) { bool* retransmitted) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
++num_packets_; ++num_packets_;
// Does this packet belong to an old frame? // Does this packet belong to an old frame?
@ -577,7 +572,7 @@ void VCMJitterBuffer::FindAndInsertContinuousFramesWithState(
} }
uint32_t VCMJitterBuffer::EstimatedJitterMs() { uint32_t VCMJitterBuffer::EstimatedJitterMs() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
const double rtt_mult = 1.0f; const double rtt_mult = 1.0f;
return jitter_estimate_.GetJitterEstimate(rtt_mult, absl::nullopt); 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, void VCMJitterBuffer::SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack, int max_packet_age_to_nack,
int max_incomplete_time_ms) { int max_incomplete_time_ms) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
assert(max_packet_age_to_nack >= 0); assert(max_packet_age_to_nack >= 0);
assert(max_incomplete_time_ms_ >= 0); assert(max_incomplete_time_ms_ >= 0);
max_nack_list_size_ = max_nack_list_size; 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) { std::vector<uint16_t> VCMJitterBuffer::GetNackList(bool* request_key_frame) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
*request_key_frame = false; *request_key_frame = false;
if (last_decoded_state_.in_initial_state()) { if (last_decoded_state_.in_initial_state()) {
VCMFrameBuffer* next_frame = NextFrame(); 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() { void VCMJitterBuffer::CleanUpOldOrEmptyFrames() {
decodable_frames_.CleanUpOldOrEmptyFrames(&last_decoded_state_, decodable_frames_.CleanUpOldOrEmptyFrames(&last_decoded_state_,
&free_frames_); &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 { bool VCMJitterBuffer::IsPacketRetransmitted(const VCMPacket& packet) const {
return missing_sequence_numbers_.find(packet.seqNum) != return missing_sequence_numbers_.find(packet.seqNum) !=
missing_sequence_numbers_.end(); 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 // called with retransmitted frames, they must be filtered out before this
// function is called. // function is called.
void VCMJitterBuffer::UpdateJitterEstimate(const VCMJitterSample& sample, void VCMJitterBuffer::UpdateJitterEstimate(const VCMJitterSample& sample,
@ -856,7 +851,7 @@ void VCMJitterBuffer::UpdateJitterEstimate(const VCMJitterSample& sample,
sample.frame_size, incomplete_frame); 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 // called with retransmitted frames, they must be filtered out before this
// function is called. // function is called.
void VCMJitterBuffer::UpdateJitterEstimate(const VCMFrameBuffer& frame, void VCMJitterBuffer::UpdateJitterEstimate(const VCMFrameBuffer& frame,
@ -870,7 +865,7 @@ void VCMJitterBuffer::UpdateJitterEstimate(const VCMFrameBuffer& frame,
frame.size(), incomplete_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 // called with retransmitted frames, they must be filtered out before this
// function is called. // function is called.
void VCMJitterBuffer::UpdateJitterEstimate(int64_t latest_packet_time_ms, void VCMJitterBuffer::UpdateJitterEstimate(int64_t latest_packet_time_ms,

View File

@ -28,7 +28,7 @@
#include "modules/video_coding/jitter_buffer_common.h" #include "modules/video_coding/jitter_buffer_common.h"
#include "modules/video_coding/jitter_estimator.h" #include "modules/video_coding/jitter_estimator.h"
#include "rtc_base/constructor_magic.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 "rtc_base/thread_annotations.h"
namespace webrtc { namespace webrtc {
@ -143,66 +143,66 @@ class VCMJitterBuffer {
VCMFrameBufferEnum GetFrame(const VCMPacket& packet, VCMFrameBufferEnum GetFrame(const VCMPacket& packet,
VCMFrameBuffer** frame, VCMFrameBuffer** frame,
FrameList** frame_list) 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 // Returns true if |frame| is continuous in |decoding_state|, not taking
// decodable frames into account. // decodable frames into account.
bool IsContinuousInState(const VCMFrameBuffer& frame, bool IsContinuousInState(const VCMFrameBuffer& frame,
const VCMDecodingState& decoding_state) const 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 // Returns true if |frame| is continuous in the |last_decoded_state_|, taking
// all decodable frames into account. // all decodable frames into account.
bool IsContinuous(const VCMFrameBuffer& frame) const 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 // Looks for frames in |incomplete_frames_| which are continuous in the
// provided |decoded_state|. Starts the search from the timestamp of // provided |decoded_state|. Starts the search from the timestamp of
// |decoded_state|. // |decoded_state|.
void FindAndInsertContinuousFramesWithState( void FindAndInsertContinuousFramesWithState(
const VCMDecodingState& decoded_state) 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 // Looks for frames in |incomplete_frames_| which are continuous in
// |last_decoded_state_| taking all decodable frames into account. Starts // |last_decoded_state_| taking all decodable frames into account. Starts
// the search from |new_frame|. // the search from |new_frame|.
void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame) void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if the NACK list was updated to cover sequence numbers up to // 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 // |sequence_number|. If false a key frame is needed to get into a state where
// we can continue decoding. // we can continue decoding.
bool UpdateNackList(uint16_t sequence_number) bool UpdateNackList(uint16_t sequence_number)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool TooLargeNackList() const; bool TooLargeNackList() const;
// Returns true if the NACK list was reduced without problem. If false a key // 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. // 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 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 // 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 // list. If false, a key frame is needed to get into a state where we can
// continue decoding. // continue decoding.
bool HandleTooOldPackets(uint16_t latest_sequence_number) 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|. // Drops all packets in the NACK list up until |last_decoded_sequence_number|.
void DropPacketsFromNackList(uint16_t 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 // Gets an empty frame, creating a new frame if necessary (i.e. increases
// jitter buffer size). // 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 // Attempts to increase the size of the jitter buffer. Returns true on
// success, false otherwise. // 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 // Recycles oldest frames until a key frame is found. Used if jitter buffer is
// completely full. Returns true if a key frame was found. // 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. // Update rolling average of packets per frame.
void UpdateAveragePacketsPerFrame(int current_number_packets_); void UpdateAveragePacketsPerFrame(int current_number_packets_);
// Cleans the frame list in the JB from old/empty frames. // Cleans the frame list in the JB from old/empty frames.
// Should only be called prior to actual use. // 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. // Returns true if |packet| is likely to have been retransmitted.
bool IsPacketRetransmitted(const VCMPacket& packet) const; bool IsPacketRetransmitted(const VCMPacket& packet) const;
@ -217,35 +217,34 @@ class VCMJitterBuffer {
unsigned int frame_size, unsigned int frame_size,
bool incomplete_frame); bool incomplete_frame);
int NonContinuousOrIncompleteDuration() int NonContinuousOrIncompleteDuration() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const; uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const;
// Reset frame buffer and return it to free_frames_. // Reset frame buffer and return it to free_frames_.
void RecycleFrameBuffer(VCMFrameBuffer* frame) void RecycleFrameBuffer(VCMFrameBuffer* frame)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* clock_; Clock* clock_;
// If we are running (have started) or not. // If we are running (have started) or not.
bool running_; bool running_;
rtc::CriticalSection crit_sect_; mutable Mutex mutex_;
// Event to signal when we have a frame ready for decoder. // Event to signal when we have a frame ready for decoder.
std::unique_ptr<EventWrapper> frame_event_; std::unique_ptr<EventWrapper> frame_event_;
// Number of allocated frames. // Number of allocated frames.
int max_number_of_frames_; int max_number_of_frames_;
UnorderedFrameList free_frames_ RTC_GUARDED_BY(crit_sect_); UnorderedFrameList free_frames_ RTC_GUARDED_BY(mutex_);
FrameList decodable_frames_ RTC_GUARDED_BY(crit_sect_); FrameList decodable_frames_ RTC_GUARDED_BY(mutex_);
FrameList incomplete_frames_ RTC_GUARDED_BY(crit_sect_); FrameList incomplete_frames_ RTC_GUARDED_BY(mutex_);
VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(crit_sect_); VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(mutex_);
bool first_packet_since_reset_; bool first_packet_since_reset_;
// Number of packets in a row that have been too old. // Number of packets in a row that have been too old.
int num_consecutive_old_packets_; int num_consecutive_old_packets_;
// Number of packets received. // Number of packets received.
int num_packets_ RTC_GUARDED_BY(crit_sect_); int num_packets_ RTC_GUARDED_BY(mutex_);
// Number of duplicated packets received. // Number of duplicated packets received.
int num_duplicated_packets_ RTC_GUARDED_BY(crit_sect_); int num_duplicated_packets_ RTC_GUARDED_BY(mutex_);
// Jitter estimation. // Jitter estimation.
// Filter for estimating jitter. // Filter for estimating jitter.

View File

@ -47,7 +47,7 @@ VCMTiming::~VCMTiming() {
} }
void VCMTiming::Reset() { void VCMTiming::Reset() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
ts_extrapolator_->Reset(clock_->TimeInMilliseconds()); ts_extrapolator_->Reset(clock_->TimeInMilliseconds());
codec_timer_.reset(new VCMCodecTimer()); codec_timer_.reset(new VCMCodecTimer());
render_delay_ms_ = kDefaultRenderDelayMs; render_delay_ms_ = kDefaultRenderDelayMs;
@ -58,32 +58,32 @@ void VCMTiming::Reset() {
} }
void VCMTiming::set_render_delay(int render_delay_ms) { void VCMTiming::set_render_delay(int render_delay_ms) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
render_delay_ms_ = render_delay_ms; render_delay_ms_ = render_delay_ms;
} }
void VCMTiming::set_min_playout_delay(int min_playout_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; min_playout_delay_ms_ = min_playout_delay_ms;
} }
int VCMTiming::min_playout_delay() { int VCMTiming::min_playout_delay() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return min_playout_delay_ms_; return min_playout_delay_ms_;
} }
void VCMTiming::set_max_playout_delay(int max_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; max_playout_delay_ms_ = max_playout_delay_ms;
} }
int VCMTiming::max_playout_delay() { int VCMTiming::max_playout_delay() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return max_playout_delay_ms_; return max_playout_delay_ms_;
} }
void VCMTiming::SetJitterDelay(int jitter_delay_ms) { void VCMTiming::SetJitterDelay(int jitter_delay_ms) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
if (jitter_delay_ms != jitter_delay_ms_) { if (jitter_delay_ms != jitter_delay_ms_) {
jitter_delay_ms_ = jitter_delay_ms; jitter_delay_ms_ = jitter_delay_ms;
// When in initial state, set current delay to minimum delay. // 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) { void VCMTiming::UpdateCurrentDelay(uint32_t frame_timestamp) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
int target_delay_ms = TargetDelayInternal(); int target_delay_ms = TargetDelayInternal();
if (current_delay_ms_ == 0) { if (current_delay_ms_ == 0) {
@ -135,7 +135,7 @@ void VCMTiming::UpdateCurrentDelay(uint32_t frame_timestamp) {
void VCMTiming::UpdateCurrentDelay(int64_t render_time_ms, void VCMTiming::UpdateCurrentDelay(int64_t render_time_ms,
int64_t actual_decode_time_ms) { int64_t actual_decode_time_ms) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
uint32_t target_delay_ms = TargetDelayInternal(); uint32_t target_delay_ms = TargetDelayInternal();
int64_t delayed_ms = int64_t delayed_ms =
actual_decode_time_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) { 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); codec_timer_->AddTiming(decode_time_ms, now_ms);
assert(decode_time_ms >= 0); assert(decode_time_ms >= 0);
++num_decoded_frames_; ++num_decoded_frames_;
} }
void VCMTiming::IncomingTimestamp(uint32_t time_stamp, int64_t now_ms) { 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); ts_extrapolator_->Update(now_ms, time_stamp);
} }
int64_t VCMTiming::RenderTimeMs(uint32_t frame_timestamp, int64_t VCMTiming::RenderTimeMs(uint32_t frame_timestamp,
int64_t now_ms) const { int64_t now_ms) const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return RenderTimeMsInternal(frame_timestamp, now_ms); 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 VCMTiming::MaxWaitingTime(int64_t render_time_ms,
int64_t now_ms) const { int64_t now_ms) const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
const int64_t max_wait_time_ms = const int64_t max_wait_time_ms =
render_time_ms - now_ms - RequiredDecodeTimeMs() - render_delay_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 { int VCMTiming::TargetVideoDelay() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return TargetDelayInternal(); return TargetDelayInternal();
} }
@ -226,7 +226,7 @@ bool VCMTiming::GetTimings(int* max_decode_ms,
int* jitter_buffer_ms, int* jitter_buffer_ms,
int* min_playout_delay_ms, int* min_playout_delay_ms,
int* render_delay_ms) const { int* render_delay_ms) const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
*max_decode_ms = RequiredDecodeTimeMs(); *max_decode_ms = RequiredDecodeTimeMs();
*current_delay_ms = current_delay_ms_; *current_delay_ms = current_delay_ms_;
*target_delay_ms = TargetDelayInternal(); *target_delay_ms = TargetDelayInternal();
@ -237,12 +237,12 @@ bool VCMTiming::GetTimings(int* max_decode_ms,
} }
void VCMTiming::SetTimingFrameInfo(const TimingFrameInfo& info) { void VCMTiming::SetTimingFrameInfo(const TimingFrameInfo& info) {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
timing_frame_info_.emplace(info); timing_frame_info_.emplace(info);
} }
absl::optional<TimingFrameInfo> VCMTiming::GetTimingFrameInfo() { absl::optional<TimingFrameInfo> VCMTiming::GetTimingFrameInfo() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return timing_frame_info_; return timing_frame_info_;
} }

View File

@ -16,7 +16,7 @@
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/video/video_timing.h" #include "api/video/video_timing.h"
#include "modules/video_coding/codec_timer.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" #include "rtc_base/thread_annotations.h"
namespace webrtc { namespace webrtc {
@ -104,30 +104,30 @@ class VCMTiming {
enum { kDelayMaxChangeMsPerS = 100 }; enum { kDelayMaxChangeMsPerS = 100 };
protected: 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 int64_t RenderTimeMsInternal(uint32_t frame_timestamp, int64_t now_ms) const
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
int TargetDelayInternal() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); int TargetDelayInternal() const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
private: private:
rtc::CriticalSection crit_sect_; mutable Mutex mutex_;
Clock* const clock_; Clock* const clock_;
bool master_ RTC_GUARDED_BY(crit_sect_); bool master_ RTC_GUARDED_BY(mutex_);
TimestampExtrapolator* ts_extrapolator_ RTC_GUARDED_BY(crit_sect_); TimestampExtrapolator* ts_extrapolator_ RTC_GUARDED_BY(mutex_);
std::unique_ptr<VCMCodecTimer> codec_timer_ RTC_GUARDED_BY(crit_sect_); std::unique_ptr<VCMCodecTimer> codec_timer_ RTC_GUARDED_BY(mutex_);
int render_delay_ms_ RTC_GUARDED_BY(crit_sect_); int render_delay_ms_ RTC_GUARDED_BY(mutex_);
// Best-effort playout delay range for frames from capture to render. // Best-effort playout delay range for frames from capture to render.
// The receiver tries to keep the delay between |min_playout_delay_ms_| // The receiver tries to keep the delay between |min_playout_delay_ms_|
// and |max_playout_delay_ms_| taking the network jitter into account. // 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, // 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. // in which case the receiver tries to play the frames as they arrive.
int min_playout_delay_ms_ RTC_GUARDED_BY(crit_sect_); int min_playout_delay_ms_ RTC_GUARDED_BY(mutex_);
int max_playout_delay_ms_ RTC_GUARDED_BY(crit_sect_); int max_playout_delay_ms_ RTC_GUARDED_BY(mutex_);
int jitter_delay_ms_ RTC_GUARDED_BY(crit_sect_); int jitter_delay_ms_ RTC_GUARDED_BY(mutex_);
int current_delay_ms_ RTC_GUARDED_BY(crit_sect_); int current_delay_ms_ RTC_GUARDED_BY(mutex_);
uint32_t prev_frame_timestamp_ RTC_GUARDED_BY(crit_sect_); uint32_t prev_frame_timestamp_ RTC_GUARDED_BY(mutex_);
absl::optional<TimingFrameInfo> timing_frame_info_ RTC_GUARDED_BY(crit_sect_); absl::optional<TimingFrameInfo> timing_frame_info_ RTC_GUARDED_BY(mutex_);
size_t num_decoded_frames_ RTC_GUARDED_BY(crit_sect_); size_t num_decoded_frames_ RTC_GUARDED_BY(mutex_);
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -24,6 +24,7 @@
#include "modules/video_coding/receiver.h" #include "modules/video_coding/receiver.h"
#include "modules/video_coding/timing.h" #include "modules/video_coding/timing.h"
#include "rtc_base/one_time_event.h" #include "rtc_base/one_time_event.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h" #include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
@ -100,7 +101,7 @@ class VideoReceiver : public Module {
rtc::ThreadChecker decoder_thread_checker_; rtc::ThreadChecker decoder_thread_checker_;
rtc::ThreadChecker module_thread_checker_; rtc::ThreadChecker module_thread_checker_;
Clock* const clock_; Clock* const clock_;
rtc::CriticalSection process_crit_; Mutex process_mutex_;
VCMTiming* _timing; VCMTiming* _timing;
VCMReceiver _receiver; VCMReceiver _receiver;
VCMDecodedFrameCallback _decodedFrameCallback; VCMDecodedFrameCallback _decodedFrameCallback;
@ -111,8 +112,8 @@ class VideoReceiver : public Module {
VCMPacketRequestCallback* _packetRequestCallback; VCMPacketRequestCallback* _packetRequestCallback;
// Used on both the module and decoder thread. // Used on both the module and decoder thread.
bool _scheduleKeyRequest RTC_GUARDED_BY(process_crit_); bool _scheduleKeyRequest RTC_GUARDED_BY(process_mutex_);
bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_crit_); bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_mutex_);
// Modified on the construction thread while not attached to the process // Modified on the construction thread while not attached to the process
// thread. Once attached to the process thread, its value is only read // thread. Once attached to the process thread, its value is only read

View File

@ -31,7 +31,6 @@
#include "modules/video_coding/timing.h" #include "modules/video_coding/timing.h"
#include "modules/video_coding/video_coding_impl.h" #include "modules/video_coding/video_coding_impl.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/location.h" #include "rtc_base/location.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/one_time_event.h" #include "rtc_base/one_time_event.h"
@ -71,7 +70,7 @@ void VideoReceiver::Process() {
_keyRequestTimer.Processed(); _keyRequestTimer.Processed();
bool request_key_frame = _frameTypeCallback != nullptr; bool request_key_frame = _frameTypeCallback != nullptr;
if (request_key_frame) { if (request_key_frame) {
rtc::CritScope cs(&process_crit_); MutexLock lock(&process_mutex_);
request_key_frame = _scheduleKeyRequest; request_key_frame = _scheduleKeyRequest;
} }
if (request_key_frame) if (request_key_frame)
@ -94,7 +93,7 @@ void VideoReceiver::Process() {
ret = RequestKeyFrame(); ret = RequestKeyFrame();
} }
if (ret == VCM_OK && !nackList.empty()) { if (ret == VCM_OK && !nackList.empty()) {
rtc::CritScope cs(&process_crit_); MutexLock lock(&process_mutex_);
if (_packetRequestCallback != nullptr) { if (_packetRequestCallback != nullptr) {
_packetRequestCallback->ResendPackets(&nackList[0], nackList.size()); _packetRequestCallback->ResendPackets(&nackList[0], nackList.size());
} }
@ -183,7 +182,7 @@ int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
bool drop_frame = false; bool drop_frame = false;
{ {
rtc::CritScope cs(&process_crit_); MutexLock lock(&process_mutex_);
if (drop_frames_until_keyframe_) { if (drop_frames_until_keyframe_) {
// Still getting delta frames, schedule another keyframe request as if // Still getting delta frames, schedule another keyframe request as if
// decode failed. // decode failed.
@ -229,7 +228,7 @@ int32_t VideoReceiver::RequestKeyFrame() {
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
rtc::CritScope cs(&process_crit_); MutexLock lock(&process_mutex_);
_scheduleKeyRequest = false; _scheduleKeyRequest = false;
} else { } else {
return VCM_MISSING_CALLBACK; return VCM_MISSING_CALLBACK;
@ -291,7 +290,7 @@ int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
// request scheduling to throttle the requests. // request scheduling to throttle the requests.
if (ret == VCM_FLUSH_INDICATOR) { if (ret == VCM_FLUSH_INDICATOR) {
{ {
rtc::CritScope cs(&process_crit_); MutexLock lock(&process_mutex_);
drop_frames_until_keyframe_ = true; drop_frames_until_keyframe_ = true;
} }
RequestKeyFrame(); RequestKeyFrame();