Shaka Packager SDK
bandwidth_estimator.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef MPD_BASE_BANDWIDTH_ESTIMATOR_H_
8 #define MPD_BASE_BANDWIDTH_ESTIMATOR_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include <list>
14 
16  public:
19  explicit BandwidthEstimator(int num_blocks);
21 
22  // @param size is the size of the block in bytes. Should be positive.
23  // @param duration is the length in seconds. Should be positive.
24  void AddBlock(uint64_t size, double duration);
25 
26  // @return The estimate bandwidth, in bits per second, from the harmonic mean
27  // of the number of blocks specified in the constructor. The value is
28  // rounded up to the nearest integer.
29  uint64_t Estimate() const;
30 
31  static const int kUseAllBlocks;
32 
33  private:
34  const int num_blocks_for_estimation_;
35  double harmonic_mean_denominator_;
36 
37  // This is not used when num_blocks_for_estimation_ != 0. Therefore it should
38  // always be 0 if num_blocks_for_estimation_ != 0.
39  size_t num_blocks_added_;
40  std::list<double> history_;
41 };
42 
43 #endif // MPD_BASE_BANDWIDTH_ESTIMATOR_H_
BandwidthEstimator(int num_blocks)