From 6cc893ad778a0965e2b7a8e614f3c98aa81bee5b Mon Sep 17 00:00:00 2001 From: Markus Handell Date: Wed, 8 Jul 2020 10:19:18 +0200 Subject: [PATCH] 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 Reviewed-by: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#31662} --- test/pc/e2e/BUILD.gn | 12 ++++ .../audio/default_audio_quality_analyzer.cc | 6 +- .../audio/default_audio_quality_analyzer.h | 4 +- .../video/default_video_quality_analyzer.cc | 68 +++++++++---------- .../video/default_video_quality_analyzer.h | 8 +-- .../video/example_video_quality_analyzer.cc | 32 ++++----- .../video/example_video_quality_analyzer.h | 4 +- .../video/quality_analyzing_video_decoder.cc | 18 ++--- .../video/quality_analyzing_video_decoder.h | 6 +- .../video/quality_analyzing_video_encoder.cc | 21 +++--- .../video/quality_analyzing_video_encoder.h | 4 +- ...gle_process_encoded_image_data_injector.cc | 4 +- ...ngle_process_encoded_image_data_injector.h | 4 +- ...video_quality_analyzer_injection_helper.cc | 4 +- .../video_quality_analyzer_injection_helper.h | 4 +- .../video/video_quality_metrics_reporter.cc | 4 +- .../video/video_quality_metrics_reporter.h | 4 +- test/pc/e2e/cross_media_metrics_reporter.cc | 4 +- test/pc/e2e/cross_media_metrics_reporter.h | 6 +- .../e2e/network_quality_metrics_reporter.cc | 4 +- .../pc/e2e/network_quality_metrics_reporter.h | 4 +- test/pc/e2e/peer_connection_quality_test.cc | 2 +- test/pc/e2e/peer_connection_quality_test.h | 5 +- test/pc/e2e/test_activities_executor.cc | 6 +- test/pc/e2e/test_activities_executor.h | 4 +- 25 files changed, 127 insertions(+), 115 deletions(-) diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index 8ce9ca1ad5..396552e88f 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -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 = [ diff --git a/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.cc b/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.cc index 7979a0b5ce..11fded290d 100644 --- a/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.cc @@ -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 DefaultAudioQualityAnalyzer::GetAudioStreamsStats() const { - rtc::CritScope crit(&lock_); + MutexLock lock(&lock_); return streams_stats_; } diff --git a/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h b/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h index 24623ce0b2..c842fd2790 100644 --- a/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h +++ b/test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h @@ -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 streams_stats_ RTC_GUARDED_BY(lock_); std::map last_stats_sample_ RTC_GUARDED_BY(lock_); }; diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc index 075abebee5..db866077e7 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc @@ -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 DefaultVideoQualityAnalyzer::GetKnownVideoStreams() const { - rtc::CritScope crit1(&lock_); - rtc::CritScope crit2(&comparison_lock_); + MutexLock lock1(&lock_); + MutexLock lock2(&comparison_lock_); std::set out; for (auto& item : stream_stats_) { RTC_LOG(INFO) << item.first.ToString() << " ==> " @@ -583,13 +583,13 @@ std::set DefaultVideoQualityAnalyzer::GetKnownVideoStreams() const { } const FrameCounters& DefaultVideoQualityAnalyzer::GetGlobalCounters() const { - rtc::CritScope crit(&lock_); + MutexLock lock(&lock_); return frame_counters_; } std::map DefaultVideoQualityAnalyzer::GetPerStreamCounters() const { - rtc::CritScope crit(&lock_); + MutexLock lock(&lock_); std::map out; for (auto& item : stream_frame_counters_) { out.emplace(ToStatsKey(item.first), item.second); @@ -598,8 +598,8 @@ DefaultVideoQualityAnalyzer::GetPerStreamCounters() const { } std::map DefaultVideoQualityAnalyzer::GetStats() const { - rtc::CritScope crit1(&lock_); - rtc::CritScope crit2(&comparison_lock_); + MutexLock lock1(&lock_); + MutexLock lock2(&comparison_lock_); std::map out; for (auto& item : stream_stats_) { out.emplace(ToStatsKey(item.first), item.second); @@ -608,7 +608,7 @@ std::map 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 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(cpu_time_) / wallclock_time_ * 100.0; } diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h index 75449412f8..51ded74f6b 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h @@ -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 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> stream_to_frame_id_history_ RTC_GUARDED_BY(lock_); - rtc::CriticalSection comparison_lock_; + mutable Mutex comparison_lock_; std::map stream_stats_ RTC_GUARDED_BY(comparison_lock_); std::map stream_last_freeze_end_time_ @@ -550,7 +550,7 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface { std::vector> 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; }; diff --git a/test/pc/e2e/analyzer/video/example_video_quality_analyzer.cc b/test/pc/e2e/analyzer/video/example_video_quality_analyzer.cc index a980b0e9d0..198a6cb42f 100644 --- a/test/pc/e2e/analyzer/video/example_video_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/video/example_video_quality_analyzer.cc @@ -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_; } diff --git a/test/pc/e2e/analyzer/video/example_video_quality_analyzer.h b/test/pc/e2e/analyzer/video/example_video_quality_analyzer.h index 0126093c87..9f004396ae 100644 --- a/test/pc/e2e/analyzer/video/example_video_quality_analyzer.h +++ b/test/pc/e2e/analyzer/video/example_video_quality_analyzer.h @@ -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. diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.cc b/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.cc index 9e81c8728b..196f900bd3 100644 --- a/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.cc +++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.cc @@ -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 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 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 diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.h b/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.h index decb844bc2..2381f593b9 100644 --- a/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.h +++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_decoder.h @@ -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 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 timestamp_to_frame_id_ RTC_GUARDED_BY(lock_); // Stores currently being decoded images by frame id. Because diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc index 4d04a2ccbb..27b8f92bed 100644 --- a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc +++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc @@ -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* 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 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); diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h index f6db1369b0..3486c55a5f 100644 --- a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h +++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h @@ -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_); diff --git a/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.cc b/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.cc index 75f1265e1f..8e7a511878 100644 --- a/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.cc +++ b/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.cc @@ -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. diff --git a/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h b/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h index f79532e096..c70c25bc7d 100644 --- a/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h +++ b/test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h @@ -18,7 +18,7 @@ #include #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 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 diff --git a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc index 1948777848..dfd6a8db4a 100644 --- a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc +++ b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc @@ -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( @@ -203,7 +203,7 @@ void VideoQualityAnalyzerInjectionHelper::OnFrame(absl::string_view peer_name, std::vector>>* 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; diff --git a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h index ca5243484d..6139cfd46a 100644 --- a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h +++ b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h @@ -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> video_writers_; - rtc::CriticalSection lock_; + Mutex lock_; std::map known_video_configs_ RTC_GUARDED_BY(lock_); std::map>>> diff --git a/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.cc b/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.cc index f1d9a58629..cc675cc2df 100644 --- a/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.cc +++ b/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.cc @@ -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); } diff --git a/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.h b/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.h index aab8a34cd5..188aa42ef1 100644 --- a/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.h +++ b/test/pc/e2e/analyzer/video/video_quality_metrics_reporter.h @@ -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 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 video_bwe_stats_ diff --git a/test/pc/e2e/cross_media_metrics_reporter.cc b/test/pc/e2e/cross_media_metrics_reporter.cc index 3bae6c9d0e..96f661fd4f 100644 --- a/test/pc/e2e/cross_media_metrics_reporter.cc +++ b/test/pc/e2e/cross_media_metrics_reporter.cc @@ -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", diff --git a/test/pc/e2e/cross_media_metrics_reporter.h b/test/pc/e2e/cross_media_metrics_reporter.h index bff5a3167a..af2a62e77a 100644 --- a/test/pc/e2e/cross_media_metrics_reporter.h +++ b/test/pc/e2e/cross_media_metrics_reporter.h @@ -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 stats_info_ RTC_GUARDED_BY(lock_); + Mutex mutex_; + std::map stats_info_ RTC_GUARDED_BY(mutex_); }; } // namespace webrtc_pc_e2e diff --git a/test/pc/e2e/network_quality_metrics_reporter.cc b/test/pc/e2e/network_quality_metrics_reporter.cc index 33d7492610..85276ee3c3 100644 --- a/test/pc/e2e/network_quality_metrics_reporter.cc +++ b/test/pc/e2e/network_quality_metrics_reporter.cc @@ -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); } diff --git a/test/pc/e2e/network_quality_metrics_reporter.h b/test/pc/e2e/network_quality_metrics_reporter.h index 6fe71a4b29..4c81f9d716 100644 --- a/test/pc/e2e/network_quality_metrics_reporter.h +++ b/test/pc/e2e/network_quality_metrics_reporter.h @@ -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 pc_stats_ RTC_GUARDED_BY(lock_); }; diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc index 2027b3b26d..ee21b05012 100644 --- a/test/pc/e2e/peer_connection_quality_test.cc +++ b/test/pc/e2e/peer_connection_quality_test.cc @@ -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; } diff --git a/test/pc/e2e/peer_connection_quality_test.h b/test/pc/e2e/peer_connection_quality_test.h index 833384d61a..9ce19a80e4 100644 --- a/test/pc/e2e/peer_connection_quality_test.h +++ b/test/pc/e2e/peer_connection_quality_test.h @@ -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. diff --git a/test/pc/e2e/test_activities_executor.cc b/test/pc/e2e/test_activities_executor.cc index 4ace6ae7d8..ded39920f2 100644 --- a/test/pc/e2e/test_activities_executor.cc +++ b/test/pc/e2e/test_activities_executor.cc @@ -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)); diff --git a/test/pc/e2e/test_activities_executor.h b/test/pc/e2e/test_activities_executor.h index 09bfe4167f..94e73d1e5f 100644 --- a/test/pc/e2e/test_activities_executor.h +++ b/test/pc/e2e/test_activities_executor.h @@ -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();