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/numerics/samples_stats_counter.h" 19 #include "api/test/audio_quality_analyzer_interface.h" 20 #include "api/test/metrics/metrics_logger.h" 21 #include "api/test/track_id_stream_info_map.h" 22 #include "api/units/time_delta.h" 23 #include "rtc_base/synchronization/mutex.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 explicit DefaultAudioQualityAnalyzer( 40 test::MetricsLogger* const metrics_logger); 41 42 void Start(std::string test_case_name, 43 TrackIdStreamInfoMap* analyzer_helper) override; 44 void OnStatsReports( 45 absl::string_view pc_label, 46 const rtc::scoped_refptr<const RTCStatsReport>& report) override; 47 void Stop() override; 48 49 // Returns audio quality stats per stream label. 50 std::map<std::string, AudioStreamStats> GetAudioStreamsStats() const; 51 52 private: 53 struct StatsSample { 54 uint64_t total_samples_received = 0; 55 uint64_t concealed_samples = 0; 56 uint64_t removed_samples_for_acceleration = 0; 57 uint64_t inserted_samples_for_deceleration = 0; 58 uint64_t silent_concealed_samples = 0; 59 TimeDelta jitter_buffer_delay = TimeDelta::Zero(); 60 TimeDelta jitter_buffer_target_delay = TimeDelta::Zero(); 61 uint64_t jitter_buffer_emitted_count = 0; 62 }; 63 64 std::string GetTestCaseName(const std::string& stream_label) const; 65 66 test::MetricsLogger* const metrics_logger_; 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, TrackIdStreamInfoMap::StreamInfo> stream_info_ 74 RTC_GUARDED_BY(lock_); 75 std::map<std::string, StatsSample> last_stats_sample_ RTC_GUARDED_BY(lock_); 76 }; 77 78 } // namespace webrtc_pc_e2e 79 } // namespace webrtc 80 81 #endif // TEST_PC_E2E_ANALYZER_AUDIO_DEFAULT_AUDIO_QUALITY_ANALYZER_H_ 82