Migrate test/pc/e2e to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: Iaec1d2f5112deed96abc8cf8c5d0a89e5d5a260d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178817
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31662}
This commit is contained in:
Markus Handell
2020-07-08 10:19:18 +02:00
committed by Commit Bot
parent bfb6124a73
commit 6cc893ad77
25 changed files with 127 additions and 115 deletions

View File

@ -101,6 +101,7 @@ if (!build_with_chromium) {
"../../../api/video:encoded_image",
"../../../rtc_base:checks",
"../../../rtc_base:criticalsection",
"../../../rtc_base/synchronization:mutex",
]
absl_deps = [ "//third_party/abseil-cpp/absl/memory" ]
}
@ -148,6 +149,7 @@ if (!build_with_chromium) {
"../../../modules/video_coding:video_codec_interface",
"../../../rtc_base:criticalsection",
"../../../rtc_base:logging",
"../../../rtc_base/synchronization:mutex",
]
absl_deps = [
"//third_party/abseil-cpp/absl/strings",
@ -173,6 +175,7 @@ if (!build_with_chromium) {
"../../../modules/video_coding:video_codec_interface",
"../../../rtc_base:criticalsection",
"../../../rtc_base:logging",
"../../../rtc_base/synchronization:mutex",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
@ -200,6 +203,7 @@ if (!build_with_chromium) {
"../../../api/video:video_rtp_headers",
"../../../api/video_codecs:video_codecs_api",
"../../../rtc_base:criticalsection",
"../../../rtc_base/synchronization:mutex",
"../../../test:video_test_common",
"../../../test:video_test_support",
]
@ -344,6 +348,7 @@ if (!build_with_chromium) {
"../../../rtc_base:logging",
"../../../rtc_base:rtc_base_approved",
"../../../rtc_base:task_queue_for_test",
"../../../rtc_base/synchronization:mutex",
"../../../rtc_base/task_utils:repeating_task",
"../../../system_wrappers",
]
@ -401,6 +406,7 @@ if (!build_with_chromium) {
"../../../rtc_base:rtc_base_approved",
"../../../rtc_base:safe_conversions",
"../../../rtc_base:task_queue_for_test",
"../../../rtc_base/synchronization:mutex",
"../../../system_wrappers",
"../../../system_wrappers:field_trial",
]
@ -564,6 +570,7 @@ if (!build_with_chromium) {
"../../../rtc_base:criticalsection",
"../../../rtc_base:logging",
"../../../rtc_base:rtc_numerics",
"../../../rtc_base/synchronization:mutex",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
@ -584,6 +591,7 @@ if (!build_with_chromium) {
"../../../api/video:video_rtp_headers",
"../../../rtc_base:criticalsection",
"../../../rtc_base:logging",
"../../../rtc_base/synchronization:mutex",
]
}
@ -606,6 +614,7 @@ if (!build_with_chromium) {
"../../../api/units:timestamp",
"../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_numerics",
"../../../rtc_base/synchronization:mutex",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
@ -638,6 +647,7 @@ if (!build_with_chromium) {
"../../../rtc_base:rtc_event",
"../../../rtc_base:rtc_numerics",
"../../../rtc_base:timeutils",
"../../../rtc_base/synchronization:mutex",
"../../../system_wrappers",
]
}
@ -658,6 +668,7 @@ if (!build_with_chromium) {
"../../../api/units:data_size",
"../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_event",
"../../../rtc_base/synchronization:mutex",
"../../../system_wrappers:field_trial",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
@ -680,6 +691,7 @@ if (!build_with_chromium) {
"../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_event",
"../../../rtc_base:rtc_numerics",
"../../../rtc_base/synchronization:mutex",
"../../../system_wrappers:field_trial",
]
absl_deps = [

View File

@ -55,7 +55,7 @@ void DefaultAudioQualityAnalyzer::OnStatsReports(
const std::string stream_label = std::string(
analyzer_helper_->GetStreamLabelFromTrackId(*stat->track_identifier));
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
StatsSample prev_sample = last_stats_sample_[stream_label];
RTC_CHECK_GE(sample.total_samples_received,
prev_sample.total_samples_received);
@ -109,7 +109,7 @@ std::string DefaultAudioQualityAnalyzer::GetTestCaseName(
void DefaultAudioQualityAnalyzer::Stop() {
using ::webrtc::test::ImproveDirection;
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
for (auto& item : streams_stats_) {
ReportResult("expand_rate", item.first, item.second.expand_rate, "unitless",
ImproveDirection::kSmallerIsBetter);
@ -128,7 +128,7 @@ void DefaultAudioQualityAnalyzer::Stop() {
std::map<std::string, AudioStreamStats>
DefaultAudioQualityAnalyzer::GetAudioStreamsStats() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return streams_stats_;
}

View File

@ -18,8 +18,8 @@
#include "api/test/audio_quality_analyzer_interface.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/time_delta.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/testsupport/perf_test.h"
namespace webrtc {
@ -66,7 +66,7 @@ class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
std::string test_case_name_;
TrackIdStreamInfoMap* analyzer_helper_;
rtc::CriticalSection lock_;
mutable Mutex lock_;
std::map<std::string, AudioStreamStats> streams_stats_ RTC_GUARDED_BY(lock_);
std::map<std::string, StatsSample> last_stats_sample_ RTC_GUARDED_BY(lock_);
};

View File

@ -152,7 +152,7 @@ void DefaultVideoQualityAnalyzer::Start(
thread_pool_.push_back(std::move(thread));
}
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_CHECK(start_time_.IsMinusInfinity());
state_ = State::kActive;
@ -171,7 +171,7 @@ uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured(
size_t peer_index = peers_->index(peer_name);
size_t stream_index;
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
// Create a local copy of start_time_ to access it under
// |comparison_lock_| without holding a |lock_|
start_time = start_time_;
@ -179,7 +179,7 @@ uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured(
}
{
// Ensure stats for this stream exists.
rtc::CritScope crit(&comparison_lock_);
MutexLock lock(&comparison_lock_);
for (size_t i = 0; i < peers_->size(); ++i) {
if (i == peer_index) {
continue;
@ -202,7 +202,7 @@ uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured(
}
}
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
stream_to_sender_[stream_index] = peer_index;
frame_counters_.captured++;
for (size_t i = 0; i < peers_->size(); ++i) {
@ -236,7 +236,7 @@ uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured(
InternalStatsKey key(stream_index, peer_index, i);
stream_frame_counters_.at(key).dropped++;
rtc::CritScope crit1(&comparison_lock_);
MutexLock lock1(&comparison_lock_);
analyzer_stats_.frames_in_flight_left_count.AddSample(
captured_frames_in_flight_.size());
AddComparison(InternalStatsKey(stream_index, peer_index, i),
@ -281,7 +281,7 @@ uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured(
void DefaultVideoQualityAnalyzer::OnFramePreEncode(
absl::string_view peer_name,
const webrtc::VideoFrame& frame) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
auto it = captured_frames_in_flight_.find(frame.id());
RTC_DCHECK(it != captured_frames_in_flight_.end())
<< "Frame id=" << frame.id() << " not found";
@ -301,7 +301,7 @@ void DefaultVideoQualityAnalyzer::OnFrameEncoded(
uint16_t frame_id,
const webrtc::EncodedImage& encoded_image,
const EncoderStats& stats) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
auto it = captured_frames_in_flight_.find(frame_id);
RTC_DCHECK(it != captured_frames_in_flight_.end());
// For SVC we can receive multiple encoded images for one frame, so to cover
@ -331,7 +331,7 @@ void DefaultVideoQualityAnalyzer::OnFramePreDecode(
absl::string_view peer_name,
uint16_t frame_id,
const webrtc::EncodedImage& input_image) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
size_t peer_index = peers_->index(peer_name);
auto it = captured_frames_in_flight_.find(frame_id);
@ -368,7 +368,7 @@ void DefaultVideoQualityAnalyzer::OnFrameDecoded(
absl::string_view peer_name,
const webrtc::VideoFrame& frame,
const DecoderStats& stats) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
size_t peer_index = peers_->index(peer_name);
auto it = captured_frames_in_flight_.find(frame.id());
@ -391,7 +391,7 @@ void DefaultVideoQualityAnalyzer::OnFrameDecoded(
void DefaultVideoQualityAnalyzer::OnFrameRendered(
absl::string_view peer_name,
const webrtc::VideoFrame& raw_frame) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
size_t peer_index = peers_->index(peer_name);
auto frame_it = captured_frames_in_flight_.find(raw_frame.id());
@ -449,7 +449,7 @@ void DefaultVideoQualityAnalyzer::OnFrameRendered(
dropped_frame_it->second.MarkDropped(peer_index);
{
rtc::CritScope crit1(&comparison_lock_);
MutexLock lock1(&comparison_lock_);
analyzer_stats_.frames_in_flight_left_count.AddSample(
captured_frames_in_flight_.size());
AddComparison(stats_key, dropped_frame, absl::nullopt, true,
@ -470,12 +470,12 @@ void DefaultVideoQualityAnalyzer::OnFrameRendered(
state->SetLastRenderedFrameTime(peer_index,
frame_in_flight->rendered_time(peer_index));
{
rtc::CritScope cr(&comparison_lock_);
MutexLock cr(&comparison_lock_);
stream_stats_[stats_key].skipped_between_rendered.AddSample(dropped_count);
}
{
rtc::CritScope crit(&comparison_lock_);
MutexLock lock(&comparison_lock_);
analyzer_stats_.frames_in_flight_left_count.AddSample(
captured_frames_in_flight_.size());
AddComparison(stats_key, captured_frame, frame, false,
@ -505,7 +505,7 @@ void DefaultVideoQualityAnalyzer::OnDecoderError(absl::string_view peer_name,
void DefaultVideoQualityAnalyzer::Stop() {
StopMeasuringCpuProcessTime();
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
if (state_ == State::kStopped) {
return;
}
@ -524,8 +524,8 @@ void DefaultVideoQualityAnalyzer::Stop() {
// Time between freezes.
// Count time since the last freeze to the end of the call as time
// between freezes.
rtc::CritScope crit1(&lock_);
rtc::CritScope crit2(&comparison_lock_);
MutexLock lock1(&lock_);
MutexLock lock2(&comparison_lock_);
for (auto& state_entry : stream_states_) {
const size_t stream_index = state_entry.first;
const StreamState& stream_state = state_entry.second;
@ -555,7 +555,7 @@ void DefaultVideoQualityAnalyzer::Stop() {
}
std::string DefaultVideoQualityAnalyzer::GetStreamLabel(uint16_t frame_id) {
rtc::CritScope crit1(&lock_);
MutexLock lock1(&lock_);
auto it = captured_frames_in_flight_.find(frame_id);
if (it != captured_frames_in_flight_.end()) {
return streams_.name(it->second.stream());
@ -571,8 +571,8 @@ std::string DefaultVideoQualityAnalyzer::GetStreamLabel(uint16_t frame_id) {
}
std::set<StatsKey> DefaultVideoQualityAnalyzer::GetKnownVideoStreams() const {
rtc::CritScope crit1(&lock_);
rtc::CritScope crit2(&comparison_lock_);
MutexLock lock1(&lock_);
MutexLock lock2(&comparison_lock_);
std::set<StatsKey> out;
for (auto& item : stream_stats_) {
RTC_LOG(INFO) << item.first.ToString() << " ==> "
@ -583,13 +583,13 @@ std::set<StatsKey> DefaultVideoQualityAnalyzer::GetKnownVideoStreams() const {
}
const FrameCounters& DefaultVideoQualityAnalyzer::GetGlobalCounters() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frame_counters_;
}
std::map<StatsKey, FrameCounters>
DefaultVideoQualityAnalyzer::GetPerStreamCounters() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
std::map<StatsKey, FrameCounters> out;
for (auto& item : stream_frame_counters_) {
out.emplace(ToStatsKey(item.first), item.second);
@ -598,8 +598,8 @@ DefaultVideoQualityAnalyzer::GetPerStreamCounters() const {
}
std::map<StatsKey, StreamStats> DefaultVideoQualityAnalyzer::GetStats() const {
rtc::CritScope crit1(&lock_);
rtc::CritScope crit2(&comparison_lock_);
MutexLock lock1(&lock_);
MutexLock lock2(&comparison_lock_);
std::map<StatsKey, StreamStats> out;
for (auto& item : stream_stats_) {
out.emplace(ToStatsKey(item.first), item.second);
@ -608,7 +608,7 @@ std::map<StatsKey, StreamStats> DefaultVideoQualityAnalyzer::GetStats() const {
}
AnalyzerStats DefaultVideoQualityAnalyzer::GetAnalyzerStats() const {
rtc::CritScope crit(&comparison_lock_);
MutexLock lock(&comparison_lock_);
return analyzer_stats_;
}
@ -648,7 +648,7 @@ void DefaultVideoQualityAnalyzer::ProcessComparisons() {
// Try to pick next comparison to perform from the queue.
absl::optional<FrameComparison> comparison = absl::nullopt;
{
rtc::CritScope crit(&comparison_lock_);
MutexLock lock(&comparison_lock_);
if (!comparisons_.empty()) {
comparison = comparisons_.front();
comparisons_.pop_front();
@ -662,7 +662,7 @@ void DefaultVideoQualityAnalyzer::ProcessComparisons() {
{
// If there are no comparisons and state is stopped =>
// no more frames expected.
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
more_frames_expected = state_ != State::kStopped;
}
if (!more_frames_expected) {
@ -692,7 +692,7 @@ void DefaultVideoQualityAnalyzer::ProcessComparison(
const FrameStats& frame_stats = comparison.frame_stats;
rtc::CritScope crit(&comparison_lock_);
MutexLock lock(&comparison_lock_);
auto stats_it = stream_stats_.find(comparison.stats_key);
RTC_CHECK(stats_it != stream_stats_.end()) << comparison.stats_key.ToString();
StreamStats* stats = &stats_it->second;
@ -761,8 +761,8 @@ void DefaultVideoQualityAnalyzer::ProcessComparison(
void DefaultVideoQualityAnalyzer::ReportResults() {
using ::webrtc::test::ImproveDirection;
rtc::CritScope crit1(&lock_);
rtc::CritScope crit2(&comparison_lock_);
MutexLock lock1(&lock_);
MutexLock lock2(&comparison_lock_);
for (auto& item : stream_stats_) {
ReportResults(GetTestCaseName(StatsKeyToMetricName(ToStatsKey(item.first))),
item.second, stream_frame_counters_.at(item.first));
@ -916,29 +916,29 @@ std::string DefaultVideoQualityAnalyzer::StatsKeyToMetricName(
}
void DefaultVideoQualityAnalyzer::StartMeasuringCpuProcessTime() {
rtc::CritScope lock(&cpu_measurement_lock_);
MutexLock lock(&cpu_measurement_lock_);
cpu_time_ -= rtc::GetProcessCpuTimeNanos();
wallclock_time_ -= rtc::SystemTimeNanos();
}
void DefaultVideoQualityAnalyzer::StopMeasuringCpuProcessTime() {
rtc::CritScope lock(&cpu_measurement_lock_);
MutexLock lock(&cpu_measurement_lock_);
cpu_time_ += rtc::GetProcessCpuTimeNanos();
wallclock_time_ += rtc::SystemTimeNanos();
}
void DefaultVideoQualityAnalyzer::StartExcludingCpuThreadTime() {
rtc::CritScope lock(&cpu_measurement_lock_);
MutexLock lock(&cpu_measurement_lock_);
cpu_time_ += rtc::GetThreadCpuTimeNanos();
}
void DefaultVideoQualityAnalyzer::StopExcludingCpuThreadTime() {
rtc::CritScope lock(&cpu_measurement_lock_);
MutexLock lock(&cpu_measurement_lock_);
cpu_time_ -= rtc::GetThreadCpuTimeNanos();
}
double DefaultVideoQualityAnalyzer::GetCpuUsagePercent() {
rtc::CritScope lock(&cpu_measurement_lock_);
MutexLock lock(&cpu_measurement_lock_);
return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
}

View File

@ -24,10 +24,10 @@
#include "api/units/timestamp.h"
#include "api/video/encoded_image.h"
#include "api/video/video_frame.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/clock.h"
#include "test/pc/e2e/analyzer/video/multi_head_queue.h"
#include "test/testsupport/perf_test.h"
@ -507,7 +507,7 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface {
std::string test_label_;
std::unique_ptr<NamesCollection> peers_;
rtc::CriticalSection lock_;
mutable Mutex lock_;
State state_ RTC_GUARDED_BY(lock_) = State::kNew;
Timestamp start_time_ RTC_GUARDED_BY(lock_) = Timestamp::MinusInfinity();
// Mapping from stream label to unique size_t value to use in stats and avoid
@ -539,7 +539,7 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface {
std::map<size_t, std::set<uint16_t>> stream_to_frame_id_history_
RTC_GUARDED_BY(lock_);
rtc::CriticalSection comparison_lock_;
mutable Mutex comparison_lock_;
std::map<InternalStatsKey, StreamStats> stream_stats_
RTC_GUARDED_BY(comparison_lock_);
std::map<InternalStatsKey, Timestamp> stream_last_freeze_end_time_
@ -550,7 +550,7 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface {
std::vector<std::unique_ptr<rtc::PlatformThread>> thread_pool_;
rtc::Event comparison_available_event_;
rtc::CriticalSection cpu_measurement_lock_;
Mutex cpu_measurement_lock_;
int64_t cpu_time_ RTC_GUARDED_BY(cpu_measurement_lock_) = 0;
int64_t wallclock_time_ RTC_GUARDED_BY(cpu_measurement_lock_) = 0;
};

View File

@ -28,7 +28,7 @@ uint16_t ExampleVideoQualityAnalyzer::OnFrameCaptured(
absl::string_view peer_name,
const std::string& stream_label,
const webrtc::VideoFrame& frame) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
uint16_t frame_id = next_frame_id_++;
auto it = frames_in_flight_.find(frame_id);
if (it == frames_in_flight_.end()) {
@ -51,7 +51,7 @@ uint16_t ExampleVideoQualityAnalyzer::OnFrameCaptured(
void ExampleVideoQualityAnalyzer::OnFramePreEncode(
absl::string_view peer_name,
const webrtc::VideoFrame& frame) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
++frames_pre_encoded_;
}
@ -60,7 +60,7 @@ void ExampleVideoQualityAnalyzer::OnFrameEncoded(
uint16_t frame_id,
const webrtc::EncodedImage& encoded_image,
const EncoderStats& stats) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
++frames_encoded_;
}
@ -68,7 +68,7 @@ void ExampleVideoQualityAnalyzer::OnFrameDropped(
absl::string_view peer_name,
webrtc::EncodedImageCallback::DropReason reason) {
RTC_LOG(INFO) << "Frame dropped by encoder";
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
++frames_dropped_;
}
@ -76,7 +76,7 @@ void ExampleVideoQualityAnalyzer::OnFramePreDecode(
absl::string_view peer_name,
uint16_t frame_id,
const webrtc::EncodedImage& encoded_image) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
++frames_received_;
}
@ -84,14 +84,14 @@ void ExampleVideoQualityAnalyzer::OnFrameDecoded(
absl::string_view peer_name,
const webrtc::VideoFrame& frame,
const DecoderStats& stats) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
++frames_decoded_;
}
void ExampleVideoQualityAnalyzer::OnFrameRendered(
absl::string_view peer_name,
const webrtc::VideoFrame& frame) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
frames_in_flight_.erase(frame.id());
++frames_rendered_;
}
@ -112,14 +112,14 @@ void ExampleVideoQualityAnalyzer::OnDecoderError(absl::string_view peer_name,
}
void ExampleVideoQualityAnalyzer::Stop() {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_LOG(INFO) << "There are " << frames_in_flight_.size()
<< " frames in flight, assuming all of them are dropped";
frames_dropped_ += frames_in_flight_.size();
}
std::string ExampleVideoQualityAnalyzer::GetStreamLabel(uint16_t frame_id) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
auto it = frames_to_stream_label_.find(frame_id);
RTC_DCHECK(it != frames_to_stream_label_.end())
<< "Unknown frame_id=" << frame_id;
@ -127,37 +127,37 @@ std::string ExampleVideoQualityAnalyzer::GetStreamLabel(uint16_t frame_id) {
}
uint64_t ExampleVideoQualityAnalyzer::frames_captured() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_captured_;
}
uint64_t ExampleVideoQualityAnalyzer::frames_pre_encoded() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_pre_encoded_;
}
uint64_t ExampleVideoQualityAnalyzer::frames_encoded() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_encoded_;
}
uint64_t ExampleVideoQualityAnalyzer::frames_received() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_received_;
}
uint64_t ExampleVideoQualityAnalyzer::frames_decoded() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_decoded_;
}
uint64_t ExampleVideoQualityAnalyzer::frames_rendered() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_rendered_;
}
uint64_t ExampleVideoQualityAnalyzer::frames_dropped() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
return frames_dropped_;
}

View File

@ -20,7 +20,7 @@
#include "api/test/video_quality_analyzer_interface.h"
#include "api/video/encoded_image.h"
#include "api/video/video_frame.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
namespace webrtc_pc_e2e {
@ -79,7 +79,7 @@ class ExampleVideoQualityAnalyzer : public VideoQualityAnalyzerInterface {
// when it will be received in peer B, so we need to guard it with lock.
// Also because analyzer will serve for all video streams it can be called
// from different threads inside one peer.
rtc::CriticalSection lock_;
mutable Mutex lock_;
// Stores frame ids, that are currently going from one peer to another. We
// need to keep them to correctly determine dropped frames and also correctly
// process frame id overlap.

View File

@ -79,7 +79,7 @@ int32_t QualityAnalyzingVideoDecoder::Decode(const EncodedImage& input_image,
EncodedImage* origin_image;
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
// Store id to be able to retrieve it in analyzing callback.
timestamp_to_frame_id_.insert({input_image.Timestamp(), out.id});
// Store encoded image to prevent its destruction while it is used in
@ -96,7 +96,7 @@ int32_t QualityAnalyzingVideoDecoder::Decode(const EncodedImage& input_image,
if (result != WEBRTC_VIDEO_CODEC_OK) {
// If delegate decoder failed, then cleanup data for this image.
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
timestamp_to_frame_id_.erase(input_image.Timestamp());
decoding_images_.erase(out.id);
}
@ -116,7 +116,7 @@ int32_t QualityAnalyzingVideoDecoder::Release() {
// frames, so we don't take a lock to prevent deadlock.
int32_t result = delegate_->Release();
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
analyzing_callback_->SetDelegateCallback(nullptr);
timestamp_to_frame_id_.clear();
decoding_images_.clear();
@ -138,7 +138,7 @@ QualityAnalyzingVideoDecoder::DecoderCallback::~DecoderCallback() = default;
void QualityAnalyzingVideoDecoder::DecoderCallback::SetDelegateCallback(
DecodedImageCallback* delegate) {
rtc::CritScope crit(&callback_lock_);
MutexLock lock(&callback_lock_);
delegate_callback_ = delegate;
}
@ -150,7 +150,7 @@ int32_t QualityAnalyzingVideoDecoder::DecoderCallback::Decoded(
decoder_->OnFrameDecoded(&decodedImage, /*decode_time_ms=*/absl::nullopt,
/*qp=*/absl::nullopt);
rtc::CritScope crit(&callback_lock_);
MutexLock lock(&callback_lock_);
RTC_DCHECK(delegate_callback_);
return delegate_callback_->Decoded(decodedImage);
}
@ -160,7 +160,7 @@ int32_t QualityAnalyzingVideoDecoder::DecoderCallback::Decoded(
int64_t decode_time_ms) {
decoder_->OnFrameDecoded(&decodedImage, decode_time_ms, /*qp=*/absl::nullopt);
rtc::CritScope crit(&callback_lock_);
MutexLock lock(&callback_lock_);
RTC_DCHECK(delegate_callback_);
return delegate_callback_->Decoded(decodedImage, decode_time_ms);
}
@ -171,7 +171,7 @@ void QualityAnalyzingVideoDecoder::DecoderCallback::Decoded(
absl::optional<uint8_t> qp) {
decoder_->OnFrameDecoded(&decodedImage, decode_time_ms, qp);
rtc::CritScope crit(&callback_lock_);
MutexLock lock(&callback_lock_);
RTC_DCHECK(delegate_callback_);
delegate_callback_->Decoded(decodedImage, decode_time_ms, qp);
}
@ -186,7 +186,7 @@ QualityAnalyzingVideoDecoder::DecoderCallback::IrrelevantSimulcastStreamDecoded(
.set_timestamp_rtp(timestamp_ms)
.set_id(frame_id)
.build();
rtc::CritScope crit(&callback_lock_);
MutexLock lock(&callback_lock_);
RTC_DCHECK(delegate_callback_);
delegate_callback_->Decoded(dummy_frame, absl::nullopt, absl::nullopt);
return WEBRTC_VIDEO_CODEC_OK;
@ -207,7 +207,7 @@ void QualityAnalyzingVideoDecoder::OnFrameDecoded(
absl::optional<uint8_t> qp) {
uint16_t frame_id;
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
auto it = timestamp_to_frame_id_.find(frame->timestamp());
if (it == timestamp_to_frame_id_.end()) {
// Ensure, that we have info about this frame. It can happen that for some

View File

@ -23,7 +23,7 @@
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/pc/e2e/analyzer/video/encoded_image_data_injector.h"
#include "test/pc/e2e/analyzer/video/id_generator.h"
@ -97,7 +97,7 @@ class QualityAnalyzingVideoDecoder : public VideoDecoder {
rtc::scoped_refptr<webrtc::VideoFrameBuffer> dummy_frame_buffer_;
rtc::CriticalSection callback_lock_;
Mutex callback_lock_;
DecodedImageCallback* delegate_callback_ RTC_GUARDED_BY(callback_lock_);
};
@ -116,7 +116,7 @@ class QualityAnalyzingVideoDecoder : public VideoDecoder {
// VideoDecoder interface assumes async delivery of decoded video frames.
// This lock is used to protect shared state, that have to be propagated
// from received EncodedImage to resulted VideoFrame.
rtc::CriticalSection lock_;
Mutex lock_;
std::map<uint32_t, uint16_t> timestamp_to_frame_id_ RTC_GUARDED_BY(lock_);
// Stores currently being decoded images by frame id. Because

View File

@ -18,7 +18,6 @@
#include "api/video/video_codec_type.h"
#include "api/video_codecs/video_encoder.h"
#include "modules/video_coding/include/video_error_codes.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h"
namespace webrtc {
@ -80,7 +79,7 @@ void QualityAnalyzingVideoEncoder::SetFecControllerOverride(
int32_t QualityAnalyzingVideoEncoder::InitEncode(
const VideoCodec* codec_settings,
const Settings& settings) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
codec_settings_ = *codec_settings;
mode_ = SimulcastMode::kNormal;
if (codec_settings->codecType == kVideoCodecVP9) {
@ -111,7 +110,7 @@ int32_t QualityAnalyzingVideoEncoder::RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) {
// We need to get a lock here because delegate_callback can be hypothetically
// accessed from different thread (encoder one) concurrently.
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
delegate_callback_ = callback;
return delegate_->RegisterEncodeCompleteCallback(this);
}
@ -121,7 +120,7 @@ int32_t QualityAnalyzingVideoEncoder::Release() {
// frames, so we don't take a lock to prevent deadlock.
int32_t result = delegate_->Release();
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
delegate_callback_ = nullptr;
return result;
}
@ -130,7 +129,7 @@ int32_t QualityAnalyzingVideoEncoder::Encode(
const VideoFrame& frame,
const std::vector<VideoFrameType>* frame_types) {
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
// Store id to be able to retrieve it in analyzing callback.
timestamp_to_frame_id_list_.push_back({frame.timestamp(), frame.id()});
// If this list is growing, it means that we are not receiving new encoded
@ -142,7 +141,7 @@ int32_t QualityAnalyzingVideoEncoder::Encode(
if (result != WEBRTC_VIDEO_CODEC_OK) {
// If origin encoder failed, then cleanup data for this frame.
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
// The timestamp-frame_id pair can be not the last one, so we need to
// find it first and then remove. We will search from the end, because
// usually it will be the last or close to the last one.
@ -165,7 +164,7 @@ void QualityAnalyzingVideoEncoder::SetRates(
RTC_DCHECK_GT(bitrate_multiplier_, 0.0);
if (fabs(bitrate_multiplier_ - kNoMultiplier) < kEps) {
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
bitrate_allocation_ = parameters.bitrate;
}
return delegate_->SetRates(parameters);
@ -208,7 +207,7 @@ void QualityAnalyzingVideoEncoder::SetRates(
RateControlParameters adjusted_params = parameters;
adjusted_params.bitrate = multiplied_allocation;
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
bitrate_allocation_ = adjusted_params.bitrate;
}
return delegate_->SetRates(adjusted_params);
@ -239,7 +238,7 @@ EncodedImageCallback::Result QualityAnalyzingVideoEncoder::OnEncodedImage(
bool discard = false;
uint32_t target_encode_bitrate = 0;
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
std::pair<uint32_t, uint16_t> timestamp_frame_id;
while (!timestamp_to_frame_id_list_.empty()) {
timestamp_frame_id = timestamp_to_frame_id_list_.front();
@ -291,7 +290,7 @@ EncodedImageCallback::Result QualityAnalyzingVideoEncoder::OnEncodedImage(
const EncodedImage& image =
injector_->InjectData(frame_id, discard, encoded_image, id_);
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_DCHECK(delegate_callback_);
return delegate_callback_->OnEncodedImage(image, codec_specific_info,
fragmentation);
@ -300,7 +299,7 @@ EncodedImageCallback::Result QualityAnalyzingVideoEncoder::OnEncodedImage(
void QualityAnalyzingVideoEncoder::OnDroppedFrame(
EncodedImageCallback::DropReason reason) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
analyzer_->OnFrameDropped(peer_name_, reason);
RTC_DCHECK(delegate_callback_);
delegate_callback_->OnDroppedFrame(reason);

View File

@ -23,7 +23,7 @@
#include "api/video_codecs/video_codec.h"
#include "api/video_codecs/video_encoder.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/pc/e2e/analyzer/video/encoded_image_data_injector.h"
#include "test/pc/e2e/analyzer/video/id_generator.h"
@ -157,7 +157,7 @@ class QualityAnalyzingVideoEncoder : public VideoEncoder,
// VideoEncoder interface assumes async delivery of encoded images.
// This lock is used to protect shared state, that have to be propagated
// from received VideoFrame to resulted EncodedImage.
rtc::CriticalSection lock_;
Mutex lock_;
VideoCodec codec_settings_;
SimulcastMode mode_ RTC_GUARDED_BY(lock_);

View File

@ -38,7 +38,7 @@ EncodedImage SingleProcessEncodedImageDataInjector::InjectData(
memcpy(info.origin_data, &source.data()[insertion_pos],
ExtractionInfo::kUsedBufferSize);
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
// Will create new one if missed.
ExtractionInfoVector& ev = extraction_cache_[id];
info.sub_id = ev.next_sub_id++;
@ -93,7 +93,7 @@ EncodedImageExtractionResult SingleProcessEncodedImageDataInjector::ExtractData(
id = next_id;
ExtractionInfo info;
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
auto ext_vector_it = extraction_cache_.find(next_id);
// TODO(titovartem) add support for receiving single frame multiple times
// when in simulcast key frame for another spatial stream can be received.

View File

@ -18,7 +18,7 @@
#include <vector>
#include "api/video/encoded_image.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/pc/e2e/analyzer/video/encoded_image_data_injector.h"
namespace webrtc {
@ -78,7 +78,7 @@ class SingleProcessEncodedImageDataInjector : public EncodedImageDataInjector,
std::map<uint8_t, ExtractionInfo> infos;
};
rtc::CriticalSection lock_;
Mutex lock_;
// Stores a mapping from frame id to extraction info for spatial layers
// for this frame id. There can be a lot of them, because if frame was
// dropped we can't clean it up, because we won't receive a signal on

View File

@ -130,7 +130,7 @@ VideoQualityAnalyzerInjectionHelper::CreateFramePreprocessor(
config.width, config.height)));
}
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
known_video_configs_.insert({*config.stream_label, config});
}
return std::make_unique<AnalyzingFramePreprocessor>(
@ -203,7 +203,7 @@ void VideoQualityAnalyzerInjectionHelper::OnFrame(absl::string_view peer_name,
std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>>*
VideoQualityAnalyzerInjectionHelper::PopulateSinks(
const std::string& stream_label) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
auto sinks_it = sinks_.find(stream_label);
if (sinks_it != sinks_.end()) {
return &sinks_it->second;

View File

@ -25,7 +25,7 @@
#include "api/video/video_sink_interface.h"
#include "api/video_codecs/video_decoder_factory.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/pc/e2e/analyzer/video/encoded_image_data_injector.h"
#include "test/pc/e2e/analyzer/video/id_generator.h"
#include "test/test_video_capturer.h"
@ -117,7 +117,7 @@ class VideoQualityAnalyzerInjectionHelper : public StatsObserverInterface {
std::vector<std::unique_ptr<test::VideoFrameWriter>> video_writers_;
rtc::CriticalSection lock_;
Mutex lock_;
std::map<std::string, VideoConfig> known_video_configs_ RTC_GUARDED_BY(lock_);
std::map<std::string,
std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>>>

View File

@ -63,7 +63,7 @@ void VideoQualityMetricsReporter::OnStatsReports(
DataSize::Bytes(s->header_bytes_sent.ValueOrDefault(0ul));
}
rtc::CritScope crit(&video_bwe_stats_lock_);
MutexLock lock(&video_bwe_stats_lock_);
VideoBweStats& video_bwe_stats = video_bwe_stats_[std::string(pc_label)];
if (ice_candidate_pair_stats.available_outgoing_bitrate.is_defined()) {
video_bwe_stats.available_send_bandwidth.AddSample(
@ -97,7 +97,7 @@ void VideoQualityMetricsReporter::OnStatsReports(
}
void VideoQualityMetricsReporter::StopAndReportResults() {
rtc::CritScope video_bwe_crit(&video_bwe_stats_lock_);
MutexLock video_bwemutex_(&video_bwe_stats_lock_);
for (const auto& item : video_bwe_stats_) {
ReportVideoBweResults(GetTestCaseName(item.first), item.second);
}

View File

@ -19,8 +19,8 @@
#include "api/test/track_id_stream_info_map.h"
#include "api/units/data_size.h"
#include "api/units/timestamp.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/testsupport/perf_test.h"
namespace webrtc {
@ -71,7 +71,7 @@ class VideoQualityMetricsReporter
std::string test_case_name_;
absl::optional<Timestamp> start_time_;
rtc::CriticalSection video_bwe_stats_lock_;
Mutex video_bwe_stats_lock_;
// Map between a peer connection label (provided by the framework) and
// its video BWE stats.
std::map<std::string, VideoBweStats> video_bwe_stats_

View File

@ -45,7 +45,7 @@ void CrossMediaMetricsReporter::OnStatsReports(
}
}
rtc::CritScope cs(&lock_);
MutexLock lock(&mutex_);
for (const auto& pair : sync_group_stats) {
// If there is less than two streams, it is not a sync group.
if (pair.second.size() < 2) {
@ -95,7 +95,7 @@ void CrossMediaMetricsReporter::OnStatsReports(
}
void CrossMediaMetricsReporter::StopAndReportResults() {
rtc::CritScope cs(&lock_);
MutexLock lock(&mutex_);
for (const auto& pair : stats_info_) {
const std::string& sync_group = pair.first;
ReportResult("audio_ahead_ms",

View File

@ -19,8 +19,8 @@
#include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/timestamp.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/numerics/samples_stats_counter.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/testsupport/perf_test.h"
namespace webrtc {
@ -60,8 +60,8 @@ class CrossMediaMetricsReporter
std::string test_case_name_;
const TrackIdStreamInfoMap* reporter_helper_;
rtc::CriticalSection lock_;
std::map<std::string, StatsInfo> stats_info_ RTC_GUARDED_BY(lock_);
Mutex mutex_;
std::map<std::string, StatsInfo> stats_info_ RTC_GUARDED_BY(mutex_);
};
} // namespace webrtc_pc_e2e

View File

@ -62,7 +62,7 @@ void NetworkQualityMetricsReporter::OnStatsReports(
stat->header_bytes_sent.ValueOrDefault(0ul));
}
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
PCStats& stats = pc_stats_[std::string(pc_label)];
stats.payload_received = payload_received;
stats.payload_sent = payload_sent;
@ -81,7 +81,7 @@ void NetworkQualityMetricsReporter::StopAndReportResults() {
<< "Non-standard GetStats; \"payload\" counts include RTP headers";
}
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
for (const auto& pair : pc_stats_) {
ReportPCStats(pair.first, pair.second);
}

View File

@ -18,7 +18,7 @@
#include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/data_size.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
namespace webrtc_pc_e2e {
@ -63,7 +63,7 @@ class NetworkQualityMetricsReporter
EmulatedNetworkManagerInterface* alice_network_;
EmulatedNetworkManagerInterface* bob_network_;
rtc::CriticalSection lock_;
Mutex lock_;
std::map<std::string, PCStats> pc_stats_ RTC_GUARDED_BY(lock_);
};

View File

@ -367,7 +367,7 @@ void PeerConnectionE2EQualityTest::Run(RunParams run_params) {
Timestamp end_time = Now();
RTC_LOG(INFO) << "All peers are disconnected.";
{
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
real_test_duration_ = end_time - start_time;
}

View File

@ -22,6 +22,7 @@
#include "api/test/time_controller.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_annotations.h"
@ -74,7 +75,7 @@ class PeerConnectionE2EQualityTest
void Run(RunParams run_params) override;
TimeDelta GetRealTestDuration() const override {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_CHECK_NE(real_test_duration_, TimeDelta::Zero());
return real_test_duration_;
}
@ -131,7 +132,7 @@ class PeerConnectionE2EQualityTest
output_video_sinks_;
AnalyzerHelper analyzer_helper_;
rtc::CriticalSection lock_;
mutable Mutex lock_;
TimeDelta real_test_duration_ RTC_GUARDED_BY(lock_) = TimeDelta::Zero();
// Task queue, that is used for running activities during test call.

View File

@ -24,7 +24,7 @@ namespace webrtc_pc_e2e {
void TestActivitiesExecutor::Start(TaskQueueForTest* task_queue) {
RTC_DCHECK(task_queue);
task_queue_ = task_queue;
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
start_time_ = Now();
while (!scheduled_activities_.empty()) {
PostActivity(std::move(scheduled_activities_.front()));
@ -39,7 +39,7 @@ void TestActivitiesExecutor::Stop() {
}
task_queue_->SendTask(
[this]() {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
for (auto& handle : repeating_task_handles_) {
handle.Stop();
}
@ -56,7 +56,7 @@ void TestActivitiesExecutor::ScheduleActivity(
initial_delay_since_start >= TimeDelta::Zero());
RTC_CHECK(!interval ||
(interval->IsFinite() && *interval > TimeDelta::Zero()));
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
ScheduledActivity activity(initial_delay_since_start, interval, func);
if (start_time_.IsInfinite()) {
scheduled_activities_.push(std::move(activity));

View File

@ -17,7 +17,7 @@
#include "absl/types/optional.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/task_utils/repeating_task.h"
#include "system_wrappers/include/clock.h"
@ -63,7 +63,7 @@ class TestActivitiesExecutor {
TaskQueueForTest* task_queue_;
rtc::CriticalSection lock_;
Mutex lock_;
// Time when test was started. Minus infinity means that it wasn't started
// yet.
Timestamp start_time_ RTC_GUARDED_BY(lock_) = Timestamp::MinusInfinity();