move cache saving to renderprocessor
In my testing, this doesn't seem to help performance whatsoever, but at least the code is cleaner.
This commit is contained in:
@@ -202,16 +202,8 @@ void PreviewAutoCacher::VideoRendered()
|
||||
// Assume that a "result" is a fully completed image and a non-result is a cancelled ticket
|
||||
if (watcher->HasResult()) {
|
||||
// Download frame in another thread
|
||||
if (FramePtr frame = watcher->Get().value<FramePtr>()) {
|
||||
RenderTicketWatcher* w = new RenderTicketWatcher();
|
||||
w->setProperty("job", QVariant::fromValue(last_update_time_));
|
||||
w->setProperty("frame", QVariant::fromValue(frame));
|
||||
video_download_tasks_.insert(w, it.value());
|
||||
connect(w, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::VideoDownloaded);
|
||||
w->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_node_->video_frame_cache(),
|
||||
frame,
|
||||
it.value(),
|
||||
RenderTicketPriority::kHigh));
|
||||
if (watcher->GetTicket()->property("cached").toBool()) {
|
||||
viewer_node_->video_frame_cache()->ValidateTime(it.value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,30 +227,6 @@ void PreviewAutoCacher::VideoRendered()
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::VideoDownloaded()
|
||||
{
|
||||
RenderTicketWatcher* watcher = static_cast<RenderTicketWatcher*>(sender());
|
||||
|
||||
// If the task list doesn't contain this watcher, presumably it was cleared as a result of a
|
||||
// viewer switch, so we'll completely ignore this watcher
|
||||
if (video_download_tasks_.contains(watcher)) {
|
||||
// Remove from task list
|
||||
rational time = video_download_tasks_.take(watcher);
|
||||
|
||||
// Assume that `true` is a completely successful frame save
|
||||
if (watcher->Get().toBool()) {
|
||||
viewer_node_->video_frame_cache()->ValidateTime(time);
|
||||
} else {
|
||||
qCritical() << "Failed to download video frame";
|
||||
}
|
||||
|
||||
// No need to call TryRender here because it would not have been held up by a download task
|
||||
// nor does the completion of this ticket automatically trigger another ticket
|
||||
}
|
||||
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::ProcessUpdateQueue()
|
||||
{
|
||||
// Iterate everything that happened to the graph and do the same thing on our end
|
||||
@@ -434,13 +402,6 @@ void PreviewAutoCacher::SetPlayhead(const rational &playhead)
|
||||
RequeueFrames();
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::WaitForVideoDownloadsToFinish()
|
||||
{
|
||||
for (auto it=video_download_tasks_.cbegin(); it!=video_download_tasks_.cend(); it++) {
|
||||
it.key()->WaitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CancelTasks(const T &task_list, bool and_wait)
|
||||
{
|
||||
@@ -563,7 +524,7 @@ void PreviewAutoCacher::TryRender()
|
||||
RenderTicketWatcher* render_task = video_tasks_.key(t);
|
||||
|
||||
// We want this hash, if we're not already rendering, start render now
|
||||
if (!render_task && !video_download_tasks_.key(t)) {
|
||||
if (!render_task) {
|
||||
// Don't render any hash more than once
|
||||
RenderFrame(t, RenderTicketPriority::kNormal, false);
|
||||
}
|
||||
@@ -724,11 +685,6 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
|
||||
CancelAudioTasks(true);
|
||||
}
|
||||
|
||||
// Handle video download tasks
|
||||
if (!video_download_tasks_.isEmpty()) {
|
||||
WaitForVideoDownloadsToFinish();
|
||||
}
|
||||
|
||||
// Clear iterators
|
||||
queued_frame_iterator_.reset();
|
||||
audio_iterator_.clear();
|
||||
|
||||
@@ -73,8 +73,6 @@ public:
|
||||
*/
|
||||
void SetPlayhead(const rational& playhead);
|
||||
|
||||
void WaitForVideoDownloadsToFinish();
|
||||
|
||||
/**
|
||||
* @brief Call cancel on all currently running video tasks
|
||||
*
|
||||
@@ -175,7 +173,6 @@ private:
|
||||
|
||||
QMap<RenderTicketWatcher*, TimeRange> audio_tasks_;
|
||||
QMap<RenderTicketWatcher*, rational> video_tasks_;
|
||||
QMap<RenderTicketWatcher*, rational> video_download_tasks_;
|
||||
QMap<RenderTicketWatcher*, QVector<RenderTicketPtr> > video_immediate_passthroughs_;
|
||||
|
||||
JobTime graph_changed_time_;
|
||||
@@ -216,11 +213,6 @@ private slots:
|
||||
*/
|
||||
void VideoRendered();
|
||||
|
||||
/**
|
||||
* @brief Handler for when we've saved a video frame to the cache
|
||||
*/
|
||||
void VideoDownloaded();
|
||||
|
||||
void NodeAdded(Node* node);
|
||||
|
||||
void NodeRemoved(Node* node);
|
||||
|
||||
@@ -121,6 +121,8 @@ RenderTicketPtr RenderManager::RenderFrame(ViewerOutput *viewer, ColorManager* c
|
||||
|
||||
if (cache) {
|
||||
ticket->setProperty("cache", cache->GetCacheDirectory());
|
||||
ticket->setProperty("cachetimebase", QVariant::fromValue(cache->GetTimebase()));
|
||||
ticket->setProperty("cacheuuid", QVariant::fromValue(cache->GetUuid()));
|
||||
}
|
||||
|
||||
AddTicket(ticket, priority);
|
||||
@@ -150,23 +152,6 @@ RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange
|
||||
return ticket;
|
||||
}
|
||||
|
||||
RenderTicketPtr RenderManager::SaveFrameToCache(FrameHashCache *cache, FramePtr frame, const rational &time, RenderTicketPriority priority)
|
||||
{
|
||||
// Create ticket
|
||||
RenderTicketPtr ticket = std::make_shared<RenderTicket>();
|
||||
|
||||
ticket->setProperty("cache", cache->GetCacheDirectory());
|
||||
ticket->setProperty("frame", QVariant::fromValue(frame));
|
||||
ticket->setProperty("time", QVariant::fromValue(time));
|
||||
ticket->setProperty("timebase", QVariant::fromValue(cache->GetTimebase()));
|
||||
ticket->setProperty("uuid", QVariant::fromValue(cache->GetUuid()));
|
||||
ticket->setProperty("type", kTypeVideoDownload);
|
||||
|
||||
AddTicket(ticket, priority);
|
||||
|
||||
return ticket;
|
||||
}
|
||||
|
||||
void RenderManager::RunTicket(RenderTicketPtr ticket) const
|
||||
{
|
||||
// Setup the ticket for ::Process
|
||||
|
||||
@@ -92,14 +92,11 @@ public:
|
||||
RenderTicketPtr RenderAudio(ViewerOutput* viewer, const TimeRange& r, const AudioParams& params, RenderMode::Mode mode, bool generate_waveforms, RenderTicketPriority priority = RenderTicketPriority::kNormal);
|
||||
RenderTicketPtr RenderAudio(ViewerOutput *viewer, const TimeRange& r, RenderMode::Mode mode, bool generate_waveforms, RenderTicketPriority priority = RenderTicketPriority::kNormal);
|
||||
|
||||
RenderTicketPtr SaveFrameToCache(FrameHashCache* cache, FramePtr frame, const rational &time, RenderTicketPriority priority = RenderTicketPriority::kNormal);
|
||||
|
||||
virtual void RunTicket(RenderTicketPtr ticket) const override;
|
||||
|
||||
enum TicketType {
|
||||
kTypeVideo,
|
||||
kTypeAudio,
|
||||
kTypeVideoDownload
|
||||
kTypeAudio
|
||||
};
|
||||
|
||||
Backend backend() const
|
||||
|
||||
@@ -182,6 +182,14 @@ void RenderProcessor::Run()
|
||||
// Convert to CPU frame
|
||||
FramePtr frame = GenerateFrame(texture, time);
|
||||
|
||||
QString cache = ticket_->property("cache").toString();
|
||||
if (!cache.isEmpty()) {
|
||||
rational timebase = ticket_->property("cachetimebase").value<rational>();
|
||||
QUuid uuid = ticket_->property("cacheuuid").value<QUuid>();
|
||||
bool cache_result = FrameHashCache::SaveCacheFrame(cache, uuid, time, timebase, frame);
|
||||
ticket_->setProperty("cached", cache_result);
|
||||
}
|
||||
|
||||
ticket_->Finish(QVariant::fromValue(frame));
|
||||
}
|
||||
break;
|
||||
@@ -215,17 +223,6 @@ void RenderProcessor::Run()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RenderManager::kTypeVideoDownload:
|
||||
{
|
||||
QString cache = ticket_->property("cache").toString();
|
||||
FramePtr frame = ticket_->property("frame").value<FramePtr>();
|
||||
rational time = ticket_->property("time").value<rational>();
|
||||
rational timebase = ticket_->property("timebase").value<rational>();
|
||||
QUuid uuid = ticket_->property("uuid").value<QUuid>();
|
||||
|
||||
ticket_->Finish(FrameHashCache::SaveCacheFrame(cache, uuid, time, timebase, frame));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Fail
|
||||
ticket_->Finish();
|
||||
|
||||
@@ -241,12 +241,12 @@ bool RenderTask::Render(ColorManager* manager,
|
||||
|
||||
bool RenderTask::DownloadFrame(QThread *thread, FramePtr frame, const rational &time)
|
||||
{
|
||||
RenderTicketWatcher* watcher = new RenderTicketWatcher();
|
||||
PrepareWatcher(watcher, thread);
|
||||
//RenderTicketWatcher* watcher = new RenderTicketWatcher();
|
||||
//PrepareWatcher(watcher, thread);
|
||||
|
||||
IncrementRunningTickets();
|
||||
//IncrementRunningTickets();
|
||||
|
||||
watcher->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_->video_frame_cache(), frame, time));
|
||||
//watcher->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_->video_frame_cache(), frame, time));
|
||||
|
||||
// NOTE: Doesn't reflect the actual return result of SaveFrameToCache
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user