1 #ifndef _FRAME_ON_DISK_H
2 #define _FRAME_ON_DISK_H 1
12 extern std::mutex frame_mu;
14 int64_t pts = -1; // -1 means empty.
16 unsigned filename_idx;
17 uint32_t size; // Not using size_t saves a few bytes; we can have so many frames. TODO: Not anymore due to audio_size.
19 // Unfortunately, 32 bits wasted in padding here.
21 extern std::vector<FrameOnDisk> frames[MAX_STREAMS]; // Under frame_mu.
22 extern std::vector<std::string> frame_filenames; // Under frame_mu.
24 static bool inline operator==(const FrameOnDisk &a, const FrameOnDisk &b)
26 return a.pts == b.pts &&
27 a.offset == b.offset &&
28 a.filename_idx == b.filename_idx &&
30 a.audio_size == b.audio_size;
33 // A helper class to read frames from disk. It caches the file descriptor
34 // so that the kernel has a better chance of doing readahead when it sees
35 // the sequential reads. (For this reason, each display has a private
36 // FrameReader. Thus, we can easily keep multiple open file descriptors around
37 // for a single .frames file.)
39 // Thread-compatible, but not thread-safe.
49 Frame read_frame(FrameOnDisk frame, bool read_video, bool read_audio);
53 int last_filename_idx = -1;
56 // Utility functions for dealing with binary search.
57 inline std::vector<FrameOnDisk>::iterator
58 find_last_frame_before(std::vector<FrameOnDisk> &frames, int64_t pts_origin)
60 return std::lower_bound(frames.begin(), frames.end(), pts_origin,
61 [](const FrameOnDisk &frame, int64_t pts) { return frame.pts < pts; });
64 inline std::vector<FrameOnDisk>::const_iterator
65 find_last_frame_before(const std::vector<FrameOnDisk> &frames, int64_t pts_origin)
67 return std::lower_bound(frames.begin(), frames.end(), pts_origin,
68 [](const FrameOnDisk &frame, int64_t pts) { return frame.pts < pts; });
71 inline std::vector<FrameOnDisk>::iterator
72 find_first_frame_at_or_after(std::vector<FrameOnDisk> &frames, int64_t pts_origin)
74 return std::upper_bound(frames.begin(), frames.end(), pts_origin - 1,
75 [](int64_t pts, const FrameOnDisk &frame) { return pts < frame.pts; });
78 inline std::vector<FrameOnDisk>::const_iterator
79 find_first_frame_at_or_after(const std::vector<FrameOnDisk> &frames, int64_t pts_origin)
81 return std::upper_bound(frames.begin(), frames.end(), pts_origin - 1,
82 [](int64_t pts, const FrameOnDisk &frame) { return pts < frame.pts; });
85 #endif // !defined(_FRAME_ON_DISK_H)