diff --git a/src/Qt/VideoCacheThread.cpp b/src/Qt/VideoCacheThread.cpp index 94257df2..597bc8cb 100644 --- a/src/Qt/VideoCacheThread.cpp +++ b/src/Qt/VideoCacheThread.cpp @@ -145,33 +145,9 @@ namespace openshot { const int64_t timeline_end = resolveTimelineEnd(); const int64_t clamped_new_position = clampToTimelineRange(new_position, timeline_end); - const bool past_timeline_end = (timeline_end > 0 && new_position > timeline_end); const int64_t current_requested = requested_display_frame.load(); const int64_t clamped_requested = clampToTimelineRange(current_requested, timeline_end); - // Out-of-range seeks past timeline end should not churn cache. - if (past_timeline_end) { - int64_t new_cached_count = cached_frame_count.load(); - if (CacheBase* cache = reader ? reader->GetCache() : nullptr) { - new_cached_count = cache->Count(); - } - const bool is_paused = (speed.load() == 0); - std::lock_guard guard(seek_state_mutex); - requested_display_frame.store(clamped_new_position); - cached_frame_count.store(new_cached_count); - preroll_on_next_fill.store(false); - clear_cache_on_next_fill.store(false); - userSeeked.store(false); - if (start_preroll) { - scrub_active.store(false); - } else if (is_paused) { - scrub_active.store(true); - } else { - scrub_active.store(false); - } - return; - } - bool should_mark_seek = false; bool should_preroll = false; int64_t new_cached_count = cached_frame_count.load(); @@ -409,9 +385,6 @@ namespace openshot CacheBase* cache) { const int64_t timeline_end = resolveTimelineEnd(); - if (timeline_end > 0 && playhead >= timeline_end) { - return false; - } int64_t cache_playhead = playhead; if (reader) { cache_playhead = clampToTimelineRange(playhead, timeline_end); diff --git a/tests/VideoCacheThread.cpp b/tests/VideoCacheThread.cpp index 2ec416e8..f0c2d80b 100644 --- a/tests/VideoCacheThread.cpp +++ b/tests/VideoCacheThread.cpp @@ -196,7 +196,7 @@ TEST_CASE("clearCacheIfPaused: clears only when paused and not in cache", "[Vide CHECK(cache.Contains(5)); } -TEST_CASE("clearCacheIfPaused: does not clear when paused slightly past timeline end", "[VideoCacheThread]") { +TEST_CASE("clearCacheIfPaused: clears when paused past timeline end and playhead frame is missing", "[VideoCacheThread]") { TestableVideoCacheThread thread; CacheMemory cache(/*max_bytes=*/100000000); @@ -208,13 +208,13 @@ TEST_CASE("clearCacheIfPaused: does not clear when paused slightly past timeline const int64_t end = timeline.info.video_length; REQUIRE(end > 1); - cache.Add(std::make_shared(end, 0, 0)); + cache.Add(std::make_shared(end - 1, 0, 0)); const int64_t initial_count = cache.Count(); + REQUIRE(initial_count > 0); const bool didClear = thread.clearCacheIfPaused(/*playhead=*/end + 12, /*paused=*/true, &cache); - CHECK(!didClear); - CHECK(cache.Count() == initial_count); - CHECK(cache.Contains(end)); + CHECK(didClear); + CHECK(cache.Count() == 0); } TEST_CASE("handleUserSeek: sets last_cached_index to playhead - dir", "[VideoCacheThread]") { @@ -475,7 +475,7 @@ TEST_CASE("Seek preview: paused out-of-range seek clamps to end and preserves ca CHECK(cache.Contains(end)); } -TEST_CASE("Seek commit: paused out-of-range seek past end does not enable cache rebuild", "[VideoCacheThread]") { +TEST_CASE("Seek commit: paused out-of-range seek past end enables cache rebuild when end is uncached", "[VideoCacheThread]") { TestableVideoCacheThread thread; CacheMemory cache(/*max_bytes=*/100000000); Timeline timeline(/*width=*/1280, /*height=*/720, /*fps=*/Fraction(24,1), @@ -486,18 +486,18 @@ TEST_CASE("Seek commit: paused out-of-range seek past end does not enable cache const int64_t end = timeline.info.video_length; REQUIRE(end > 1); - cache.Add(std::make_shared(end, 0, 0)); - cache.Add(std::make_shared(end - 1, 0, 0)); - thread.setLastCachedIndex(end - 1); + cache.Add(std::make_shared(1, 0, 0)); + cache.Add(std::make_shared(2, 0, 0)); + thread.setLastCachedIndex(2); thread.Seek(/*new_position=*/end + 24, /*start_preroll=*/true); CHECK(!thread.isScrubbing()); - CHECK(!thread.getUserSeekedFlag()); - CHECK(!thread.getPrerollOnNextFill()); + CHECK(thread.getUserSeekedFlag()); + CHECK(thread.getPrerollOnNextFill()); CHECK(thread.getRequestedDisplayFrame() == end); CHECK(thread.getLastCachedIndex() == end - 1); - CHECK(cache.Contains(end)); + CHECK(!cache.Contains(end)); } TEST_CASE("NotifyPlaybackPosition: ignored while scrubbing, applied after commit", "[VideoCacheThread]") {