+// Utility functions for dealing with binary search.
+inline std::vector<FrameOnDisk>::iterator
+find_last_frame_before(std::vector<FrameOnDisk> &frames, int64_t pts_origin)
+{
+ return std::lower_bound(frames.begin(), frames.end(), pts_origin,
+ [](const FrameOnDisk &frame, int64_t pts) { return frame.pts < pts; });
+}
+
+inline std::vector<FrameOnDisk>::iterator
+find_first_frame_at_or_after(std::vector<FrameOnDisk> &frames, int64_t pts_origin)
+{
+ return std::upper_bound(frames.begin(), frames.end(), pts_origin - 1,
+ [](int64_t pts, const FrameOnDisk &frame) { return pts < frame.pts; });
+}
+