neteq_stats_getter.h (3651B)
1 /* 2 * Copyright (c) 2018 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 MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_STATS_GETTER_H_ 12 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_STATS_GETTER_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <string> 18 #include <utility> 19 #include <vector> 20 21 #include "api/audio/audio_frame.h" 22 #include "api/neteq/neteq.h" 23 #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" 24 #include "modules/audio_coding/neteq/tools/neteq_test.h" 25 26 namespace webrtc { 27 namespace test { 28 29 class NetEqStatsGetter : public NetEqGetAudioCallback { 30 public: 31 // This struct is a replica of webrtc::NetEqNetworkStatistics, but with all 32 // values stored in double precision. 33 struct Stats { 34 double current_buffer_size_ms = 0.0; 35 double preferred_buffer_size_ms = 0.0; 36 double jitter_peaks_found = 0.0; 37 double packet_loss_rate = 0.0; 38 double expand_rate = 0.0; 39 double speech_expand_rate = 0.0; 40 double preemptive_rate = 0.0; 41 double accelerate_rate = 0.0; 42 double secondary_decoded_rate = 0.0; 43 double secondary_discarded_rate = 0.0; 44 double clockdrift_ppm = 0.0; 45 double added_zero_samples = 0.0; 46 double mean_waiting_time_ms = 0.0; 47 double median_waiting_time_ms = 0.0; 48 double min_waiting_time_ms = 0.0; 49 double max_waiting_time_ms = 0.0; 50 }; 51 52 struct ConcealmentEvent { 53 uint64_t duration_ms; 54 size_t concealment_event_number; 55 int64_t time_from_previous_event_end_ms; 56 std::string ToString() const; 57 }; 58 59 // Takes a pointer to another callback object, which will be invoked after 60 // this object finishes. This does not transfer ownership, and null is a 61 // valid value. 62 explicit NetEqStatsGetter(std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer); 63 64 void set_stats_query_interval_ms(int64_t stats_query_interval_ms) { 65 stats_query_interval_ms_ = stats_query_interval_ms; 66 } 67 68 void BeforeGetAudio(NetEq* neteq) override; 69 70 void AfterGetAudio(int64_t time_now_ms, 71 const AudioFrame& audio_frame, 72 bool muted, 73 NetEq* neteq) override; 74 75 double AverageSpeechExpandRate() const; 76 77 NetEqDelayAnalyzer* delay_analyzer() const { return delay_analyzer_.get(); } 78 79 const std::vector<ConcealmentEvent>& concealment_events() const { 80 // Do not account for the last concealment event to avoid potential end 81 // call skewing. 82 return concealment_events_; 83 } 84 85 const std::vector<std::pair<int64_t, NetEqNetworkStatistics>>* stats() const { 86 return &stats_; 87 } 88 89 const std::vector<std::pair<int64_t, NetEqLifetimeStatistics>>* 90 lifetime_stats() const { 91 return &lifetime_stats_; 92 } 93 94 Stats AverageStats() const; 95 96 private: 97 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer_; 98 int64_t stats_query_interval_ms_ = 1000; 99 int64_t last_stats_query_time_ms_ = 0; 100 std::vector<std::pair<int64_t, NetEqNetworkStatistics>> stats_; 101 std::vector<std::pair<int64_t, NetEqLifetimeStatistics>> lifetime_stats_; 102 size_t current_concealment_event_ = 1; 103 uint64_t voice_concealed_samples_until_last_event_ = 0; 104 std::vector<ConcealmentEvent> concealment_events_; 105 int64_t last_event_end_time_ms_ = 0; 106 }; 107 108 } // namespace test 109 } // namespace webrtc 110 111 #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_STATS_GETTER_H_