+// Find the frame immediately before and after this point.
+bool Player::find_surrounding_frames(int64_t pts, int stream_idx, int64_t *pts_lower, int64_t *pts_upper)
+{
+ lock_guard<mutex> lock(frame_mu);
+
+ // Find the first frame such that frame.pts >= pts.
+ auto it = lower_bound(frames[stream_idx].begin(),
+ frames[stream_idx].end(),
+ pts);
+ if (it == frames[stream_idx].end()) {
+ return false;
+ }
+ *pts_upper = *it;
+
+ // Find the last frame such that in_pts <= frame.pts (if any).
+ if (it == frames[stream_idx].begin()) {
+ *pts_lower = *it;
+ } else {
+ *pts_lower = *(it - 1);
+ }
+ assert(pts >= *pts_lower);
+ assert(pts <= *pts_upper);
+ return true;
+}
+