philipel | 5ab4c6d | 2016-03-08 11:36:15 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_HISTOGRAM_H_ |
| 12 | #define MODULES_VIDEO_CODING_HISTOGRAM_H_ |
philipel | 5ab4c6d | 2016-03-08 11:36:15 | [diff] [blame] | 13 | |
| 14 | #include <cstddef> |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace webrtc { |
| 18 | namespace video_coding { |
| 19 | class Histogram { |
| 20 | public: |
| 21 | // A discrete histogram where every bucket with range [0, num_buckets). |
| 22 | // Values greater or equal to num_buckets will be placed in the last bucket. |
| 23 | Histogram(size_t num_buckets, size_t max_num_values); |
| 24 | |
| 25 | // Add a value to the histogram. If there already is max_num_values in the |
| 26 | // histogram then the oldest value will be replaced with the new value. |
| 27 | void Add(size_t value); |
| 28 | |
| 29 | // Calculates how many buckets have to be summed in order to accumulate at |
| 30 | // least the given probability. |
| 31 | size_t InverseCdf(float probability) const; |
| 32 | |
| 33 | // How many values that make up this histogram. |
| 34 | size_t NumValues() const; |
| 35 | |
| 36 | private: |
| 37 | // A circular buffer that holds the values that make up the histogram. |
| 38 | std::vector<size_t> values_; |
| 39 | std::vector<size_t> buckets_; |
| 40 | size_t index_; |
| 41 | }; |
| 42 | |
| 43 | } // namespace video_coding |
| 44 | } // namespace webrtc |
| 45 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 46 | #endif // MODULES_VIDEO_CODING_HISTOGRAM_H_ |