From 7084d0feb65b65ff92e51610a47acae92c5f0a5f Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon, 16 May 2022 20:33:59 -0700 Subject: [PATCH] moved more cache functions out of viewer --- app/dialog/sequence/sequence.cpp | 8 +- .../sequence/sequencedialogparametertab.cpp | 2 +- app/node/node.cpp | 9 ++ app/node/output/viewer/viewer.cpp | 52 ++------ app/node/output/viewer/viewer.h | 44 ------- app/node/project/footage/footage.cpp | 1 - app/render/playbackcache.cpp | 3 +- app/render/playbackcache.h | 13 ++ app/render/previewautocacher.cpp | 121 +++++++++++------- app/render/previewautocacher.h | 3 + app/widget/viewer/viewer.cpp | 2 +- 11 files changed, 114 insertions(+), 144 deletions(-) diff --git a/app/dialog/sequence/sequence.cpp b/app/dialog/sequence/sequence.cpp index 954cb9502..5e8d08e8e 100644 --- a/app/dialog/sequence/sequence.cpp +++ b/app/dialog/sequence/sequence.cpp @@ -136,7 +136,7 @@ void SequenceDialog::accept() sequence_->SetVideoParams(video_params); sequence_->SetAudioParams(audio_params); sequence_->SetLabel(name_field_->text()); - sequence_->SetVideoAutoCacheEnabled(parameter_tab_->GetSelectedPreviewAutoCache()); + sequence_->video_frame_cache()->SetEnabled(parameter_tab_->GetSelectedPreviewAutoCache()); } QDialog::accept(); @@ -171,7 +171,7 @@ SequenceDialog::SequenceParamCommand::SequenceParamCommand(Sequence* s, old_video_params_(s->GetVideoParams()), old_audio_params_(s->GetAudioParams()), old_name_(s->GetLabel()), - old_autocache_(s->GetVideoAutoCacheEnabled()) + old_autocache_(s->video_frame_cache()->IsEnabled()) { } @@ -189,7 +189,7 @@ void SequenceDialog::SequenceParamCommand::redo() sequence_->SetAudioParams(new_audio_params_); } sequence_->SetLabel(new_name_); - sequence_->SetVideoAutoCacheEnabled(new_autocache_); + sequence_->video_frame_cache()->SetEnabled(new_autocache_); } void SequenceDialog::SequenceParamCommand::undo() @@ -201,7 +201,7 @@ void SequenceDialog::SequenceParamCommand::undo() sequence_->SetAudioParams(old_audio_params_); } sequence_->SetLabel(old_name_); - sequence_->SetVideoAutoCacheEnabled(old_autocache_); + sequence_->video_frame_cache()->SetEnabled(old_autocache_); } } diff --git a/app/dialog/sequence/sequencedialogparametertab.cpp b/app/dialog/sequence/sequencedialogparametertab.cpp index 00f89e002..73eff0f1e 100644 --- a/app/dialog/sequence/sequencedialogparametertab.cpp +++ b/app/dialog/sequence/sequencedialogparametertab.cpp @@ -89,7 +89,7 @@ SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidg interlacing_combo_->SetInterlaceMode(vp.interlacing()); preview_resolution_field_->SetDivider(vp.divider()); preview_format_field_->SetPixelFormat(vp.format()); - preview_autocache_field_->setChecked(sequence->GetVideoAutoCacheEnabled()); + preview_autocache_field_->setChecked(sequence->video_frame_cache()->IsEnabled()); audio_sample_rate_field_->SetSampleRate(ap.sample_rate()); audio_channels_field_->SetChannelLayout(ap.channel_layout()); diff --git a/app/node/node.cpp b/app/node/node.cpp index 2350025d5..143f1e9ee 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -932,6 +932,15 @@ void Node::InvalidateCache(const TimeRange &range, const QString &from, int elem Q_UNUSED(from) Q_UNUSED(element) + if (range.in() != range.out()) { + if (video_cache_->IsEnabled()) { + video_frame_cache()->Invalidate(range); + } + if (audio_cache_->IsEnabled()) { + audio_playback_cache()->Invalidate(range); + } + } + SendInvalidateCache(range, options); } diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index f90b50298..bdf583f1b 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -31,17 +31,13 @@ const QString ViewerOutput::kAudioParamsInput = QStringLiteral("audio_param_in") const QString ViewerOutput::kSubtitleParamsInput = QStringLiteral("subtitle_param_in"); const QString ViewerOutput::kTextureInput = QStringLiteral("tex_in"); const QString ViewerOutput::kSamplesInput = QStringLiteral("samples_in"); -const QString ViewerOutput::kVideoAutoCacheInput = QStringLiteral("video_autocache_in"); -const QString ViewerOutput::kAudioAutoCacheInput = QStringLiteral("audio_autocache_in"); #define super Node ViewerOutput::ViewerOutput(bool create_buffer_inputs, bool create_default_streams) : last_length_(0), video_length_(0), - audio_length_(0), - video_cache_enabled_(true), - audio_cache_enabled_(true) + audio_length_(0) { AddInput(kVideoParamsInput, NodeValue::kVideoParams, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable | kInputFlagArray | kInputFlagHidden)); @@ -52,12 +48,6 @@ ViewerOutput::ViewerOutput(bool create_buffer_inputs, bool create_default_stream if (create_buffer_inputs) { AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable)); AddInput(kSamplesInput, NodeValue::kSamples, InputFlags(kInputFlagNotKeyframable)); - - AddInput(kVideoAutoCacheInput, NodeValue::kBoolean, false, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable)); - IgnoreInvalidationsFrom(kVideoAutoCacheInput); - - AddInput(kAudioAutoCacheInput, NodeValue::kBoolean, false, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable)); - IgnoreInvalidationsFrom(kAudioAutoCacheInput); } if (create_default_streams) { @@ -224,27 +214,13 @@ void ViewerOutput::set_default_parameters() AudioParams::kInternalFormat )); - SetVideoAutoCacheEnabled(OLIVE_CONFIG("DefaultSequenceAutoCache").toBool()); + video_frame_cache()->SetEnabled(OLIVE_CONFIG("DefaultSequenceAutoCache").toBool()); } void ViewerOutput::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options) { Q_UNUSED(element) - if ((video_cache_enabled_ && (from == kTextureInput || from == kVideoParamsInput)) - || (audio_cache_enabled_ && (from == kSamplesInput || from == kAudioParamsInput))) { - TimeRange invalidated_range(qMax(rational(0), range.in()), - qMin(GetLength(), range.out())); - - if (invalidated_range.in() != invalidated_range.out()) { - if (from == kTextureInput || from == kVideoParamsInput) { - video_frame_cache()->Invalidate(invalidated_range); - } else { - audio_playback_cache()->Invalidate(invalidated_range); - } - } - } - VerifyLength(); super::InvalidateCache(range, from, element, options); @@ -302,14 +278,6 @@ void ViewerOutput::Retranslate() if (HasInputWithID(kSamplesInput)) { SetInputName(kSamplesInput, tr("Samples")); } - - if (HasInputWithID(kVideoAutoCacheInput)) { - SetInputName(kVideoAutoCacheInput, tr("Auto-Cache Video")); - } - - if (HasInputWithID(kAudioAutoCacheInput)) { - SetInputName(kAudioAutoCacheInput, tr("Auto-Cache Audio")); - } } void ViewerOutput::VerifyLength() @@ -400,11 +368,7 @@ Node::ValueHint ViewerOutput::GetConnectedSampleValueHint() void ViewerOutput::InputValueChangedEvent(const QString &input, int element) { - if (input == kVideoAutoCacheInput) { - emit VideoAutoCacheChanged(GetVideoAutoCacheEnabled()); - } else if (input == kAudioAutoCacheInput) { - emit AudioAutoCacheChanged(GetAudioAutoCacheEnabled()); - } else if (element == 0) { + if (element == 0) { if (input == kVideoParamsInput) { VideoParams new_video_params = GetVideoParams(); @@ -427,9 +391,10 @@ void ViewerOutput::InputValueChangedEvent(const QString &input, int element) } if (frame_rate_changed) { - if (video_cache_enabled_) { + // FIXME: Will need to find a better way to update this soon + //if (video_frame_cache()->IsEnabled()) { video_frame_cache()->SetTimebase(new_video_params.frame_rate_as_time_base()); - } + //} emit FrameRateChanged(new_video_params.frame_rate()); } @@ -449,9 +414,10 @@ void ViewerOutput::InputValueChangedEvent(const QString &input, int element) emit AudioParamsChanged(); - if (audio_cache_enabled_) { + // FIXME: Will need to find a better way to update this soon + //if (audio_playback_cache()->IsEnabled()) { audio_playback_cache()->SetParameters(GetAudioParams()); - } + //} cached_audio_params_ = new_audio_params; diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index 43b4decc4..b0ba3ec8c 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -163,41 +163,6 @@ public: virtual ValueHint GetConnectedSampleValueHint(); - void SetViewerVideoCacheEnabled(bool e) { video_cache_enabled_ = e; } - void SetViewerAudioCacheEnabled(bool e) { audio_cache_enabled_ = e; } - - bool GetVideoAutoCacheEnabled() const - { - if (HasInputWithID(kVideoAutoCacheInput)) { - return GetStandardValue(kVideoAutoCacheInput).toBool(); - } else { - return false; - } - } - - void SetVideoAutoCacheEnabled(bool e) - { - if (HasInputWithID(kVideoAutoCacheInput)) { - return SetStandardValue(kVideoAutoCacheInput, e); - } - } - - bool GetAudioAutoCacheEnabled() const - { - if (HasInputWithID(kAudioAutoCacheInput)) { - return GetStandardValue(kAudioAutoCacheInput).toBool(); - } else { - return false; - } - } - - void SetAudioAutoCacheEnabled(bool e) - { - if (HasInputWithID(kAudioAutoCacheInput)) { - return SetStandardValue(kAudioAutoCacheInput, e); - } - } - static const QString kVideoParamsInput; static const QString kAudioParamsInput; static const QString kSubtitleParamsInput; @@ -205,9 +170,6 @@ public: static const QString kTextureInput; static const QString kSamplesInput; - static const QString kVideoAutoCacheInput; - static const QString kAudioAutoCacheInput; - signals: void FrameRateChanged(const rational&); @@ -219,9 +181,6 @@ signals: void InterlacingChanged(VideoParams::Interlacing mode); - void VideoAutoCacheChanged(bool e); - void AudioAutoCacheChanged(bool e); - void VideoParamsChanged(); void AudioParamsChanged(); @@ -254,9 +213,6 @@ private: TimelinePoints *timeline_points_; - bool video_cache_enabled_; - bool audio_cache_enabled_; - }; } diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index 72f37dab2..2feda5725 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -46,7 +46,6 @@ Footage::Footage(const QString &filename) : cancelled_(nullptr) { SetCacheTextures(true); - SetViewerVideoCacheEnabled(false); PrependInput(kLoopModeInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable)); diff --git a/app/render/playbackcache.cpp b/app/render/playbackcache.cpp index 0aec6bcf5..d12325c75 100644 --- a/app/render/playbackcache.cpp +++ b/app/render/playbackcache.cpp @@ -72,7 +72,8 @@ Project *PlaybackCache::GetProject() const } PlaybackCache::PlaybackCache(QObject *parent) : - QObject(parent) + QObject(parent), + enabled_(false) { uuid_ = QUuid::createUuid(); } diff --git a/app/render/playbackcache.h b/app/render/playbackcache.h index 26f18a5e4..b10b48686 100644 --- a/app/render/playbackcache.h +++ b/app/render/playbackcache.h @@ -42,6 +42,15 @@ public: const QUuid &GetUuid() const { return uuid_; } void SetUuid(const QUuid &u) { uuid_ = u; } + bool IsEnabled() const { return enabled_; } + void SetEnabled(bool e) + { + if (enabled_ != e) { + enabled_ = e; + emit EnabledChanged(e); + } + } + TimeRangeList GetInvalidatedRanges(TimeRange intersecting); TimeRangeList GetInvalidatedRanges(const rational &length) { @@ -70,6 +79,8 @@ signals: void Validated(const olive::TimeRange& r); + void EnabledChanged(bool e); + protected: void Validate(const TimeRange& r, bool signal = true); @@ -82,6 +93,8 @@ private: QUuid uuid_; + bool enabled_; + }; } diff --git a/app/render/previewautocacher.cpp b/app/render/previewautocacher.cpp index 123b2056c..f697a6aca 100644 --- a/app/render/previewautocacher.cpp +++ b/app/render/previewautocacher.cpp @@ -91,7 +91,7 @@ void PreviewAutoCacher::VideoInvalidated(const TimeRange &range) CancelVideoTasks(); // If auto-cache is enabled and a slider is not being dragged, queue up to hash these frames - if (viewer_node_->GetVideoAutoCacheEnabled() && !NodeInputDragger::IsInputBeingDragged()) { + if (viewer_node_->video_frame_cache()->IsEnabled() && !NodeInputDragger::IsInputBeingDragged()) { StartCachingVideoRange(range); } } @@ -103,7 +103,7 @@ void PreviewAutoCacher::AudioInvalidated(const TimeRange &range) // ClearAudioQueue(); // If we're auto-caching audio or require realtime waveforms, we'll have to render this - if (viewer_node_->GetAudioAutoCacheEnabled() || kRealTimeWaveformsEnabled) { + if (viewer_node_->audio_playback_cache()->IsEnabled() || kRealTimeWaveformsEnabled) { StartCachingAudioRange(range); } } @@ -127,7 +127,7 @@ void PreviewAutoCacher::AudioRendered() AudioVisualWaveform waveform = watcher->GetTicket()->property("waveform").value(); - if (viewer_node_->GetAudioAutoCacheEnabled()) { + if (viewer_node_->audio_playback_cache()->IsEnabled()) { // WritePCM is tolerant to its buffer being null, it will just write silence instead viewer_node_->audio_playback_cache()->WritePCM(range, valid_ranges, @@ -202,7 +202,9 @@ void PreviewAutoCacher::VideoRendered() if (watcher->HasResult()) { // Download frame in another thread if (watcher->GetTicket()->property("cached").toBool()) { - viewer_node_->video_frame_cache()->ValidateTime(it.value()); + if (FrameHashCache *cache = Node::ValueToPtr(watcher->property("cache"))) { + cache->ValidateTime(it.value()); + } } } @@ -283,6 +285,9 @@ void PreviewAutoCacher::RemoveNode(Node *node) // Find our copy and remove it Node* copy = copy_map_.take(node); + // Disconnect from node's caches + DisconnectFromNodeCache(node); + // Remove from created list created_nodes_.removeOne(copy); @@ -340,6 +345,61 @@ void PreviewAutoCacher::InsertIntoCopyMap(Node *node, Node *copy) // Copy parameters Node::CopyInputs(node, copy, false); + + // Connect to node's cache + ConnectToNodeCache(node); +} + +void PreviewAutoCacher::ConnectToNodeCache(Node *node) +{ + // TEMP: Retain existing behavior until more work is done + if (node == viewer_node_) { + connect(node->video_frame_cache(), + &PlaybackCache::EnabledChanged, + this, + &PreviewAutoCacher::VideoAutoCacheEnableChanged); + + connect(node->audio_playback_cache(), + &PlaybackCache::EnabledChanged, + this, + &PreviewAutoCacher::AudioAutoCacheEnableChanged); + + connect(node->video_frame_cache(), + &PlaybackCache::Invalidated, + this, + &PreviewAutoCacher::VideoInvalidated); + + connect(node->audio_playback_cache(), + &PlaybackCache::Invalidated, + this, + &PreviewAutoCacher::AudioInvalidated); + } +} + +void PreviewAutoCacher::DisconnectFromNodeCache(Node *node) +{ + // TEMP: Retain existing behavior until more work is done + if (node == viewer_node_) { + disconnect(node->video_frame_cache(), + &PlaybackCache::EnabledChanged, + this, + &PreviewAutoCacher::VideoAutoCacheEnableChanged); + + disconnect(node->audio_playback_cache(), + &PlaybackCache::EnabledChanged, + this, + &PreviewAutoCacher::AudioAutoCacheEnableChanged); + + disconnect(node->video_frame_cache(), + &PlaybackCache::Invalidated, + this, + &PreviewAutoCacher::VideoInvalidated); + + disconnect(node->audio_playback_cache(), + &PlaybackCache::Invalidated, + this, + &PreviewAutoCacher::AudioInvalidated); + } } void PreviewAutoCacher::UpdateGraphChangeValue() @@ -525,7 +585,7 @@ void PreviewAutoCacher::TryRender() // We want this hash, if we're not already rendering, start render now if (!render_task) { // Don't render any hash more than once - RenderFrame(t, RenderTicketPriority::kNormal, copied_viewer_node_->video_frame_cache()); + RenderFrame(t, RenderTicketPriority::kNormal, viewer_node_->video_frame_cache()); } emit SignalCacheProxyTaskProgress(double(queued_frame_iterator_.frame_index()) / double(queued_frame_iterator_.size())); @@ -555,6 +615,7 @@ RenderTicketWatcher* PreviewAutoCacher::RenderFrame(Node *node, const rational& { RenderTicketWatcher* watcher = new RenderTicketWatcher(); watcher->setProperty("job", QVariant::fromValue(last_update_time_)); + watcher->setProperty("cache", Node::PtrToValue(cache)); connect(watcher, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::VideoRendered); video_tasks_.insert(watcher, time); watcher->SetTicket(RenderManager::instance()->RenderFrame(node, @@ -586,7 +647,7 @@ void PreviewAutoCacher::RequeueFrames() delayed_requeue_timer_.stop(); if (viewer_node_ - && (viewer_node_->GetVideoAutoCacheEnabled() || use_custom_range_) + && (viewer_node_->video_frame_cache()->IsEnabled() || use_custom_range_) && viewer_node_->video_frame_cache()->HasInvalidatedRanges(viewer_node_->GetVideoLength()) && !IsRenderingCustomRange()) { TimeRange using_range = use_custom_range_ ? custom_autocache_range_ : cache_range_; @@ -703,6 +764,11 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node) // Not interested in audio conforming anymore audio_needing_conform_.clear(); + // Disconnect from all node cache's + for (auto it=copy_map_.cbegin(); it!=copy_map_.cend(); it++) { + DisconnectFromNodeCache(it.key()); + } + // Delete all of our copied nodes qDeleteAll(created_nodes_); created_nodes_.clear(); @@ -721,27 +787,6 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node) disconnect(graph, &NodeGraph::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved); disconnect(graph, &NodeGraph::ValueChanged, this, &PreviewAutoCacher::ValueChanged); disconnect(graph, &NodeGraph::InputValueHintChanged, this, &PreviewAutoCacher::ValueHintChanged); - - // Disconnect signal (will be a no-op if the signal was never connected) - disconnect(viewer_node_, - &ViewerOutput::VideoAutoCacheChanged, - this, - &PreviewAutoCacher::VideoAutoCacheEnableChanged); - - disconnect(viewer_node_, - &ViewerOutput::AudioAutoCacheChanged, - this, - &PreviewAutoCacher::AudioAutoCacheEnableChanged); - - disconnect(viewer_node_->video_frame_cache(), - &PlaybackCache::Invalidated, - this, - &PreviewAutoCacher::VideoInvalidated); - - disconnect(viewer_node_->audio_playback_cache(), - &PlaybackCache::Invalidated, - this, - &PreviewAutoCacher::AudioInvalidated); } viewer_node_ = viewer_node; @@ -760,8 +805,6 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node) // Find copied viewer node copied_viewer_node_ = static_cast(copy_map_.value(viewer_node_)); - copied_viewer_node_->SetViewerVideoCacheEnabled(false); - copied_viewer_node_->SetViewerAudioCacheEnabled(false); copied_color_manager_ = static_cast(copy_map_.value(viewer_node_->project()->color_manager())); // Add all connections @@ -783,26 +826,6 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node) connect(graph, &NodeGraph::ValueChanged, this, &PreviewAutoCacher::ValueChanged, Qt::DirectConnection); connect(graph, &NodeGraph::InputValueHintChanged, this, &PreviewAutoCacher::ValueHintChanged, Qt::DirectConnection); - connect(viewer_node_, - &ViewerOutput::VideoAutoCacheChanged, - this, - &PreviewAutoCacher::VideoAutoCacheEnableChanged); - - connect(viewer_node_, - &ViewerOutput::AudioAutoCacheChanged, - this, - &PreviewAutoCacher::AudioAutoCacheEnableChanged); - - connect(viewer_node_->video_frame_cache(), - &PlaybackCache::Invalidated, - this, - &PreviewAutoCacher::VideoInvalidated); - - connect(viewer_node_->audio_playback_cache(), - &PlaybackCache::Invalidated, - this, - &PreviewAutoCacher::AudioInvalidated); - // Copy invalidated ranges and start rendering if necessary VideoInvalidatedList(viewer_node_->video_frame_cache()->GetInvalidatedRanges(viewer_node_->GetVideoLength())); AudioInvalidatedList(viewer_node_->audio_playback_cache()->GetInvalidatedRanges(viewer_node_->GetAudioLength())); diff --git a/app/render/previewautocacher.h b/app/render/previewautocacher.h index 440b165bb..4c20a72d6 100644 --- a/app/render/previewautocacher.h +++ b/app/render/previewautocacher.h @@ -129,6 +129,9 @@ private: void InsertIntoCopyMap(Node* node, Node* copy); + void ConnectToNodeCache(Node *node); + void DisconnectFromNodeCache(Node *node); + void UpdateGraphChangeValue(); void UpdateLastSyncedValue(); diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index ad37fb118..a32c5df02 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -685,7 +685,7 @@ void ViewerWidget::UpdateTextureFromNode() nonqueue_watchers_.append(watcher); // Clear queue because we want this frame more than any others - if (!GetConnectedNode()->GetVideoAutoCacheEnabled() && !auto_cacher_.IsRenderingCustomRange()) { + if (!GetConnectedNode()->video_frame_cache()->IsEnabled() && !auto_cacher_.IsRenderingCustomRange()) { ClearVideoAutoCacherQueue(); }