X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fdisk_space_estimator.h;fp=nageru%2Fdisk_space_estimator.h;h=163b7efd555dd81ac2df84a5fc8591f63b393673;hb=827606868bf9f1dd16208882f0e3ca424b3e9e0a;hp=ce81321638e2350adc9626d2d347fa8c3daa0b2e;hpb=c290898058c364494fa74398c70566f3bff1ae4c;p=nageru diff --git a/nageru/disk_space_estimator.h b/shared/disk_space_estimator.h similarity index 65% rename from nageru/disk_space_estimator.h rename to shared/disk_space_estimator.h index ce81321..163b7ef 100644 --- a/nageru/disk_space_estimator.h +++ b/shared/disk_space_estimator.h @@ -9,21 +9,26 @@ // // The bitrate is measured over a simple 30-second sliding window. -#include -#include #include #include #include +#include #include +#include #include "shared/timebase.h" -class DiskSpaceEstimator -{ +class DiskSpaceEstimator { public: typedef std::function callback_t; DiskSpaceEstimator(callback_t callback); + // Report that a video frame with the given pts and size has just been + // written (possibly appended) to the given file. + // + // is taken to be in TIMEBASE units (see shared/timebase.h). + void report_write(const std::string &filename, off_t bytes, uint64_t pts); + // Report that a video frame with the given pts has just been written // to the given file, so the estimator should stat the file and see // by how much it grew since last time. Called by the Mux object @@ -31,13 +36,19 @@ public: // // If the filename changed since last time, the estimation is reset. // is taken to be in TIMEBASE units (see shared/timebase.h). - void report_write(const std::string &filename, uint64_t pts); + // + // You should probably not mix this and report_write() on the same + // object. Really, report_write() matches Futatabi's controlled writes + // to a custom format, and report_append() matches Nageru's use of Mux + // (where we don't see the bytes flowing past). + void report_append(const std::string &filename, uint64_t pts); private: static constexpr int64_t window_length = 30 * TIMEBASE; + void report_write_internal(const std::string &filename, off_t file_size, uint64_t pts); + callback_t callback; - std::string last_filename; struct MeasurePoint { uint64_t pts; @@ -46,6 +57,9 @@ private: std::deque measure_points; uint64_t last_pts_reported = 0; + off_t total_size = 0; // For report_write(). + std::string last_filename; // For report_append(). + // Metrics. std::atomic metric_disk_free_bytes{-1}; };