2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_
16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
18 #include "webrtc/typedefs.h"
22 // Forward declarations.
26 // This class handles various network statistics in NetEq.
27 class StatisticsCalculator {
29 StatisticsCalculator();
31 virtual ~StatisticsCalculator() {}
33 // Resets most of the counters.
36 // Resets the counters that are not handled by Reset().
39 // Resets the waiting time statistics.
40 void ResetWaitingTimeStatistics();
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);
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);
50 // Reports that |num_samples| samples were produced through preemptive
52 void PreemptiveExpandedSamples(int num_samples);
54 // Reports that |num_samples| samples were removed through accelerate.
55 void AcceleratedSamples(int num_samples);
57 // Reports that |num_samples| zeros were inserted into the output.
58 void AddZeros(int num_samples);
60 // Reports that |num_packets| packets were discarded.
61 void PacketsDiscarded(int num_packets);
63 // Reports that |num_samples| were lost.
64 void LostSamples(int num_samples);
66 // Increases the report interval counter with |num_samples| at a sample rate
68 void IncreaseCounter(int num_samples, int fs_hz);
70 // Stores new packet waiting time in waiting time statistics.
71 void StoreWaitingTime(int waiting_time_ms);
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);
84 void WaitingTimes(std::vector<int>* waiting_times);
87 static const int kMaxReportPeriod = 60; // Seconds before auto-reset.
88 static const int kLenWaitingTimes = 100;
90 // Calculates numerator / denominator, and returns the value in Q14.
91 static int CalculateQ14Ratio(uint32_t numerator, uint32_t denominator);
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 timestamps_since_last_report_;
101 int waiting_times_[kLenWaitingTimes]; // Used as a circular buffer.
102 int len_waiting_times_;
103 int next_waiting_time_index_;
105 DISALLOW_COPY_AND_ASSIGN(StatisticsCalculator);
108 } // namespace webrtc
109 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_STATISTICS_CALCULATOR_H_