6 #include "disk_space_estimator.h"
9 DiskSpaceEstimator::DiskSpaceEstimator(DiskSpaceEstimator::callback_t callback)
14 void DiskSpaceEstimator::report_write(const std::string &filename, uint64_t pts)
16 if (filename != last_filename) {
17 last_filename = filename;
18 measure_points.clear();
21 // Reject points that are out-of-order (happens with B-frames).
22 if (!measure_points.empty() && pts < measure_points.back().pts) {
26 // Remove too old points.
27 while (measure_points.size() > 1 && measure_points.front().pts + window_length < pts) {
28 measure_points.pop_front();
32 if (stat(filename.c_str(), &st) == -1) {
33 perror(filename.c_str());
38 if (statfs(filename.c_str(), &fst) == -1) {
39 perror(filename.c_str());
43 if (!measure_points.empty()) {
44 off_t free_bytes = off_t(fst.f_bavail) * fst.f_frsize;
45 double bytes_per_second = double(st.st_size - measure_points.front().size) /
46 (pts - measure_points.front().pts) * TIMEBASE;
47 double seconds_left = free_bytes / bytes_per_second;
48 callback(free_bytes, seconds_left);
51 measure_points.push_back({ pts, st.st_size });
54 DiskSpaceEstimator *global_disk_space_estimator = nullptr; // Created in MainWindow::MainWindow().