1 #ifndef _FRAME_ON_DISK_H
2 #define _FRAME_ON_DISK_H 1
13 extern std::mutex frame_mu;
15 int64_t pts = -1; // -1 means empty.
17 unsigned filename_idx;
18 uint32_t size; // Not using size_t saves a few bytes; we can have so many frames.
20 extern std::vector<FrameOnDisk> frames[MAX_STREAMS]; // Under frame_mu.
21 extern std::vector<std::string> frame_filenames; // Under frame_mu.
23 // A helper class to read frames from disk. It caches the file descriptor
24 // so that the kernel has a better chance of doing readahead when it sees
25 // the sequential reads. (For this reason, each display has a private
26 // FrameReader. Thus, we can easily keep multiple open file descriptors around
27 // for a single .frames file.)
31 std::string read_frame(FrameOnDisk frame);
35 int last_filename_idx = -1;
38 // Utility functions for dealing with binary search.
39 inline std::vector<FrameOnDisk>::iterator
40 find_last_frame_before(std::vector<FrameOnDisk> &frames, int64_t pts_origin)
42 return std::lower_bound(frames.begin(), frames.end(), pts_origin,
43 [](const FrameOnDisk &frame, int64_t pts) { return frame.pts < pts; });
46 inline std::vector<FrameOnDisk>::iterator
47 find_first_frame_at_or_after(std::vector<FrameOnDisk> &frames, int64_t pts_origin)
49 return std::upper_bound(frames.begin(), frames.end(), pts_origin - 1,
50 [](int64_t pts, const FrameOnDisk &frame) { return pts < frame.pts; });
53 #endif // !defined(_FRAME_ON_DISK_H)