various changes to rendering flow and structure

This commit is contained in:
itsmattkc
2019-10-23 00:42:52 +11:00
parent 5f86b9b9c7
commit 7dec79ceaa
42 changed files with 663 additions and 888 deletions
+23 -69
View File
@@ -36,9 +36,6 @@
VideoRendererProcessor::VideoRendererProcessor(QObject *parent) :
QObject(parent),
started_(false),
width_(0),
height_(0),
divider_(1),
caching_(false),
push_time_(-1),
starting_(false),
@@ -63,7 +60,7 @@ void VideoRendererProcessor::SetCacheName(const QString &s)
void VideoRendererProcessor::InvalidateCache(const rational &start_range, const rational &end_range)
{
if (timebase_.isNull()) {
if (!params_.is_valid()) {
return;
}
@@ -78,11 +75,11 @@ void VideoRendererProcessor::InvalidateCache(const rational &start_range, const
// 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());
double start_range_numf = start_range_dbl * static_cast<double>(params_.time_base().denominator());
int64_t start_range_numround = qFloor(start_range_numf/static_cast<double>(params_.time_base().numerator())) * params_.time_base().numerator();
rational true_start_range(start_range_numround, params_.time_base().denominator());
for (rational r=true_start_range;r<=end_range_adj;r+=timebase_) {
for (rational r=true_start_range;r<=end_range_adj;r+=params_.time_base()) {
// Try to order the queue from closest to the playhead to furthest
rational last_time = last_time_requested_;
@@ -129,48 +126,14 @@ void VideoRendererProcessor::InvalidateCache(const rational &start_range, const
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)
void VideoRendererProcessor::SetParameters(const VideoRenderingParams& params)
{
// 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();
params_ = params;
// Regenerate the cache ID
GenerateCacheIDInternal();
@@ -193,7 +156,7 @@ void VideoRendererProcessor::Start()
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] = std::make_shared<RendererProcessThread>(this, ctx, params_);
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
@@ -221,7 +184,7 @@ void VideoRendererProcessor::Start()
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] = std::make_shared<VideoRendererDownloadThread>(ctx, params_);
download_threads_[i]->StartThread(QThread::LowPriority);
connect(download_threads_[i].get(),
@@ -238,14 +201,14 @@ void VideoRendererProcessor::Start()
// Create master texture (the one sent to the viewer)
master_texture_ = std::make_shared<RenderTexture>();
master_texture_->Create(ctx, effective_width_, effective_height_, format_);
master_texture_->Create(ctx, params_.effective_width(), params_.effective_height(), params_.format());
// Create internal FBO for copying textures
copy_buffer_.Create(ctx);
copy_buffer_.Attach(master_texture_);
copy_pipeline_ = olive::ShaderGenerator::DefaultPipeline();
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(format_, effective_width_, effective_height_));
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(params_.format(), params_.effective_width(), params_.effective_height()));
started_ = true;
}
@@ -277,7 +240,7 @@ void VideoRendererProcessor::Stop()
void VideoRendererProcessor::GenerateCacheIDInternal()
{
if (cache_name_.isEmpty() || effective_width_ == 0 || effective_height_ == 0) {
if (cache_name_.isEmpty() || !params_.is_valid()) {
return;
}
@@ -285,10 +248,10 @@ void VideoRendererProcessor::GenerateCacheIDInternal()
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());
hash.addData(QString::number(params_.width()).toUtf8());
hash.addData(QString::number(params_.height()).toUtf8());
hash.addData(QString::number(params_.format()).toUtf8());
hash.addData(QString::number(params_.divider()).toUtf8());
QByteArray bytes = hash.result();
cache_id_ = bytes.toHex();
@@ -307,7 +270,7 @@ void VideoRendererProcessor::CacheNext()
qDebug() << "Caching" << cache_frame.toDouble();
threads_.first()->Queue(NodeDependency(viewer_node_->texture_input()->get_connected_output(), cache_frame), true, false);
threads_.first()->Queue(NodeDependency(viewer_node_->texture_input()->get_connected_output(), cache_frame, cache_frame), true, false);
caching_ = true;
}
@@ -358,12 +321,6 @@ bool VideoRendererProcessor::TryCache(const QByteArray &hash)
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
@@ -485,12 +442,12 @@ RenderTexturePtr VideoRendererProcessor::GetCachedFrame(const rational &time)
}
if (cache_id_.isEmpty()) {
qWarning() << "RendererProcessor has no cache ID";
qWarning() << "No cache ID";
return nullptr;
}
if (timebase_.isNull()) {
qWarning() << "RendererProcessor has no timebase";
if (!params_.is_valid()) {
qWarning() << "Invalid parameters";
return nullptr;
}
@@ -502,7 +459,7 @@ RenderTexturePtr VideoRendererProcessor::GetCachedFrame(const rational &time)
auto in = OIIO::ImageInput::open(fn.toStdString());
if (in) {
in->read_image(PixelService::GetPixelFormatInfo(format_).oiio_desc, cache_frame_load_buffer_.data());
in->read_image(PixelService::GetPixelFormatInfo(params_.format()).oiio_desc, cache_frame_load_buffer_.data());
in->close();
@@ -529,10 +486,7 @@ void VideoRendererProcessor::SetViewerNode(ViewerOutput *viewer)
if (viewer_node_ != nullptr) {
connect(viewer_node_, SIGNAL(TextureChangedBetween(const rational&, const rational&)), this, SLOT(InvalidateCache(const rational&, const rational&)));
// FIXME: Hardcoded format and mode
SetParameters(viewer_node_->ViewerWidth(),
viewer_node_->ViewerHeight(),
olive::PIX_FMT_RGBA16F,
olive::kOffline);
// FIXME: Hardcoded format, mode, and divider
SetParameters(VideoRenderingParams(viewer_node_->video_params(), olive::PIX_FMT_RGBA16F, olive::kOffline, 2));
}
}
+2 -24
View File
@@ -49,8 +49,6 @@ public:
void SetCacheName(const QString& s);
void SetTimebase(const rational& timebase);
/**
* @brief Set parameters of the Renderer
*
@@ -69,13 +67,7 @@ public:
*
* 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);
void SetParameters(const VideoRenderingParams &params);
/**
* @brief Return whether a frame with this hash already exists
@@ -156,24 +148,10 @@ private:
*/
bool started_;
int width_;
int height_;
void CalculateEffectiveDimensions();
int divider_;
int effective_width_;
int effective_height_;
olive::PixelFormat format_;
olive::RenderMode mode_;
VideoRenderingParams params_;
rational last_time_requested_;
rational timebase_;
double timebase_dbl_;
QLinkedList<rational> cache_queue_;
QString cache_name_;
qint64 cache_time_;
@@ -8,12 +8,8 @@
#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),
const VideoRenderingParams& params) :
VideoRendererThreadBase(share_ctx, params),
cancelled_(false)
{
}
@@ -49,17 +45,17 @@ void VideoRendererDownloadThread::ProcessLoop()
DownloadQueueEntry entry;
int buffer_size = PixelService::GetBufferSize(render_instance()->format(),
render_instance()->width(),
render_instance()->height());
int buffer_size = PixelService::GetBufferSize(render_instance()->params().format(),
render_instance()->params().width(),
render_instance()->params().height());
QVector<uchar> data_buffer;
data_buffer.resize(buffer_size);
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(render_instance()->format());
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(render_instance()->params().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);
OIIO::ImageSpec spec(render_instance()->params().width(), render_instance()->params().height(), kRGBAChannels, format_info.oiio_desc);
spec.attribute("compression", "dwaa:200");
while (!cancelled_) {
@@ -8,11 +8,7 @@ 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);
const VideoRenderingParams &params);
void Queue(RenderTexturePtr texture, const QString &fn, const QByteArray &hash);
@@ -24,12 +24,8 @@
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),
const VideoRenderingParams &params) :
VideoRendererThreadBase(share_ctx, params),
parent_(parent),
cancelled_(false)
{
@@ -109,7 +105,7 @@ void RendererProcessThread::ProcessLoop()
// Check hash
QCryptographicHash hasher(QCryptographicHash::Sha1);
node_to_process->Hash(&hasher, output_to_process, path_.time());
node_to_process->Hash(&hasher, output_to_process, path_.in());
hash_ = hasher.result();
has_hash = parent_->HasHash(hash_);
@@ -120,7 +116,7 @@ void RendererProcessThread::ProcessLoop()
if ((can_cache = parent_->TryCache(hash_))) {
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.time());
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.in());
// Ask for other threads to run these deps while we're here
if (!deps.isEmpty()) {
@@ -130,7 +126,7 @@ void RendererProcessThread::ProcessLoop()
}
// Get the requested value
texture_ = output_to_process->get_value(path_.time(), path_.time()).value<RenderTexturePtr>();
texture_ = output_to_process->get_value(path_.in(), path_.in()).value<RenderTexturePtr>();
render_instance()->context()->functions()->glFinish();
}
@@ -146,10 +142,10 @@ void RendererProcessThread::ProcessLoop()
if (can_cache) {
// We cached this frame, signal that it will need to be downloaded to disk
emit CachedFrame(texture_, path_.time(), hash_);
emit CachedFrame(texture_, path_.in(), hash_);
} else {
// This hash already exists, no need to cache, just map it
emit FrameSkipped(path_.time(), hash_);
emit FrameSkipped(path_.in(), hash_);
}
}
}
@@ -31,10 +31,7 @@ class RendererProcessThread : public VideoRendererThreadBase
public:
RendererProcessThread(VideoRendererProcessor* parent,
QOpenGLContext* share_ctx,
const int& width,
const int& height, const int &divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode);
const VideoRenderingParams &params);
bool Queue(const NodeDependency &dep, bool wait, bool sibling);
+2 -2
View File
@@ -22,9 +22,9 @@
#include <QDebug>
VideoRendererThreadBase::VideoRendererThreadBase(QOpenGLContext *share_ctx, const int &width, const int &height, const int &divider, const olive::PixelFormat &format, const olive::RenderMode &mode) :
VideoRendererThreadBase::VideoRendererThreadBase(QOpenGLContext *share_ctx, const VideoRenderingParams &params) :
share_ctx_(share_ctx),
render_instance_(width, height, divider, format, mode)
render_instance_(params)
{
connect(share_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Cancel()));
}
+1 -6
View File
@@ -33,12 +33,7 @@ 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);
VideoRendererThreadBase(QOpenGLContext* share_ctx, const VideoRenderingParams& params);
RenderInstance* render_instance();