2014-05-22 02:16:17 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef MPD_BASE_BANDWIDTH_ESTIMATOR_H_
|
|
|
|
#define MPD_BASE_BANDWIDTH_ESTIMATOR_H_
|
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-04-13 18:48:11 +00:00
|
|
|
namespace shaka {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
class BandwidthEstimator {
|
|
|
|
public:
|
2018-11-14 20:47:48 +00:00
|
|
|
explicit BandwidthEstimator(double target_segment_duration);
|
2014-05-22 02:16:17 +00:00
|
|
|
~BandwidthEstimator();
|
|
|
|
|
2018-04-13 18:48:11 +00:00
|
|
|
/// @param size is the size of the block in bytes. Should be positive.
|
|
|
|
/// @param duration is the length in seconds. Should be positive.
|
2018-06-22 23:19:30 +00:00
|
|
|
void AddBlock(uint64_t size_in_bytes, double duration);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-06-22 23:19:30 +00:00
|
|
|
/// @return The estimate bandwidth, in bits per second, calculated from the
|
|
|
|
/// sum of the sizes of every block, divided by the sum of durations
|
|
|
|
/// of every block, of the number of blocks specified in the
|
|
|
|
/// constructor. The value is rounded up to the nearest integer.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint64_t Estimate() const;
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-04-13 18:48:11 +00:00
|
|
|
/// @return The max bandwidth, in bits per second, of the number of blocks
|
|
|
|
/// specified in the constructor. The value is rounded up to the
|
|
|
|
/// nearest integer.
|
|
|
|
uint64_t Max() const;
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-13 18:48:11 +00:00
|
|
|
BandwidthEstimator(const BandwidthEstimator&) = delete;
|
|
|
|
BandwidthEstimator& operator=(const BandwidthEstimator&) = delete;
|
|
|
|
|
2018-11-14 20:47:48 +00:00
|
|
|
const double target_segment_duration_ = 0;
|
2018-06-22 23:19:30 +00:00
|
|
|
uint64_t total_size_in_bits_ = 0;
|
|
|
|
double total_duration_ = 0;
|
|
|
|
uint64_t max_bitrate_ = 0;
|
2014-05-22 02:16:17 +00:00
|
|
|
};
|
|
|
|
|
2018-04-13 18:48:11 +00:00
|
|
|
} // namespace shaka
|
|
|
|
|
2014-05-22 02:16:17 +00:00
|
|
|
#endif // MPD_BASE_BANDWIDTH_ESTIMATOR_H_
|