• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "absl/strings/string_view.h"
18 #include "api/test/audio_quality_analyzer_interface.h"
19 #include "api/test/track_id_stream_info_map.h"
20 #include "api/units/time_delta.h"
21 #include "rtc_base/numerics/samples_stats_counter.h"
22 #include "rtc_base/synchronization/mutex.h"
23 #include "test/testsupport/perf_test.h"
24 
25 namespace webrtc {
26 namespace webrtc_pc_e2e {
27 
28 struct AudioStreamStats {
29   SamplesStatsCounter expand_rate;
30   SamplesStatsCounter accelerate_rate;
31   SamplesStatsCounter preemptive_rate;
32   SamplesStatsCounter speech_expand_rate;
33   SamplesStatsCounter average_jitter_buffer_delay_ms;
34   SamplesStatsCounter preferred_buffer_size_ms;
35 };
36 
37 class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
38  public:
39   void Start(std::string test_case_name,
40              TrackIdStreamInfoMap* analyzer_helper) override;
41   void OnStatsReports(
42       absl::string_view pc_label,
43       const rtc::scoped_refptr<const RTCStatsReport>& report) override;
44   void Stop() override;
45 
46   // Returns audio quality stats per stream label.
47   std::map<std::string, AudioStreamStats> GetAudioStreamsStats() const;
48 
49  private:
50   struct StatsSample {
51     uint64_t total_samples_received = 0;
52     uint64_t concealed_samples = 0;
53     uint64_t removed_samples_for_acceleration = 0;
54     uint64_t inserted_samples_for_deceleration = 0;
55     uint64_t silent_concealed_samples = 0;
56     TimeDelta jitter_buffer_delay = TimeDelta::Zero();
57     TimeDelta jitter_buffer_target_delay = TimeDelta::Zero();
58     uint64_t jitter_buffer_emitted_count = 0;
59   };
60 
61   std::string GetTestCaseName(const std::string& stream_label) const;
62   void ReportResult(const std::string& metric_name,
63                     const std::string& stream_label,
64                     const SamplesStatsCounter& counter,
65                     const std::string& unit,
66                     webrtc::test::ImproveDirection improve_direction) const;
67 
68   std::string test_case_name_;
69   TrackIdStreamInfoMap* analyzer_helper_;
70 
71   mutable Mutex lock_;
72   std::map<std::string, AudioStreamStats> streams_stats_ RTC_GUARDED_BY(lock_);
73   std::map<std::string, StatsSample> last_stats_sample_ RTC_GUARDED_BY(lock_);
74 };
75 
76 }  // namespace webrtc_pc_e2e
77 }  // namespace webrtc
78 
79 #endif  // TEST_PC_E2E_ANALYZER_AUDIO_DEFAULT_AUDIO_QUALITY_ANALYZER_H_
80