1 /* 2 * Copyright (c) 2013 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 WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ 13 14 #include <vector> 15 16 #include "webrtc/base/constructormagic.h" 17 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h" 18 #include "webrtc/typedefs.h" 19 20 namespace webrtc { 21 22 // Forward declarations. 23 class DecisionLogic; 24 class DelayManager; 25 26 // This class handles various network statistics in NetEq. 27 class StatisticsCalculator { 28 public: 29 StatisticsCalculator(); 30 31 virtual ~StatisticsCalculator() {} 32 33 // Resets most of the counters. 34 void Reset(); 35 36 // Resets the counters that are not handled by Reset(). 37 void ResetMcu(); 38 39 // Resets the waiting time statistics. 40 void ResetWaitingTimeStatistics(); 41 42 // Reports that |num_samples| samples were produced through expansion, and 43 // that the expansion produced other than just noise samples. 44 void ExpandedVoiceSamples(int num_samples); 45 46 // Reports that |num_samples| samples were produced through expansion, and 47 // that the expansion produced only noise samples. 48 void ExpandedNoiseSamples(int num_samples); 49 50 // Reports that |num_samples| samples were produced through preemptive 51 // expansion. 52 void PreemptiveExpandedSamples(int num_samples); 53 54 // Reports that |num_samples| samples were removed through accelerate. 55 void AcceleratedSamples(int num_samples); 56 57 // Reports that |num_samples| zeros were inserted into the output. 58 void AddZeros(int num_samples); 59 60 // Reports that |num_packets| packets were discarded. 61 void PacketsDiscarded(int num_packets); 62 63 // Reports that |num_samples| were lost. 64 void LostSamples(int num_samples); 65 66 // Increases the report interval counter with |num_samples| at a sample rate 67 // of |fs_hz|. 68 void IncreaseCounter(int num_samples, int fs_hz); 69 70 // Stores new packet waiting time in waiting time statistics. 71 void StoreWaitingTime(int waiting_time_ms); 72 73 // Returns the current network statistics in |stats|. The current sample rate 74 // is |fs_hz|, the total number of samples in packet buffer and sync buffer 75 // yet to play out is |num_samples_in_buffers|, and the number of samples per 76 // packet is |samples_per_packet|. 77 void GetNetworkStatistics(int fs_hz, 78 int num_samples_in_buffers, 79 int samples_per_packet, 80 const DelayManager& delay_manager, 81 const DecisionLogic& decision_logic, 82 NetEqNetworkStatistics *stats); 83 84 void WaitingTimes(std::vector<int>* waiting_times); 85 86 private: 87 static const int kMaxReportPeriod = 60; // Seconds before auto-reset. 88 static const int kLenWaitingTimes = 100; 89 90 // Calculates numerator / denominator, and returns the value in Q14. 91 static int CalculateQ14Ratio(uint32_t numerator, uint32_t denominator); 92 93 uint32_t preemptive_samples_; 94 uint32_t accelerate_samples_; 95 int added_zero_samples_; 96 uint32_t expanded_voice_samples_; 97 uint32_t expanded_noise_samples_; 98 int discarded_packets_; 99 uint32_t lost_timestamps_; 100 uint32_t last_report_timestamp_; 101 int waiting_times_[kLenWaitingTimes]; // Used as a circular buffer. 102 int len_waiting_times_; 103 int next_waiting_time_index_; 104 105 DISALLOW_COPY_AND_ASSIGN(StatisticsCalculator); 106 }; 107 108 } // namespace webrtc 109 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_ 110