moved more cache functions out of viewer

This commit is contained in:
itsmattkc
2022-05-16 20:33:59 -07:00
parent e73f01b527
commit 7084d0feb6
11 changed files with 114 additions and 144 deletions
+4 -4
View File
@@ -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_);
}
}
@@ -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());
+9
View File
@@ -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);
}
+9 -43
View File
@@ -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;
-44
View File
@@ -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_;
};
}
-1
View File
@@ -46,7 +46,6 @@ Footage::Footage(const QString &filename) :
cancelled_(nullptr)
{
SetCacheTextures(true);
SetViewerVideoCacheEnabled(false);
PrependInput(kLoopModeInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
+2 -1
View File
@@ -72,7 +72,8 @@ Project *PlaybackCache::GetProject() const
}
PlaybackCache::PlaybackCache(QObject *parent) :
QObject(parent)
QObject(parent),
enabled_(false)
{
uuid_ = QUuid::createUuid();
}
+13
View File
@@ -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_;
};
}
+72 -49
View File
@@ -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<AudioVisualWaveform>();
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<FrameHashCache>(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<ViewerOutput*>(copy_map_.value(viewer_node_));
copied_viewer_node_->SetViewerVideoCacheEnabled(false);
copied_viewer_node_->SetViewerAudioCacheEnabled(false);
copied_color_manager_ = static_cast<ColorManager*>(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()));
+3
View File
@@ -129,6 +129,9 @@ private:
void InsertIntoCopyMap(Node* node, Node* copy);
void ConnectToNodeCache(Node *node);
void DisconnectFromNodeCache(Node *node);
void UpdateGraphChangeValue();
void UpdateLastSyncedValue();
+1 -1
View File
@@ -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();
}