}
int64_t in_pts_lower, in_pts_upper;
-
- // Find the frame immediately before and after this point.
- {
- lock_guard<mutex> lock(frame_mu);
-
- // Find the first frame such that in_pts >= frame.pts.
- auto it = lower_bound(frames[stream_idx].begin(),
- frames[stream_idx].end(),
- in_pts);
- if (it == frames[stream_idx].end() || *it >= clip.pts_out) {
- break;
- }
- in_pts_upper = *it;
-
- // Find the last frame such that in_pts <= frame.pts (if any).
- if (it == frames[stream_idx].begin()) {
- in_pts_lower = *it;
- } else {
- in_pts_lower = *(it - 1);
- }
+ bool ok = find_surrounding_frames(in_pts, stream_idx, &in_pts_lower, &in_pts_upper);
+ if (!ok || in_pts_upper >= clip.pts_out) {
+ break;
}
- assert(in_pts >= in_pts_lower);
- assert(in_pts <= in_pts_upper);
// Sleep until the next frame start, or until there's a new clip we're supposed to play.
{
}
}
+// 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;
+}
+
Player::Player(JPEGFrameView *destination, bool also_output_to_stream)
: destination(destination)
{
static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
+ // Find the frame immediately before and after this point.
+ // Returns false if pts is after the last frame.
+ bool find_surrounding_frames(int64_t pts, int stream_idx, int64_t *pts_lower, int64_t *pts_upper);
+
JPEGFrameView *destination;
done_callback_func done_callback;
progress_callback_func progress_callback;