• 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 MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
12 #define MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
13 
14 #include <string.h>  // Provide access to size_t.
15 
16 #include <vector>
17 
18 #include "absl/types/optional.h"
19 
20 namespace webrtc {
21 
22 class Histogram {
23  public:
24   // Creates histogram with capacity |num_buckets| and |forget_factor| in Q15.
25   Histogram(size_t num_buckets,
26             int forget_factor,
27             absl::optional<double> start_forget_weight = absl::nullopt);
28 
29   virtual ~Histogram();
30 
31   // Resets the histogram to the default start distribution.
32   virtual void Reset();
33 
34   // Add entry in bucket |index|.
35   virtual void Add(int index);
36 
37   // Calculates the quantile at |probability| (in Q30) of the histogram
38   // distribution.
39   virtual int Quantile(int probability);
40 
41   // Returns the number of buckets in the histogram.
42   virtual int NumBuckets() const;
43 
44   // Returns the probability for each bucket in Q30.
buckets()45   std::vector<int> buckets() const { return buckets_; }
46 
47   // Accessors only intended for testing purposes.
base_forget_factor_for_testing()48   int base_forget_factor_for_testing() const { return base_forget_factor_; }
forget_factor_for_testing()49   int forget_factor_for_testing() const { return forget_factor_; }
start_forget_weight_for_testing()50   absl::optional<double> start_forget_weight_for_testing() const {
51     return start_forget_weight_;
52   }
53 
54  private:
55   std::vector<int> buckets_;
56   int forget_factor_;  // Q15
57   const int base_forget_factor_;
58   int add_count_;
59   const absl::optional<double> start_forget_weight_;
60 };
61 
62 }  // namespace webrtc
63 
64 #endif  // MODULES_AUDIO_CODING_NETEQ_HISTOGRAM_H_
65