double next_clip_fade_time = -1.0;
for ( ;; ) {
+wait_for_clip:
bool clip_ready;
steady_clock::time_point before_sleep = steady_clock::now();
if (!clip_ready) {
if (video_stream != nullptr) {
- video_stream->schedule_refresh_frame(pts);
+ video_stream->schedule_refresh_frame(pts, /*display_func=*/nullptr);
}
continue;
}
new_clip_changed.wait_until(lock, next_frame_start, [this]{
return new_clip_ready || override_stream_idx != -1;
});
- if (new_clip_ready) break;
+ if (new_clip_ready) {
+ goto wait_for_clip;
+ }
if (override_stream_idx != -1) {
stream_idx = override_stream_idx;
override_stream_idx = -1;
}
if (in_pts_lower == in_pts_upper) {
- destination->setFrame(primary_stream_idx, in_pts_lower, /*interpolated=*/false, secondary_stream_idx, secondary_pts, fade_alpha);
- if (video_stream != nullptr) {
+ auto display_func = [this, primary_stream_idx, in_pts_lower, secondary_stream_idx, secondary_pts, fade_alpha]{
+ destination->setFrame(primary_stream_idx, in_pts_lower, /*interpolated=*/false, secondary_stream_idx, secondary_pts, fade_alpha);
+ };
+ if (video_stream == nullptr) {
+ display_func();
+ } else {
if (secondary_stream_idx == -1) {
- video_stream->schedule_original_frame(pts, primary_stream_idx, in_pts_lower);
+ video_stream->schedule_original_frame(pts, display_func, primary_stream_idx, in_pts_lower);
} else {
- video_stream->schedule_faded_frame(pts, primary_stream_idx, in_pts_lower, secondary_stream_idx, secondary_pts, fade_alpha);
+ video_stream->schedule_faded_frame(pts, display_func, primary_stream_idx, in_pts_lower, secondary_stream_idx, secondary_pts, fade_alpha);
}
}
continue;
for (int64_t snap_pts : { in_pts_lower, in_pts_upper }) {
double snap_pts_as_frameno = (snap_pts - in_pts_origin) * output_framerate / TIMEBASE / speed;
if (fabs(snap_pts_as_frameno - frameno) < 0.01) {
- destination->setFrame(primary_stream_idx, snap_pts, /*interpolated=*/false, secondary_stream_idx, secondary_pts, fade_alpha);
- if (video_stream != nullptr) {
+ auto display_func = [this, primary_stream_idx, snap_pts, secondary_stream_idx, secondary_pts, fade_alpha]{
+ destination->setFrame(primary_stream_idx, snap_pts, /*interpolated=*/false, secondary_stream_idx, secondary_pts, fade_alpha);
+ };
+ if (video_stream == nullptr) {
+ display_func();
+ } else {
if (secondary_stream_idx == -1) {
- video_stream->schedule_original_frame(pts, primary_stream_idx, snap_pts);
+ video_stream->schedule_original_frame(pts, display_func, primary_stream_idx, snap_pts);
} else {
- video_stream->schedule_faded_frame(pts, primary_stream_idx, snap_pts, secondary_stream_idx, secondary_pts, fade_alpha);
+ video_stream->schedule_faded_frame(pts, display_func, primary_stream_idx, snap_pts, secondary_stream_idx, secondary_pts, fade_alpha);
}
}
in_pts_origin += snap_pts - in_pts;
} else {
// Calculate the interpolated frame. When it's done, the destination
// will be unblocked.
- destination->setFrame(primary_stream_idx, pts, /*interpolated=*/true, secondary_stream_idx, secondary_pts, fade_alpha);
- video_stream->schedule_interpolated_frame(pts, primary_stream_idx, in_pts_lower, in_pts_upper, alpha, secondary_stream_idx, secondary_pts, fade_alpha);
+ auto display_func = [this, primary_stream_idx, pts, secondary_stream_idx, secondary_pts, fade_alpha]{
+ destination->setFrame(primary_stream_idx, pts, /*interpolated=*/true, secondary_stream_idx, secondary_pts, fade_alpha);
+ };
+ video_stream->schedule_interpolated_frame(pts, display_func, primary_stream_idx, in_pts_lower, in_pts_upper, alpha, secondary_stream_idx, secondary_pts, fade_alpha);
}
}