You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

920 lines
36 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
  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. #include "video/receive_statistics_proxy.h"
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <utility>
  14. #include "modules/video_coding/include/video_codec_interface.h"
  15. #include "rtc_base/checks.h"
  16. #include "rtc_base/logging.h"
  17. #include "rtc_base/strings/string_builder.h"
  18. #include "rtc_base/time_utils.h"
  19. #include "system_wrappers/include/clock.h"
  20. #include "system_wrappers/include/field_trial.h"
  21. #include "system_wrappers/include/metrics.h"
  22. namespace webrtc {
  23. namespace {
  24. // Periodic time interval for processing samples for |freq_offset_counter_|.
  25. const int64_t kFreqOffsetProcessIntervalMs = 40000;
  26. // Configuration for bad call detection.
  27. const int kBadCallMinRequiredSamples = 10;
  28. const int kMinSampleLengthMs = 990;
  29. const int kNumMeasurements = 10;
  30. const int kNumMeasurementsVariance = kNumMeasurements * 1.5;
  31. const float kBadFraction = 0.8f;
  32. // For fps:
  33. // Low means low enough to be bad, high means high enough to be good
  34. const int kLowFpsThreshold = 12;
  35. const int kHighFpsThreshold = 14;
  36. // For qp and fps variance:
  37. // Low means low enough to be good, high means high enough to be bad
  38. const int kLowQpThresholdVp8 = 60;
  39. const int kHighQpThresholdVp8 = 70;
  40. const int kLowVarianceThreshold = 1;
  41. const int kHighVarianceThreshold = 2;
  42. // Some metrics are reported as a maximum over this period.
  43. // This should be synchronized with a typical getStats polling interval in
  44. // the clients.
  45. const int kMovingMaxWindowMs = 1000;
  46. // How large window we use to calculate the framerate/bitrate.
  47. const int kRateStatisticsWindowSizeMs = 1000;
  48. // Some sane ballpark estimate for maximum common value of inter-frame delay.
  49. // Values below that will be stored explicitly in the array,
  50. // values above - in the map.
  51. const int kMaxCommonInterframeDelayMs = 500;
  52. const char* UmaPrefixForContentType(VideoContentType content_type) {
  53. if (videocontenttypehelpers::IsScreenshare(content_type))
  54. return "WebRTC.Video.Screenshare";
  55. return "WebRTC.Video";
  56. }
  57. std::string UmaSuffixForContentType(VideoContentType content_type) {
  58. char ss_buf[1024];
  59. rtc::SimpleStringBuilder ss(ss_buf);
  60. int simulcast_id = videocontenttypehelpers::GetSimulcastId(content_type);
  61. if (simulcast_id > 0) {
  62. ss << ".S" << simulcast_id - 1;
  63. }
  64. int experiment_id = videocontenttypehelpers::GetExperimentId(content_type);
  65. if (experiment_id > 0) {
  66. ss << ".ExperimentGroup" << experiment_id - 1;
  67. }
  68. return ss.str();
  69. }
  70. } // namespace
  71. ReceiveStatisticsProxy::ReceiveStatisticsProxy(
  72. const VideoReceiveStream::Config* config,
  73. Clock* clock)
  74. : clock_(clock),
  75. config_(*config),
  76. start_ms_(clock->TimeInMilliseconds()),
  77. enable_decode_time_histograms_(
  78. !field_trial::IsEnabled("WebRTC-DecodeTimeHistogramsKillSwitch")),
  79. last_sample_time_(clock->TimeInMilliseconds()),
  80. fps_threshold_(kLowFpsThreshold,
  81. kHighFpsThreshold,
  82. kBadFraction,
  83. kNumMeasurements),
  84. qp_threshold_(kLowQpThresholdVp8,
  85. kHighQpThresholdVp8,
  86. kBadFraction,
  87. kNumMeasurements),
  88. variance_threshold_(kLowVarianceThreshold,
  89. kHighVarianceThreshold,
  90. kBadFraction,
  91. kNumMeasurementsVariance),
  92. num_bad_states_(0),
  93. num_certain_states_(0),
  94. // 1000ms window, scale 1000 for ms to s.
  95. decode_fps_estimator_(1000, 1000),
  96. renders_fps_estimator_(1000, 1000),
  97. render_fps_tracker_(100, 10u),
  98. render_pixel_tracker_(100, 10u),
  99. video_quality_observer_(
  100. new VideoQualityObserver(VideoContentType::UNSPECIFIED)),
  101. interframe_delay_max_moving_(kMovingMaxWindowMs),
  102. freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs),
  103. avg_rtt_ms_(0),
  104. last_content_type_(VideoContentType::UNSPECIFIED),
  105. last_codec_type_(kVideoCodecVP8),
  106. num_delayed_frames_rendered_(0),
  107. sum_missed_render_deadline_ms_(0),
  108. timing_frame_info_counter_(kMovingMaxWindowMs) {
  109. decode_thread_.Detach();
  110. network_thread_.Detach();
  111. stats_.ssrc = config_.rtp.remote_ssrc;
  112. }
  113. void ReceiveStatisticsProxy::UpdateHistograms(
  114. absl::optional<int> fraction_lost,
  115. const StreamDataCounters& rtp_stats,
  116. const StreamDataCounters* rtx_stats) {
  117. // Not actually running on the decoder thread, but must be called after
  118. // DecoderThreadStopped, which detaches the thread checker. It is therefore
  119. // safe to access |qp_counters_|, which were updated on the decode thread
  120. // earlier.
  121. RTC_DCHECK_RUN_ON(&decode_thread_);
  122. rtc::CritScope lock(&crit_);
  123. char log_stream_buf[8 * 1024];
  124. rtc::SimpleStringBuilder log_stream(log_stream_buf);
  125. int stream_duration_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000;
  126. if (stats_.frame_counts.key_frames > 0 ||
  127. stats_.frame_counts.delta_frames > 0) {
  128. RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.ReceiveStreamLifetimeInSeconds",
  129. stream_duration_sec);
  130. log_stream << "WebRTC.Video.ReceiveStreamLifetimeInSeconds "
  131. << stream_duration_sec << '\n';
  132. }
  133. log_stream << "Frames decoded " << stats_.frames_decoded << '\n';
  134. if (num_unique_frames_) {
  135. int num_dropped_frames = *num_unique_frames_ - stats_.frames_decoded;
  136. RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DroppedFrames.Receiver",
  137. num_dropped_frames);
  138. log_stream << "WebRTC.Video.DroppedFrames.Receiver " << num_dropped_frames
  139. << '\n';
  140. }
  141. if (fraction_lost && stream_duration_sec >= metrics::kMinRunTimeInSeconds) {
  142. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent",
  143. *fraction_lost);
  144. log_stream << "WebRTC.Video.ReceivedPacketsLostInPercent " << *fraction_lost
  145. << '\n';
  146. }
  147. if (first_decoded_frame_time_ms_) {
  148. const int64_t elapsed_ms =
  149. (clock_->TimeInMilliseconds() - *first_decoded_frame_time_ms_);
  150. if (elapsed_ms >=
  151. metrics::kMinRunTimeInSeconds * rtc::kNumMillisecsPerSec) {
  152. int decoded_fps = static_cast<int>(
  153. (stats_.frames_decoded * 1000.0f / elapsed_ms) + 0.5f);
  154. RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.DecodedFramesPerSecond",
  155. decoded_fps);
  156. log_stream << "WebRTC.Video.DecodedFramesPerSecond " << decoded_fps
  157. << '\n';
  158. const uint32_t frames_rendered = stats_.frames_rendered;
  159. if (frames_rendered > 0) {
  160. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.DelayedFramesToRenderer",
  161. static_cast<int>(num_delayed_frames_rendered_ *
  162. 100 / frames_rendered));
  163. if (num_delayed_frames_rendered_ > 0) {
  164. RTC_HISTOGRAM_COUNTS_1000(
  165. "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs",
  166. static_cast<int>(sum_missed_render_deadline_ms_ /
  167. num_delayed_frames_rendered_));
  168. }
  169. }
  170. }
  171. }
  172. const int kMinRequiredSamples = 200;
  173. int samples = static_cast<int>(render_fps_tracker_.TotalSampleCount());
  174. if (samples >= kMinRequiredSamples) {
  175. int rendered_fps = round(render_fps_tracker_.ComputeTotalRate());
  176. RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond",
  177. rendered_fps);
  178. log_stream << "WebRTC.Video.RenderFramesPerSecond " << rendered_fps << '\n';
  179. RTC_HISTOGRAM_COUNTS_100000(
  180. "WebRTC.Video.RenderSqrtPixelsPerSecond",
  181. round(render_pixel_tracker_.ComputeTotalRate()));
  182. }
  183. absl::optional<int> sync_offset_ms =
  184. sync_offset_counter_.Avg(kMinRequiredSamples);
  185. if (sync_offset_ms) {
  186. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs",
  187. *sync_offset_ms);
  188. log_stream << "WebRTC.Video.AVSyncOffsetInMs " << *sync_offset_ms << '\n';
  189. }
  190. AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats();
  191. if (freq_offset_stats.num_samples > 0) {
  192. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz",
  193. freq_offset_stats.average);
  194. log_stream << "WebRTC.Video.RtpToNtpFreqOffsetInKhz "
  195. << freq_offset_stats.ToString() << '\n';
  196. }
  197. int num_total_frames =
  198. stats_.frame_counts.key_frames + stats_.frame_counts.delta_frames;
  199. if (num_total_frames >= kMinRequiredSamples) {
  200. int num_key_frames = stats_.frame_counts.key_frames;
  201. int key_frames_permille =
  202. (num_key_frames * 1000 + num_total_frames / 2) / num_total_frames;
  203. RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille",
  204. key_frames_permille);
  205. log_stream << "WebRTC.Video.KeyFramesReceivedInPermille "
  206. << key_frames_permille << '\n';
  207. }
  208. absl::optional<int> qp = qp_counters_.vp8.Avg(kMinRequiredSamples);
  209. if (qp) {
  210. RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", *qp);
  211. log_stream << "WebRTC.Video.Decoded.Vp8.Qp " << *qp << '\n';
  212. }
  213. absl::optional<int> decode_ms = decode_time_counter_.Avg(kMinRequiredSamples);
  214. if (decode_ms) {
  215. RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", *decode_ms);
  216. log_stream << "WebRTC.Video.DecodeTimeInMs " << *decode_ms << '\n';
  217. }
  218. absl::optional<int> jb_delay_ms =
  219. jitter_buffer_delay_counter_.Avg(kMinRequiredSamples);
  220. if (jb_delay_ms) {
  221. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs",
  222. *jb_delay_ms);
  223. log_stream << "WebRTC.Video.JitterBufferDelayInMs " << *jb_delay_ms << '\n';
  224. }
  225. absl::optional<int> target_delay_ms =
  226. target_delay_counter_.Avg(kMinRequiredSamples);
  227. if (target_delay_ms) {
  228. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs",
  229. *target_delay_ms);
  230. log_stream << "WebRTC.Video.TargetDelayInMs " << *target_delay_ms << '\n';
  231. }
  232. absl::optional<int> current_delay_ms =
  233. current_delay_counter_.Avg(kMinRequiredSamples);
  234. if (current_delay_ms) {
  235. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs",
  236. *current_delay_ms);
  237. log_stream << "WebRTC.Video.CurrentDelayInMs " << *current_delay_ms << '\n';
  238. }
  239. absl::optional<int> delay_ms = delay_counter_.Avg(kMinRequiredSamples);
  240. if (delay_ms)
  241. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", *delay_ms);
  242. // Aggregate content_specific_stats_ by removing experiment or simulcast
  243. // information;
  244. std::map<VideoContentType, ContentSpecificStats> aggregated_stats;
  245. for (const auto& it : content_specific_stats_) {
  246. // Calculate simulcast specific metrics (".S0" ... ".S2" suffixes).
  247. VideoContentType content_type = it.first;
  248. if (videocontenttypehelpers::GetSimulcastId(content_type) > 0) {
  249. // Aggregate on experiment id.
  250. videocontenttypehelpers::SetExperimentId(&content_type, 0);
  251. aggregated_stats[content_type].Add(it.second);
  252. }
  253. // Calculate experiment specific metrics (".ExperimentGroup[0-7]" suffixes).
  254. content_type = it.first;
  255. if (videocontenttypehelpers::GetExperimentId(content_type) > 0) {
  256. // Aggregate on simulcast id.
  257. videocontenttypehelpers::SetSimulcastId(&content_type, 0);
  258. aggregated_stats[content_type].Add(it.second);
  259. }
  260. // Calculate aggregated metrics (no suffixes. Aggregated on everything).
  261. content_type = it.first;
  262. videocontenttypehelpers::SetSimulcastId(&content_type, 0);
  263. videocontenttypehelpers::SetExperimentId(&content_type, 0);
  264. aggregated_stats[content_type].Add(it.second);
  265. }
  266. for (const auto& it : aggregated_stats) {
  267. // For the metric Foo we report the following slices:
  268. // WebRTC.Video.Foo,
  269. // WebRTC.Video.Screenshare.Foo,
  270. // WebRTC.Video.Foo.S[0-3],
  271. // WebRTC.Video.Foo.ExperimentGroup[0-7],
  272. // WebRTC.Video.Screenshare.Foo.S[0-3],
  273. // WebRTC.Video.Screenshare.Foo.ExperimentGroup[0-7].
  274. auto content_type = it.first;
  275. auto stats = it.second;
  276. std::string uma_prefix = UmaPrefixForContentType(content_type);
  277. std::string uma_suffix = UmaSuffixForContentType(content_type);
  278. // Metrics can be sliced on either simulcast id or experiment id but not
  279. // both.
  280. RTC_DCHECK(videocontenttypehelpers::GetExperimentId(content_type) == 0 ||
  281. videocontenttypehelpers::GetSimulcastId(content_type) == 0);
  282. absl::optional<int> e2e_delay_ms =
  283. stats.e2e_delay_counter.Avg(kMinRequiredSamples);
  284. if (e2e_delay_ms) {
  285. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  286. uma_prefix + ".EndToEndDelayInMs" + uma_suffix, *e2e_delay_ms);
  287. log_stream << uma_prefix << ".EndToEndDelayInMs" << uma_suffix << " "
  288. << *e2e_delay_ms << '\n';
  289. }
  290. absl::optional<int> e2e_delay_max_ms = stats.e2e_delay_counter.Max();
  291. if (e2e_delay_max_ms && e2e_delay_ms) {
  292. RTC_HISTOGRAM_COUNTS_SPARSE_100000(
  293. uma_prefix + ".EndToEndDelayMaxInMs" + uma_suffix, *e2e_delay_max_ms);
  294. log_stream << uma_prefix << ".EndToEndDelayMaxInMs" << uma_suffix << " "
  295. << *e2e_delay_max_ms << '\n';
  296. }
  297. absl::optional<int> interframe_delay_ms =
  298. stats.interframe_delay_counter.Avg(kMinRequiredSamples);
  299. if (interframe_delay_ms) {
  300. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  301. uma_prefix + ".InterframeDelayInMs" + uma_suffix,
  302. *interframe_delay_ms);
  303. log_stream << uma_prefix << ".InterframeDelayInMs" << uma_suffix << " "
  304. << *interframe_delay_ms << '\n';
  305. }
  306. absl::optional<int> interframe_delay_max_ms =
  307. stats.interframe_delay_counter.Max();
  308. if (interframe_delay_max_ms && interframe_delay_ms) {
  309. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  310. uma_prefix + ".InterframeDelayMaxInMs" + uma_suffix,
  311. *interframe_delay_max_ms);
  312. log_stream << uma_prefix << ".InterframeDelayMaxInMs" << uma_suffix << " "
  313. << *interframe_delay_max_ms << '\n';
  314. }
  315. absl::optional<uint32_t> interframe_delay_95p_ms =
  316. stats.interframe_delay_percentiles.GetPercentile(0.95f);
  317. if (interframe_delay_95p_ms && interframe_delay_ms != -1) {
  318. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  319. uma_prefix + ".InterframeDelay95PercentileInMs" + uma_suffix,
  320. *interframe_delay_95p_ms);
  321. log_stream << uma_prefix << ".InterframeDelay95PercentileInMs"
  322. << uma_suffix << " " << *interframe_delay_95p_ms << '\n';
  323. }
  324. absl::optional<int> width = stats.received_width.Avg(kMinRequiredSamples);
  325. if (width) {
  326. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  327. uma_prefix + ".ReceivedWidthInPixels" + uma_suffix, *width);
  328. log_stream << uma_prefix << ".ReceivedWidthInPixels" << uma_suffix << " "
  329. << *width << '\n';
  330. }
  331. absl::optional<int> height = stats.received_height.Avg(kMinRequiredSamples);
  332. if (height) {
  333. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  334. uma_prefix + ".ReceivedHeightInPixels" + uma_suffix, *height);
  335. log_stream << uma_prefix << ".ReceivedHeightInPixels" << uma_suffix << " "
  336. << *height << '\n';
  337. }
  338. if (content_type != VideoContentType::UNSPECIFIED) {
  339. // Don't report these 3 metrics unsliced, as more precise variants
  340. // are reported separately in this method.
  341. float flow_duration_sec = stats.flow_duration_ms / 1000.0;
  342. if (flow_duration_sec >= metrics::kMinRunTimeInSeconds) {
  343. int media_bitrate_kbps = static_cast<int>(stats.total_media_bytes * 8 /
  344. flow_duration_sec / 1000);
  345. RTC_HISTOGRAM_COUNTS_SPARSE_10000(
  346. uma_prefix + ".MediaBitrateReceivedInKbps" + uma_suffix,
  347. media_bitrate_kbps);
  348. log_stream << uma_prefix << ".MediaBitrateReceivedInKbps" << uma_suffix
  349. << " " << media_bitrate_kbps << '\n';
  350. }
  351. int num_total_frames =
  352. stats.frame_counts.key_frames + stats.frame_counts.delta_frames;
  353. if (num_total_frames >= kMinRequiredSamples) {
  354. int num_key_frames = stats.frame_counts.key_frames;
  355. int key_frames_permille =
  356. (num_key_frames * 1000 + num_total_frames / 2) / num_total_frames;
  357. RTC_HISTOGRAM_COUNTS_SPARSE_1000(
  358. uma_prefix + ".KeyFramesReceivedInPermille" + uma_suffix,
  359. key_frames_permille);
  360. log_stream << uma_prefix << ".KeyFramesReceivedInPermille" << uma_suffix
  361. << " " << key_frames_permille << '\n';
  362. }
  363. absl::optional<int> qp = stats.qp_counter.Avg(kMinRequiredSamples);
  364. if (qp) {
  365. RTC_HISTOGRAM_COUNTS_SPARSE_200(
  366. uma_prefix + ".Decoded.Vp8.Qp" + uma_suffix, *qp);
  367. log_stream << uma_prefix << ".Decoded.Vp8.Qp" << uma_suffix << " "
  368. << *qp << '\n';
  369. }
  370. }
  371. }
  372. StreamDataCounters rtp_rtx_stats = rtp_stats;
  373. if (rtx_stats)
  374. rtp_rtx_stats.Add(*rtx_stats);
  375. int64_t elapsed_sec =
  376. rtp_rtx_stats.TimeSinceFirstPacketInMs(clock_->TimeInMilliseconds()) /
  377. 1000;
  378. if (elapsed_sec >= metrics::kMinRunTimeInSeconds) {
  379. RTC_HISTOGRAM_COUNTS_10000(
  380. "WebRTC.Video.BitrateReceivedInKbps",
  381. static_cast<int>(rtp_rtx_stats.transmitted.TotalBytes() * 8 /
  382. elapsed_sec / 1000));
  383. int media_bitrate_kbs = static_cast<int>(rtp_stats.MediaPayloadBytes() * 8 /
  384. elapsed_sec / 1000);
  385. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.MediaBitrateReceivedInKbps",
  386. media_bitrate_kbs);
  387. log_stream << "WebRTC.Video.MediaBitrateReceivedInKbps "
  388. << media_bitrate_kbs << '\n';
  389. RTC_HISTOGRAM_COUNTS_10000(
  390. "WebRTC.Video.PaddingBitrateReceivedInKbps",
  391. static_cast<int>(rtp_rtx_stats.transmitted.padding_bytes * 8 /
  392. elapsed_sec / 1000));
  393. RTC_HISTOGRAM_COUNTS_10000(
  394. "WebRTC.Video.RetransmittedBitrateReceivedInKbps",
  395. static_cast<int>(rtp_rtx_stats.retransmitted.TotalBytes() * 8 /
  396. elapsed_sec / 1000));
  397. if (rtx_stats) {
  398. RTC_HISTOGRAM_COUNTS_10000(
  399. "WebRTC.Video.RtxBitrateReceivedInKbps",
  400. static_cast<int>(rtx_stats->transmitted.TotalBytes() * 8 /
  401. elapsed_sec / 1000));
  402. }
  403. const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts;
  404. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute",
  405. counters.nack_packets * 60 / elapsed_sec);
  406. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute",
  407. counters.fir_packets * 60 / elapsed_sec);
  408. RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute",
  409. counters.pli_packets * 60 / elapsed_sec);
  410. if (counters.nack_requests > 0) {
  411. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent",
  412. counters.UniqueNackRequestsInPercent());
  413. }
  414. }
  415. if (num_certain_states_ >= kBadCallMinRequiredSamples) {
  416. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.Any",
  417. 100 * num_bad_states_ / num_certain_states_);
  418. }
  419. absl::optional<double> fps_fraction =
  420. fps_threshold_.FractionHigh(kBadCallMinRequiredSamples);
  421. if (fps_fraction) {
  422. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.FrameRate",
  423. static_cast<int>(100 * (1 - *fps_fraction)));
  424. }
  425. absl::optional<double> variance_fraction =
  426. variance_threshold_.FractionHigh(kBadCallMinRequiredSamples);
  427. if (variance_fraction) {
  428. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.FrameRateVariance",
  429. static_cast<int>(100 * *variance_fraction));
  430. }
  431. absl::optional<double> qp_fraction =
  432. qp_threshold_.FractionHigh(kBadCallMinRequiredSamples);
  433. if (qp_fraction) {
  434. RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.Qp",
  435. static_cast<int>(100 * *qp_fraction));
  436. }
  437. RTC_LOG(LS_INFO) << log_stream.str();
  438. video_quality_observer_->UpdateHistograms();
  439. }
  440. void ReceiveStatisticsProxy::QualitySample() {
  441. int64_t now = clock_->TimeInMilliseconds();
  442. if (last_sample_time_ + kMinSampleLengthMs > now)
  443. return;
  444. double fps =
  445. render_fps_tracker_.ComputeRateForInterval(now - last_sample_time_);
  446. absl::optional<int> qp = qp_sample_.Avg(1);
  447. bool prev_fps_bad = !fps_threshold_.IsHigh().value_or(true);
  448. bool prev_qp_bad = qp_threshold_.IsHigh().value_or(false);
  449. bool prev_variance_bad = variance_threshold_.IsHigh().value_or(false);
  450. bool prev_any_bad = prev_fps_bad || prev_qp_bad || prev_variance_bad;
  451. fps_threshold_.AddMeasurement(static_cast<int>(fps));
  452. if (qp)
  453. qp_threshold_.AddMeasurement(*qp);
  454. absl::optional<double> fps_variance_opt = fps_threshold_.CalculateVariance();
  455. double fps_variance = fps_variance_opt.value_or(0);
  456. if (fps_variance_opt) {
  457. variance_threshold_.AddMeasurement(static_cast<int>(fps_variance));
  458. }
  459. bool fps_bad = !fps_threshold_.IsHigh().value_or(true);
  460. bool qp_bad = qp_threshold_.IsHigh().value_or(false);
  461. bool variance_bad = variance_threshold_.IsHigh().value_or(false);
  462. bool any_bad = fps_bad || qp_bad || variance_bad;
  463. if (!prev_any_bad && any_bad) {
  464. RTC_LOG(LS_INFO) << "Bad call (any) start: " << now;
  465. } else if (prev_any_bad && !any_bad) {
  466. RTC_LOG(LS_INFO) << "Bad call (any) end: " << now;
  467. }
  468. if (!prev_fps_bad && fps_bad) {
  469. RTC_LOG(LS_INFO) << "Bad call (fps) start: " << now;
  470. } else if (prev_fps_bad && !fps_bad) {
  471. RTC_LOG(LS_INFO) << "Bad call (fps) end: " << now;
  472. }
  473. if (!prev_qp_bad && qp_bad) {
  474. RTC_LOG(LS_INFO) << "Bad call (qp) start: " << now;
  475. } else if (prev_qp_bad && !qp_bad) {
  476. RTC_LOG(LS_INFO) << "Bad call (qp) end: " << now;
  477. }
  478. if (!prev_variance_bad && variance_bad) {
  479. RTC_LOG(LS_INFO) << "Bad call (variance) start: " << now;
  480. } else if (prev_variance_bad && !variance_bad) {
  481. RTC_LOG(LS_INFO) << "Bad call (variance) end: " << now;
  482. }
  483. RTC_LOG(LS_VERBOSE) << "SAMPLE: sample_length: " << (now - last_sample_time_)
  484. << " fps: " << fps << " fps_bad: " << fps_bad
  485. << " qp: " << qp.value_or(-1) << " qp_bad: " << qp_bad
  486. << " variance_bad: " << variance_bad
  487. << " fps_variance: " << fps_variance;
  488. last_sample_time_ = now;
  489. qp_sample_.Reset();
  490. if (fps_threshold_.IsHigh() || variance_threshold_.IsHigh() ||
  491. qp_threshold_.IsHigh()) {
  492. if (any_bad)
  493. ++num_bad_states_;
  494. ++num_certain_states_;
  495. }
  496. }
  497. void ReceiveStatisticsProxy::UpdateFramerate(int64_t now_ms) const {
  498. int64_t old_frames_ms = now_ms - kRateStatisticsWindowSizeMs;
  499. while (!frame_window_.empty() &&
  500. frame_window_.begin()->first < old_frames_ms) {
  501. frame_window_.erase(frame_window_.begin());
  502. }
  503. size_t framerate =
  504. (frame_window_.size() * 1000 + 500) / kRateStatisticsWindowSizeMs;
  505. stats_.network_frame_rate = static_cast<int>(framerate);
  506. }
  507. void ReceiveStatisticsProxy::UpdateDecodeTimeHistograms(
  508. int width,
  509. int height,
  510. int decode_time_ms) const {
  511. bool is_4k = (width == 3840 || width == 4096) && height == 2160;
  512. bool is_hd = width == 1920 && height == 1080;
  513. // Only update histograms for 4k/HD and VP9/H264.
  514. if ((is_4k || is_hd) && (last_codec_type_ == kVideoCodecVP9 ||
  515. last_codec_type_ == kVideoCodecH264)) {
  516. const std::string kDecodeTimeUmaPrefix =
  517. "WebRTC.Video.DecodeTimePerFrameInMs.";
  518. // Each histogram needs its own line for it to not be reused in the wrong
  519. // way when the format changes.
  520. if (last_codec_type_ == kVideoCodecVP9) {
  521. bool is_sw_decoder =
  522. stats_.decoder_implementation_name.compare(0, 6, "libvpx") == 0;
  523. if (is_4k) {
  524. if (is_sw_decoder)
  525. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "Vp9.4k.Sw",
  526. decode_time_ms);
  527. else
  528. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "Vp9.4k.Hw",
  529. decode_time_ms);
  530. } else {
  531. if (is_sw_decoder)
  532. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "Vp9.Hd.Sw",
  533. decode_time_ms);
  534. else
  535. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "Vp9.Hd.Hw",
  536. decode_time_ms);
  537. }
  538. } else {
  539. bool is_sw_decoder =
  540. stats_.decoder_implementation_name.compare(0, 6, "FFmpeg") == 0;
  541. if (is_4k) {
  542. if (is_sw_decoder)
  543. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "H264.4k.Sw",
  544. decode_time_ms);
  545. else
  546. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "H264.4k.Hw",
  547. decode_time_ms);
  548. } else {
  549. if (is_sw_decoder)
  550. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "H264.Hd.Sw",
  551. decode_time_ms);
  552. else
  553. RTC_HISTOGRAM_COUNTS_1000(kDecodeTimeUmaPrefix + "H264.Hd.Hw",
  554. decode_time_ms);
  555. }
  556. }
  557. }
  558. }
  559. VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
  560. rtc::CritScope lock(&crit_);
  561. // Get current frame rates here, as only updating them on new frames prevents
  562. // us from ever correctly displaying frame rate of 0.
  563. int64_t now_ms = clock_->TimeInMilliseconds();
  564. UpdateFramerate(now_ms);
  565. stats_.render_frame_rate = renders_fps_estimator_.Rate(now_ms).value_or(0);
  566. stats_.decode_frame_rate = decode_fps_estimator_.Rate(now_ms).value_or(0);
  567. stats_.interframe_delay_max_ms =
  568. interframe_delay_max_moving_.Max(now_ms).value_or(-1);
  569. stats_.freeze_count = video_quality_observer_->NumFreezes();
  570. stats_.pause_count = video_quality_observer_->NumPauses();
  571. stats_.total_freezes_duration_ms =
  572. video_quality_observer_->TotalFreezesDurationMs();
  573. stats_.total_pauses_duration_ms =
  574. video_quality_observer_->TotalPausesDurationMs();
  575. stats_.total_frames_duration_ms =
  576. video_quality_observer_->TotalFramesDurationMs();
  577. stats_.sum_squared_frame_durations =
  578. video_quality_observer_->SumSquaredFrameDurationsSec();
  579. stats_.content_type = last_content_type_;
  580. stats_.timing_frame_info = timing_frame_info_counter_.Max(now_ms);
  581. stats_.jitter_buffer_delay_seconds =
  582. static_cast<double>(current_delay_counter_.Sum(1).value_or(0)) /
  583. rtc::kNumMillisecsPerSec;
  584. stats_.jitter_buffer_emitted_count = current_delay_counter_.NumSamples();
  585. return stats_;
  586. }
  587. void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) {
  588. rtc::CritScope lock(&crit_);
  589. stats_.current_payload_type = payload_type;
  590. }
  591. void ReceiveStatisticsProxy::OnDecoderImplementationName(
  592. const char* implementation_name) {
  593. rtc::CritScope lock(&crit_);
  594. stats_.decoder_implementation_name = implementation_name;
  595. }
  596. void ReceiveStatisticsProxy::OnFrameBufferTimingsUpdated(
  597. int max_decode_ms,
  598. int current_delay_ms,
  599. int target_delay_ms,
  600. int jitter_buffer_ms,
  601. int min_playout_delay_ms,
  602. int render_delay_ms) {
  603. rtc::CritScope lock(&crit_);
  604. stats_.max_decode_ms = max_decode_ms;
  605. stats_.current_delay_ms = current_delay_ms;
  606. stats_.target_delay_ms = target_delay_ms;
  607. stats_.jitter_buffer_ms = jitter_buffer_ms;
  608. stats_.min_playout_delay_ms = min_playout_delay_ms;
  609. stats_.render_delay_ms = render_delay_ms;
  610. jitter_buffer_delay_counter_.Add(jitter_buffer_ms);
  611. target_delay_counter_.Add(target_delay_ms);
  612. current_delay_counter_.Add(current_delay_ms);
  613. // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time +
  614. // render delay).
  615. delay_counter_.Add(target_delay_ms + avg_rtt_ms_ / 2);
  616. }
  617. void ReceiveStatisticsProxy::OnUniqueFramesCounted(int num_unique_frames) {
  618. rtc::CritScope lock(&crit_);
  619. num_unique_frames_.emplace(num_unique_frames);
  620. }
  621. void ReceiveStatisticsProxy::OnTimingFrameInfoUpdated(
  622. const TimingFrameInfo& info) {
  623. rtc::CritScope lock(&crit_);
  624. if (info.flags != VideoSendTiming::kInvalid) {
  625. int64_t now_ms = clock_->TimeInMilliseconds();
  626. timing_frame_info_counter_.Add(info, now_ms);
  627. }
  628. // Measure initial decoding latency between the first frame arriving and the
  629. // first frame being decoded.
  630. if (!first_frame_received_time_ms_.has_value()) {
  631. first_frame_received_time_ms_ = info.receive_finish_ms;
  632. }
  633. if (stats_.first_frame_received_to_decoded_ms == -1 &&
  634. first_decoded_frame_time_ms_) {
  635. stats_.first_frame_received_to_decoded_ms =
  636. *first_decoded_frame_time_ms_ - *first_frame_received_time_ms_;
  637. }
  638. }
  639. void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
  640. uint32_t ssrc,
  641. const RtcpPacketTypeCounter& packet_counter) {
  642. rtc::CritScope lock(&crit_);
  643. if (stats_.ssrc != ssrc)
  644. return;
  645. stats_.rtcp_packet_type_counts = packet_counter;
  646. }
  647. void ReceiveStatisticsProxy::OnCname(uint32_t ssrc, absl::string_view cname) {
  648. rtc::CritScope lock(&crit_);
  649. // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we
  650. // receive stats from one of them.
  651. if (stats_.ssrc != ssrc)
  652. return;
  653. stats_.c_name = std::string(cname);
  654. }
  655. void ReceiveStatisticsProxy::OnDecodedFrame(const VideoFrame& frame,
  656. absl::optional<uint8_t> qp,
  657. int32_t decode_time_ms,
  658. VideoContentType content_type) {
  659. rtc::CritScope lock(&crit_);
  660. uint64_t now_ms = clock_->TimeInMilliseconds();
  661. if (videocontenttypehelpers::IsScreenshare(content_type) !=
  662. videocontenttypehelpers::IsScreenshare(last_content_type_)) {
  663. // Reset the quality observer if content type is switched. But first report
  664. // stats for the previous part of the call.
  665. video_quality_observer_->UpdateHistograms();
  666. video_quality_observer_.reset(new VideoQualityObserver(content_type));
  667. }
  668. video_quality_observer_->OnDecodedFrame(frame, qp, last_codec_type_);
  669. ContentSpecificStats* content_specific_stats =
  670. &content_specific_stats_[content_type];
  671. ++stats_.frames_decoded;
  672. if (qp) {
  673. if (!stats_.qp_sum) {
  674. if (stats_.frames_decoded != 1) {
  675. RTC_LOG(LS_WARNING)
  676. << "Frames decoded was not 1 when first qp value was received.";
  677. }
  678. stats_.qp_sum = 0;
  679. }
  680. *stats_.qp_sum += *qp;
  681. content_specific_stats->qp_counter.Add(*qp);
  682. } else if (stats_.qp_sum) {
  683. RTC_LOG(LS_WARNING)
  684. << "QP sum was already set and no QP was given for a frame.";
  685. stats_.qp_sum.reset();
  686. }
  687. decode_time_counter_.Add(decode_time_ms);
  688. stats_.decode_ms = decode_time_ms;
  689. stats_.total_decode_time_ms += decode_time_ms;
  690. if (enable_decode_time_histograms_) {
  691. UpdateDecodeTimeHistograms(frame.width(), frame.height(), decode_time_ms);
  692. }
  693. last_content_type_ = content_type;
  694. decode_fps_estimator_.Update(1, now_ms);
  695. if (last_decoded_frame_time_ms_) {
  696. int64_t interframe_delay_ms = now_ms - *last_decoded_frame_time_ms_;
  697. RTC_DCHECK_GE(interframe_delay_ms, 0);
  698. interframe_delay_max_moving_.Add(interframe_delay_ms, now_ms);
  699. content_specific_stats->interframe_delay_counter.Add(interframe_delay_ms);
  700. content_specific_stats->interframe_delay_percentiles.Add(
  701. interframe_delay_ms);
  702. content_specific_stats->flow_duration_ms += interframe_delay_ms;
  703. }
  704. if (stats_.frames_decoded == 1) {
  705. first_decoded_frame_time_ms_.emplace(now_ms);
  706. }
  707. last_decoded_frame_time_ms_.emplace(now_ms);
  708. }
  709. void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) {
  710. int width = frame.width();
  711. int height = frame.height();
  712. RTC_DCHECK_GT(width, 0);
  713. RTC_DCHECK_GT(height, 0);
  714. int64_t now_ms = clock_->TimeInMilliseconds();
  715. rtc::CritScope lock(&crit_);
  716. video_quality_observer_->OnRenderedFrame(frame, now_ms);
  717. ContentSpecificStats* content_specific_stats =
  718. &content_specific_stats_[last_content_type_];
  719. renders_fps_estimator_.Update(1, now_ms);
  720. ++stats_.frames_rendered;
  721. stats_.width = width;
  722. stats_.height = height;
  723. render_fps_tracker_.AddSamples(1);
  724. render_pixel_tracker_.AddSamples(sqrt(width * height));
  725. content_specific_stats->received_width.Add(width);
  726. content_specific_stats->received_height.Add(height);
  727. // Consider taking stats_.render_delay_ms into account.
  728. const int64_t time_until_rendering_ms = frame.render_time_ms() - now_ms;
  729. if (time_until_rendering_ms < 0) {
  730. sum_missed_render_deadline_ms_ += -time_until_rendering_ms;
  731. ++num_delayed_frames_rendered_;
  732. }
  733. if (frame.ntp_time_ms() > 0) {
  734. int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms();
  735. if (delay_ms >= 0) {
  736. content_specific_stats->e2e_delay_counter.Add(delay_ms);
  737. }
  738. }
  739. QualitySample();
  740. }
  741. void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms,
  742. double estimated_freq_khz) {
  743. rtc::CritScope lock(&crit_);
  744. sync_offset_counter_.Add(std::abs(sync_offset_ms));
  745. stats_.sync_offset_ms = sync_offset_ms;
  746. const double kMaxFreqKhz = 10000.0;
  747. int offset_khz = kMaxFreqKhz;
  748. // Should not be zero or negative. If so, report max.
  749. if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0)
  750. offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5);
  751. freq_offset_counter_.Add(offset_khz);
  752. }
  753. void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe,
  754. size_t size_bytes,
  755. VideoContentType content_type) {
  756. rtc::CritScope lock(&crit_);
  757. if (is_keyframe) {
  758. ++stats_.frame_counts.key_frames;
  759. } else {
  760. ++stats_.frame_counts.delta_frames;
  761. }
  762. // Content type extension is set only for keyframes and should be propagated
  763. // for all the following delta frames. Here we may receive frames out of order
  764. // and miscategorise some delta frames near the layer switch.
  765. // This may slightly offset calculated bitrate and keyframes permille metrics.
  766. VideoContentType propagated_content_type =
  767. is_keyframe ? content_type : last_content_type_;
  768. ContentSpecificStats* content_specific_stats =
  769. &content_specific_stats_[propagated_content_type];
  770. content_specific_stats->total_media_bytes += size_bytes;
  771. if (is_keyframe) {
  772. ++content_specific_stats->frame_counts.key_frames;
  773. } else {
  774. ++content_specific_stats->frame_counts.delta_frames;
  775. }
  776. int64_t now_ms = clock_->TimeInMilliseconds();
  777. frame_window_.insert(std::make_pair(now_ms, size_bytes));
  778. UpdateFramerate(now_ms);
  779. }
  780. void ReceiveStatisticsProxy::OnDroppedFrames(uint32_t frames_dropped) {
  781. rtc::CritScope lock(&crit_);
  782. stats_.frames_dropped += frames_dropped;
  783. }
  784. void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) {
  785. RTC_DCHECK_RUN_ON(&decode_thread_);
  786. rtc::CritScope lock(&crit_);
  787. last_codec_type_ = codec_type;
  788. if (last_codec_type_ == kVideoCodecVP8 && qp != -1) {
  789. qp_counters_.vp8.Add(qp);
  790. qp_sample_.Add(qp);
  791. }
  792. }
  793. void ReceiveStatisticsProxy::OnStreamInactive() {
  794. // TODO(sprang): Figure out any other state that should be reset.
  795. rtc::CritScope lock(&crit_);
  796. // Don't report inter-frame delay if stream was paused.
  797. last_decoded_frame_time_ms_.reset();
  798. video_quality_observer_->OnStreamInactive();
  799. }
  800. void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms,
  801. int64_t max_rtt_ms) {
  802. rtc::CritScope lock(&crit_);
  803. avg_rtt_ms_ = avg_rtt_ms;
  804. }
  805. void ReceiveStatisticsProxy::DecoderThreadStarting() {
  806. RTC_DCHECK_RUN_ON(&main_thread_);
  807. }
  808. void ReceiveStatisticsProxy::DecoderThreadStopped() {
  809. RTC_DCHECK_RUN_ON(&main_thread_);
  810. decode_thread_.Detach();
  811. }
  812. ReceiveStatisticsProxy::ContentSpecificStats::ContentSpecificStats()
  813. : interframe_delay_percentiles(kMaxCommonInterframeDelayMs) {}
  814. ReceiveStatisticsProxy::ContentSpecificStats::~ContentSpecificStats() = default;
  815. void ReceiveStatisticsProxy::ContentSpecificStats::Add(
  816. const ContentSpecificStats& other) {
  817. e2e_delay_counter.Add(other.e2e_delay_counter);
  818. interframe_delay_counter.Add(other.interframe_delay_counter);
  819. flow_duration_ms += other.flow_duration_ms;
  820. total_media_bytes += other.total_media_bytes;
  821. received_height.Add(other.received_height);
  822. received_width.Add(other.received_width);
  823. qp_counter.Add(other.qp_counter);
  824. frame_counts.key_frames += other.frame_counts.key_frames;
  825. frame_counts.delta_frames += other.frame_counts.delta_frames;
  826. interframe_delay_percentiles.Add(other.interframe_delay_percentiles);
  827. }
  828. } // namespace webrtc