From 549427353d3f852096a17822d03dd81b83e5c7aa Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 27 Dec 2019 05:08:55 +1100 Subject: [PATCH] updates to video render backend to speed up single frame previews Allows single frame previews and improves communication with receiving viewer classes. --- app/render/backend/videorenderbackend.cpp | 48 +++++++++++++++-------- app/render/backend/videorenderbackend.h | 2 + 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/render/backend/videorenderbackend.cpp b/app/render/backend/videorenderbackend.cpp index 0a9181b7b..a735e328d 100644 --- a/app/render/backend/videorenderbackend.cpp +++ b/app/render/backend/videorenderbackend.cpp @@ -59,6 +59,11 @@ void VideoRenderBackend::InvalidateCache(const rational &start_range, const rati int64_t timestamp = Timecode::time_to_timestamp(start_range_adj, params_.time_base()); rational true_start = Timecode::timestamp_to_time(timestamp, params_.time_base()); + if (true_start == end_range_adj) { + // Ensure that a single frame is always rendered + end_range_adj += params_.time_base(); + } + for (rational r=true_start;r times_with_this_hash = frame_cache()->DeferredMapsWithHash(hash); - foreach (const rational& t, times_with_this_hash) { - EmitCachedFrameReady(t, texture); - } - } } - if (!export_mode_) { + if (export_mode_) { + QList times_with_this_hash = frame_cache()->DeferredMapsWithHash(hash); + foreach (const rational& t, times_with_this_hash) { + EmitCachedFrameReady(t, texture); + } + } else { if (texture.isNull()) { // No frame received, we set hash to an empty frame_cache()->RemoveHash(path.in(), hash); @@ -285,15 +288,11 @@ void VideoRenderBackend::ThreadCompletedFrame(NodeDependency path, QByteArray ha void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, QByteArray hash) { + // Set hash, but DON'T signal time because it's most likely this frame has been signalled in ThreadCompletedFrame() frame_cache()->SetHash(dep.in(), hash); - emit CachedTimeReady(dep.in()); // Emit for each frame that has this hash (some may have been added in ThreadSkippedFrame) - QList times_with_this_hash = frame_cache()->DeferredMapsWithHash(hash); - foreach (const rational& t, times_with_this_hash) { - frame_cache()->SetHash(t, hash); - emit CachedTimeReady(t); - } + DumpDeferredMappings(frame_cache()->DeferredMapsWithHash(hash), hash); } void VideoRenderBackend::ThreadSkippedFrame(NodeDependency dep, QByteArray hash) @@ -306,7 +305,12 @@ void VideoRenderBackend::ThreadSkippedFrame(NodeDependency dep, QByteArray hash) void VideoRenderBackend::ThreadHashAlreadyExists(NodeDependency dep, QByteArray hash) { - ThreadCompletedDownload(dep, hash); + // Emit for each frame that has this hash (some may have been added in ThreadSkippedFrame) + QList times_with_this_hash = frame_cache()->DeferredMapsWithHash(hash); + times_with_this_hash.append(dep.in()); + DumpDeferredMappings(times_with_this_hash, hash); + + //ThreadCompletedDownload(dep, hash); SetWorkerBusyState(static_cast(sender()), false); // Queue up a new frame for this worker @@ -317,3 +321,15 @@ bool VideoRenderBackend::TimeIsQueued(const TimeRange &time) { return cache_queue_.contains(time); } + +void VideoRenderBackend::DumpDeferredMappings(const QList& times_with_this_hash, const QByteArray& hash) +{ + foreach (const rational& t, times_with_this_hash) { + if (frame_cache()->TimeToHash(t) != hash) { + frame_cache()->SetHash(t, hash); + if (last_time_requested_ == t && !TimeIsQueued(TimeRange(t, t))) { + emit CachedTimeReady(t); + } + } + } +} diff --git a/app/render/backend/videorenderbackend.h b/app/render/backend/videorenderbackend.h index 7b9f8d7a3..e69841e90 100644 --- a/app/render/backend/videorenderbackend.h +++ b/app/render/backend/videorenderbackend.h @@ -108,6 +108,8 @@ signals: private: bool TimeIsQueued(const TimeRange &time); + void DumpDeferredMappings(const QList ×_with_this_hash, const QByteArray &hash); + VideoRenderingParams params_; QByteArray cache_frame_load_buffer_;