1 /*
2  *  Copyright (c) 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 
11 #ifndef TEST_PC_E2E_ANALYZER_AUDIO_DEFAULT_AUDIO_QUALITY_ANALYZER_H_
12 #define TEST_PC_E2E_ANALYZER_AUDIO_DEFAULT_AUDIO_QUALITY_ANALYZER_H_
13 
14 #include <map>
15 #include <string>
16 
17 #include "api/stats_types.h"
18 #include "api/test/audio_quality_analyzer_interface.h"
19 #include "api/test/track_id_stream_label_map.h"
20 #include "rtc_base/critical_section.h"
21 #include "rtc_base/numerics/samples_stats_counter.h"
22 #include "test/testsupport/perf_test.h"
23 
24 namespace webrtc {
25 namespace webrtc_pc_e2e {
26 
27 struct AudioStreamStats {
28   SamplesStatsCounter expand_rate;
29   SamplesStatsCounter accelerate_rate;
30   SamplesStatsCounter preemptive_rate;
31   SamplesStatsCounter speech_expand_rate;
32   SamplesStatsCounter preferred_buffer_size_ms;
33 };
34 
35 // TODO(bugs.webrtc.org/10430): Migrate to the new GetStats as soon as
36 // bugs.webrtc.org/10428 is fixed.
37 class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
38  public:
39   void Start(std::string test_case_name,
40              TrackIdStreamLabelMap* analyzer_helper) override;
41   void OnStatsReports(const std::string& pc_label,
42                       const StatsReports& stats_reports) override;
43   void Stop() override;
44 
45   // Returns audio quality stats per stream label.
46   std::map<std::string, AudioStreamStats> GetAudioStreamsStats() const;
47 
48  private:
49   const std::string& GetStreamLabelFromStatsReport(
50       const StatsReport* stats_report) const;
51   std::string GetTestCaseName(const std::string& stream_label) const;
52   void ReportResult(const std::string& metric_name,
53                     const std::string& stream_label,
54                     const SamplesStatsCounter& counter,
55                     const std::string& unit,
56                     webrtc::test::ImproveDirection improve_direction) const;
57 
58   std::string test_case_name_;
59   TrackIdStreamLabelMap* analyzer_helper_;
60 
61   rtc::CriticalSection lock_;
62   std::map<std::string, AudioStreamStats> streams_stats_ RTC_GUARDED_BY(lock_);
63 };
64 
65 }  // namespace webrtc_pc_e2e
66 }  // namespace webrtc
67 
68 #endif  // TEST_PC_E2E_ANALYZER_AUDIO_DEFAULT_AUDIO_QUALITY_ANALYZER_H_
69