cache: reimplemented auto-caching
Implemented a smarter auto-cache that's context sensitive. Caching will automatically pause when playback begins or values are being changed and resume when inactive.
This commit is contained in:
Vendored
+3
-1
@@ -50,12 +50,14 @@ bool CacheTask::Run()
|
||||
|
||||
Render(range_to_cache, QMatrix4x4(), false);
|
||||
|
||||
download_threads_.waitForDone();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QFuture<void> CacheTask::DownloadFrame(FramePtr frame, const QByteArray &hash)
|
||||
{
|
||||
return QtConcurrent::run(FrameHashCache::SaveCacheFrame, hash, frame);
|
||||
return QtConcurrent::run(&download_threads_, FrameHashCache::SaveCacheFrame, hash, frame);
|
||||
}
|
||||
|
||||
void CacheTask::FrameDownloaded(const QByteArray &hash, const QLinkedList<rational> ×)
|
||||
|
||||
Vendored
+2
@@ -47,6 +47,8 @@ protected:
|
||||
private:
|
||||
bool in_out_only_;
|
||||
|
||||
QThreadPool download_threads_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -92,7 +92,7 @@ void RenderTask::Render(const TimeRangeList& range_to_cache,
|
||||
QLinkedList<HashTimePair> sorted_times;
|
||||
QLinkedList<HashTimePair>::iterator sorted_iterator;
|
||||
|
||||
// Rendering is more efficient if we cache in order
|
||||
// Rendering is more efficient if we cache in order, so here we sort
|
||||
QMap< QByteArray, QLinkedList<rational> >::const_iterator i;
|
||||
for (i=times_to_render.constBegin(); i!=times_to_render.constEnd(); i++) {
|
||||
const QByteArray& hash = i.key();
|
||||
@@ -141,9 +141,10 @@ void RenderTask::Render(const TimeRangeList& range_to_cache,
|
||||
QLinkedList<HashDownloadFuturePair>::iterator j;
|
||||
QLinkedList<RangeSampleFuturePair>::iterator k;
|
||||
|
||||
while (!render_lookup_table.isEmpty()
|
||||
|| !download_futures.isEmpty()
|
||||
|| !audio_lookup_table.isEmpty()) {
|
||||
while (!IsCancelled()
|
||||
&& (!render_lookup_table.isEmpty()
|
||||
|| !download_futures.isEmpty()
|
||||
|| !audio_lookup_table.isEmpty())) {
|
||||
|
||||
i = render_lookup_table.begin();
|
||||
|
||||
@@ -197,4 +198,9 @@ void RenderTask::AudioDownloaded(const TimeRange &, SampleBufferPtr)
|
||||
{
|
||||
}
|
||||
|
||||
void RenderTask::SetAnchorPoint(const rational &r)
|
||||
{
|
||||
anchor_point_ = r;
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -57,6 +57,8 @@ protected:
|
||||
return audio_params_;
|
||||
}
|
||||
|
||||
void SetAnchorPoint(const rational& r);
|
||||
|
||||
private:
|
||||
ViewerOutput* viewer_;
|
||||
|
||||
@@ -64,6 +66,8 @@ private:
|
||||
|
||||
AudioRenderingParams audio_params_;
|
||||
|
||||
rational anchor_point_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -72,6 +72,17 @@ Task *TaskManager::GetFirstTask() const
|
||||
return tasks_.begin().value();
|
||||
}
|
||||
|
||||
void TaskManager::CancelTaskAndWait(Task* t)
|
||||
{
|
||||
t->Cancel();
|
||||
|
||||
QFutureWatcher<bool>* w = tasks_.key(t);
|
||||
|
||||
if (w) {
|
||||
w->waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
void TaskManager::AddTask(Task* t)
|
||||
{
|
||||
// Create a watcher for signalling
|
||||
@@ -89,6 +100,17 @@ void TaskManager::AddTask(Task* t)
|
||||
emit TaskListChanged();
|
||||
}
|
||||
|
||||
void TaskManager::CancelTask(Task *t)
|
||||
{
|
||||
if (failed_tasks_.contains(t)) {
|
||||
failed_tasks_.removeOne(t);
|
||||
emit TaskRemoved(t);
|
||||
t->deleteLater();
|
||||
} else {
|
||||
t->Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void TaskManager::TaskFinished()
|
||||
{
|
||||
QFutureWatcher<bool>* watcher = static_cast<QFutureWatcher<bool>*>(sender());
|
||||
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
|
||||
Task* GetFirstTask() const;
|
||||
|
||||
void CancelTaskAndWait(Task* t);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Add a new Task
|
||||
@@ -81,6 +83,8 @@ public slots:
|
||||
*/
|
||||
void AddTask(Task *t);
|
||||
|
||||
void CancelTask(Task* t);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a Task is added by AddTask()
|
||||
|
||||
Reference in New Issue
Block a user