7 #include "packager/mpd/base/bandwidth_estimator.h" 11 #include "packager/base/logging.h" 15 BandwidthEstimator::BandwidthEstimator(
size_t num_blocks)
16 : sliding_queue_(num_blocks) {}
17 BandwidthEstimator::~BandwidthEstimator() {}
20 DCHECK_GT(duration, 0.0);
23 const int kBitsInByte = 8;
24 const double bits_per_second_reciprocal = duration / (kBitsInByte * size);
25 sliding_queue_.Add(bits_per_second_reciprocal);
29 return sliding_queue_.size() == 0
31 :
static_cast<uint64_t
>(
32 ceil(sliding_queue_.size() / sliding_queue_.sum()));
38 return sliding_queue_.size() == 0
40 :
static_cast<uint64_t
>(ceil(1 / sliding_queue_.min()));
43 BandwidthEstimator::SlidingQueue::SlidingQueue(
size_t window_size)
44 : window_size_(window_size) {}
46 void BandwidthEstimator::SlidingQueue::Add(
double value) {
48 while (!min_.empty() && min_.back() > value)
50 min_.push_back(value);
52 if (window_size_ == kUseAllBlocks) {
59 window_.push_back(value);
62 if (window_.size() <= window_size_) {
67 if (min_.front() == window_.front())
70 sum_ -= window_.front();
All the methods that are virtual are virtual for mocking.
void AddBlock(uint64_t size, double duration)
uint64_t Estimate() const