remove hashtraverser

This commit is contained in:
itsmattkc
2022-05-09 18:22:32 -07:00
parent 0f99d8a662
commit 0538c01f45
15 changed files with 42 additions and 542 deletions
+15 -127
View File
@@ -93,40 +93,6 @@ RenderTicketPtr PreviewAutoCacher::GetRangeOfAudio(TimeRange range, bool priorit
return RenderAudio(range, false, prioritize);
}
QVector<PreviewAutoCacher::HashData> PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector<rational> &times)
{
QVector<HashData> hash_data(times.size());
QVector<QByteArray> existing_hashes;
for (int i=0; i<times.size(); i++) {
const rational &time = times.at(i);
// See if hash already exists in disk cache
QByteArray hash = RenderManager::Hash(viewer->GetConnectedTextureOutput(),
viewer->GetConnectedTextureValueHint(),
viewer->GetVideoParams(),
time);
// Check memory list since disk checking is slow
bool hash_exists = existing_hashes.contains(hash);
if (!hash_exists) {
// FIXME: Using CachePathName here is NOT thread safe and should be replaced
hash_exists = QFileInfo::exists(cache->CachePathName(hash));
if (hash_exists) {
existing_hashes.push_back(hash);
}
}
// Set hash in FrameHashCache's thread rather than in ours to prevent race conditions
hash_data[i] = {time, hash, hash_exists};
}
return hash_data;
}
void PreviewAutoCacher::VideoInvalidated(const TimeRange &range)
{
// Stop any current render tasks because a) they might be out of date now anyway, and b) we
@@ -151,39 +117,6 @@ void PreviewAutoCacher::AudioInvalidated(const TimeRange &range)
}
}
void PreviewAutoCacher::HashesProcessed()
{
// Receive watcher
QFutureWatcher< QVector<HashData> >* watcher = static_cast<QFutureWatcher<QVector<HashData> >*>(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 (hash_tasks_.contains(watcher)) {
// Remove task from hash task list
hash_tasks_.removeOne(watcher);
// Set all hashes we received that are still current
JobTime job_time = watcher->property("job").value<JobTime>();
auto hashes = watcher->result();
foreach (auto hash, hashes) {
if (video_job_tracker_.isCurrent(hash.time, job_time)) {
viewer_node_->video_frame_cache()->SetHash(hash.time, hash.hash, hash.exists);
}
}
// 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();
}
// Continue rendering
TryRender();
}
delete watcher;
}
void PreviewAutoCacher::AudioRendered()
{
// Receive watcher
@@ -271,24 +204,23 @@ void PreviewAutoCacher::VideoRendered()
// 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_tasks_.contains(watcher)) {
if (video_tasks_.remove(watcher)) {
// Assume that a "result" is a fully completed image and a non-result is a cancelled ticket
QByteArray hash = video_tasks_.take(watcher);
if (watcher->HasResult()) {
qDebug() << "FIXME: oops no frame downloading";
/*
// Download frame in another thread
if (!hash.isEmpty()) {
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, hash);
connect(w, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::VideoDownloaded);
w->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_node_->video_frame_cache(),
frame,
hash,
true));
}
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, hash);
connect(w, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::VideoDownloaded);
w->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_node_->video_frame_cache(),
frame,
true));
*/
}
// Continue rendering
@@ -508,13 +440,6 @@ void PreviewAutoCacher::SetPlayhead(const rational &playhead)
RequeueFrames();
}
void PreviewAutoCacher::WaitForHashesToFinish()
{
for (auto it=hash_tasks_.cbegin(); it!=hash_tasks_.cend(); it++) {
(*it)->waitForFinished();
}
}
void PreviewAutoCacher::WaitForVideoDownloadsToFinish()
{
for (auto it=video_download_tasks_.cbegin(); it!=video_download_tasks_.cend(); it++) {
@@ -598,8 +523,7 @@ void PreviewAutoCacher::TryRender()
// Check if we have jobs running in other threads that shouldn't be interrupted right now
// NOTE: We don't check for downloads because, while they run in another thread, they don't
// require any access to the graph and therefore don't risk race conditions.
if (!hash_tasks_.isEmpty()
|| !audio_tasks_.isEmpty()
if (!audio_tasks_.isEmpty()
|| !video_tasks_.isEmpty()) {
return;
}
@@ -649,32 +573,6 @@ void PreviewAutoCacher::TryRender()
// Ensure we are running tasks if we have any
const int max_tasks = RenderManager::GetNumberOfIdealConcurrentJobs();
// Handle hash tasks
while (hash_tasks_.size() < max_tasks && hash_iterator_.HasNext()) {
// Magic number: dunno what the best number for this is yet
static const int kMaxFrames = 1000;
QVector<rational> times(kMaxFrames);
for (int i=0; i<kMaxFrames; i++) {
rational r;
if (hash_iterator_.GetNext(&r)) {
times[i] = r;
} else {
times.resize(i);
break;
}
}
QFutureWatcher< QVector<HashData> >* watcher = new QFutureWatcher< QVector<HashData> >();
watcher->setProperty("job", QVariant::fromValue(last_update_time_));
hash_tasks_.append(watcher);
connect(watcher, &QFutureWatcher< QVector<HashData> >::finished, this, &PreviewAutoCacher::HashesProcessed);
watcher->setFuture(QtConcurrent::run(PreviewAutoCacher::GenerateHashes,
copied_viewer_node_,
viewer_node_->video_frame_cache(),
times));
}
// Handle video tasks
rational t;
while (video_tasks_.size() < max_tasks && queued_frame_iterator_.GetNext(&t)) {
@@ -747,7 +645,6 @@ void PreviewAutoCacher::RequeueFrames()
if (viewer_node_
&& (viewer_node_->GetVideoAutoCacheEnabled() || use_custom_range_)
&& viewer_node_->video_frame_cache()->HasInvalidatedRanges(viewer_node_->GetVideoLength())
&& hash_tasks_.isEmpty()
&& !IsRenderingCustomRange()) {
TimeRange using_range = use_custom_range_ ? custom_autocache_range_ : cache_range_;
@@ -834,15 +731,6 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
// Stop requeue timer if it's running
delayed_requeue_timer_.stop();
// Handle hashes
if (!hash_tasks_.isEmpty()) {
// Wait for hashes to finish
WaitForHashesToFinish();
// Clear the hash list to indicate we're not interested in the results of any of these
hash_tasks_.clear();
}
// Handle video rendering tasks
if (!video_tasks_.isEmpty()) {
// Cancel any video tasks and wait for them to finish
-24
View File
@@ -72,16 +72,6 @@ public:
*/
void SetPlayhead(const rational& playhead);
/**
* @brief If any hashes are currently running, wait for them to finish
*
* Once this function returns, it can be guaranteed that all hash tasks have been finished.
* They will NOT have been removed from the hash task list yet until they run HashesProcessed.
* If you don't want the continued processing in HashesProcessed to run, remove the task manually
* from the list after calling this function. It will still call HashesProcessed, but will be
* largely ignored (that function will simply free it).
*/
void WaitForHashesToFinish();
void WaitForVideoDownloadsToFinish();
/**
@@ -142,14 +132,6 @@ private:
void StartCachingVideoRange(const TimeRange &range);
void StartCachingAudioRange(const TimeRange &range);
struct HashData {
rational time;
QByteArray hash;
bool exists;
};
static QVector<HashData> GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector<rational> &times);
class QueuedJob {
public:
enum Type {
@@ -190,7 +172,6 @@ private:
RenderTicketPtr single_frame_render_;
QList<QFutureWatcher< QVector<HashData> >*> hash_tasks_;
QMap<RenderTicketWatcher*, TimeRange> audio_tasks_;
QMap<RenderTicketWatcher*, QByteArray> video_tasks_;
QMap<RenderTicketWatcher*, QByteArray> video_download_tasks_;
@@ -225,11 +206,6 @@ private slots:
*/
void AudioInvalidated(const olive::TimeRange &range);
/**
* @brief Handler for when we have applied all the hashes to the FrameHashCache
*/
void HashesProcessed();
/**
* @brief Handler for when the RenderManager has returned rendered audio
*/
+1 -16
View File
@@ -26,7 +26,6 @@
#include "config/config.h"
#include "core.h"
#include "node/hashtraverser.h"
#include "render/opengl/openglrenderer.h"
#include "render/rendererthreadwrapper.h"
#include "renderprocessor.h"
@@ -100,19 +99,6 @@ void RenderManager::ClearOldDecoders()
}
}
QByteArray RenderManager::Hash(const Node *n, const Node::ValueHint &output, const VideoParams &params, const rational &time)
{
Q_ASSERT(n);
if (n) {
HashTraverser hasher;
return hasher.GetHash(n, output, params, TimeRange(time, time + params.frame_rate_as_time_base()));
} else {
qCritical() << "Hash called with null node";
return QByteArray();
}
}
RenderTicketPtr RenderManager::RenderFrame(ViewerOutput *viewer, ColorManager* color_manager,
const rational& time, RenderMode::Mode mode,
FrameHashCache* cache, bool prioritize, bool texture_only)
@@ -201,14 +187,13 @@ RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange
return ticket;
}
RenderTicketPtr RenderManager::SaveFrameToCache(FrameHashCache *cache, FramePtr frame, const QByteArray &hash, bool prioritize)
RenderTicketPtr RenderManager::SaveFrameToCache(FrameHashCache *cache, FramePtr frame, bool prioritize)
{
// Create ticket
RenderTicketPtr ticket = std::make_shared<RenderTicket>();
ticket->setProperty("cache", cache->GetCacheDirectory());
ticket->setProperty("frame", QVariant::fromValue(frame));
ticket->setProperty("hash", hash);
ticket->setProperty("type", kTypeVideoDownload);
if (ticket->thread() != this->thread()) {
+1 -6
View File
@@ -63,11 +63,6 @@ public:
return instance_;
}
/**
* @brief Generate a unique identifier for a certain node at a cconst Node *n, const Node::ValueHint &outputertain time
*/
static QByteArray Hash(const Node *n, const Node::ValueHint &output, const VideoParams &params, const rational &time);
/**
* @brief Asynchronously generate a frame at a given time
*
@@ -103,7 +98,7 @@ public:
RenderTicketPtr RenderAudio(ViewerOutput* viewer, const TimeRange& r, const AudioParams& params, RenderMode::Mode mode, bool generate_waveforms, bool prioritize = false);
RenderTicketPtr RenderAudio(ViewerOutput *viewer, const TimeRange& r, RenderMode::Mode mode, bool generate_waveforms, bool prioritize = false);
RenderTicketPtr SaveFrameToCache(FrameHashCache* cache, FramePtr frame, const QByteArray& hash, bool prioritize = false);
RenderTicketPtr SaveFrameToCache(FrameHashCache* cache, FramePtr frame, bool prioritize = false);
virtual void RunTicket(RenderTicketPtr ticket) const override;