base audio renderer classes created

This commit is contained in:
itsmattkc
2019-10-16 13:51:56 +11:00
parent fe2b0f2dc2
commit d6483916ac
33 changed files with 896 additions and 116 deletions
@@ -0,0 +1,28 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/processor/videorenderer/videorenderer.h
node/processor/videorenderer/videorenderer.cpp
node/processor/videorenderer/videorendererthreadbase.h
node/processor/videorenderer/videorendererthreadbase.cpp
node/processor/videorenderer/videorendererdownloadthread.h
node/processor/videorenderer/videorendererdownloadthread.cpp
node/processor/videorenderer/videorendererprocessthread.h
node/processor/videorenderer/videorendererprocessthread.cpp
PARENT_SCOPE
)
@@ -0,0 +1,542 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "videorenderer.h"
#include <OpenImageIO/imageio.h>
#include <QApplication>
#include <QCryptographicHash>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QtMath>
#include "common/filefunctions.h"
#include "render/pixelservice.h"
VideoRendererProcessor::VideoRendererProcessor() :
started_(false),
width_(0),
height_(0),
divider_(1),
caching_(false),
starting_(false)
{
texture_input_ = new NodeInput("tex_in");
texture_input_->add_data_input(NodeInput::kTexture);
AddParameter(texture_input_);
length_input_ = new NodeInput("length_in");
length_input_->add_data_input(NodeInput::kRational);
AddParameter(length_input_);
texture_output_ = new NodeOutput("tex_out");
texture_output_->set_data_type(NodeInput::kTexture);
AddParameter(texture_output_);
}
QString VideoRendererProcessor::Name()
{
return tr("Video Renderer");
}
QString VideoRendererProcessor::Category()
{
return tr("Processor");
}
QString VideoRendererProcessor::Description()
{
return tr("A multi-threaded OpenGL hardware-accelerated node compositor.");
}
QString VideoRendererProcessor::id()
{
return "org.olivevideoeditor.Olive.renderervenus";
}
void VideoRendererProcessor::SetCacheName(const QString &s)
{
cache_name_ = s;
cache_time_ = QDateTime::currentMSecsSinceEpoch();
GenerateCacheIDInternal();
}
QVariant VideoRendererProcessor::Value(NodeOutput* output, const rational& time)
{
if (output == texture_output_) {
if (!texture_input_->IsConnected()) {
// Nothing is connected - nothing to show or render
return 0;
}
if (cache_id_.isEmpty()) {
qWarning() << "RendererProcessor has no cache ID";
return 0;
}
if (timebase_.isNull()) {
qWarning() << "RendererProcessor has no timebase";
return 0;
}
// Find frame in map
if (time_hash_map_.contains(time)) {
QString fn = CachePathName(time_hash_map_[time]);
if (QFileInfo::exists(fn)) {
auto in = OIIO::ImageInput::open(fn.toStdString());
if (in) {
in->read_image(PixelService::GetPixelFormatInfo(format_).oiio_desc, cache_frame_load_buffer_.data());
in->close();
master_texture_->Upload(cache_frame_load_buffer_.data());
return QVariant::fromValue(master_texture_);
} else {
qWarning() << "OIIO Error:" << OIIO::geterror().c_str();
}
}
}
}
return 0;
}
void VideoRendererProcessor::Release()
{
Stop();
}
void VideoRendererProcessor::InvalidateCache(const rational &start_range, const rational &end_range, NodeInput *from)
{
Q_UNUSED(from)
if (timebase_.isNull()) {
return;
}
//ClearCachedValuesInParameters(start_range, end_range);
texture_input_->ClearCachedValue();
length_input_->ClearCachedValue();
// Adjust range to min/max values
rational start_range_adj = qMax(rational(0), start_range);
rational end_range_adj = qMin(length_input()->get_value(0).value<rational>(), end_range);
qDebug() << "Cache invalidated between"
<< start_range_adj.toDouble()
<< "and"
<< end_range_adj.toDouble();
// Snap start_range to timebase
double start_range_dbl = start_range_adj.toDouble();
double start_range_numf = start_range_dbl * static_cast<double>(timebase_.denominator());
int64_t start_range_numround = qFloor(start_range_numf/static_cast<double>(timebase_.numerator())) * timebase_.numerator();
rational true_start_range(start_range_numround, timebase_.denominator());
for (rational r=true_start_range;r<=end_range_adj;r+=timebase_) {
// Try to order the queue from closest to the playhead to furthest
rational last_time = texture_output()->LastRequestedTime();
rational diff = r - last_time;
if (diff < 0) {
// FIXME: Hardcoded number
// If the number is before the playhead, we still prioritize its closeness but not nearly as much (5:1 in this
// example)
diff = qAbs(diff) * 5;
}
bool contains = false;
bool added = false;
QLinkedList<rational>::iterator insert_iterator;
for (QLinkedList<rational>::iterator i = cache_queue_.begin();i != cache_queue_.end();i++) {
rational compare = *i;
if (!added) {
rational compare_diff = compare - last_time;
if (compare_diff > diff) {
insert_iterator = i;
added = true;
}
}
if (compare == r) {
contains = true;
break;
}
}
if (!contains) {
if (added) {
cache_queue_.insert(insert_iterator, r);
} else {
cache_queue_.append(r);
}
}
}
CacheNext();
}
void VideoRendererProcessor::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
timebase_dbl_ = timebase_.toDouble();
}
void VideoRendererProcessor::SetParameters(const int &width,
const int &height,
const olive::PixelFormat &format,
const olive::RenderMode &mode,
const int& divider)
{
// Since we're changing parameters, all the existing threads are invalid and must be removed. They will start again
// next time this Node has to process anything.
Stop();
// Set new parameters
width_ = width;
height_ = height;
format_ = format;
mode_ = mode;
// divider's default value is 0, so we can assume if it's 0 a divider wasn't specified
if (divider > 0) {
divider_ = divider;
}
CalculateEffectiveDimensions();
// Regenerate the cache ID
GenerateCacheIDInternal();
}
void VideoRendererProcessor::SetDivider(const int &divider)
{
Q_ASSERT(divider_ > 0);
Stop();
divider_ = divider;
CalculateEffectiveDimensions();
// Regenerate the cache ID
GenerateCacheIDInternal();
}
void VideoRendererProcessor::Start()
{
if (started_) {
return;
}
QOpenGLContext* ctx = QOpenGLContext::currentContext();
int background_thread_count = QThread::idealThreadCount();
// Some OpenGL implementations (notably wgl) require the context not to be current before sharing
QSurface* old_surface = ctx->surface();
ctx->doneCurrent();
threads_.resize(background_thread_count);
for (int i=0;i<threads_.size();i++) {
threads_[i] = std::make_shared<RendererProcessThread>(this, ctx, effective_width_, effective_height_, divider_, format_, mode_);
threads_[i]->StartThread(QThread::LowPriority);
// Ensure this connection is "Queued" so that it always runs in this object's threaded rather than any of the
// other threads
connect(threads_.at(i).get(),
SIGNAL(RequestSibling(NodeDependency)),
this,
SLOT(ThreadRequestSibling(NodeDependency)),
Qt::QueuedConnection);
}
// Connect first thread (master thread) to the callback
connect(threads_.first().get(),
SIGNAL(CachedFrame(RenderTexturePtr, const rational&, const QByteArray&)),
this,
SLOT(ThreadCallback(RenderTexturePtr, const rational&, const QByteArray&)),
Qt::QueuedConnection);
connect(threads_.first().get(),
SIGNAL(FrameSkipped(const rational&, const QByteArray&)),
this,
SLOT(ThreadSkippedFrame(const rational&, const QByteArray&)),
Qt::QueuedConnection);
download_threads_.resize(background_thread_count);
for (int i=0;i<download_threads_.size();i++) {
// Create download thread
download_threads_[i] = std::make_shared<VideoRendererDownloadThread>(ctx, effective_width_, effective_height_, divider_, format_, mode_);
download_threads_[i]->StartThread(QThread::LowPriority);
connect(download_threads_[i].get(),
SIGNAL(Downloaded(const QByteArray&)),
this,
SLOT(DownloadThreadComplete(const QByteArray&)),
Qt::QueuedConnection);
}
last_download_thread_ = 0;
// Restore context now that thread creation is complete
ctx->makeCurrent(old_surface);
// Create master texture (the one sent to the viewer)
master_texture_ = std::make_shared<RenderTexture>();
master_texture_->Create(ctx, effective_width_, effective_height_, format_);
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(format_, effective_width_, effective_height_));
started_ = true;
}
void VideoRendererProcessor::Stop()
{
if (!started_) {
return;
}
started_ = false;
foreach (RendererDownloadThreadPtr download_thread_, download_threads_) {
download_thread_->Cancel();
}
download_threads_.clear();
foreach (RendererProcessThreadPtr process_thread, threads_) {
process_thread->Cancel();
}
threads_.clear();
master_texture_ = nullptr;
cache_frame_load_buffer_.clear();
}
void VideoRendererProcessor::GenerateCacheIDInternal()
{
if (cache_name_.isEmpty() || effective_width_ == 0 || effective_height_ == 0) {
return;
}
// Generate an ID that is more or less guaranteed to be unique to this Sequence
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(cache_name_.toUtf8());
hash.addData(QString::number(cache_time_).toUtf8());
hash.addData(QString::number(width_).toUtf8());
hash.addData(QString::number(height_).toUtf8());
hash.addData(QString::number(format_).toUtf8());
hash.addData(QString::number(divider_).toUtf8());
QByteArray bytes = hash.result();
cache_id_ = bytes.toHex();
}
void VideoRendererProcessor::CacheNext()
{
if (cache_queue_.isEmpty() || !texture_input_->IsConnected() || caching_) {
return;
}
// Make sure cache has started
Start();
rational cache_frame = cache_queue_.takeFirst();
qDebug() << "Caching" << cache_frame.toDouble();
threads_.first()->Queue(NodeDependency(texture_input_->get_connected_output(), cache_frame), true, false);
caching_ = true;
}
QString VideoRendererProcessor::CachePathName(const QByteArray &hash)
{
QDir this_cache_dir = QDir(GetMediaCacheLocation()).filePath(cache_id_);
this_cache_dir.mkpath(".");
QString filename = QString("%1.exr").arg(QString(hash.toHex()));
return this_cache_dir.filePath(filename);
}
void VideoRendererProcessor::DeferMap(const rational &time, const QByteArray &hash)
{
deferred_maps_.append({time, hash});
}
bool VideoRendererProcessor::HasHash(const QByteArray &hash)
{
return QFileInfo::exists(CachePathName(hash));
}
bool VideoRendererProcessor::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 VideoRendererProcessor::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 VideoRendererProcessor::CalculateEffectiveDimensions()
{
effective_width_ = width_ / divider_;
effective_height_ = height_ / divider_;
}
void VideoRendererProcessor::ThreadCallback(RenderTexturePtr texture, const rational& time, const QByteArray& hash)
{
// Threads are all done now, time to proceed
caching_ = false;
DeferMap(time, hash);
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);
last_download_thread_++;
} else {
// There was no texture here, we must update the viewer
DownloadThreadComplete(hash);
}
// If the connected output is using this time, signal it to update
if (texture_output_->IsConnected()
&& texture_output_->LastRequestedTime() == time) {
texture_output_->push_value(QVariant::fromValue(texture), time);
SendInvalidateCache(time, time);
}
CacheNext();
}
void VideoRendererProcessor::ThreadRequestSibling(NodeDependency dep)
{
// Try to queue another thread to run this dep in advance
for (int i=1;i<threads_.size();i++) {
if (threads_.at(i)->Queue(dep, false, true)) {
return;
}
}
}
void VideoRendererProcessor::ThreadSkippedFrame(const rational& time, const QByteArray& hash)
{
caching_ = false;
DeferMap(time, hash);
if (!IsCaching(hash)) {
DownloadThreadComplete(hash);
// Signal output to update value
if (texture_output_->IsConnected()
&& texture_output_->LastRequestedTime() == time) {
texture_output_->ClearCachedValue();
SendInvalidateCache(time, time);
}
}
CacheNext();
}
void VideoRendererProcessor::DownloadThreadComplete(const QByteArray &hash)
{
cache_hash_list_mutex_.lock();
cache_hash_list_.removeAll(hash);
cache_hash_list_mutex_.unlock();
for (int i=0;i<deferred_maps_.size();i++) {
const HashTimeMapping& deferred = deferred_maps_.at(i);
if (deferred_maps_.at(i).hash == hash) {
// Insert into hash map
time_hash_map_.insert(deferred.time, deferred.hash);
deferred_maps_.removeAt(i);
i--;
}
}
}
VideoRendererThreadBase* VideoRendererProcessor::CurrentThread()
{
return dynamic_cast<VideoRendererThreadBase*>(QThread::currentThread());
}
RenderInstance *VideoRendererProcessor::CurrentInstance()
{
VideoRendererThreadBase* thread = CurrentThread();
if (thread != nullptr) {
return thread->render_instance();
}
return nullptr;
}
NodeInput *VideoRendererProcessor::texture_input()
{
return texture_input_;
}
NodeInput *VideoRendererProcessor::length_input()
{
return length_input_;
}
NodeOutput *VideoRendererProcessor::texture_output()
{
return texture_output_;
}
@@ -0,0 +1,223 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef RENDERER_H
#define RENDERER_H
#include <QLinkedList>
#include <QOpenGLTexture>
#include "node/node.h"
#include "render/pixelformat.h"
#include "render/rendermodes.h"
#include "videorendererdownloadthread.h"
#include "videorendererprocessthread.h"
/**
* @brief A multithreaded OpenGL based renderer for node systems
*/
class VideoRendererProcessor : public Node
{
Q_OBJECT
public:
/**
* @brief Renderer Constructor
*
* Constructing a Renderer object will not start any threads/backend on its own. Use Start() to do this and Stop()
* when the Renderer is about to be destroyed.
*/
VideoRendererProcessor();
virtual QString Name() override;
virtual QString Category() override;
virtual QString Description() override;
virtual QString id() override;
void SetCacheName(const QString& s);
virtual void Release() override;
virtual void InvalidateCache(const rational &start_range, const rational &end_range, NodeInput *from = nullptr) override;
void SetTimebase(const rational& timebase);
/**
* @brief Set parameters of the Renderer
*
* The Renderer owns the buffers that are used in the rendering process and this function sets the kind of buffers
* to use. The Renderer must be stopped when calling this function.
*
* @param width
*
* Buffer width
*
* @param height
*
* Buffer height
*
* @param format
*
* Buffer pixel format
*/
void SetParameters(const int& width,
const int& height,
const olive::PixelFormat& format,
const olive::RenderMode& mode,
const int &divider = 0);
void SetDivider(const int& divider);
/**
* @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 current instance of a RenderThread (or nullptr if there is none)
*
* This function attempts a dynamic_cast on QThread::currentThread() to RendererThread, which will return nullptr if
* the cast fails (e.g. if this function is called from the main thread rather than a RendererThread).
*/
static VideoRendererThreadBase* CurrentThread();
static RenderInstance* CurrentInstance();
NodeInput* texture_input();
NodeInput* length_input();
NodeOutput* texture_output();
protected:
virtual QVariant Value(NodeOutput* output, const rational& time) override;
private:
struct HashTimeMapping {
rational time;
QByteArray hash;
};
/**
* @brief Allocate and start the multithreaded backend
*/
void Start();
/**
* @brief Terminate and deallocate the multithreaded backend
*/
void Stop();
/**
* @brief Internal function for generating the cache ID
*/
void GenerateCacheIDInternal();
/**
* @brief Function called when there are frames in the queue to cache
*
* This function is NOT thread-safe and should only be called in the main thread.
*/
void CacheNext();
bool ShouldPushTexture(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);
/**
* @brief Internal list of RenderProcessThreads
*/
QVector<RendererProcessThreadPtr> threads_;
/**
* @brief Internal variable that contains whether the Renderer has started or not
*/
bool started_;
NodeInput* texture_input_;
NodeInput* length_input_;
NodeOutput* texture_output_;
int width_;
int height_;
void CalculateEffectiveDimensions();
int divider_;
int effective_width_;
int effective_height_;
olive::PixelFormat format_;
olive::RenderMode mode_;
rational timebase_;
double timebase_dbl_;
QLinkedList<rational> cache_queue_;
QString cache_name_;
qint64 cache_time_;
QString cache_id_;
bool caching_;
QVector<uchar*> cache_frame_load_buffer_;
QVector<RendererDownloadThreadPtr> download_threads_;
int last_download_thread_;
RenderTexturePtr master_texture_;
QMap<rational, QByteArray> time_hash_map_;
QMutex cache_hash_list_mutex_;
QVector<QByteArray> cache_hash_list_;
QList<HashTimeMapping> deferred_maps_;
bool starting_;
private slots:
void ThreadCallback(RenderTexturePtr texture, const rational& time, const QByteArray& hash);
void ThreadRequestSibling(NodeDependency dep);
void ThreadSkippedFrame(const rational &time, const QByteArray &hash);
void DownloadThreadComplete(const QByteArray &hash);
};
#endif // RENDERER_H
@@ -0,0 +1,128 @@
#include "videorendererdownloadthread.h"
#include <QFile>
#include <QFloat16>
#include <OpenImageIO/imageio.h>
#include "common/define.h"
#include "render/pixelservice.h"
VideoRendererDownloadThread::VideoRendererDownloadThread(QOpenGLContext *share_ctx,
const int &width,
const int &height,
const int &divider,
const olive::PixelFormat &format,
const olive::RenderMode &mode) :
VideoRendererThreadBase(share_ctx, width, height, divider, format, mode),
cancelled_(false)
{
}
void VideoRendererDownloadThread::Queue(RenderTexturePtr texture, const QString& fn, const QByteArray &hash)
{
texture_queue_lock_.lock();
texture_queue_.append({texture, fn, hash});
wait_cond_.wakeAll();
texture_queue_lock_.unlock();
}
void VideoRendererDownloadThread::Cancel()
{
cancelled_ = true;
texture_queue_lock_.lock();
wait_cond_.wakeAll();
texture_queue_lock_.unlock();
wait();
}
void VideoRendererDownloadThread::ProcessLoop()
{
QOpenGLFunctions* f = render_instance()->context()->functions();
QOpenGLExtraFunctions* xf = render_instance()->context()->extraFunctions();
f->glGenFramebuffers(1, &read_buffer_);
DownloadQueueEntry entry;
int buffer_size = PixelService::GetBufferSize(render_instance()->format(),
render_instance()->width(),
render_instance()->height());
QVector<uchar> data_buffer;
data_buffer.resize(buffer_size);
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(render_instance()->format());
// Set up OIIO::ImageSpec for compressing cached images on disk
OIIO::ImageSpec spec(render_instance()->width(), render_instance()->height(), kRGBAChannels, format_info.oiio_desc);
spec.attribute("compression", "dwaa:200");
while (!cancelled_) {
// Check queue for textures to download (use mutex to prevent collisions)
texture_queue_lock_.lock();
while (texture_queue_.isEmpty()) {
// Main waiting condition
wait_cond_.wait(&texture_queue_lock_);
if (cancelled_) {
break;
}
}
if (cancelled_) {
texture_queue_lock_.unlock();
break;
}
entry = texture_queue_.takeFirst();
texture_queue_lock_.unlock();
// Download the texture
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, read_buffer_);
xf->glFramebufferTexture2D(GL_READ_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
entry.texture->texture(),
0);
f->glReadPixels(0,
0,
entry.texture->width(),
entry.texture->height(),
format_info.pixel_format,
format_info.pixel_type,
data_buffer.data());
xf->glFramebufferTexture2D(GL_READ_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
0,
0);
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
std::string working_fn_std = entry.filename.toStdString();
std::unique_ptr<OIIO::ImageOutput> out = OIIO::ImageOutput::create(working_fn_std);
if (out) {
out->open(working_fn_std, spec);
out->write_image(format_info.oiio_desc, data_buffer.data());
out->close();
emit Downloaded(entry.hash);
} else {
qWarning() << tr("Failed to open output file \"%1\"").arg(entry.filename);
}
}
f->glDeleteFramebuffers(1, &read_buffer_);
}
@@ -0,0 +1,49 @@
#ifndef RENDERERDOWNLOADTHREAD_H
#define RENDERERDOWNLOADTHREAD_H
#include "videorendererthreadbase.h"
class VideoRendererDownloadThread : public VideoRendererThreadBase
{
Q_OBJECT
public:
VideoRendererDownloadThread(QOpenGLContext* share_ctx,
const int& width,
const int& height,
const int &divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode);
void Queue(RenderTexturePtr texture, const QString &fn, const QByteArray &hash);
public slots:
virtual void Cancel() override;
signals:
void Downloaded(const QByteArray& hash);
protected:
virtual void ProcessLoop() override;
private:
struct DownloadQueueEntry {
RenderTexturePtr texture;
QString filename;
QByteArray hash;
};
GLuint read_buffer_;
QVector<DownloadQueueEntry> texture_queue_;
QMutex texture_queue_lock_;
QAtomicInt cancelled_;
QByteArray hash_;
};
using RendererDownloadThreadPtr = std::shared_ptr<VideoRendererDownloadThread>;
#endif // RENDERERDOWNLOADTHREAD_H
@@ -0,0 +1,155 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "videorendererprocessthread.h"
#include "videorenderer.h"
RendererProcessThread::RendererProcessThread(VideoRendererProcessor* parent,
QOpenGLContext *share_ctx,
const int &width,
const int &height,
const int &divider,
const olive::PixelFormat &format,
const olive::RenderMode &mode) :
VideoRendererThreadBase(share_ctx, width, height, divider, format, mode),
parent_(parent),
cancelled_(false)
{
}
bool RendererProcessThread::Queue(const NodeDependency& dep, bool wait, bool sibling)
{
if (wait) {
// Wait for thread to be available
mutex_.lock();
} else if (!mutex_.tryLock()) {
return false;
}
// We can now change params without the other thread using them
path_ = dep;
sibling_ = sibling;
// Prepare to wait for thread to respond
caller_mutex_.lock();
// Wake up our main thread
wait_cond_.wakeAll();
mutex_.unlock();
// Wait for thread to start before returning
wait_cond_.wait(&caller_mutex_);
caller_mutex_.unlock();
return true;
}
void RendererProcessThread::Cancel()
{
cancelled_ = true;
mutex_.lock();
wait_cond_.wakeAll();
mutex_.unlock();
wait();
}
void RendererProcessThread::ProcessLoop()
{
while (!cancelled_) {
// Main waiting condition
wait_cond_.wait(&mutex_);
if (cancelled_) {
break;
}
// Wake up main thread
caller_mutex_.lock();
wait_cond_.wakeAll();
caller_mutex_.unlock();
// Process the Node
NodeOutput* output_to_process = path_.node();
Node* node_to_process = output_to_process->parent();
texture_ = nullptr;
QList<Node*> all_deps;
bool has_hash = false;
bool can_cache = true;
if (!sibling_) {
node_to_process->Lock();
all_deps = node_to_process->GetDependencies();
foreach (Node* dep, all_deps) {
dep->Lock();
}
// Check hash
QCryptographicHash hasher(QCryptographicHash::Sha1);
node_to_process->Hash(&hasher, output_to_process, path_.time());
hash_ = hasher.result();
has_hash = parent_->HasHash(hash_);
can_cache = false;
}
if (!has_hash){
if ((can_cache = parent_->TryCache(hash_))) {
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.time());
// Ask for other threads to run these deps while we're here
if (!deps.isEmpty()) {
for (int i=1;i<deps.size();i++) {
emit RequestSibling(deps.at(i));
}
}
// Get the requested value
texture_ = output_to_process->get_value(path_.time()).value<RenderTexturePtr>();
render_instance()->context()->functions()->glFinish();
}
}
if (!sibling_) {
foreach (Node* dep, all_deps) {
dep->Unlock();
}
node_to_process->Unlock();
}
if (can_cache) {
// We cached this frame, signal that it will need to be downloaded to disk
emit CachedFrame(texture_, path_.time(), hash_);
} else {
// This hash already exists, no need to cache, just map it
emit FrameSkipped(path_.time(), hash_);
}
}
}
@@ -0,0 +1,71 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef RENDERERPROCESSTHREAD_H
#define RENDERERPROCESSTHREAD_H
#include "videorendererthreadbase.h"
class VideoRendererProcessor;
class RendererProcessThread : public VideoRendererThreadBase
{
Q_OBJECT
public:
RendererProcessThread(VideoRendererProcessor* parent,
QOpenGLContext* share_ctx,
const int& width,
const int& height, const int &divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode);
bool Queue(const NodeDependency &dep, bool wait, bool sibling);
public slots:
virtual void Cancel() override;
protected:
virtual void ProcessLoop() override;
signals:
void RequestSibling(NodeDependency dep);
void CachedFrame(RenderTexturePtr texture, const rational& time, const QByteArray& hash);
void FrameSkipped(const rational& time, const QByteArray& hash);
private:
VideoRendererProcessor* parent_;
NodeDependency path_;
QByteArray hash_;
RenderTexturePtr texture_;
QAtomicInt cancelled_;
bool sibling_;
};
using RendererProcessThreadPtr = std::shared_ptr<RendererProcessThread>;
#endif // RENDERERPROCESSTHREAD_H
@@ -0,0 +1,83 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "videorendererthreadbase.h"
#include <QDebug>
VideoRendererThreadBase::VideoRendererThreadBase(QOpenGLContext *share_ctx, const int &width, const int &height, const int &divider, const olive::PixelFormat &format, const olive::RenderMode &mode) :
share_ctx_(share_ctx),
render_instance_(width, height, divider, format, mode)
{
connect(share_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Cancel()));
}
RenderInstance *VideoRendererThreadBase::render_instance()
{
return &render_instance_;
}
void VideoRendererThreadBase::run()
{
// Lock mutex for main loop
mutex_.lock();
render_instance_.SetShareContext(share_ctx_);
// Allocate and create resources
bool started = render_instance_.Start();
// Signal that main thread can continue now
WakeCaller();
if (started) {
// Main loop (use Cancel() to exit it)
ProcessLoop();
}
// Free all resources
render_instance_.Stop();
// Unlock mutex before exiting
mutex_.unlock();
}
void VideoRendererThreadBase::WakeCaller()
{
// Signal that main thread can continue now
caller_mutex_.lock();
wait_cond_.wakeAll();
caller_mutex_.unlock();
}
void VideoRendererThreadBase::StartThread(QThread::Priority priority)
{
caller_mutex_.lock();
// Start the thread
QThread::start(priority);
// Wait for thread to finish completion
wait_cond_.wait(&caller_mutex_);
caller_mutex_.unlock();
}
@@ -0,0 +1,72 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef RENDERTHREAD_H
#define RENDERTHREAD_H
#include <memory>
#include <QMutex>
#include <QThread>
#include <QWaitCondition>
#include "node/node.h"
#include "render/renderinstance.h"
class VideoRendererThreadBase : public QThread
{
Q_OBJECT
public:
VideoRendererThreadBase(QOpenGLContext* share_ctx,
const int& width,
const int& height,
const int& divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode);
RenderInstance* render_instance();
void StartThread(Priority priority = InheritPriority);
virtual void run() override;
public slots:
virtual void Cancel() = 0;
protected:
virtual void ProcessLoop() = 0;
QWaitCondition wait_cond_;
QMutex mutex_;
QMutex caller_mutex_;
private:
void WakeCaller();
QOpenGLContext* share_ctx_;
RenderInstance render_instance_;
};
using RendererThreadPtr = std::shared_ptr<VideoRendererThreadBase>;
#endif // RENDERTHREAD_H
@@ -0,0 +1,477 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "rendermanager.h"
#include <OpenImageIO/imageio.h>
#include <QApplication>
#include <QCryptographicHash>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QtMath>
#include "common/filefunctions.h"
#include "render/pixelservice.h"
RenderManager* RenderManager::instance_ = nullptr;
RenderManager::RenderManager() :
started_(false),
width_(0),
height_(0),
divider_(1),
caching_(false),
texture_input_(nullptr)
{
}
void RenderManager::CreateInstance()
{
if (instance_ == nullptr) {
instance_ = new RenderManager();
}
}
void RenderManager::DestroyInstance()
{
delete instance_;
instance_ = nullptr;
}
RenderManager *RenderManager::instance()
{
return instance_;
}
void RenderManager::SetCacheName(const QString &s)
{
cache_name_ = s;
cache_time_ = QDateTime::currentMSecsSinceEpoch();
GenerateCacheIDInternal();
}
void RenderManager::InvalidateCache(const rational &start_range, const rational &end_range, const rational& last_requested_time)
{
if (timebase_.isNull()) {
return;
}
qDebug() << "Cache invalidated between"
<< start_range.toDouble()
<< "and"
<< end_range.toDouble();
// Snap start_range to timebase
double start_range_dbl = start_range.toDouble();
double start_range_numf = start_range_dbl * static_cast<double>(timebase_.denominator());
int64_t start_range_numround = qFloor(start_range_numf/static_cast<double>(timebase_.numerator())) * timebase_.numerator();
rational true_start_range(start_range_numround, timebase_.denominator());
for (rational r=true_start_range;r<=end_range;r+=timebase_) {
// Try to order the queue from closest to the playhead to furthest
rational diff = r - last_requested_time;
if (diff < 0) {
// FIXME: Hardcoded number
// If the number is before the playhead, we still prioritize its closeness but not nearly as much (5:1 in this
// example)
diff = qAbs(diff) * 5;
}
bool contains = false;
bool added = false;
QLinkedList<rational>::iterator insert_iterator;
for (QLinkedList<rational>::iterator i = cache_queue_.begin();i != cache_queue_.end();i++) {
rational compare = *i;
if (!added) {
rational compare_diff = compare - last_requested_time;
if (compare_diff > diff) {
insert_iterator = i;
added = true;
}
}
if (compare == r) {
contains = true;
break;
}
}
if (!contains) {
if (added) {
cache_queue_.insert(insert_iterator, r);
} else {
cache_queue_.append(r);
}
}
}
CacheNext();
}
void RenderManager::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
timebase_dbl_ = timebase_.toDouble();
}
void RenderManager::SetParameters(const int &width,
const int &height,
const olive::PixelFormat &format,
const olive::RenderMode &mode,
NodeInput* input,
const int& divider)
{
// Since we're changing parameters, all the existing threads are invalid and must be removed. They will start again
// next time this Node has to process anything.
Stop();
// Set new parameters
width_ = width;
height_ = height;
format_ = format;
mode_ = mode;
texture_input_ = input;
// divider's default value is 0, so we can assume if it's 0 a divider wasn't specified
if (divider > 0) {
divider_ = divider;
}
CalculateEffectiveDimensions();
// Regenerate the cache ID
GenerateCacheIDInternal();
}
void RenderManager::SetDivider(const int &divider)
{
Q_ASSERT(divider_ > 0);
Stop();
divider_ = divider;
CalculateEffectiveDimensions();
// Regenerate the cache ID
GenerateCacheIDInternal();
}
void RenderManager::Start()
{
if (started_) {
return;
}
QOpenGLContext* ctx = QOpenGLContext::currentContext();
int background_thread_count = QThread::idealThreadCount();
// Some OpenGL implementations (notably wgl) require the context not to be current before sharing
QSurface* old_surface = ctx->surface();
ctx->doneCurrent();
threads_.resize(background_thread_count);
for (int i=0;i<threads_.size();i++) {
threads_[i] = std::make_shared<RendererProcessThread>(this, ctx, effective_width_, effective_height_, divider_, format_, mode_);
threads_[i]->StartThread(QThread::LowPriority);
// Ensure this connection is "Queued" so that it always runs in this object's threaded rather than any of the
// other threads
connect(threads_.at(i).get(),
SIGNAL(RequestSibling(NodeDependency)),
this,
SLOT(ThreadRequestSibling(NodeDependency)),
Qt::QueuedConnection);
}
// Connect first thread (master thread) to the callback
connect(threads_.first().get(),
SIGNAL(CachedFrame(RenderTexturePtr, const rational&, const QByteArray&)),
this,
SLOT(ThreadCallback(RenderTexturePtr, const rational&, const QByteArray&)),
Qt::QueuedConnection);
connect(threads_.first().get(),
SIGNAL(FrameSkipped(const rational&, const QByteArray&)),
this,
SLOT(ThreadSkippedFrame(const rational&, const QByteArray&)),
Qt::QueuedConnection);
download_threads_.resize(background_thread_count);
for (int i=0;i<download_threads_.size();i++) {
// Create download thread
download_threads_[i] = std::make_shared<RendererDownloadThread>(ctx, effective_width_, effective_height_, divider_, format_, mode_);
download_threads_[i]->StartThread(QThread::LowPriority);
connect(download_threads_[i].get(),
SIGNAL(Downloaded(const QByteArray&)),
this,
SLOT(DownloadThreadComplete(const QByteArray&)),
Qt::QueuedConnection);
}
last_download_thread_ = 0;
// Restore context now that thread creation is complete
ctx->makeCurrent(old_surface);
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(format_, effective_width_, effective_height_));
started_ = true;
}
void RenderManager::Stop()
{
if (!started_) {
return;
}
started_ = false;
foreach (RendererDownloadThreadPtr download_thread_, download_threads_) {
download_thread_->Cancel();
}
download_threads_.clear();
foreach (RendererProcessThreadPtr process_thread, threads_) {
process_thread->Cancel();
}
threads_.clear();
cache_frame_load_buffer_.clear();
}
void RenderManager::GenerateCacheIDInternal()
{
if (cache_name_.isEmpty() || effective_width_ == 0 || effective_height_ == 0) {
return;
}
// Generate an ID that is more or less guaranteed to be unique to this Sequence
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(cache_name_.toUtf8());
hash.addData(QString::number(cache_time_).toUtf8());
hash.addData(QString::number(width_).toUtf8());
hash.addData(QString::number(height_).toUtf8());
hash.addData(QString::number(format_).toUtf8());
hash.addData(QString::number(divider_).toUtf8());
QByteArray bytes = hash.result();
cache_id_ = bytes.toHex();
}
void RenderManager::CacheNext()
{
if (texture_input_ == nullptr || cache_queue_.isEmpty() || !texture_input_->IsConnected() || caching_) {
return;
}
// Make sure cache has started
Start();
rational cache_frame = cache_queue_.takeFirst();
qDebug() << "Caching" << cache_frame.toDouble();
threads_.first()->Queue(NodeDependency(texture_input_->get_connected_output(), cache_frame), true, false);
caching_ = true;
}
QString RenderManager::CachePathName(const QByteArray &hash)
{
QDir this_cache_dir = QDir(GetMediaCacheLocation()).filePath(cache_id_);
this_cache_dir.mkpath(".");
QString filename = QString("%1.exr").arg(QString(hash.toHex()));
return this_cache_dir.filePath(filename);
}
void RenderManager::DeferMap(const rational &time, const QByteArray &hash)
{
deferred_maps_.append({time, hash});
}
bool RenderManager::HasHash(const QByteArray &hash)
{
return QFileInfo::exists(CachePathName(hash));
}
bool RenderManager::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 RenderManager::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 RenderManager::RetrieveImage(RenderTexturePtr destination_texture, const rational &time)
{
if (cache_id_.isEmpty()) {
qWarning() << "RendererProcessor has no cache ID";
return;
}
if (timebase_.isNull()) {
qWarning() << "RendererProcessor has no timebase";
return;
}
// Find frame in map
if (time_hash_map_.contains(time)) {
QString fn = CachePathName(time_hash_map_[time]);
if (QFileInfo::exists(fn)) {
auto in = OIIO::ImageInput::open(fn.toStdString());
if (in) {
in->read_image(PixelService::GetPixelFormatInfo(format_).oiio_desc, cache_frame_load_buffer_.data());
in->close();
destination_texture->Upload(cache_frame_load_buffer_.data());
} else {
qWarning() << "OIIO Error:" << OIIO::geterror().c_str();
}
}
}
}
void RenderManager::CalculateEffectiveDimensions()
{
effective_width_ = width_ / divider_;
effective_height_ = height_ / divider_;
}
void RenderManager::ThreadCallback(RenderTexturePtr texture, const rational& time, const QByteArray& hash)
{
// Threads are all done now, time to proceed
caching_ = false;
DeferMap(time, hash);
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);
last_download_thread_++;
} else {
// There was no texture here, we must update the viewer
DownloadThreadComplete(hash);
}
emit FrameReadyWithTexture(time, texture);
CacheNext();
}
void RenderManager::ThreadRequestSibling(NodeDependency dep)
{
// Try to queue another thread to run this dep in advance
for (int i=1;i<threads_.size();i++) {
if (threads_.at(i)->Queue(dep, false, true)) {
return;
}
}
}
void RenderManager::ThreadSkippedFrame(const rational& time, const QByteArray& hash)
{
caching_ = false;
DeferMap(time, hash);
if (!IsCaching(hash)) {
DownloadThreadComplete(hash);
// Signal output to update value
emit FrameReady(time);
}
CacheNext();
}
void RenderManager::DownloadThreadComplete(const QByteArray &hash)
{
cache_hash_list_mutex_.lock();
cache_hash_list_.removeAll(hash);
cache_hash_list_mutex_.unlock();
for (int i=0;i<deferred_maps_.size();i++) {
const HashTimeMapping& deferred = deferred_maps_.at(i);
if (deferred_maps_.at(i).hash == hash) {
// Insert into hash map
time_hash_map_.insert(deferred.time, deferred.hash);
deferred_maps_.removeAt(i);
i--;
}
}
}
RendererThreadBase* RenderManager::CurrentThread()
{
return dynamic_cast<RendererThreadBase*>(QThread::currentThread());
}
RenderInstance *RenderManager::CurrentInstance()
{
RendererThreadBase* thread = CurrentThread();
if (thread != nullptr) {
return thread->render_instance();
}
return nullptr;
}
@@ -0,0 +1,218 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef RENDERMANAGER_H
#define RENDERMANAGER_H
#include <QLinkedList>
#include <QOpenGLTexture>
#include "node/node.h"
#include "render/pixelformat.h"
#include "render/rendermodes.h"
#include "rendererdownloadthread.h"
#include "rendererprocessthread.h"
/**
* @brief A multithreaded OpenGL based renderer for node systems
*/
class RenderManager : public QObject
{
Q_OBJECT
public:
/**
* @brief Renderer Constructor
*
* Constructing a Renderer object will not start any threads/backend on its own. Use Start() to do this and Stop()
* when the Renderer is about to be destroyed.
*/
RenderManager();
static void CreateInstance();
static void DestroyInstance();
static RenderManager* instance();
void SetCacheName(const QString& s);
void SetTimebase(const rational& timebase);
void InvalidateCache(const rational &start_range, const rational &end_range, const rational &last_requested_time);
/**
* @brief Set parameters of the Renderer
*
* The Renderer owns the buffers that are used in the rendering process and this function sets the kind of buffers
* to use. The Renderer must be stopped when calling this function.
*
* @param width
*
* Buffer width
*
* @param height
*
* Buffer height
*
* @param format
*
* Buffer pixel format
*/
void SetParameters(const int& width,
const int& height,
const olive::PixelFormat& format,
const olive::RenderMode& mode,
NodeInput *input,
const int &divider = 0);
void SetDivider(const int& divider);
/**
* @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 Retrieve the cached frame at `time` and upload it to `destination_texture`
*/
void RetrieveImage(RenderTexturePtr destination_texture, const rational& time);
/**
* @brief Allocate and start the multithreaded backend
*/
void Start();
/**
* @brief Terminate and deallocate the multithreaded backend
*/
void Stop();
/**
* @brief Return current instance of a RenderThread (or nullptr if there is none)
*
* This function attempts a dynamic_cast on QThread::currentThread() to RendererThread, which will return nullptr if
* the cast fails (e.g. if this function is called from the main thread rather than a RendererThread).
*/
static RendererThreadBase* CurrentThread();
static RenderInstance* CurrentInstance();
signals:
void FrameReady(rational time);
void FrameReadyWithTexture(rational time, RenderTexturePtr texture);
private:
static RenderManager* instance_;
struct HashTimeMapping {
rational time;
QByteArray hash;
};
/**
* @brief Internal function for generating the cache ID
*/
void GenerateCacheIDInternal();
/**
* @brief Function called when there are frames in the queue to cache
*
* This function is NOT thread-safe and should only be called in the main thread.
*/
void CacheNext();
bool ShouldPushTexture(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);
/**
* @brief Internal list of RenderProcessThreads
*/
QVector<RendererProcessThreadPtr> threads_;
/**
* @brief Internal variable that contains whether the Renderer has started or not
*/
bool started_;
int width_;
int height_;
void CalculateEffectiveDimensions();
int divider_;
int effective_width_;
int effective_height_;
olive::PixelFormat format_;
olive::RenderMode mode_;
rational timebase_;
double timebase_dbl_;
QLinkedList<rational> cache_queue_;
QString cache_name_;
qint64 cache_time_;
QString cache_id_;
bool caching_;
QVector<uchar*> cache_frame_load_buffer_;
QVector<RendererDownloadThreadPtr> download_threads_;
int last_download_thread_;
QMap<rational, QByteArray> time_hash_map_;
QMutex cache_hash_list_mutex_;
QVector<QByteArray> cache_hash_list_;
QList<HashTimeMapping> deferred_maps_;
NodeInput* texture_input_;
private slots:
void ThreadCallback(RenderTexturePtr texture, const rational& time, const QByteArray& hash);
void ThreadRequestSibling(NodeDependency dep);
void ThreadSkippedFrame(const rational &time, const QByteArray &hash);
void DownloadThreadComplete(const QByteArray &hash);
};
#endif // RENDERMANAGER_H