moved frame cache to external class that's easier to pass around
This commit is contained in:
@@ -20,18 +20,21 @@ add_subdirectory(vulkan)
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
|
||||
render/backend/decodercache.h
|
||||
render/backend/decodercache.cpp
|
||||
|
||||
render/backend/renderbackend.h
|
||||
render/backend/renderbackend.cpp
|
||||
|
||||
render/backend/audiorenderbackend.h
|
||||
render/backend/audiorenderbackend.cpp
|
||||
|
||||
render/backend/videorenderbackend.h
|
||||
render/backend/videorenderbackend.cpp
|
||||
render/backend/videorenderframecache.h
|
||||
render/backend/videorenderframecache.cpp
|
||||
render/backend/videorenderworker.h
|
||||
render/backend/videorenderworker.cpp
|
||||
|
||||
render/backend/decodercache.h
|
||||
render/backend/decodercache.cpp
|
||||
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -206,10 +206,9 @@ void OpenGLBackend::ThreadCompletedFrame(NodeDependency path)
|
||||
caching_ = false;
|
||||
|
||||
OpenGLTexturePtr texture = path.node()->get_cached_value(path.range()).value<OpenGLTexturePtr>();
|
||||
qDebug() << "Retrieved texture for time" << path.in();
|
||||
|
||||
if (texture != nullptr) {
|
||||
QString cache_fn = CachePathName(QStringLiteral("%1-%2").arg(QString::number(path.in().numerator()), QString::number(path.in().denominator())).toLatin1());
|
||||
QString cache_fn = frame_cache()->CachePathName(QStringLiteral("%1-%2").arg(QString::number(path.in().numerator()), QString::number(path.in().denominator())).toLatin1());
|
||||
|
||||
// Find an available worker to download this texture
|
||||
foreach (OpenGLWorker* worker, processors_) {
|
||||
@@ -229,7 +228,7 @@ void OpenGLBackend::ThreadCompletedFrame(NodeDependency path)
|
||||
CacheNext();
|
||||
}
|
||||
|
||||
void OpenGLBackend::ThreadCallback(OpenGLTexturePtr texture, const rational& time, const QByteArray& hash)
|
||||
/*void OpenGLBackend::ThreadCallback(OpenGLTexturePtr texture, const rational& time, const QByteArray& hash)
|
||||
{
|
||||
// Threads are all done now, time to proceed
|
||||
caching_ = false;
|
||||
@@ -239,10 +238,6 @@ void OpenGLBackend::ThreadCallback(OpenGLTexturePtr texture, const rational& tim
|
||||
if (texture != nullptr) {
|
||||
// We received a texture, time to start downloading it
|
||||
QString fn = CachePathName(hash);
|
||||
|
||||
/*download_threads_[last_download_thread_%download_threads_.size()]->Queue(texture,
|
||||
fn,
|
||||
hash);*/
|
||||
} else {
|
||||
// There was no texture here, we must update the viewer
|
||||
DownloadThreadComplete(hash);
|
||||
@@ -279,7 +274,7 @@ void OpenGLBackend::ThreadCallback(OpenGLTexturePtr texture, const rational& tim
|
||||
}
|
||||
|
||||
CacheNext();
|
||||
}
|
||||
}*/
|
||||
|
||||
void OpenGLBackend::ThreadRequestedSibling(NodeDependency dep)
|
||||
{
|
||||
@@ -295,7 +290,7 @@ void OpenGLBackend::ThreadRequestedSibling(NodeDependency dep)
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLBackend::ThreadSkippedFrame(const rational& time, const QByteArray& hash)
|
||||
/*void OpenGLBackend::ThreadSkippedFrame(const rational& time, const QByteArray& hash)
|
||||
{
|
||||
caching_ = false;
|
||||
|
||||
@@ -309,9 +304,9 @@ void OpenGLBackend::ThreadSkippedFrame(const rational& time, const QByteArray& h
|
||||
}
|
||||
|
||||
CacheNext();
|
||||
}
|
||||
}*/
|
||||
|
||||
void OpenGLBackend::DownloadThreadComplete(const QByteArray &hash)
|
||||
/*void OpenGLBackend::DownloadThreadComplete(const QByteArray &hash)
|
||||
{
|
||||
cache_hash_list_mutex_.lock();
|
||||
cache_hash_list_.removeAll(hash);
|
||||
@@ -328,4 +323,4 @@ void OpenGLBackend::DownloadThreadComplete(const QByteArray &hash)
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -50,12 +50,12 @@ private slots:
|
||||
|
||||
|
||||
|
||||
void ThreadCallback(OpenGLTexturePtr texture, const rational& time, const QByteArray& hash);
|
||||
//void ThreadCallback(OpenGLTexturePtr texture, const rational& time, const QByteArray& hash);
|
||||
|
||||
|
||||
void ThreadSkippedFrame(const rational &time, const QByteArray &hash);
|
||||
//void ThreadSkippedFrame(const rational &time, const QByteArray &hash);
|
||||
|
||||
void DownloadThreadComplete(const QByteArray &hash);
|
||||
//void DownloadThreadComplete(const QByteArray &hash);
|
||||
};
|
||||
|
||||
#endif // OPENGLBACKEND_H
|
||||
|
||||
@@ -126,6 +126,7 @@ void RenderBackend::RegenerateCacheID()
|
||||
|| !cache_time_
|
||||
|| !GenerateCacheIDInternal(hash)) {
|
||||
cache_id_.clear();
|
||||
CacheIDChangedEvent(QString());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,6 +135,7 @@ void RenderBackend::RegenerateCacheID()
|
||||
|
||||
QByteArray bytes = hash.result();
|
||||
cache_id_ = bytes.toHex();
|
||||
CacheIDChangedEvent(cache_id_);
|
||||
}
|
||||
|
||||
void RenderBackend::SetError(const QString &error)
|
||||
@@ -155,3 +157,8 @@ const QVector<QThread *> &RenderBackend::threads()
|
||||
{
|
||||
return threads_;
|
||||
}
|
||||
|
||||
void RenderBackend::CacheIDChangedEvent(const QString &id)
|
||||
{
|
||||
Q_UNUSED(id)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ protected:
|
||||
*/
|
||||
virtual bool GenerateCacheIDInternal(QCryptographicHash& hash) = 0;
|
||||
|
||||
virtual void CacheIDChangedEvent(const QString& id);
|
||||
|
||||
void SetError(const QString& error);
|
||||
|
||||
virtual void ViewerNodeChangedEvent(ViewerOutput* node);
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <QDir>
|
||||
#include <QtMath>
|
||||
|
||||
#include "common/filefunctions.h"
|
||||
#include "opengl/functions.h"
|
||||
#include "render/pixelservice.h"
|
||||
|
||||
@@ -164,6 +163,16 @@ bool VideoRenderBackend::GenerateCacheIDInternal(QCryptographicHash& hash)
|
||||
return true;
|
||||
}
|
||||
|
||||
void VideoRenderBackend::CacheIDChangedEvent(const QString &id)
|
||||
{
|
||||
frame_cache_.SetCacheID(id);
|
||||
}
|
||||
|
||||
VideoRenderFrameCache *VideoRenderBackend::frame_cache()
|
||||
{
|
||||
return &frame_cache_;
|
||||
}
|
||||
|
||||
void VideoRenderBackend::CacheNext()
|
||||
{
|
||||
if (!Init() || cache_queue_.isEmpty() || viewer_node() == nullptr || caching_) {
|
||||
@@ -179,52 +188,6 @@ void VideoRenderBackend::CacheNext()
|
||||
caching_ = true;
|
||||
}
|
||||
|
||||
QString VideoRenderBackend::CachePathName(const QByteArray &hash)
|
||||
{
|
||||
QDir this_cache_dir = QDir(GetMediaCacheLocation()).filePath(cache_id_);
|
||||
this_cache_dir.mkpath(".");
|
||||
|
||||
QString filename = QStringLiteral("%1.exr").arg(QString(hash.toHex()));
|
||||
|
||||
return this_cache_dir.filePath(filename);
|
||||
}
|
||||
|
||||
void VideoRenderBackend::DeferMap(const rational &time, const QByteArray &hash)
|
||||
{
|
||||
deferred_maps_.append({time, hash});
|
||||
}
|
||||
|
||||
bool VideoRenderBackend::HasHash(const QByteArray &hash)
|
||||
{
|
||||
return QFileInfo::exists(CachePathName(hash));
|
||||
}
|
||||
|
||||
bool VideoRenderBackend::IsCaching(const QByteArray &hash)
|
||||
{
|
||||
cache_hash_list_mutex_.lock();
|
||||
|
||||
bool is_caching = cache_hash_list_.contains(hash);
|
||||
|
||||
cache_hash_list_mutex_.unlock();
|
||||
|
||||
return is_caching;
|
||||
}
|
||||
|
||||
bool VideoRenderBackend::TryCache(const QByteArray &hash)
|
||||
{
|
||||
cache_hash_list_mutex_.lock();
|
||||
|
||||
bool is_caching = cache_hash_list_.contains(hash);
|
||||
|
||||
if (!is_caching) {
|
||||
cache_hash_list_.append(hash);
|
||||
}
|
||||
|
||||
cache_hash_list_mutex_.unlock();
|
||||
|
||||
return !is_caching;
|
||||
}
|
||||
|
||||
const char *VideoRenderBackend::GetCachedFrame(const rational &time)
|
||||
{
|
||||
last_time_requested_ = time;
|
||||
@@ -245,8 +208,10 @@ const char *VideoRenderBackend::GetCachedFrame(const rational &time)
|
||||
}
|
||||
|
||||
// Find frame in map
|
||||
if (time_hash_map_.contains(time)) {
|
||||
QString fn = CachePathName(time_hash_map_[time]);
|
||||
QByteArray frame_hash = frame_cache_.TimeToHash(time);
|
||||
|
||||
if (!frame_hash.isEmpty()) {
|
||||
QString fn = frame_cache_.CachePathName(frame_hash);
|
||||
|
||||
if (QFileInfo::exists(fn)) {
|
||||
auto in = OIIO::ImageInput::open(fn.toStdString());
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "renderbackend.h"
|
||||
#include "render/pixelformat.h"
|
||||
#include "render/rendermodes.h"
|
||||
#include "videorenderframecache.h"
|
||||
|
||||
/**
|
||||
* @brief A multithreaded OpenGL based renderer for node systems
|
||||
@@ -65,21 +66,6 @@ public:
|
||||
*/
|
||||
void SetParameters(const VideoRenderingParams ¶ms);
|
||||
|
||||
/**
|
||||
* @brief Return whether a frame with this hash already exists
|
||||
*/
|
||||
bool HasHash(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Return whether a frame is currently being cached
|
||||
*/
|
||||
bool IsCaching(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Check if a frame is currently being cached, and if not reserve it
|
||||
*/
|
||||
bool TryCache(const QByteArray& hash);
|
||||
|
||||
public slots:
|
||||
virtual void InvalidateCache(const rational &start_range, const rational &end_range) override;
|
||||
|
||||
@@ -105,12 +91,7 @@ protected:
|
||||
|
||||
const char *GetCachedFrame(const rational& time);
|
||||
|
||||
/**
|
||||
* @brief Return the path of the cached image at this time
|
||||
*/
|
||||
QString CachePathName(const QByteArray &hash);
|
||||
|
||||
void DeferMap(const rational &time, const QByteArray &hash);
|
||||
VideoRenderFrameCache* frame_cache();
|
||||
|
||||
/**
|
||||
* @brief Function called when there are frames in the queue to cache
|
||||
@@ -121,26 +102,20 @@ protected:
|
||||
|
||||
const VideoRenderingParams& params() const;
|
||||
|
||||
QMap<rational, QByteArray> time_hash_map_;
|
||||
|
||||
QList<HashTimeMapping> deferred_maps_;
|
||||
|
||||
QMutex cache_hash_list_mutex_;
|
||||
QVector<QByteArray> cache_hash_list_;
|
||||
|
||||
rational last_time_requested_;
|
||||
|
||||
bool caching_;
|
||||
|
||||
signals:
|
||||
void CachedFrameReady(const rational& time);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Internal function for generating the cache ID
|
||||
*/
|
||||
virtual bool GenerateCacheIDInternal(QCryptographicHash& hash) override;
|
||||
|
||||
virtual void CacheIDChangedEvent(const QString& id) override;
|
||||
|
||||
signals:
|
||||
void CachedFrameReady(const rational& time);
|
||||
|
||||
private:
|
||||
VideoRenderingParams params_;
|
||||
|
||||
@@ -148,6 +123,8 @@ private:
|
||||
|
||||
QByteArray cache_frame_load_buffer_;
|
||||
|
||||
VideoRenderFrameCache frame_cache_;
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "videorenderframecache.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "common/filefunctions.h"
|
||||
|
||||
VideoRenderFrameCache::VideoRenderFrameCache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool VideoRenderFrameCache::HasHash(const QByteArray &hash)
|
||||
{
|
||||
return QFileInfo::exists(CachePathName(hash));
|
||||
}
|
||||
|
||||
bool VideoRenderFrameCache::IsCaching(const QByteArray &hash)
|
||||
{
|
||||
cache_hash_list_mutex_.lock();
|
||||
|
||||
bool is_caching = cache_hash_list_.contains(hash);
|
||||
|
||||
cache_hash_list_mutex_.unlock();
|
||||
|
||||
return is_caching;
|
||||
}
|
||||
|
||||
bool VideoRenderFrameCache::TryCache(const QByteArray &hash)
|
||||
{
|
||||
cache_hash_list_mutex_.lock();
|
||||
|
||||
bool is_caching = cache_hash_list_.contains(hash);
|
||||
|
||||
if (!is_caching) {
|
||||
cache_hash_list_.append(hash);
|
||||
}
|
||||
|
||||
cache_hash_list_mutex_.unlock();
|
||||
|
||||
return !is_caching;
|
||||
}
|
||||
|
||||
void VideoRenderFrameCache::SetCacheID(const QString &id)
|
||||
{
|
||||
cache_id_ = id;
|
||||
}
|
||||
|
||||
QByteArray VideoRenderFrameCache::TimeToHash(const rational &time)
|
||||
{
|
||||
return time_hash_map_.value(time);
|
||||
}
|
||||
|
||||
QString VideoRenderFrameCache::CachePathName(const QByteArray &hash)
|
||||
{
|
||||
QDir this_cache_dir = QDir(GetMediaCacheLocation()).filePath(cache_id_);
|
||||
this_cache_dir.mkpath(".");
|
||||
|
||||
QString filename = QStringLiteral("%1.exr").arg(QString(hash.toHex()));
|
||||
|
||||
return this_cache_dir.filePath(filename);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef VIDEORENDERFRAMECACHE_H
|
||||
#define VIDEORENDERFRAMECACHE_H
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
#include "common/rational.h"
|
||||
|
||||
class VideoRenderFrameCache
|
||||
{
|
||||
public:
|
||||
VideoRenderFrameCache();
|
||||
|
||||
/**
|
||||
* @brief Return whether a frame with this hash already exists
|
||||
*/
|
||||
bool HasHash(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Return whether a frame is currently being cached
|
||||
*/
|
||||
bool IsCaching(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Check if a frame is currently being cached, and if not reserve it
|
||||
*/
|
||||
bool TryCache(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Return the path of the cached image at this time
|
||||
*/
|
||||
QString CachePathName(const QByteArray &hash);
|
||||
|
||||
void SetCacheID(const QString& id);
|
||||
|
||||
QByteArray TimeToHash(const rational& time);
|
||||
|
||||
private:
|
||||
QMap<rational, QByteArray> time_hash_map_;
|
||||
|
||||
QMutex cache_hash_list_mutex_;
|
||||
QVector<QByteArray> cache_hash_list_;
|
||||
|
||||
QString cache_id_;
|
||||
};
|
||||
|
||||
#endif // VIDEORENDERFRAMECACHE_H
|
||||
Reference in New Issue
Block a user