From f70ca4b877bdc1e299e6a27661fb2f121a9d0e78 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Tue, 1 Feb 2022 15:33:32 -0600 Subject: [PATCH] Break out of cache loop if playback speed changes during caching. Move getFrame() below pause code, to prevent accidental incrementing video_position. --- src/Qt/PlayerPrivate.cpp | 6 +++--- src/Qt/VideoCacheThread.cpp | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Qt/PlayerPrivate.cpp b/src/Qt/PlayerPrivate.cpp index 865868b0..ef0e11c7 100644 --- a/src/Qt/PlayerPrivate.cpp +++ b/src/Qt/PlayerPrivate.cpp @@ -71,9 +71,6 @@ namespace openshot const auto frame_duration = double_micro_sec(1000000.0 / reader->info.fps.ToDouble()); const auto max_sleep = frame_duration * 4; ///< Don't sleep longer than X times a frame duration - // Get the current video frame - frame = getFrame(); - // Pausing Code (if frame has not changed) // Also pause at end of timeline, and pause if 'playing' and // the pre-roll is not yet ready @@ -92,6 +89,9 @@ namespace openshot continue; } + // Get the current video frame + frame = getFrame(); + // Set the video frame on the video thread and render frame videoPlayback->frame = frame; videoPlayback->render.signal(); diff --git a/src/Qt/VideoCacheThread.cpp b/src/Qt/VideoCacheThread.cpp index b2288866..89f2afbb 100644 --- a/src/Qt/VideoCacheThread.cpp +++ b/src/Qt/VideoCacheThread.cpp @@ -79,6 +79,7 @@ namespace openshot while (!threadShouldExit() && is_playing) { // Calculate on-screen time for a single frame const auto frame_duration = double_micro_sec(1000000.0 / reader->info.fps.ToDouble()); + int current_speed = speed; // Calculate bytes per frame. If we have a reference openshot::Frame, use that instead (the preview // window can be smaller, can thus reduce the bytes per frame) @@ -141,6 +142,10 @@ namespace openshot break; } } + // Check if playback speed changed (if so, break out of cache loop) + if (current_speed != speed) { + break; + } } // Update current display frame