stats_collection.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2019 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 TEST_SCENARIO_STATS_COLLECTION_H_
  11. #define TEST_SCENARIO_STATS_COLLECTION_H_
  12. #include <map>
  13. #include <memory>
  14. #include "absl/types/optional.h"
  15. #include "call/call.h"
  16. #include "rtc_base/thread.h"
  17. #include "test/logging/log_writer.h"
  18. #include "test/scenario/performance_stats.h"
  19. namespace webrtc {
  20. namespace test {
  21. struct VideoQualityAnalyzerConfig {
  22. double psnr_coverage = 1;
  23. rtc::Thread* thread = nullptr;
  24. };
  25. class VideoLayerAnalyzer {
  26. public:
  27. void HandleCapturedFrame(const VideoFramePair& sample);
  28. void HandleRenderedFrame(const VideoFramePair& sample);
  29. void HandleFramePair(VideoFramePair sample,
  30. double psnr,
  31. RtcEventLogOutput* writer);
  32. VideoQualityStats stats_;
  33. Timestamp last_capture_time_ = Timestamp::MinusInfinity();
  34. Timestamp last_render_time_ = Timestamp::MinusInfinity();
  35. Timestamp last_freeze_time_ = Timestamp::MinusInfinity();
  36. int skip_count_ = 0;
  37. };
  38. class VideoQualityAnalyzer {
  39. public:
  40. explicit VideoQualityAnalyzer(
  41. VideoQualityAnalyzerConfig config = VideoQualityAnalyzerConfig(),
  42. std::unique_ptr<RtcEventLogOutput> writer = nullptr);
  43. ~VideoQualityAnalyzer();
  44. void HandleFramePair(VideoFramePair sample);
  45. std::vector<VideoQualityStats> layer_stats() const;
  46. VideoQualityStats& stats();
  47. void PrintHeaders();
  48. void PrintFrameInfo(const VideoFramePair& sample);
  49. std::function<void(const VideoFramePair&)> Handler();
  50. private:
  51. void HandleFramePair(VideoFramePair sample, double psnr);
  52. const VideoQualityAnalyzerConfig config_;
  53. std::map<int, VideoLayerAnalyzer> layer_analyzers_;
  54. const std::unique_ptr<RtcEventLogOutput> writer_;
  55. absl::optional<VideoQualityStats> cached_;
  56. };
  57. class CallStatsCollector {
  58. public:
  59. void AddStats(Call::Stats sample);
  60. CollectedCallStats& stats() { return stats_; }
  61. private:
  62. CollectedCallStats stats_;
  63. };
  64. class AudioReceiveStatsCollector {
  65. public:
  66. void AddStats(AudioReceiveStream::Stats sample);
  67. CollectedAudioReceiveStats& stats() { return stats_; }
  68. private:
  69. CollectedAudioReceiveStats stats_;
  70. };
  71. class VideoSendStatsCollector {
  72. public:
  73. void AddStats(VideoSendStream::Stats sample, Timestamp at_time);
  74. CollectedVideoSendStats& stats() { return stats_; }
  75. private:
  76. CollectedVideoSendStats stats_;
  77. Timestamp last_update_ = Timestamp::MinusInfinity();
  78. size_t last_fec_bytes_ = 0;
  79. };
  80. class VideoReceiveStatsCollector {
  81. public:
  82. void AddStats(VideoReceiveStream::Stats sample);
  83. CollectedVideoReceiveStats& stats() { return stats_; }
  84. private:
  85. CollectedVideoReceiveStats stats_;
  86. };
  87. struct CallStatsCollectors {
  88. CallStatsCollector call;
  89. AudioReceiveStatsCollector audio_receive;
  90. VideoSendStatsCollector video_send;
  91. VideoReceiveStatsCollector video_receive;
  92. };
  93. } // namespace test
  94. } // namespace webrtc
  95. #endif // TEST_SCENARIO_STATS_COLLECTION_H_