2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-05-22 02:16:17 +00:00
|
|
|
//
|
|
|
|
// 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_
|
|
|
|
|
2023-10-11 08:49:50 +00:00
|
|
|
#include <cstdint>
|
2019-07-11 21:32:10 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-04-13 18:48:11 +00:00
|
|
|
namespace shaka {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
class BandwidthEstimator {
|
|
|
|
public:
|
2019-07-11 21:32:10 +00:00
|
|
|
BandwidthEstimator();
|
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
|
2019-07-11 21:32:10 +00:00
|
|
|
/// nearest integer. Note that small blocks w.r.t.
|
|
|
|
/// |target_block_duration| are not counted.
|
2018-04-13 18:48:11 +00:00
|
|
|
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;
|
|
|
|
|
2019-07-11 21:32:10 +00:00
|
|
|
struct Block {
|
|
|
|
uint64_t size_in_bits;
|
|
|
|
double duration;
|
|
|
|
};
|
|
|
|
// Return the average block duration of the blocks in |initial_blocks_|.
|
|
|
|
double GetAverageBlockDuration() const;
|
|
|
|
// Return the bitrate of the block. Note that a bitrate of 0 is returned if
|
|
|
|
// the block duration is less than 50% of target block duration.
|
|
|
|
uint64_t GetBitrate(const Block& block, double target_block_duration) const;
|
|
|
|
|
|
|
|
std::vector<Block> initial_blocks_;
|
|
|
|
// Target block duration will be estimated from the average duration of the
|
|
|
|
// initial blocks.
|
|
|
|
double target_block_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_
|