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