• - Fix VideoCacheThread::isReady() so preroll readiness is clamped by frames actually available to the timeline boundary (end/start), preventing playback from stalling in PLAY near the end.

- Add regression coverage in tests/VideoCacheThread.cpp (isReady: clamps preroll requirement at timeline boundaries) for forward-near-end and backward-near-start cases.
This commit is contained in:
Jonathan Thomas
2026-02-12 23:41:51 -06:00
parent 57c1fb2ec3
commit fb41a3c479
4 changed files with 90 additions and 5 deletions

View File

@@ -58,10 +58,32 @@ namespace openshot
}
int dir = computeDirection();
if (dir > 0) {
return (last_cached_index >= requested_display_frame + min_frames_ahead);
// Near timeline boundaries, don't require more pre-roll than can exist.
int64_t max_frame = reader->info.video_length;
if (auto* timeline = dynamic_cast<Timeline*>(reader)) {
const int64_t timeline_max = timeline->GetMaxFrame();
if (timeline_max > 0) {
max_frame = timeline_max;
}
}
return (last_cached_index <= requested_display_frame - min_frames_ahead);
if (max_frame < 1) {
return false;
}
int64_t required_ahead = min_frames_ahead;
if (required_ahead < 0) {
required_ahead = 0;
}
int64_t available_ahead = (dir > 0)
? std::max<int64_t>(0, max_frame - requested_display_frame)
: std::max<int64_t>(0, requested_display_frame - 1);
required_ahead = std::min(required_ahead, available_ahead);
if (dir > 0) {
return (last_cached_index >= requested_display_frame + required_ahead);
}
return (last_cached_index <= requested_display_frame - required_ahead);
}
void VideoCacheThread::setSpeed(int new_speed)