proxy: cleaned up, re-use the render cache's disk save system for proxies, multithreaded compression
This commit is contained in:
@@ -263,17 +263,12 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
|
||||
return TimeRange(frame_range.in(), frame_range.in());
|
||||
}
|
||||
|
||||
void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, qint64 job_time, QByteArray hash, bool texture_existed)
|
||||
void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, qint64 job_time, QByteArray hash)
|
||||
{
|
||||
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
|
||||
|
||||
SetFrameHash(dep, hash, job_time);
|
||||
|
||||
// Register frame with the disk manager
|
||||
if (texture_existed && operating_mode_ & VideoRenderWorker::kDownloadOnly) {
|
||||
DiskManager::instance()->CreatedFile(frame_cache()->CachePathName(hash, params_.format()), hash);
|
||||
}
|
||||
|
||||
QList<rational> hashes_with_time = frame_cache()->FramesWithHash(hash);
|
||||
|
||||
foreach (const rational& t, hashes_with_time) {
|
||||
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
bool pop_toggle_;
|
||||
|
||||
private slots:
|
||||
void ThreadCompletedDownload(NodeDependency dep, qint64 job_time, QByteArray hash, bool texture_existed);
|
||||
void ThreadCompletedDownload(NodeDependency dep, qint64 job_time, QByteArray hash);
|
||||
void ThreadSkippedFrame(NodeDependency dep, qint64 job_time, QByteArray hash);
|
||||
void ThreadHashAlreadyExists(NodeDependency dep, qint64 job_time, QByteArray hash);
|
||||
void ThreadGeneratedFrame();
|
||||
|
||||
@@ -20,10 +20,16 @@
|
||||
|
||||
#include "videorenderframecache.h"
|
||||
|
||||
#include <OpenEXR/ImfFloatAttribute.h>
|
||||
#include <OpenEXR/ImfInputFile.h>
|
||||
#include <OpenEXR/ImfOutputFile.h>
|
||||
#include <OpenEXR/ImfChannelList.h>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "codec/frame.h"
|
||||
#include "common/filefunctions.h"
|
||||
#include "render/diskmanager.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -139,25 +145,126 @@ const QMap<rational, QByteArray> &VideoRenderFrameCache::time_hash_map() const
|
||||
return time_hash_map_;
|
||||
}
|
||||
|
||||
QString VideoRenderFrameCache::GetFormatExtension(const PixelFormat::Format &f)
|
||||
{
|
||||
if (PixelFormat::FormatIsFloat(f)) {
|
||||
return QStringLiteral(".exr");
|
||||
} else {
|
||||
return QStringLiteral(".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
void VideoRenderFrameCache::SaveCacheFrame(const QByteArray& hash,
|
||||
char* data,
|
||||
const VideoRenderingParams& vparam) const
|
||||
{
|
||||
QString fn = CachePathName(hash, vparam.format());
|
||||
|
||||
if (SaveCacheFrame(fn, data, vparam)) {
|
||||
// Register frame with the disk manager
|
||||
DiskManager::instance()->CreatedFile(fn, hash);
|
||||
}
|
||||
}
|
||||
|
||||
QString VideoRenderFrameCache::CachePathName(const QByteArray& hash, const PixelFormat::Format& pix_fmt) const
|
||||
{
|
||||
QString ext;
|
||||
|
||||
if (pix_fmt == PixelFormat::PIX_FMT_RGB8
|
||||
|| pix_fmt == PixelFormat::PIX_FMT_RGBA8
|
||||
|| pix_fmt == PixelFormat::PIX_FMT_RGB16U
|
||||
|| pix_fmt == PixelFormat::PIX_FMT_RGBA16U) {
|
||||
ext = QStringLiteral("jpg");
|
||||
} else {
|
||||
ext = QStringLiteral("exr");
|
||||
}
|
||||
QString ext = GetFormatExtension(pix_fmt);
|
||||
|
||||
QDir cache_dir(QDir(FileFunctions::GetMediaCacheLocation()).filePath(QString(hash.left(1).toHex())));
|
||||
cache_dir.mkpath(".");
|
||||
|
||||
QString filename = QStringLiteral("%1.%2").arg(QString(hash.mid(1).toHex()), ext);
|
||||
QString filename = QStringLiteral("%1%2").arg(QString(hash.mid(1).toHex()), ext);
|
||||
|
||||
return cache_dir.filePath(filename);
|
||||
}
|
||||
|
||||
bool VideoRenderFrameCache::SaveCacheFrame(const QString &filename, char *data, const VideoRenderingParams &vparam)
|
||||
{
|
||||
switch (vparam.format()) {
|
||||
case PixelFormat::PIX_FMT_RGB8:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_RGB16U:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
{
|
||||
// Integer types are stored in JPEG which we run through OIIO
|
||||
|
||||
std::string fn_std = filename.toStdString();
|
||||
|
||||
auto out = OIIO::ImageOutput::create(fn_std);
|
||||
|
||||
if (out) {
|
||||
// Attempt to keep this write to one thread
|
||||
out->threads(1);
|
||||
|
||||
out->open(fn_std, OIIO::ImageSpec(vparam.width(),
|
||||
vparam.height(),
|
||||
PixelFormat::ChannelCount(vparam.format()),
|
||||
PixelFormat::GetOIIOTypeDesc(vparam.format())));
|
||||
|
||||
out->write_image(PixelFormat::GetOIIOTypeDesc(vparam.format()), data);
|
||||
|
||||
out->close();
|
||||
|
||||
#if OIIO_VERSION < 10903
|
||||
OIIO::ImageOutput::destroy(out);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
} else {
|
||||
qCritical() << "Failed to write JPEG file:" << OIIO::geterror().c_str();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case PixelFormat::PIX_FMT_RGB16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGB32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
{
|
||||
// Floating point types are stored in EXR
|
||||
Imf::PixelType pix_type;
|
||||
|
||||
if (vparam.format() == PixelFormat::PIX_FMT_RGB16F
|
||||
|| vparam.format() == PixelFormat::PIX_FMT_RGBA16F) {
|
||||
pix_type = Imf::HALF;
|
||||
} else {
|
||||
pix_type = Imf::FLOAT;
|
||||
}
|
||||
|
||||
Imf::Header header(vparam.effective_width(),
|
||||
vparam.effective_height());
|
||||
header.channels().insert("R", Imf::Channel(pix_type));
|
||||
header.channels().insert("G", Imf::Channel(pix_type));
|
||||
header.channels().insert("B", Imf::Channel(pix_type));
|
||||
header.channels().insert("A", Imf::Channel(pix_type));
|
||||
|
||||
header.compression() = Imf::DWAA_COMPRESSION;
|
||||
header.insert("dwaCompressionLevel", Imf::FloatAttribute(200.0f));
|
||||
|
||||
Imf::OutputFile out(filename.toUtf8(), header, 0);
|
||||
|
||||
int bpc = PixelFormat::BytesPerChannel(vparam.format());
|
||||
|
||||
size_t xs = kRGBAChannels * bpc;
|
||||
size_t ys = vparam.effective_width() * kRGBAChannels * bpc;
|
||||
|
||||
Imf::FrameBuffer framebuffer;
|
||||
framebuffer.insert("R", Imf::Slice(pix_type, data, xs, ys));
|
||||
framebuffer.insert("G", Imf::Slice(pix_type, data + bpc, xs, ys));
|
||||
framebuffer.insert("B", Imf::Slice(pix_type, data + 2*bpc, xs, ys));
|
||||
framebuffer.insert("A", Imf::Slice(pix_type, data + 3*bpc, xs, ys));
|
||||
out.setFrameBuffer(framebuffer);
|
||||
|
||||
out.writePixels(vparam.effective_height());
|
||||
|
||||
return true;
|
||||
}
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
qCritical() << "Unable to cache invalid pixel format" << vparam.format();
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "render/pixelformat.h"
|
||||
#include "render/videoparams.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -50,11 +51,6 @@ public:
|
||||
*/
|
||||
bool TryCache(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Return the path of the cached image at this time
|
||||
*/
|
||||
QString CachePathName(const QByteArray &hash, const PixelFormat::Format& pix_fmt) const;
|
||||
|
||||
void SetCacheID(const QString& id);
|
||||
|
||||
QByteArray TimeToHash(const rational& time) const;
|
||||
@@ -77,6 +73,16 @@ public:
|
||||
|
||||
const QMap<rational, QByteArray>& time_hash_map() const;
|
||||
|
||||
static QString GetFormatExtension(const PixelFormat::Format& f);
|
||||
|
||||
/**
|
||||
* @brief Return the path of the cached image at this time
|
||||
*/
|
||||
QString CachePathName(const QByteArray &hash, const PixelFormat::Format& pix_fmt) const;
|
||||
|
||||
static bool SaveCacheFrame(const QString& filename, char *data, const VideoRenderingParams &vparam);
|
||||
void SaveCacheFrame(const QByteArray& hash, char *data, const VideoRenderingParams &vparam) const;
|
||||
|
||||
private:
|
||||
QMap<rational, QByteArray> time_hash_map_;
|
||||
|
||||
|
||||
@@ -20,11 +20,6 @@
|
||||
|
||||
#include "videorenderworker.h"
|
||||
|
||||
#include <OpenEXR/ImfFloatAttribute.h>
|
||||
#include <OpenEXR/ImfInputFile.h>
|
||||
#include <OpenEXR/ImfOutputFile.h>
|
||||
#include <OpenEXR/ImfChannelList.h>
|
||||
|
||||
#include "common/define.h"
|
||||
#include "common/functiontimer.h"
|
||||
#include "node/block/transition/transition.h"
|
||||
@@ -84,7 +79,7 @@ NodeValueTable VideoRenderWorker::RenderInternal(const NodeDependency& path, con
|
||||
if (!(operating_mode_ & kRenderOnly)) {
|
||||
|
||||
// Emit only the hash
|
||||
emit CompletedDownload(path, job_time, hash, false);
|
||||
emit CompletedDownload(path, job_time, hash);
|
||||
|
||||
} else if ((operating_mode_ & kHashOnly) && frame_cache_->HasHash(hash, video_params_.format())) {
|
||||
|
||||
@@ -101,14 +96,14 @@ NodeValueTable VideoRenderWorker::RenderInternal(const NodeDependency& path, con
|
||||
|
||||
// If we actually have a texture, download it into the disk cache
|
||||
if (!texture.isNull() || (!(operating_mode_ & kDownloadOnly))) {
|
||||
Download(path.in(), texture, frame_cache_->CachePathName(hash, video_params_.format()));
|
||||
Download(hash, path.in(), texture);
|
||||
}
|
||||
|
||||
frame_cache_->RemoveHashFromCurrentlyCaching(hash);
|
||||
|
||||
// Signal that this job is complete
|
||||
if (operating_mode_ & kDownloadOnly) {
|
||||
emit CompletedDownload(path, job_time, hash, !texture.isNull());
|
||||
emit CompletedDownload(path, job_time, hash);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -162,92 +157,17 @@ void VideoRenderWorker::CloseInternal()
|
||||
download_buffer_.clear();
|
||||
}
|
||||
|
||||
void VideoRenderWorker::Download(const rational& time, QVariant texture, QString filename)
|
||||
void VideoRenderWorker::Download(const QByteArray& hash, const rational& time, QVariant texture)
|
||||
{
|
||||
if (operating_mode_ & kDownloadOnly) {
|
||||
|
||||
TextureToBuffer(texture, download_buffer_.data(), 0);
|
||||
|
||||
switch (video_params().format()) {
|
||||
case PixelFormat::PIX_FMT_RGB8:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_RGB16U:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
{
|
||||
// Integer types are stored in JPEG which we run through OIIO
|
||||
|
||||
std::string fn_std = filename.toStdString();
|
||||
|
||||
auto out = OIIO::ImageOutput::create(fn_std);
|
||||
|
||||
if (out) {
|
||||
// Attempt to keep this write to one thread
|
||||
out->threads(1);
|
||||
|
||||
out->open(fn_std, OIIO::ImageSpec(video_params().effective_width(),
|
||||
video_params().effective_height(),
|
||||
PixelFormat::ChannelCount(video_params().format()),
|
||||
PixelFormat::GetOIIOTypeDesc(video_params().format())));
|
||||
|
||||
out->write_image(PixelFormat::GetOIIOTypeDesc(video_params().format()), download_buffer_.data());
|
||||
|
||||
out->close();
|
||||
|
||||
#if OIIO_VERSION < 10903
|
||||
OIIO::ImageOutput::destroy(out);
|
||||
#endif
|
||||
} else {
|
||||
qCritical() << "Failed to write JPEG file:" << OIIO::geterror().c_str();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PixelFormat::PIX_FMT_RGB16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGB32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
{
|
||||
// Floating point types are stored in EXR
|
||||
Imf::PixelType pix_type;
|
||||
|
||||
if (video_params().format() == PixelFormat::PIX_FMT_RGB16F
|
||||
|| video_params().format() == PixelFormat::PIX_FMT_RGBA16F) {
|
||||
pix_type = Imf::HALF;
|
||||
} else {
|
||||
pix_type = Imf::FLOAT;
|
||||
}
|
||||
|
||||
Imf::Header header(video_params().effective_width(),
|
||||
video_params().effective_height());
|
||||
header.channels().insert("R", Imf::Channel(pix_type));
|
||||
header.channels().insert("G", Imf::Channel(pix_type));
|
||||
header.channels().insert("B", Imf::Channel(pix_type));
|
||||
header.channels().insert("A", Imf::Channel(pix_type));
|
||||
|
||||
header.compression() = Imf::DWAA_COMPRESSION;
|
||||
header.insert("dwaCompressionLevel", Imf::FloatAttribute(200.0f));
|
||||
|
||||
Imf::OutputFile out(filename.toUtf8(), header, 0);
|
||||
|
||||
int bpc = PixelFormat::BytesPerChannel(video_params().format());
|
||||
|
||||
size_t xs = kRGBAChannels * bpc;
|
||||
size_t ys = video_params().effective_width() * kRGBAChannels * bpc;
|
||||
|
||||
Imf::FrameBuffer framebuffer;
|
||||
framebuffer.insert("R", Imf::Slice(pix_type, download_buffer_.data(), xs, ys));
|
||||
framebuffer.insert("G", Imf::Slice(pix_type, download_buffer_.data() + bpc, xs, ys));
|
||||
framebuffer.insert("B", Imf::Slice(pix_type, download_buffer_.data() + 2*bpc, xs, ys));
|
||||
framebuffer.insert("A", Imf::Slice(pix_type, download_buffer_.data() + 3*bpc, xs, ys));
|
||||
out.setFrameBuffer(framebuffer);
|
||||
|
||||
out.writePixels(video_params().effective_height());
|
||||
break;
|
||||
}
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
qCritical() << "Unable to cache invalid pixel format" << video_params().format();
|
||||
break;
|
||||
}
|
||||
frame_cache_->SaveCacheFrame(hash,
|
||||
download_buffer_.data(),
|
||||
VideoRenderingParams(video_params_.effective_width(),
|
||||
video_params_.effective_height(),
|
||||
video_params_.format()));
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
void SetFrameGenerationParams(int width, int height, const QMatrix4x4 &matrix);
|
||||
|
||||
signals:
|
||||
void CompletedDownload(NodeDependency path, qint64 job_time, QByteArray hash, bool texture_existed);
|
||||
void CompletedDownload(NodeDependency path, qint64 job_time, QByteArray hash);
|
||||
|
||||
void HashAlreadyBeingCached(NodeDependency path, qint64 job_time, QByteArray hash);
|
||||
|
||||
@@ -103,7 +103,7 @@ protected:
|
||||
ColorProcessorCache* color_cache();
|
||||
|
||||
private:
|
||||
void Download(const rational &time, QVariant texture, QString filename);
|
||||
void Download(const QByteArray &hash, const rational &time, QVariant texture);
|
||||
|
||||
void ResizeDownloadBuffer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user