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 <stdint.h>
11 
12 #include <vector>
13 
14 namespace shaka {
15 
17  public:
20 
23  void AddBlock(uint64_t size_in_bytes, double duration);
24 
29  uint64_t Estimate() const;
30 
35  uint64_t Max() const;
36 
37  private:
38  BandwidthEstimator(const BandwidthEstimator&) = delete;
39  BandwidthEstimator& operator=(const BandwidthEstimator&) = delete;
40 
41  struct Block {
42  uint64_t size_in_bits;
43  double duration;
44  };
45  // Return the average block duration of the blocks in |initial_blocks_|.
46  double GetAverageBlockDuration() const;
47  // Return the bitrate of the block. Note that a bitrate of 0 is returned if
48  // the block duration is less than 50% of target block duration.
49  uint64_t GetBitrate(const Block& block, double target_block_duration) const;
50 
51  std::vector<Block> initial_blocks_;
52  // Target block duration will be estimated from the average duration of the
53  // initial blocks.
54  double target_block_duration_ = 0;
55 
56  uint64_t total_size_in_bits_ = 0;
57  double total_duration_ = 0;
58  uint64_t max_bitrate_ = 0;
59 };
60 
61 } // namespace shaka
62 
63 #endif // MPD_BASE_BANDWIDTH_ESTIMATOR_H_
void AddBlock(uint64_t size_in_bytes, double duration)
All the methods that are virtual are virtual for mocking.