Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 1 | /* |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Rasmus Brandt | 090fe08 | 2023-05-09 10:53:01 | [diff] [blame] | 11 | #include "video/receive_statistics_proxy.h" |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
| 14 | #include <cmath> |
| 15 | #include <utility> |
| 16 | |
| 17 | #include "modules/video_coding/include/video_codec_interface.h" |
| 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/logging.h" |
| 20 | #include "rtc_base/strings/string_builder.h" |
Tommi | 47173c9 | 2020-05-13 19:26:37 | [diff] [blame] | 21 | #include "rtc_base/thread.h" |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 22 | #include "rtc_base/time_utils.h" |
| 23 | #include "system_wrappers/include/clock.h" |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 24 | #include "system_wrappers/include/metrics.h" |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 25 | #include "video/video_receive_stream2.h" |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | namespace internal { |
| 29 | namespace { |
Artem Titov | ab30d72 | 2021-07-27 14:22:11 | [diff] [blame] | 30 | // Periodic time interval for processing samples for `freq_offset_counter_`. |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 31 | const int64_t kFreqOffsetProcessIntervalMs = 40000; |
| 32 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 33 | // Some metrics are reported as a maximum over this period. |
| 34 | // This should be synchronized with a typical getStats polling interval in |
| 35 | // the clients. |
| 36 | const int kMovingMaxWindowMs = 1000; |
| 37 | |
| 38 | // How large window we use to calculate the framerate/bitrate. |
| 39 | const int kRateStatisticsWindowSizeMs = 1000; |
| 40 | |
| 41 | // Some sane ballpark estimate for maximum common value of inter-frame delay. |
| 42 | // Values below that will be stored explicitly in the array, |
| 43 | // values above - in the map. |
| 44 | const int kMaxCommonInterframeDelayMs = 500; |
| 45 | |
| 46 | const char* UmaPrefixForContentType(VideoContentType content_type) { |
| 47 | if (videocontenttypehelpers::IsScreenshare(content_type)) |
| 48 | return "WebRTC.Video.Screenshare"; |
| 49 | return "WebRTC.Video"; |
| 50 | } |
| 51 | |
Tommi | 47173c9 | 2020-05-13 19:26:37 | [diff] [blame] | 52 | // TODO(https://bugs.webrtc.org/11572): Workaround for an issue with some |
| 53 | // rtc::Thread instances and/or implementations that don't register as the |
| 54 | // current task queue. |
| 55 | bool IsCurrentTaskQueueOrThread(TaskQueueBase* task_queue) { |
| 56 | if (task_queue->IsCurrent()) |
| 57 | return true; |
| 58 | |
| 59 | rtc::Thread* current_thread = rtc::ThreadManager::Instance()->CurrentThread(); |
| 60 | if (!current_thread) |
| 61 | return false; |
| 62 | |
| 63 | return static_cast<TaskQueueBase*>(current_thread) == task_queue; |
| 64 | } |
| 65 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 66 | } // namespace |
| 67 | |
Johannes Kron | da843fe | 2022-06-23 11:18:26 | [diff] [blame] | 68 | ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t remote_ssrc, |
| 69 | Clock* clock, |
| 70 | TaskQueueBase* worker_thread) |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 71 | : clock_(clock), |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 72 | start_ms_(clock->TimeInMilliseconds()), |
Tommi | b2db989 | 2021-08-23 20:44:49 | [diff] [blame] | 73 | remote_ssrc_(remote_ssrc), |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 74 | // 1000ms window, scale 1000 for ms to s. |
| 75 | decode_fps_estimator_(1000, 1000), |
| 76 | renders_fps_estimator_(1000, 1000), |
| 77 | render_fps_tracker_(100, 10u), |
| 78 | render_pixel_tracker_(100, 10u), |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 79 | video_quality_observer_(new VideoQualityObserver()), |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 80 | interframe_delay_max_moving_(kMovingMaxWindowMs), |
| 81 | freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs), |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 82 | last_content_type_(VideoContentType::UNSPECIFIED), |
| 83 | last_codec_type_(kVideoCodecVP8), |
| 84 | num_delayed_frames_rendered_(0), |
| 85 | sum_missed_render_deadline_ms_(0), |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 86 | timing_frame_info_counter_(kMovingMaxWindowMs), |
| 87 | worker_thread_(worker_thread) { |
| 88 | RTC_DCHECK(worker_thread); |
| 89 | decode_queue_.Detach(); |
| 90 | incoming_render_queue_.Detach(); |
Tommi | b2db989 | 2021-08-23 20:44:49 | [diff] [blame] | 91 | stats_.ssrc = remote_ssrc_; |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { |
| 95 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void ReceiveStatisticsProxy::UpdateHistograms( |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 99 | std::optional<int> fraction_lost, |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 100 | const StreamDataCounters& rtp_stats, |
| 101 | const StreamDataCounters* rtx_stats) { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 102 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 103 | |
| 104 | char log_stream_buf[8 * 1024]; |
| 105 | rtc::SimpleStringBuilder log_stream(log_stream_buf); |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 106 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 107 | int stream_duration_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000; |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 108 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 109 | if (stats_.frame_counts.key_frames > 0 || |
| 110 | stats_.frame_counts.delta_frames > 0) { |
| 111 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.ReceiveStreamLifetimeInSeconds", |
| 112 | stream_duration_sec); |
| 113 | log_stream << "WebRTC.Video.ReceiveStreamLifetimeInSeconds " |
| 114 | << stream_duration_sec << '\n'; |
| 115 | } |
| 116 | |
| 117 | log_stream << "Frames decoded " << stats_.frames_decoded << '\n'; |
| 118 | |
| 119 | if (num_unique_frames_) { |
| 120 | int num_dropped_frames = *num_unique_frames_ - stats_.frames_decoded; |
| 121 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DroppedFrames.Receiver", |
| 122 | num_dropped_frames); |
| 123 | log_stream << "WebRTC.Video.DroppedFrames.Receiver " << num_dropped_frames |
| 124 | << '\n'; |
| 125 | } |
| 126 | |
| 127 | if (fraction_lost && stream_duration_sec >= metrics::kMinRunTimeInSeconds) { |
| 128 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent", |
| 129 | *fraction_lost); |
| 130 | log_stream << "WebRTC.Video.ReceivedPacketsLostInPercent " << *fraction_lost |
| 131 | << '\n'; |
| 132 | } |
| 133 | |
| 134 | if (first_decoded_frame_time_ms_) { |
| 135 | const int64_t elapsed_ms = |
| 136 | (clock_->TimeInMilliseconds() - *first_decoded_frame_time_ms_); |
| 137 | if (elapsed_ms >= |
| 138 | metrics::kMinRunTimeInSeconds * rtc::kNumMillisecsPerSec) { |
| 139 | int decoded_fps = static_cast<int>( |
| 140 | (stats_.frames_decoded * 1000.0f / elapsed_ms) + 0.5f); |
| 141 | RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.DecodedFramesPerSecond", |
| 142 | decoded_fps); |
| 143 | log_stream << "WebRTC.Video.DecodedFramesPerSecond " << decoded_fps |
| 144 | << '\n'; |
| 145 | |
| 146 | const uint32_t frames_rendered = stats_.frames_rendered; |
| 147 | if (frames_rendered > 0) { |
| 148 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.DelayedFramesToRenderer", |
| 149 | static_cast<int>(num_delayed_frames_rendered_ * |
| 150 | 100 / frames_rendered)); |
| 151 | if (num_delayed_frames_rendered_ > 0) { |
| 152 | RTC_HISTOGRAM_COUNTS_1000( |
| 153 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs", |
| 154 | static_cast<int>(sum_missed_render_deadline_ms_ / |
| 155 | num_delayed_frames_rendered_)); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | const int kMinRequiredSamples = 200; |
| 162 | int samples = static_cast<int>(render_fps_tracker_.TotalSampleCount()); |
| 163 | if (samples >= kMinRequiredSamples) { |
| 164 | int rendered_fps = round(render_fps_tracker_.ComputeTotalRate()); |
| 165 | RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond", |
| 166 | rendered_fps); |
| 167 | log_stream << "WebRTC.Video.RenderFramesPerSecond " << rendered_fps << '\n'; |
| 168 | RTC_HISTOGRAM_COUNTS_100000( |
| 169 | "WebRTC.Video.RenderSqrtPixelsPerSecond", |
| 170 | round(render_pixel_tracker_.ComputeTotalRate())); |
| 171 | } |
| 172 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 173 | std::optional<int> sync_offset_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 174 | sync_offset_counter_.Avg(kMinRequiredSamples); |
| 175 | if (sync_offset_ms) { |
| 176 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", |
| 177 | *sync_offset_ms); |
| 178 | log_stream << "WebRTC.Video.AVSyncOffsetInMs " << *sync_offset_ms << '\n'; |
| 179 | } |
| 180 | AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats(); |
| 181 | if (freq_offset_stats.num_samples > 0) { |
| 182 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz", |
| 183 | freq_offset_stats.average); |
| 184 | log_stream << "WebRTC.Video.RtpToNtpFreqOffsetInKhz " |
| 185 | << freq_offset_stats.ToString() << '\n'; |
| 186 | } |
| 187 | |
| 188 | int num_total_frames = |
| 189 | stats_.frame_counts.key_frames + stats_.frame_counts.delta_frames; |
| 190 | if (num_total_frames >= kMinRequiredSamples) { |
| 191 | int num_key_frames = stats_.frame_counts.key_frames; |
| 192 | int key_frames_permille = |
| 193 | (num_key_frames * 1000 + num_total_frames / 2) / num_total_frames; |
| 194 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille", |
| 195 | key_frames_permille); |
| 196 | log_stream << "WebRTC.Video.KeyFramesReceivedInPermille " |
| 197 | << key_frames_permille << '\n'; |
| 198 | } |
| 199 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 200 | std::optional<int> qp = qp_counters_.vp8.Avg(kMinRequiredSamples); |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 201 | if (qp) { |
| 202 | RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", *qp); |
| 203 | log_stream << "WebRTC.Video.Decoded.Vp8.Qp " << *qp << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 204 | } |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 205 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 206 | std::optional<int> decode_ms = decode_time_counter_.Avg(kMinRequiredSamples); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 207 | if (decode_ms) { |
| 208 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", *decode_ms); |
| 209 | log_stream << "WebRTC.Video.DecodeTimeInMs " << *decode_ms << '\n'; |
| 210 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 211 | std::optional<int> jb_delay_ms = |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 212 | jitter_delay_counter_.Avg(kMinRequiredSamples); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 213 | if (jb_delay_ms) { |
| 214 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", |
| 215 | *jb_delay_ms); |
| 216 | log_stream << "WebRTC.Video.JitterBufferDelayInMs " << *jb_delay_ms << '\n'; |
| 217 | } |
| 218 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 219 | std::optional<int> target_delay_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 220 | target_delay_counter_.Avg(kMinRequiredSamples); |
| 221 | if (target_delay_ms) { |
| 222 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", |
| 223 | *target_delay_ms); |
| 224 | log_stream << "WebRTC.Video.TargetDelayInMs " << *target_delay_ms << '\n'; |
| 225 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 226 | std::optional<int> current_delay_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 227 | current_delay_counter_.Avg(kMinRequiredSamples); |
| 228 | if (current_delay_ms) { |
| 229 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs", |
| 230 | *current_delay_ms); |
| 231 | log_stream << "WebRTC.Video.CurrentDelayInMs " << *current_delay_ms << '\n'; |
| 232 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 233 | std::optional<int> delay_ms = oneway_delay_counter_.Avg(kMinRequiredSamples); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 234 | if (delay_ms) |
| 235 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", *delay_ms); |
| 236 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 237 | for (const auto& it : content_specific_stats_) { |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 238 | // For the metric Foo we report the following slices: |
| 239 | // WebRTC.Video.Foo, |
| 240 | // WebRTC.Video.Screenshare.Foo, |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 241 | auto content_type = it.first; |
| 242 | auto stats = it.second; |
| 243 | std::string uma_prefix = UmaPrefixForContentType(content_type); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 244 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 245 | std::optional<int> e2e_delay_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 246 | stats.e2e_delay_counter.Avg(kMinRequiredSamples); |
| 247 | if (e2e_delay_ms) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 248 | RTC_HISTOGRAM_COUNTS_SPARSE_10000(uma_prefix + ".EndToEndDelayInMs", |
| 249 | *e2e_delay_ms); |
| 250 | log_stream << uma_prefix << ".EndToEndDelayInMs" |
| 251 | << " " << *e2e_delay_ms << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 252 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 253 | std::optional<int> e2e_delay_max_ms = stats.e2e_delay_counter.Max(); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 254 | if (e2e_delay_max_ms && e2e_delay_ms) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 255 | RTC_HISTOGRAM_COUNTS_SPARSE_100000(uma_prefix + ".EndToEndDelayMaxInMs", |
| 256 | *e2e_delay_max_ms); |
| 257 | log_stream << uma_prefix << ".EndToEndDelayMaxInMs" |
| 258 | << " " << *e2e_delay_max_ms << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 259 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 260 | std::optional<int> interframe_delay_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 261 | stats.interframe_delay_counter.Avg(kMinRequiredSamples); |
| 262 | if (interframe_delay_ms) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 263 | RTC_HISTOGRAM_COUNTS_SPARSE_10000(uma_prefix + ".InterframeDelayInMs", |
| 264 | *interframe_delay_ms); |
| 265 | log_stream << uma_prefix << ".InterframeDelayInMs" |
| 266 | << " " << *interframe_delay_ms << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 267 | } |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 268 | std::optional<int> interframe_delay_max_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 269 | stats.interframe_delay_counter.Max(); |
| 270 | if (interframe_delay_max_ms && interframe_delay_ms) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 271 | RTC_HISTOGRAM_COUNTS_SPARSE_10000(uma_prefix + ".InterframeDelayMaxInMs", |
| 272 | *interframe_delay_max_ms); |
| 273 | log_stream << uma_prefix << ".InterframeDelayMaxInMs" |
| 274 | << " " << *interframe_delay_max_ms << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 275 | } |
| 276 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 277 | std::optional<uint32_t> interframe_delay_95p_ms = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 278 | stats.interframe_delay_percentiles.GetPercentile(0.95f); |
| 279 | if (interframe_delay_95p_ms && interframe_delay_ms != -1) { |
| 280 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 281 | uma_prefix + ".InterframeDelay95PercentileInMs", |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 282 | *interframe_delay_95p_ms); |
| 283 | log_stream << uma_prefix << ".InterframeDelay95PercentileInMs" |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 284 | << " " << *interframe_delay_95p_ms << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 285 | } |
| 286 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 287 | std::optional<int> width = stats.received_width.Avg(kMinRequiredSamples); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 288 | if (width) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 289 | RTC_HISTOGRAM_COUNTS_SPARSE_10000(uma_prefix + ".ReceivedWidthInPixels", |
| 290 | *width); |
| 291 | log_stream << uma_prefix << ".ReceivedWidthInPixels" |
| 292 | << " " << *width << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 293 | } |
| 294 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 295 | std::optional<int> height = stats.received_height.Avg(kMinRequiredSamples); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 296 | if (height) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 297 | RTC_HISTOGRAM_COUNTS_SPARSE_10000(uma_prefix + ".ReceivedHeightInPixels", |
| 298 | *height); |
| 299 | log_stream << uma_prefix << ".ReceivedHeightInPixels" |
| 300 | << " " << *height << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 301 | } |
| 302 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 303 | std::optional<double> corruption_score = stats.corruption_score.GetMean(); |
Emil Vardar | 3f1e51d | 2024-08-27 12:14:33 | [diff] [blame] | 304 | if (corruption_score) { |
| 305 | // Granularity level: 2e-3. |
| 306 | RTC_HISTOGRAM_COUNTS_SPARSE(uma_prefix + ".CorruptionLikelihoodPermille", |
| 307 | static_cast<int>(*corruption_score * 1000), |
| 308 | /*min=*/0, /*max=*/1000, |
| 309 | /*bucket_count=*/500); |
| 310 | log_stream << uma_prefix << ".CorruptionLikelihoodPermille" << " " |
| 311 | << static_cast<int>(*corruption_score * 1000) << '\n'; |
| 312 | } |
| 313 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 314 | if (content_type != VideoContentType::UNSPECIFIED) { |
| 315 | // Don't report these 3 metrics unsliced, as more precise variants |
| 316 | // are reported separately in this method. |
| 317 | float flow_duration_sec = stats.flow_duration_ms / 1000.0; |
| 318 | if (flow_duration_sec >= metrics::kMinRunTimeInSeconds) { |
| 319 | int media_bitrate_kbps = static_cast<int>(stats.total_media_bytes * 8 / |
| 320 | flow_duration_sec / 1000); |
| 321 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 322 | uma_prefix + ".MediaBitrateReceivedInKbps", media_bitrate_kbps); |
| 323 | log_stream << uma_prefix << ".MediaBitrateReceivedInKbps" |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 324 | << " " << media_bitrate_kbps << '\n'; |
| 325 | } |
| 326 | |
| 327 | int num_total_frames = |
| 328 | stats.frame_counts.key_frames + stats.frame_counts.delta_frames; |
| 329 | if (num_total_frames >= kMinRequiredSamples) { |
| 330 | int num_key_frames = stats.frame_counts.key_frames; |
| 331 | int key_frames_permille = |
| 332 | (num_key_frames * 1000 + num_total_frames / 2) / num_total_frames; |
| 333 | RTC_HISTOGRAM_COUNTS_SPARSE_1000( |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 334 | uma_prefix + ".KeyFramesReceivedInPermille", key_frames_permille); |
| 335 | log_stream << uma_prefix << ".KeyFramesReceivedInPermille" |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 336 | << " " << key_frames_permille << '\n'; |
| 337 | } |
| 338 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 339 | std::optional<int> qp = stats.qp_counter.Avg(kMinRequiredSamples); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 340 | if (qp) { |
Harald Alvestrand | 00f1122 | 2023-07-21 07:23:01 | [diff] [blame] | 341 | RTC_HISTOGRAM_COUNTS_SPARSE_200(uma_prefix + ".Decoded.Vp8.Qp", *qp); |
| 342 | log_stream << uma_prefix << ".Decoded.Vp8.Qp" |
| 343 | << " " << *qp << '\n'; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | StreamDataCounters rtp_rtx_stats = rtp_stats; |
| 349 | if (rtx_stats) |
| 350 | rtp_rtx_stats.Add(*rtx_stats); |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 351 | |
Danil Chapovalov | 0f1a2c5 | 2023-05-26 09:30:26 | [diff] [blame] | 352 | TimeDelta elapsed = rtp_rtx_stats.TimeSinceFirstPacket(clock_->CurrentTime()); |
| 353 | if (elapsed >= TimeDelta::Seconds(metrics::kMinRunTimeInSeconds)) { |
| 354 | int64_t elapsed_sec = elapsed.seconds(); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 355 | RTC_HISTOGRAM_COUNTS_10000( |
| 356 | "WebRTC.Video.BitrateReceivedInKbps", |
| 357 | static_cast<int>(rtp_rtx_stats.transmitted.TotalBytes() * 8 / |
| 358 | elapsed_sec / 1000)); |
| 359 | int media_bitrate_kbs = static_cast<int>(rtp_stats.MediaPayloadBytes() * 8 / |
| 360 | elapsed_sec / 1000); |
| 361 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.MediaBitrateReceivedInKbps", |
| 362 | media_bitrate_kbs); |
| 363 | log_stream << "WebRTC.Video.MediaBitrateReceivedInKbps " |
| 364 | << media_bitrate_kbs << '\n'; |
| 365 | RTC_HISTOGRAM_COUNTS_10000( |
| 366 | "WebRTC.Video.PaddingBitrateReceivedInKbps", |
| 367 | static_cast<int>(rtp_rtx_stats.transmitted.padding_bytes * 8 / |
| 368 | elapsed_sec / 1000)); |
| 369 | RTC_HISTOGRAM_COUNTS_10000( |
| 370 | "WebRTC.Video.RetransmittedBitrateReceivedInKbps", |
| 371 | static_cast<int>(rtp_rtx_stats.retransmitted.TotalBytes() * 8 / |
| 372 | elapsed_sec / 1000)); |
| 373 | if (rtx_stats) { |
| 374 | RTC_HISTOGRAM_COUNTS_10000( |
| 375 | "WebRTC.Video.RtxBitrateReceivedInKbps", |
| 376 | static_cast<int>(rtx_stats->transmitted.TotalBytes() * 8 / |
| 377 | elapsed_sec / 1000)); |
| 378 | } |
| 379 | const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts; |
| 380 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute", |
| 381 | counters.nack_packets * 60 / elapsed_sec); |
| 382 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute", |
| 383 | counters.fir_packets * 60 / elapsed_sec); |
| 384 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute", |
| 385 | counters.pli_packets * 60 / elapsed_sec); |
| 386 | if (counters.nack_requests > 0) { |
| 387 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent", |
| 388 | counters.UniqueNackRequestsInPercent()); |
| 389 | } |
| 390 | } |
| 391 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 392 | RTC_LOG(LS_INFO) << log_stream.str(); |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 393 | video_quality_observer_->UpdateHistograms( |
| 394 | videocontenttypehelpers::IsScreenshare(last_content_type_)); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 395 | } |
| 396 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 397 | void ReceiveStatisticsProxy::UpdateFramerate(int64_t now_ms) const { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 398 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 399 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 400 | int64_t old_frames_ms = now_ms - kRateStatisticsWindowSizeMs; |
| 401 | while (!frame_window_.empty() && |
| 402 | frame_window_.begin()->first < old_frames_ms) { |
| 403 | frame_window_.erase(frame_window_.begin()); |
| 404 | } |
| 405 | |
| 406 | size_t framerate = |
| 407 | (frame_window_.size() * 1000 + 500) / kRateStatisticsWindowSizeMs; |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 408 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 409 | stats_.network_frame_rate = static_cast<int>(framerate); |
| 410 | } |
| 411 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 412 | std::optional<int64_t> |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 413 | ReceiveStatisticsProxy::GetCurrentEstimatedPlayoutNtpTimestampMs( |
| 414 | int64_t now_ms) const { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 415 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 416 | if (!last_estimated_playout_ntp_timestamp_ms_ || |
| 417 | !last_estimated_playout_time_ms_) { |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 418 | return std::nullopt; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 419 | } |
| 420 | int64_t elapsed_ms = now_ms - *last_estimated_playout_time_ms_; |
| 421 | return *last_estimated_playout_ntp_timestamp_ms_ + elapsed_ms; |
| 422 | } |
| 423 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 424 | VideoReceiveStreamInterface::Stats ReceiveStatisticsProxy::GetStats() const { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 425 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 426 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 427 | // Like VideoReceiveStreamInterface::GetStats, called on the worker thread |
Danil Chapovalov | 9e09a1f | 2022-09-08 16:38:10 | [diff] [blame] | 428 | // from StatsCollector::ExtractMediaInfo via worker_thread()->BlockingCall(). |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 429 | // WebRtcVideoChannel::GetStats(), GetVideoReceiverInfo. |
| 430 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 431 | // Get current frame rates here, as only updating them on new frames prevents |
| 432 | // us from ever correctly displaying frame rate of 0. |
| 433 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 434 | UpdateFramerate(now_ms); |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 435 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 436 | stats_.render_frame_rate = renders_fps_estimator_.Rate(now_ms).value_or(0); |
| 437 | stats_.decode_frame_rate = decode_fps_estimator_.Rate(now_ms).value_or(0); |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 438 | |
| 439 | if (last_decoded_frame_time_ms_) { |
| 440 | // Avoid using a newer timestamp than might be pending for decoded frames. |
| 441 | // If we do use now_ms, we might roll the max window to a value that is |
| 442 | // higher than that of a decoded frame timestamp that we haven't yet |
| 443 | // captured the data for (i.e. pending call to OnDecodedFrame). |
| 444 | stats_.interframe_delay_max_ms = |
| 445 | interframe_delay_max_moving_.Max(*last_decoded_frame_time_ms_) |
| 446 | .value_or(-1); |
| 447 | } else { |
Artem Titov | ab30d72 | 2021-07-27 14:22:11 | [diff] [blame] | 448 | // We're paused. Avoid changing the state of `interframe_delay_max_moving_`. |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 449 | stats_.interframe_delay_max_ms = -1; |
| 450 | } |
| 451 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 452 | stats_.freeze_count = video_quality_observer_->NumFreezes(); |
| 453 | stats_.pause_count = video_quality_observer_->NumPauses(); |
| 454 | stats_.total_freezes_duration_ms = |
| 455 | video_quality_observer_->TotalFreezesDurationMs(); |
| 456 | stats_.total_pauses_duration_ms = |
| 457 | video_quality_observer_->TotalPausesDurationMs(); |
Sergey Silkin | ed0dd8e | 2022-12-20 12:58:15 | [diff] [blame] | 458 | stats_.total_inter_frame_delay = |
| 459 | static_cast<double>(video_quality_observer_->TotalFramesDurationMs()) / |
| 460 | rtc::kNumMillisecsPerSec; |
| 461 | stats_.total_squared_inter_frame_delay = |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 462 | video_quality_observer_->SumSquaredFrameDurationsSec(); |
Sergey Silkin | ed0dd8e | 2022-12-20 12:58:15 | [diff] [blame] | 463 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 464 | stats_.content_type = last_content_type_; |
| 465 | stats_.timing_frame_info = timing_frame_info_counter_.Max(now_ms); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 466 | stats_.estimated_playout_ntp_timestamp_ms = |
| 467 | GetCurrentEstimatedPlayoutNtpTimestampMs(now_ms); |
| 468 | return stats_; |
| 469 | } |
| 470 | |
| 471 | void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 472 | RTC_DCHECK_RUN_ON(&decode_queue_); |
Danil Chapovalov | 95eeaa7 | 2022-07-06 08:14:29 | [diff] [blame] | 473 | worker_thread_->PostTask(SafeTask(task_safety_.flag(), [payload_type, this] { |
Tommi | a98cea8 | 2020-05-13 13:06:19 | [diff] [blame] | 474 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 475 | stats_.current_payload_type = payload_type; |
| 476 | })); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 477 | } |
| 478 | |
Evan Shrubsole | 09da10e | 2022-10-14 14:38:31 | [diff] [blame] | 479 | void ReceiveStatisticsProxy::OnDecoderInfo( |
| 480 | const VideoDecoder::DecoderInfo& decoder_info) { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 481 | RTC_DCHECK_RUN_ON(&decode_queue_); |
Danil Chapovalov | 95eeaa7 | 2022-07-06 08:14:29 | [diff] [blame] | 482 | worker_thread_->PostTask(SafeTask( |
Evan Shrubsole | 09da10e | 2022-10-14 14:38:31 | [diff] [blame] | 483 | task_safety_.flag(), |
| 484 | [this, name = decoder_info.implementation_name, |
| 485 | is_hardware_accelerated = decoder_info.is_hardware_accelerated]() { |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 486 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 487 | stats_.decoder_implementation_name = name; |
Evan Shrubsole | 09da10e | 2022-10-14 14:38:31 | [diff] [blame] | 488 | stats_.power_efficient_decoder = is_hardware_accelerated; |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 489 | })); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 490 | } |
| 491 | |
Rasmus Brandt | f0820ff | 2023-05-25 07:37:16 | [diff] [blame] | 492 | void ReceiveStatisticsProxy::OnDecodableFrame(TimeDelta jitter_buffer_delay, |
| 493 | TimeDelta target_delay, |
| 494 | TimeDelta minimum_delay) { |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 495 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 496 | // Cumulative stats exposed through standardized GetStats. |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 497 | stats_.jitter_buffer_delay += jitter_buffer_delay; |
Rasmus Brandt | f0820ff | 2023-05-25 07:37:16 | [diff] [blame] | 498 | stats_.jitter_buffer_target_delay += target_delay; |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 499 | ++stats_.jitter_buffer_emitted_count; |
Rasmus Brandt | f0820ff | 2023-05-25 07:37:16 | [diff] [blame] | 500 | stats_.jitter_buffer_minimum_delay += minimum_delay; |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 501 | } |
| 502 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 503 | void ReceiveStatisticsProxy::OnFrameBufferTimingsUpdated( |
Rasmus Brandt | 24f9a8b | 2023-05-08 14:32:48 | [diff] [blame] | 504 | int estimated_max_decode_time_ms, |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 505 | int current_delay_ms, |
| 506 | int target_delay_ms, |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 507 | int jitter_delay_ms, |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 508 | int min_playout_delay_ms, |
| 509 | int render_delay_ms) { |
Evan Shrubsole | 9a99905 | 2021-12-12 14:27:00 | [diff] [blame] | 510 | RTC_DCHECK_RUN_ON(&main_thread_); |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 511 | // Instantaneous stats exposed through legacy GetStats. |
Rasmus Brandt | 24f9a8b | 2023-05-08 14:32:48 | [diff] [blame] | 512 | stats_.max_decode_ms = estimated_max_decode_time_ms; |
Evan Shrubsole | 9a99905 | 2021-12-12 14:27:00 | [diff] [blame] | 513 | stats_.current_delay_ms = current_delay_ms; |
| 514 | stats_.target_delay_ms = target_delay_ms; |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 515 | stats_.jitter_buffer_ms = jitter_delay_ms; |
Evan Shrubsole | 9a99905 | 2021-12-12 14:27:00 | [diff] [blame] | 516 | stats_.min_playout_delay_ms = min_playout_delay_ms; |
| 517 | stats_.render_delay_ms = render_delay_ms; |
Rasmus Brandt | 621cb29 | 2023-05-24 11:29:14 | [diff] [blame] | 518 | |
| 519 | // UMA stats. |
| 520 | jitter_delay_counter_.Add(jitter_delay_ms); |
Evan Shrubsole | 9a99905 | 2021-12-12 14:27:00 | [diff] [blame] | 521 | target_delay_counter_.Add(target_delay_ms); |
| 522 | current_delay_counter_.Add(current_delay_ms); |
Rasmus Brandt | 0df40d1 | 2023-05-08 09:32:59 | [diff] [blame] | 523 | // Estimated one-way delay: network delay (rtt/2) + target_delay_ms (jitter |
| 524 | // delay + decode time + render delay). |
| 525 | oneway_delay_counter_.Add(target_delay_ms + avg_rtt_ms_ / 2); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void ReceiveStatisticsProxy::OnUniqueFramesCounted(int num_unique_frames) { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 529 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 530 | num_unique_frames_.emplace(num_unique_frames); |
| 531 | } |
| 532 | |
| 533 | void ReceiveStatisticsProxy::OnTimingFrameInfoUpdated( |
| 534 | const TimingFrameInfo& info) { |
Evan Shrubsole | 9a99905 | 2021-12-12 14:27:00 | [diff] [blame] | 535 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 536 | if (info.flags != VideoSendTiming::kInvalid) { |
| 537 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 538 | timing_frame_info_counter_.Add(info, now_ms); |
| 539 | } |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 540 | |
Evan Shrubsole | 9a99905 | 2021-12-12 14:27:00 | [diff] [blame] | 541 | // Measure initial decoding latency between the first frame arriving and |
| 542 | // the first frame being decoded. |
| 543 | if (!first_frame_received_time_ms_.has_value()) { |
| 544 | first_frame_received_time_ms_ = info.receive_finish_ms; |
| 545 | } |
| 546 | if (stats_.first_frame_received_to_decoded_ms == -1 && |
| 547 | first_decoded_frame_time_ms_) { |
| 548 | stats_.first_frame_received_to_decoded_ms = |
| 549 | *first_decoded_frame_time_ms_ - *first_frame_received_time_ms_; |
| 550 | } |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated( |
| 554 | uint32_t ssrc, |
| 555 | const RtcpPacketTypeCounter& packet_counter) { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 556 | if (ssrc != remote_ssrc_) |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 557 | return; |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 558 | |
Tommi | 47173c9 | 2020-05-13 19:26:37 | [diff] [blame] | 559 | if (!IsCurrentTaskQueueOrThread(worker_thread_)) { |
Tomas Gunnarsson | f25761d | 2020-06-03 20:55:33 | [diff] [blame] | 560 | // RtpRtcpInterface::Configuration has a single |
| 561 | // RtcpPacketTypeCounterObserver and that same configuration may be used for |
| 562 | // both receiver and sender (see ModuleRtpRtcpImpl::ModuleRtpRtcpImpl). The |
| 563 | // RTCPSender implementation currently makes calls to this function on a |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 564 | // process thread whereas the RTCPReceiver implementation calls back on the |
| 565 | // [main] worker thread. |
| 566 | // So until the sender implementation has been updated, we work around this |
| 567 | // here by posting the update to the expected thread. We make a by value |
Artem Titov | ab30d72 | 2021-07-27 14:22:11 | [diff] [blame] | 568 | // copy of the `task_safety_` to handle the case if the queued task |
| 569 | // runs after the `ReceiveStatisticsProxy` has been deleted. In such a |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 570 | // case the packet_counter update won't be recorded. |
| 571 | worker_thread_->PostTask( |
Danil Chapovalov | 95eeaa7 | 2022-07-06 08:14:29 | [diff] [blame] | 572 | SafeTask(task_safety_.flag(), [ssrc, packet_counter, this]() { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 573 | RtcpPacketTypesCounterUpdated(ssrc, packet_counter); |
| 574 | })); |
| 575 | return; |
| 576 | } |
| 577 | |
| 578 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 579 | stats_.rtcp_packet_type_counts = packet_counter; |
| 580 | } |
| 581 | |
| 582 | void ReceiveStatisticsProxy::OnCname(uint32_t ssrc, absl::string_view cname) { |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 583 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 584 | // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we |
| 585 | // receive stats from one of them. |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 586 | if (remote_ssrc_ != ssrc) |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 587 | return; |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 588 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 589 | stats_.c_name = std::string(cname); |
| 590 | } |
| 591 | |
| 592 | void ReceiveStatisticsProxy::OnDecodedFrame(const VideoFrame& frame, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 593 | std::optional<uint8_t> qp, |
Philipp Hancke | d970b09 | 2022-06-17 05:34:23 | [diff] [blame] | 594 | TimeDelta decode_time, |
Philipp Hancke | 5165743 | 2023-08-15 08:20:50 | [diff] [blame] | 595 | VideoContentType content_type, |
| 596 | VideoFrameType frame_type) { |
Philipp Hancke | a204ad2 | 2022-07-08 16:43:25 | [diff] [blame] | 597 | TimeDelta processing_delay = TimeDelta::Zero(); |
Philipp Hancke | a16a6a6 | 2022-04-25 10:21:30 | [diff] [blame] | 598 | webrtc::Timestamp current_time = clock_->CurrentTime(); |
| 599 | // TODO(bugs.webrtc.org/13984): some tests do not fill packet_infos(). |
Philipp Hancke | a204ad2 | 2022-07-08 16:43:25 | [diff] [blame] | 600 | TimeDelta assembly_time = TimeDelta::Zero(); |
Philipp Hancke | a16a6a6 | 2022-04-25 10:21:30 | [diff] [blame] | 601 | if (frame.packet_infos().size() > 0) { |
Philipp Hancke | 0359ba2 | 2022-05-05 13:55:36 | [diff] [blame] | 602 | const auto [first_packet, last_packet] = std::minmax_element( |
Philipp Hancke | a16a6a6 | 2022-04-25 10:21:30 | [diff] [blame] | 603 | frame.packet_infos().cbegin(), frame.packet_infos().cend(), |
| 604 | [](const webrtc::RtpPacketInfo& a, const webrtc::RtpPacketInfo& b) { |
| 605 | return a.receive_time() < b.receive_time(); |
| 606 | }); |
Philipp Hancke | 0359ba2 | 2022-05-05 13:55:36 | [diff] [blame] | 607 | if (first_packet->receive_time().IsFinite()) { |
| 608 | processing_delay = current_time - first_packet->receive_time(); |
| 609 | // Extract frame assembly time (i.e. time between earliest and latest |
| 610 | // packet arrival). Note: for single-packet frames this will be 0. |
| 611 | assembly_time = |
| 612 | last_packet->receive_time() - first_packet->receive_time(); |
| 613 | } |
Philipp Hancke | a16a6a6 | 2022-04-25 10:21:30 | [diff] [blame] | 614 | } |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 615 | // See VCMDecodedFrameCallback::Decoded for more info on what thread/queue we |
| 616 | // may be on. E.g. on iOS this gets called on |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 617 | // "com.apple.coremedia.decompressionsession.clientcallback" |
Philipp Hancke | a16a6a6 | 2022-04-25 10:21:30 | [diff] [blame] | 618 | VideoFrameMetaData meta(frame, current_time); |
Philipp Hancke | 5165743 | 2023-08-15 08:20:50 | [diff] [blame] | 619 | worker_thread_->PostTask(SafeTask( |
| 620 | task_safety_.flag(), [meta, qp, decode_time, processing_delay, |
| 621 | assembly_time, content_type, frame_type, this]() { |
Philipp Hancke | d970b09 | 2022-06-17 05:34:23 | [diff] [blame] | 622 | OnDecodedFrame(meta, qp, decode_time, processing_delay, assembly_time, |
Philipp Hancke | 5165743 | 2023-08-15 08:20:50 | [diff] [blame] | 623 | content_type, frame_type); |
Philipp Hancke | 0359ba2 | 2022-05-05 13:55:36 | [diff] [blame] | 624 | })); |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 625 | } |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 626 | |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 627 | void ReceiveStatisticsProxy::OnDecodedFrame( |
| 628 | const VideoFrameMetaData& frame_meta, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 629 | std::optional<uint8_t> qp, |
Philipp Hancke | d970b09 | 2022-06-17 05:34:23 | [diff] [blame] | 630 | TimeDelta decode_time, |
Philipp Hancke | a204ad2 | 2022-07-08 16:43:25 | [diff] [blame] | 631 | TimeDelta processing_delay, |
| 632 | TimeDelta assembly_time, |
Philipp Hancke | 5165743 | 2023-08-15 08:20:50 | [diff] [blame] | 633 | VideoContentType content_type, |
| 634 | VideoFrameType frame_type) { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 635 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 636 | |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 637 | const bool is_screenshare = |
| 638 | videocontenttypehelpers::IsScreenshare(content_type); |
| 639 | const bool was_screenshare = |
| 640 | videocontenttypehelpers::IsScreenshare(last_content_type_); |
| 641 | |
| 642 | if (is_screenshare != was_screenshare) { |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 643 | // Reset the quality observer if content type is switched. But first report |
| 644 | // stats for the previous part of the call. |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 645 | video_quality_observer_->UpdateHistograms(was_screenshare); |
| 646 | video_quality_observer_.reset(new VideoQualityObserver()); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 647 | } |
| 648 | |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 649 | video_quality_observer_->OnDecodedFrame(frame_meta.rtp_timestamp, qp, |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 650 | last_codec_type_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 651 | |
| 652 | ContentSpecificStats* content_specific_stats = |
| 653 | &content_specific_stats_[content_type]; |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 654 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 655 | ++stats_.frames_decoded; |
Philipp Hancke | 5165743 | 2023-08-15 08:20:50 | [diff] [blame] | 656 | if (frame_type == VideoFrameType::kVideoFrameKey) { |
| 657 | ++stats_.frame_counts.key_frames; |
| 658 | } else { |
| 659 | ++stats_.frame_counts.delta_frames; |
| 660 | } |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 661 | if (qp) { |
| 662 | if (!stats_.qp_sum) { |
| 663 | if (stats_.frames_decoded != 1) { |
| 664 | RTC_LOG(LS_WARNING) |
| 665 | << "Frames decoded was not 1 when first qp value was received."; |
| 666 | } |
| 667 | stats_.qp_sum = 0; |
| 668 | } |
| 669 | *stats_.qp_sum += *qp; |
| 670 | content_specific_stats->qp_counter.Add(*qp); |
| 671 | } else if (stats_.qp_sum) { |
| 672 | RTC_LOG(LS_WARNING) |
| 673 | << "QP sum was already set and no QP was given for a frame."; |
| 674 | stats_.qp_sum.reset(); |
| 675 | } |
Philipp Hancke | d970b09 | 2022-06-17 05:34:23 | [diff] [blame] | 676 | decode_time_counter_.Add(decode_time.ms()); |
| 677 | stats_.decode_ms = decode_time.ms(); |
| 678 | stats_.total_decode_time += decode_time; |
Philipp Hancke | a16a6a6 | 2022-04-25 10:21:30 | [diff] [blame] | 679 | stats_.total_processing_delay += processing_delay; |
Philipp Hancke | 0359ba2 | 2022-05-05 13:55:36 | [diff] [blame] | 680 | stats_.total_assembly_time += assembly_time; |
| 681 | if (!assembly_time.IsZero()) { |
| 682 | ++stats_.frames_assembled_from_multiple_packets; |
| 683 | } |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 684 | |
| 685 | last_content_type_ = content_type; |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 686 | decode_fps_estimator_.Update(1, frame_meta.decode_timestamp.ms()); |
| 687 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 688 | if (last_decoded_frame_time_ms_) { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 689 | int64_t interframe_delay_ms = |
| 690 | frame_meta.decode_timestamp.ms() - *last_decoded_frame_time_ms_; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 691 | RTC_DCHECK_GE(interframe_delay_ms, 0); |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 692 | interframe_delay_max_moving_.Add(interframe_delay_ms, |
| 693 | frame_meta.decode_timestamp.ms()); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 694 | content_specific_stats->interframe_delay_counter.Add(interframe_delay_ms); |
| 695 | content_specific_stats->interframe_delay_percentiles.Add( |
| 696 | interframe_delay_ms); |
| 697 | content_specific_stats->flow_duration_ms += interframe_delay_ms; |
| 698 | } |
| 699 | if (stats_.frames_decoded == 1) { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 700 | first_decoded_frame_time_ms_.emplace(frame_meta.decode_timestamp.ms()); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 701 | } |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 702 | last_decoded_frame_time_ms_.emplace(frame_meta.decode_timestamp.ms()); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 703 | } |
| 704 | |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 705 | void ReceiveStatisticsProxy::OnRenderedFrame( |
| 706 | const VideoFrameMetaData& frame_meta) { |
| 707 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 708 | // Called from VideoReceiveStream2::OnFrame. |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 709 | |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 710 | RTC_DCHECK_GT(frame_meta.width, 0); |
| 711 | RTC_DCHECK_GT(frame_meta.height, 0); |
| 712 | |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 713 | video_quality_observer_->OnRenderedFrame(frame_meta); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 714 | |
| 715 | ContentSpecificStats* content_specific_stats = |
| 716 | &content_specific_stats_[last_content_type_]; |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 717 | renders_fps_estimator_.Update(1, frame_meta.decode_timestamp.ms()); |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 718 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 719 | ++stats_.frames_rendered; |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 720 | stats_.width = frame_meta.width; |
| 721 | stats_.height = frame_meta.height; |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 722 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 723 | render_fps_tracker_.AddSamples(1); |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 724 | render_pixel_tracker_.AddSamples(sqrt(frame_meta.width * frame_meta.height)); |
| 725 | content_specific_stats->received_width.Add(frame_meta.width); |
| 726 | content_specific_stats->received_height.Add(frame_meta.height); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 727 | |
| 728 | // Consider taking stats_.render_delay_ms into account. |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 729 | const int64_t time_until_rendering_ms = |
| 730 | frame_meta.render_time_ms() - frame_meta.decode_timestamp.ms(); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 731 | if (time_until_rendering_ms < 0) { |
| 732 | sum_missed_render_deadline_ms_ += -time_until_rendering_ms; |
| 733 | ++num_delayed_frames_rendered_; |
| 734 | } |
| 735 | |
Tommi | d7e08c8 | 2020-05-10 09:24:43 | [diff] [blame] | 736 | if (frame_meta.ntp_time_ms > 0) { |
| 737 | int64_t delay_ms = |
| 738 | clock_->CurrentNtpInMilliseconds() - frame_meta.ntp_time_ms; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 739 | if (delay_ms >= 0) { |
| 740 | content_specific_stats->e2e_delay_counter.Add(delay_ms); |
| 741 | } |
| 742 | } |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t video_playout_ntp_ms, |
| 746 | int64_t sync_offset_ms, |
| 747 | double estimated_freq_khz) { |
Tommi | 55107c8 | 2021-06-16 14:31:18 | [diff] [blame] | 748 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 749 | |
Tommi | 55107c8 | 2021-06-16 14:31:18 | [diff] [blame] | 750 | const int64_t now_ms = clock_->TimeInMilliseconds(); |
| 751 | sync_offset_counter_.Add(std::abs(sync_offset_ms)); |
| 752 | stats_.sync_offset_ms = sync_offset_ms; |
| 753 | last_estimated_playout_ntp_timestamp_ms_ = video_playout_ntp_ms; |
| 754 | last_estimated_playout_time_ms_ = now_ms; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 755 | |
Tommi | 55107c8 | 2021-06-16 14:31:18 | [diff] [blame] | 756 | const double kMaxFreqKhz = 10000.0; |
| 757 | int offset_khz = kMaxFreqKhz; |
| 758 | // Should not be zero or negative. If so, report max. |
| 759 | if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0) |
| 760 | offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5); |
| 761 | |
| 762 | freq_offset_counter_.Add(offset_khz); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe, |
| 766 | size_t size_bytes, |
| 767 | VideoContentType content_type) { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 768 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 769 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 770 | // Content type extension is set only for keyframes and should be propagated |
| 771 | // for all the following delta frames. Here we may receive frames out of order |
| 772 | // and miscategorise some delta frames near the layer switch. |
| 773 | // This may slightly offset calculated bitrate and keyframes permille metrics. |
| 774 | VideoContentType propagated_content_type = |
| 775 | is_keyframe ? content_type : last_content_type_; |
| 776 | |
| 777 | ContentSpecificStats* content_specific_stats = |
| 778 | &content_specific_stats_[propagated_content_type]; |
| 779 | |
| 780 | content_specific_stats->total_media_bytes += size_bytes; |
| 781 | if (is_keyframe) { |
| 782 | ++content_specific_stats->frame_counts.key_frames; |
| 783 | } else { |
| 784 | ++content_specific_stats->frame_counts.delta_frames; |
| 785 | } |
| 786 | |
| 787 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 788 | frame_window_.insert(std::make_pair(now_ms, size_bytes)); |
| 789 | UpdateFramerate(now_ms); |
| 790 | } |
| 791 | |
| 792 | void ReceiveStatisticsProxy::OnDroppedFrames(uint32_t frames_dropped) { |
Tommi | 430951a | 2020-05-19 21:27:29 | [diff] [blame] | 793 | // Can be called on either the decode queue or the worker thread |
| 794 | // See FrameBuffer2 for more details. |
Danil Chapovalov | 95eeaa7 | 2022-07-06 08:14:29 | [diff] [blame] | 795 | worker_thread_->PostTask( |
| 796 | SafeTask(task_safety_.flag(), [frames_dropped, this]() { |
| 797 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 798 | stats_.frames_dropped += frames_dropped; |
| 799 | })); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) { |
Evan Shrubsole | a535ee6 | 2022-08-17 09:51:25 | [diff] [blame] | 803 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 804 | last_codec_type_ = codec_type; |
| 805 | if (last_codec_type_ == kVideoCodecVP8 && qp != -1) { |
| 806 | qp_counters_.vp8.Add(qp); |
Evan Shrubsole | a535ee6 | 2022-08-17 09:51:25 | [diff] [blame] | 807 | } |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void ReceiveStatisticsProxy::OnStreamInactive() { |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 811 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 812 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 813 | // TODO(sprang): Figure out any other state that should be reset. |
| 814 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 815 | // Don't report inter-frame delay if stream was paused. |
| 816 | last_decoded_frame_time_ms_.reset(); |
Tommi | d93bf12 | 2020-05-10 18:24:59 | [diff] [blame] | 817 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 818 | video_quality_observer_->OnStreamInactive(); |
| 819 | } |
| 820 | |
Tommi | 674b0c81 | 2020-05-10 19:52:17 | [diff] [blame] | 821 | void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms) { |
Tommi | 822a874 | 2020-05-10 22:42:30 | [diff] [blame] | 822 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | ffd0a84 | 2020-05-11 06:24:47 | [diff] [blame] | 823 | avg_rtt_ms_ = avg_rtt_ms; |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 824 | } |
| 825 | |
Emil Vardar | 3f1e51d | 2024-08-27 12:14:33 | [diff] [blame] | 826 | void ReceiveStatisticsProxy::OnCorruptionScore(double corruption_score, |
| 827 | VideoContentType content_type) { |
Emil Vardar | 129f228 | 2024-10-14 14:40:56 | [diff] [blame] | 828 | worker_thread_->PostTask(SafeTask(task_safety_.flag(), [corruption_score, |
| 829 | content_type, this] { |
| 830 | RTC_DCHECK_RUN_ON(&main_thread_); |
Emil Vardar | 3f1e51d | 2024-08-27 12:14:33 | [diff] [blame] | 831 | |
Emil Vardar | 129f228 | 2024-10-14 14:40:56 | [diff] [blame] | 832 | if (!stats_.corruption_score_sum.has_value()) { |
| 833 | RTC_DCHECK(!stats_.corruption_score_squared_sum.has_value()); |
| 834 | RTC_DCHECK_EQ(stats_.corruption_score_count, 0); |
| 835 | stats_.corruption_score_sum = 0; |
| 836 | stats_.corruption_score_squared_sum = 0; |
| 837 | } |
| 838 | *stats_.corruption_score_sum += corruption_score; |
| 839 | *stats_.corruption_score_squared_sum += corruption_score * corruption_score; |
| 840 | ++stats_.corruption_score_count; |
Emil Vardar | 3f1e51d | 2024-08-27 12:14:33 | [diff] [blame] | 841 | |
Emil Vardar | 129f228 | 2024-10-14 14:40:56 | [diff] [blame] | 842 | ContentSpecificStats* content_specific_stats = |
| 843 | &content_specific_stats_[content_type]; |
| 844 | content_specific_stats->corruption_score.AddSample(corruption_score); |
| 845 | })); |
Emil Vardar | 3f1e51d | 2024-08-27 12:14:33 | [diff] [blame] | 846 | } |
| 847 | |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 848 | void ReceiveStatisticsProxy::DecoderThreadStarting() { |
| 849 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 850 | } |
| 851 | |
| 852 | void ReceiveStatisticsProxy::DecoderThreadStopped() { |
| 853 | RTC_DCHECK_RUN_ON(&main_thread_); |
Tommi | 553c869 | 2020-05-05 13:35:45 | [diff] [blame] | 854 | decode_queue_.Detach(); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | ReceiveStatisticsProxy::ContentSpecificStats::ContentSpecificStats() |
| 858 | : interframe_delay_percentiles(kMaxCommonInterframeDelayMs) {} |
| 859 | |
| 860 | ReceiveStatisticsProxy::ContentSpecificStats::~ContentSpecificStats() = default; |
| 861 | |
| 862 | void ReceiveStatisticsProxy::ContentSpecificStats::Add( |
| 863 | const ContentSpecificStats& other) { |
| 864 | e2e_delay_counter.Add(other.e2e_delay_counter); |
| 865 | interframe_delay_counter.Add(other.interframe_delay_counter); |
| 866 | flow_duration_ms += other.flow_duration_ms; |
| 867 | total_media_bytes += other.total_media_bytes; |
| 868 | received_height.Add(other.received_height); |
| 869 | received_width.Add(other.received_width); |
| 870 | qp_counter.Add(other.qp_counter); |
| 871 | frame_counts.key_frames += other.frame_counts.key_frames; |
| 872 | frame_counts.delta_frames += other.frame_counts.delta_frames; |
| 873 | interframe_delay_percentiles.Add(other.interframe_delay_percentiles); |
Emil Vardar | 3f1e51d | 2024-08-27 12:14:33 | [diff] [blame] | 874 | corruption_score.MergeStatistics(other.corruption_score); |
Tommi | 74fc574 | 2020-04-27 08:43:06 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | } // namespace internal |
| 878 | } // namespace webrtc |