video_quality_observer2.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2020 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. #ifndef VIDEO_VIDEO_QUALITY_OBSERVER2_H_
  11. #define VIDEO_VIDEO_QUALITY_OBSERVER2_H_
  12. #include <stdint.h>
  13. #include <set>
  14. #include <vector>
  15. #include "absl/types/optional.h"
  16. #include "api/video/video_codec_type.h"
  17. #include "api/video/video_content_type.h"
  18. #include "rtc_base/numerics/moving_average.h"
  19. #include "rtc_base/numerics/sample_counter.h"
  20. namespace webrtc {
  21. namespace internal {
  22. // Declared in video_receive_stream2.h.
  23. struct VideoFrameMetaData;
  24. // Calculates spatial and temporal quality metrics and reports them to UMA
  25. // stats.
  26. class VideoQualityObserver {
  27. public:
  28. // Use either VideoQualityObserver::kBlockyQpThresholdVp8 or
  29. // VideoQualityObserver::kBlockyQpThresholdVp9.
  30. VideoQualityObserver();
  31. ~VideoQualityObserver() = default;
  32. void OnDecodedFrame(uint32_t rtp_frame_timestamp,
  33. absl::optional<uint8_t> qp,
  34. VideoCodecType codec);
  35. void OnRenderedFrame(const VideoFrameMetaData& frame_meta);
  36. void OnStreamInactive();
  37. uint32_t NumFreezes() const;
  38. uint32_t NumPauses() const;
  39. uint32_t TotalFreezesDurationMs() const;
  40. uint32_t TotalPausesDurationMs() const;
  41. uint32_t TotalFramesDurationMs() const;
  42. double SumSquaredFrameDurationsSec() const;
  43. // Set |screenshare| to true if the last decoded frame was for screenshare.
  44. void UpdateHistograms(bool screenshare);
  45. static const uint32_t kMinFrameSamplesToDetectFreeze;
  46. static const uint32_t kMinIncreaseForFreezeMs;
  47. static const uint32_t kAvgInterframeDelaysWindowSizeFrames;
  48. private:
  49. enum Resolution {
  50. Low = 0,
  51. Medium = 1,
  52. High = 2,
  53. };
  54. int64_t last_frame_rendered_ms_;
  55. int64_t num_frames_rendered_;
  56. int64_t first_frame_rendered_ms_;
  57. int64_t last_frame_pixels_;
  58. bool is_last_frame_blocky_;
  59. // Decoded timestamp of the last delayed frame.
  60. int64_t last_unfreeze_time_ms_;
  61. rtc::MovingAverage render_interframe_delays_;
  62. double sum_squared_interframe_delays_secs_;
  63. // An inter-frame delay is counted as a freeze if it's significantly longer
  64. // than average inter-frame delay.
  65. rtc::SampleCounter freezes_durations_;
  66. rtc::SampleCounter pauses_durations_;
  67. // Time between freezes.
  68. rtc::SampleCounter smooth_playback_durations_;
  69. // Counters for time spent in different resolutions. Time between each two
  70. // Consecutive frames is counted to bin corresponding to the first frame
  71. // resolution.
  72. std::vector<int64_t> time_in_resolution_ms_;
  73. // Resolution of the last decoded frame. Resolution enum is used as an index.
  74. Resolution current_resolution_;
  75. int num_resolution_downgrades_;
  76. // Similar to resolution, time spent in high-QP video.
  77. int64_t time_in_blocky_video_ms_;
  78. bool is_paused_;
  79. // Set of decoded frames with high QP value.
  80. std::set<int64_t> blocky_frames_;
  81. };
  82. } // namespace internal
  83. } // namespace webrtc
  84. #endif // VIDEO_VIDEO_QUALITY_OBSERVER2_H_