45 int64_t
Target(
double fps,
int speed, int64_t capacity,
46 int64_t conservative, int64_t maximum) {
47 const int64_t stride = std::max<int64_t>(1, std::abs(
static_cast<int64_t
>(speed)));
48 const int64_t limit = std::max<int64_t>(0, std::min({capacity, maximum,
MaxProbeFrames}));
49 if (conservative < 0 || limit == 0)
return target = 0;
50 int64_t wanted = std::min(conservative, limit);
51 if (samples >= 3 && fps > 0) {
52 const double budget = 1000000.0 / fps / stride;
53 const double cost = (mean + 3 * deviation) / budget;
54 const double demand = cost < 0.5 ? 2.0 * stride
55 : std::ceil(2 + 4 * cost) * stride;
58 wanted =
static_cast<int64_t
>(std::min<double>(limit, demand));
60 wanted = std::clamp<int64_t>(wanted, 0, limit);
62 if (!target || wanted > target || wanted + 2 <= target) target = wanted;
63 return target = std::min(target, limit);
65 bool Ready(int64_t now, int64_t contiguous_ahead,
bool current_available,
66 int64_t required, int64_t minimum_step = 1) {
68 const int64_t threshold = released || timed_out ? minimum_step : required;
69 const bool ready = current_available && contiguous_ahead >= threshold;
70 if (ready) released =
true;