cache: improved code flow

This commit is contained in:
itsmattkc
2021-09-23 00:16:05 -07:00
parent e101f3f4fe
commit 0b205ece9c
8 changed files with 55 additions and 95 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_->SetAutoCacheEnabled(parameter_tab_->GetSelectedPreviewAutoCache());
sequence_->SetVideoAutoCacheEnabled(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->GetAutoCacheEnabled())
old_autocache_(s->GetVideoAutoCacheEnabled())
{
}
@@ -189,7 +189,7 @@ void SequenceDialog::SequenceParamCommand::redo()
sequence_->SetAudioParams(new_audio_params_);
}
sequence_->SetLabel(new_name_);
sequence_->SetAutoCacheEnabled(new_autocache_);
sequence_->SetVideoAutoCacheEnabled(new_autocache_);
}
void SequenceDialog::SequenceParamCommand::undo()
@@ -201,7 +201,7 @@ void SequenceDialog::SequenceParamCommand::undo()
sequence_->SetAudioParams(old_audio_params_);
}
sequence_->SetLabel(old_name_);
sequence_->SetAutoCacheEnabled(old_autocache_);
sequence_->SetVideoAutoCacheEnabled(old_autocache_);
}
}
@@ -54,7 +54,7 @@ SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidg
preview_layout->addWidget(preview_resolution_label_, row, 2);
row++;
preview_layout->addWidget(new QLabel(tr("Quality:")), row, 0);
preview_format_field_ = new PixelFormatComboBox(false);
preview_format_field_ = new PixelFormatComboBox(true);
preview_layout->addWidget(preview_format_field_, row, 1, 1, 2);
row++;
preview_layout->addWidget(new QLabel(tr("Auto-Cache:")), row, 0);
@@ -68,7 +68,7 @@ SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidg
video_section_->SetVideoParams(vp);
preview_resolution_field_->SetDivider(vp.divider());
preview_format_field_->SetPixelFormat(vp.format());
preview_autocache_field_->setChecked(sequence->GetAutoCacheEnabled());
preview_autocache_field_->setChecked(sequence->GetVideoAutoCacheEnabled());
audio_sample_rate_field_->SetSampleRate(ap.sample_rate());
audio_channels_field_->SetChannelLayout(ap.channel_layout());
+9 -9
View File
@@ -31,7 +31,7 @@ const QString ViewerOutput::kVideoParamsInput = QStringLiteral("video_param_in")
const QString ViewerOutput::kAudioParamsInput = QStringLiteral("audio_param_in");
const QString ViewerOutput::kTextureInput = QStringLiteral("tex_in");
const QString ViewerOutput::kSamplesInput = QStringLiteral("samples_in");
const QString ViewerOutput::kAutoCacheInput = QStringLiteral("autocache_in");
const QString ViewerOutput::kVideoAutoCacheInput = QStringLiteral("autocache_in");
const uint64_t ViewerOutput::kVideoParamEditMask = VideoParamEdit::kWidthHeight | VideoParamEdit::kInterlacing | VideoParamEdit::kFrameRate | VideoParamEdit::kPixelAspect;
@@ -55,9 +55,9 @@ ViewerOutput::ViewerOutput(bool create_buffer_inputs, bool create_default_stream
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kSamplesInput, NodeValue::kSamples, InputFlags(kInputFlagNotKeyframable));
AddInput(kAutoCacheInput, NodeValue::kBoolean, true, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
IgnoreHashingFrom(kAutoCacheInput);
IgnoreInvalidationsFrom(kAutoCacheInput);
AddInput(kVideoAutoCacheInput, NodeValue::kBoolean, true, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
IgnoreHashingFrom(kVideoAutoCacheInput);
IgnoreInvalidationsFrom(kVideoAutoCacheInput);
}
if (create_default_streams) {
@@ -202,7 +202,7 @@ void ViewerOutput::set_default_parameters()
AudioParams::kInternalFormat
));
SetAutoCacheEnabled(Config::Current()["DefaultSequenceAutoCache"].toBool());
SetVideoAutoCacheEnabled(Config::Current()["DefaultSequenceAutoCache"].toBool());
}
void ViewerOutput::ShiftVideoCache(const rational &from, const rational &to)
@@ -294,8 +294,8 @@ void ViewerOutput::Retranslate()
SetInputName(kSamplesInput, tr("Samples"));
}
if (HasInputWithID(kAutoCacheInput)) {
SetInputName(kAutoCacheInput, tr("Auto-Cache"));
if (HasInputWithID(kVideoAutoCacheInput)) {
SetInputName(kVideoAutoCacheInput, tr("Auto-Cache Video"));
}
}
@@ -387,8 +387,8 @@ Node::ValueHint ViewerOutput::GetConnectedSampleValueHint()
void ViewerOutput::InputValueChangedEvent(const QString &input, int element)
{
if (input == kAutoCacheInput) {
emit AutoCacheChanged(GetAutoCacheEnabled());
if (input == kVideoAutoCacheInput) {
emit VideoAutoCacheChanged(GetVideoAutoCacheEnabled());
} else if (element == 0) {
if (input == kVideoParamsInput) {
+8 -8
View File
@@ -159,19 +159,19 @@ public:
void SetViewerVideoCacheEnabled(bool e) { video_cache_enabled_ = e; }
void SetViewerAudioCacheEnabled(bool e) { audio_cache_enabled_ = e; }
bool GetAutoCacheEnabled() const
bool GetVideoAutoCacheEnabled() const
{
if (HasInputWithID(kAutoCacheInput)) {
return GetStandardValue(kAutoCacheInput).toBool();
if (HasInputWithID(kVideoAutoCacheInput)) {
return GetStandardValue(kVideoAutoCacheInput).toBool();
} else {
return false;
}
}
void SetAutoCacheEnabled(bool e)
void SetVideoAutoCacheEnabled(bool e)
{
if (HasInputWithID(kAutoCacheInput)) {
return SetStandardValue(kAutoCacheInput, e);
if (HasInputWithID(kVideoAutoCacheInput)) {
return SetStandardValue(kVideoAutoCacheInput, e);
}
}
@@ -181,7 +181,7 @@ public:
static const QString kTextureInput;
static const QString kSamplesInput;
static const QString kAutoCacheInput;
static const QString kVideoAutoCacheInput;
static const uint64_t kVideoParamEditMask;
@@ -196,7 +196,7 @@ signals:
void InterlacingChanged(VideoParams::Interlacing mode);
void AutoCacheChanged(bool e);
void VideoAutoCacheChanged(bool e);
void VideoParamsChanged();
void AudioParamsChanged();
+23 -14
View File
@@ -14,7 +14,6 @@ namespace olive {
PreviewAutoCacher::PreviewAutoCacher() :
viewer_node_(nullptr),
paused_(false),
use_custom_range_(false),
single_frame_render_(nullptr)
{
@@ -44,7 +43,7 @@ RenderTicketPtr PreviewAutoCacher::GetSingleFrame(const rational &t, bool priori
// See if we have a hash, we may or may not retrieve one depending on the state of the video
// frame cache
QByteArray hash;
if (!paused_) {
if (viewer_node_->GetVideoAutoCacheEnabled()) {
hash = viewer_node_->video_frame_cache()->GetHash(t);
}
@@ -62,11 +61,6 @@ RenderTicketPtr PreviewAutoCacher::GetSingleFrame(const rational &t, bool priori
return sfr;
}
void PreviewAutoCacher::SetPaused(bool paused)
{
paused_ = paused;
}
QVector<PreviewAutoCacher::HashData> PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector<rational> &times)
{
QVector<HashData> hash_data(times.size());
@@ -150,9 +144,8 @@ void PreviewAutoCacher::HashesProcessed()
}
}
// HACK: When viewer is first set, there's nothing to requeue the range unless the user
// manually moves the playhead, so we ensure a requeue is done here.
if (!hash_iterator_.HasNext()) {
// RequeueFrames won't run if hash tasks isn't empty, so if it is, trigger it now
if (hash_tasks_.isEmpty()) {
delayed_requeue_timer_.stop();
delayed_requeue_timer_.start();
}
@@ -254,7 +247,7 @@ void PreviewAutoCacher::VideoRendered()
if (watcher->HasResult()) {
// Download frame in another thread
if (!hash.isEmpty() && VideoParams::FormatIsFloat(viewer_node_->GetVideoParams().format())) {
if (!hash.isEmpty()) {
FramePtr frame = watcher->Get().value<FramePtr>();
RenderTicketWatcher* w = new RenderTicketWatcher();
w->setProperty("job", QVariant::fromValue(last_update_time_));
@@ -576,7 +569,7 @@ void PreviewAutoCacher::TryRender()
watcher = RenderFrame(hash,
single_frame_render_->property("time").value<rational>(),
single_frame_render_->property("prioritize").toBool(),
paused_);
!viewer_node_->GetVideoAutoCacheEnabled());
video_immediate_passthroughs_[watcher].append(single_frame_render_);
}
@@ -670,8 +663,7 @@ void PreviewAutoCacher::RequeueFrames()
if (viewer_node_
&& viewer_node_->video_frame_cache()->HasInvalidatedRanges(viewer_node_->GetVideoLength())
&& hash_tasks_.isEmpty()
&& VideoParams::FormatIsFloat(viewer_node_->GetVideoParams().format())
&& (!paused_ || use_custom_range_)) {
&& (viewer_node_->GetVideoAutoCacheEnabled() || use_custom_range_)) {
TimeRange using_range;
if (use_custom_range_) {
@@ -702,6 +694,13 @@ void PreviewAutoCacher::ConformFinished()
}
}
void PreviewAutoCacher::VideoAutoCacheEnableChanged(bool e)
{
if (e) {
RequeueFrames();
}
}
void PreviewAutoCacher::ForceCacheRange(const TimeRange &range)
{
use_custom_range_ = true;
@@ -787,6 +786,11 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
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_->video_frame_cache(),
&PlaybackCache::Invalidated,
this,
@@ -837,6 +841,11 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
connect(graph, &NodeGraph::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
connect(graph, &NodeGraph::InputValueHintChanged, this, &PreviewAutoCacher::ValueHintChanged);
connect(viewer_node_,
&ViewerOutput::VideoAutoCacheChanged,
this,
&PreviewAutoCacher::VideoAutoCacheEnableChanged);
connect(viewer_node_->video_frame_cache(),
&PlaybackCache::Invalidated,
this,
+2 -19
View File
@@ -34,23 +34,6 @@ public:
*/
void SetViewerNode(ViewerOutput *viewer_node);
/**
* @brief Returns whether the auto-cache is currently paused or not
*/
bool IsPaused() const
{
return paused_;
}
/**
* @brief Sets whether the auto-cache is currently paused or not
* @param paused
*
* If TRUE, the cache queue is cleared (any frames currently being rendered will be processed as
* normal however). If FALSE, any uncached frames in the range will automatically be queued.
*/
void SetPaused(bool paused);
/**
* @brief Force a certain range to be cached
*
@@ -153,8 +136,6 @@ private:
ColorManager* copied_color_manager_;
QVector<Node*> created_nodes_;
bool paused_;
TimeRange cache_range_;
bool use_custom_range_;
@@ -237,6 +218,8 @@ private slots:
void ConformFinished();
void VideoAutoCacheEnableChanged(bool e);
};
}
+6 -34
View File
@@ -55,8 +55,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
color_menu_enabled_(true),
time_changed_from_timer_(false),
prequeuing_(false),
active_queue_jobs_(0),
cache_time_(rational::NaN)
active_queue_jobs_(0)
{
// Set up main layout
QVBoxLayout* layout = new QVBoxLayout(this);
@@ -168,7 +167,7 @@ void ViewerWidget::TimeChangedEvent(const rational &time)
}
// Send time to auto-cacher
UpdateAutoCacher();
auto_cacher_.SetPlayhead(time);
last_time_ = time;
}
@@ -179,7 +178,6 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n)
connect(n, &ViewerOutput::PixelAspectChanged, this, &ViewerWidget::SetViewerPixelAspect);
connect(n, &ViewerOutput::LengthChanged, this, &ViewerWidget::LengthChangedSlot);
connect(n, &ViewerOutput::InterlacingChanged, this, &ViewerWidget::InterlacingChangedSlot);
connect(n, &ViewerOutput::AutoCacheChanged, this, &ViewerWidget::SetAutoCacheEnabled);
connect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererVideoParameters);
connect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters);
connect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange);
@@ -190,8 +188,6 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n)
VideoParams vp = n->GetVideoParams();
SetAutoCacheEnabled(n->GetAutoCacheEnabled());
InterlacingChangedSlot(vp.interlacing());
ruler()->SetPlaybackCache(n->video_frame_cache());
@@ -228,7 +224,6 @@ void ViewerWidget::DisconnectNodeEvent(ViewerOutput *n)
disconnect(n, &ViewerOutput::PixelAspectChanged, this, &ViewerWidget::SetViewerPixelAspect);
disconnect(n, &ViewerOutput::LengthChanged, this, &ViewerWidget::LengthChangedSlot);
disconnect(n, &ViewerOutput::InterlacingChanged, this, &ViewerWidget::InterlacingChangedSlot);
disconnect(n, &ViewerOutput::AutoCacheChanged, this, &ViewerWidget::SetAutoCacheEnabled);
disconnect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererVideoParameters);
disconnect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters);
disconnect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange);
@@ -259,7 +254,6 @@ void ViewerWidget::DisconnectNodeEvent(ViewerOutput *n)
void ViewerWidget::ConnectedNodeChangeEvent(ViewerOutput *n)
{
auto_cacher_.SetViewerNode(n);
cache_time_ = rational::NaN;
}
void ViewerWidget::ScaleChangedEvent(const double &s)
@@ -344,19 +338,6 @@ void ViewerWidget::SetFullScreen(QScreen *screen)
windows_.insert(screen, vw);
}
void ViewerWidget::SetAutoCacheEnabled(bool e)
{
auto_cacher_.SetPaused(!e);
if (e) {
// Enable auto-cache
UpdateAutoCacher();
} else {
// Disable auto-cache
ClearAutoCacherQueue();
}
}
void ViewerWidget::CacheEntireSequence()
{
auto_cacher_.ForceCacheRange(TimeRange(0, GetConnectedNode()->GetVideoLength()));
@@ -417,19 +398,12 @@ void ViewerWidget::SetEmptyImage()
void ViewerWidget::UpdateAutoCacher()
{
rational time = GetTime();
if (GetConnectedNode() // Ensure valid node
&& cache_time_ != time) { // Ensure cache hasn't already been to this time
auto_cacher_.SetPlayhead(time);
cache_time_ = time;
}
auto_cacher_.SetPlayhead(GetTime());
}
void ViewerWidget::ClearAutoCacherQueue()
void ViewerWidget::ClearVideoAutoCacherQueue()
{
auto_cacher_.CancelVideoTasks();
cache_time_ = rational::NaN;
}
void ViewerWidget::StartAudioOutput()
@@ -521,7 +495,7 @@ void ViewerWidget::UpdateTextureFromNode()
nonqueue_watchers_.append(watcher);
// Clear queue because we want this frame more than any others
ClearAutoCacherQueue();
ClearVideoAutoCacherQueue();
watcher->SetTicket(GetFrame(time, true));
}
@@ -551,7 +525,7 @@ void ViewerWidget::PlayInternal(int speed, bool in_to_out_only)
foreach (ViewerWidget* viewer, instances_) {
if (viewer != this) {
viewer->PauseInternal();
viewer->ClearAutoCacherQueue();
viewer->ClearVideoAutoCacherQueue();
}
}
@@ -1089,8 +1063,6 @@ void ViewerWidget::Play()
void ViewerWidget::Pause()
{
PauseInternal();
UpdateAutoCacher();
}
void ViewerWidget::ShuttleLeft()
+1 -5
View File
@@ -107,8 +107,6 @@ public slots:
*/
void SetSignalCursorColorEnabled(bool e);
void SetAutoCacheEnabled(bool e);
void CacheEntireSequence();
void CacheSequenceInOut();
@@ -212,7 +210,7 @@ private:
void UpdateAutoCacher();
void ClearAutoCacherQueue();
void ClearVideoAutoCacherQueue();
QStackedWidget* stack_;
@@ -256,8 +254,6 @@ private:
int active_queue_jobs_;
rational cache_time_;
static QVector<ViewerWidget*> instances_;
private slots: