From 129f228f5900d498d4e1127422706b069d2d5916 Mon Sep 17 00:00:00 2001 From: Emil Vardar Date: Mon, 14 Oct 2024 14:40:56 +0000 Subject: [PATCH] Post corruption score aggregation to worker thread. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:358039777 Change-Id: Ia7196436aaa024019869a7521243da0576dbb148 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365600 Reviewed-by: Erik Språng Commit-Queue: Åsa Persson Auto-Submit: Emil Vardar (xWF) Reviewed-by: Åsa Persson Cr-Commit-Position: refs/heads/main@{#43238} --- video/receive_statistics_proxy.cc | 29 ++++++++++++---------- video/receive_statistics_proxy_unittest.cc | 2 ++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/video/receive_statistics_proxy.cc b/video/receive_statistics_proxy.cc index e74968bdfd..671416a007 100644 --- a/video/receive_statistics_proxy.cc +++ b/video/receive_statistics_proxy.cc @@ -825,21 +825,24 @@ void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms) { void ReceiveStatisticsProxy::OnCorruptionScore(double corruption_score, VideoContentType content_type) { - RTC_DCHECK_RUN_ON(&main_thread_); + worker_thread_->PostTask(SafeTask(task_safety_.flag(), [corruption_score, + content_type, this] { + RTC_DCHECK_RUN_ON(&main_thread_); - if (!stats_.corruption_score_sum.has_value()) { - RTC_DCHECK(!stats_.corruption_score_squared_sum.has_value()); - RTC_DCHECK_EQ(stats_.corruption_score_count, 0); - stats_.corruption_score_sum = 0; - stats_.corruption_score_squared_sum = 0; - } - *stats_.corruption_score_sum += corruption_score; - *stats_.corruption_score_squared_sum += corruption_score * corruption_score; - ++stats_.corruption_score_count; + if (!stats_.corruption_score_sum.has_value()) { + RTC_DCHECK(!stats_.corruption_score_squared_sum.has_value()); + RTC_DCHECK_EQ(stats_.corruption_score_count, 0); + stats_.corruption_score_sum = 0; + stats_.corruption_score_squared_sum = 0; + } + *stats_.corruption_score_sum += corruption_score; + *stats_.corruption_score_squared_sum += corruption_score * corruption_score; + ++stats_.corruption_score_count; - ContentSpecificStats* content_specific_stats = - &content_specific_stats_[content_type]; - content_specific_stats->corruption_score.AddSample(corruption_score); + ContentSpecificStats* content_specific_stats = + &content_specific_stats_[content_type]; + content_specific_stats->corruption_score.AddSample(corruption_score); + })); } void ReceiveStatisticsProxy::DecoderThreadStarting() { diff --git a/video/receive_statistics_proxy_unittest.cc b/video/receive_statistics_proxy_unittest.cc index 22bed590ef..565d076fdb 100644 --- a/video/receive_statistics_proxy_unittest.cc +++ b/video/receive_statistics_proxy_unittest.cc @@ -555,6 +555,8 @@ TEST_F(ReceiveStatisticsProxyTest, GetStatsReportsOnCorruptionScore) { VideoContentType::UNSPECIFIED); } + time_controller_.AdvanceTime(TimeDelta::Zero()); + VideoReceiveStreamInterface::Stats stats = statistics_proxy_->GetStats(); EXPECT_THAT(kExpectedCorruptionScoreSum, DoubleEq(*stats.corruption_score_sum));