reimplemented export process

This commit is contained in:
itsmattkc
2020-11-13 22:05:43 +11:00
parent 8776bb9c4a
commit c9a8b96c89
31 changed files with 535 additions and 318 deletions
+3 -1
View File
@@ -70,8 +70,10 @@ private:
};
using ColorProcessorChain = QList<ColorProcessorPtr>;
using ColorProcessorChain = QVector<ColorProcessorPtr>;
OLIVE_NAMESPACE_EXIT
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::ColorProcessorPtr);
#endif // COLORPROCESSOR_H
-12
View File
@@ -36,16 +36,6 @@ public:
iterative_input_ = nullptr;
}
const QMatrix4x4& GetMatrix() const
{
return matrix_;
}
void SetMatrix(const QMatrix4x4& matrix)
{
matrix_ = matrix;
}
const QString& GetShaderID() const
{
return shader_id_;
@@ -101,8 +91,6 @@ private:
QHash<QString, Texture::Interpolation> interpolation_;
QMatrix4x4 matrix_;
};
OLIVE_NAMESPACE_EXIT
+3 -2
View File
@@ -431,8 +431,9 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video
static_cast<GLfloat>(destination_params.width()),
static_cast<GLfloat>(destination_params.height()));
// Set matrix to identity
shader->setUniformValue("ove_mvpmat", job.GetMatrix());
// Ensure matrix is set, at least to identity
shader->setUniformValue("ove_mvpmat",
job.GetValue(QStringLiteral("ove_mvpmat")).data.value<QMatrix4x4>());
// Set the viewport to the "physical" resolution of the destination
functions_->glViewport(0, 0,
+2 -1
View File
@@ -127,7 +127,8 @@ PixelFormat *PixelFormat::instance()
PixelFormat::Format PixelFormat::GetConfiguredFormatForMode(RenderMode::Mode mode)
{
return static_cast<PixelFormat::Format>(Core::GetPreferenceForRenderMode(mode, QStringLiteral("PixelFormat")).toInt());
return static_cast<PixelFormat::Format>(
Core::GetPreferenceForRenderMode(mode, QStringLiteral("PixelFormat")).toInt());
}
void PixelFormat::SetConfiguredFormatForMode(RenderMode::Mode mode, PixelFormat::Format format)
+8 -12
View File
@@ -23,7 +23,6 @@
#include <QFloat16>
#include "common/ocioutils.h"
#include "render/colormanager.h"
OLIVE_NAMESPACE_ENTER
@@ -57,14 +56,14 @@ TexturePtr Renderer::CreateTexture(const VideoParams &params, const void *data,
return CreateTexture(params, Texture::k2D, Texture::kRGBA, data, linesize);
}
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture *destination, bool flipped)
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture *destination, const QMatrix4x4 &matrix)
{
BlitColorManagedInternal(color_processor, source, destination, destination->params(), flipped);
BlitColorManagedInternal(color_processor, source, destination, destination->params(), matrix);
}
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params, bool flipped)
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params, const QMatrix4x4& matrix)
{
BlitColorManagedInternal(color_processor, source, nullptr, params, flipped);
BlitColorManagedInternal(color_processor, source, nullptr, params, matrix);
}
void Renderer::Destroy()
@@ -195,7 +194,7 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
}
}
void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source, Texture *destination, VideoParams params, bool flipped)
void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source, Texture *destination, VideoParams params, const QMatrix4x4& matrix)
{
ColorContext color_ctx;
if (!GetColorContext(color_processor, &color_ctx)) {
@@ -203,7 +202,10 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu
}
ShaderJob job;
job.InsertValue(QStringLiteral("ove_maintex"), ShaderValue(QVariant::fromValue(source), NodeParam::kTexture));
job.InsertValue(QStringLiteral("ove_mvpmat"), ShaderValue(matrix, NodeParam::kMatrix));
foreach (const ColorContext::LUT& l, color_ctx.lut3d_textures) {
job.InsertValue(l.name, ShaderValue(QVariant::fromValue(l.texture), NodeParam::kTexture));
job.SetInterpolation(l.name, l.interpolation);
@@ -213,12 +215,6 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu
job.SetInterpolation(l.name, l.interpolation);
}
if (flipped) {
QMatrix4x4 mat;
mat.scale(1, -1, 1);
job.SetMatrix(mat);
}
if (destination) {
BlitToTexture(color_ctx.compiled_shader, job, destination);
} else {
+3 -3
View File
@@ -60,8 +60,8 @@ public:
Blit(shader, job, nullptr, params);
}
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture* destination, bool flipped = false);
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params, bool flipped = false);
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, Texture* destination, const QMatrix4x4& matrix = QMatrix4x4());
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, VideoParams params, const QMatrix4x4& matrix = QMatrix4x4());
void Destroy();
@@ -108,7 +108,7 @@ private:
bool GetColorContext(ColorProcessorPtr color_processor, ColorContext* ctx);
void BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source,
Texture* destination, VideoParams params, bool flipped);
Texture* destination, VideoParams params, const QMatrix4x4 &matrix);
QHash<QString, ColorContext> color_cache_;
+42 -11
View File
@@ -56,8 +56,10 @@ RenderManager::RenderManager(QObject *parent) :
still_cache_ = new StillImageCache();
decoder_cache_ = new DecoderCache();
shader_cache_ = new ShaderCache();
default_shader_ = context_->CreateNativeShader(ShaderCode(QString(), QString()));
} else {
qCritical() << "Tried to initialize unknown graphics backend";
context_ = nullptr;
still_cache_ = nullptr;
decoder_cache_ = nullptr;
}
@@ -65,12 +67,16 @@ RenderManager::RenderManager(QObject *parent) :
RenderManager::~RenderManager()
{
delete shader_cache_;
delete decoder_cache_;
delete still_cache_;
if (context_) {
context_->DestroyNativeShader(default_shader_);
context_->Destroy();
delete context_;
delete shader_cache_;
delete decoder_cache_;
delete still_cache_;
context_->Destroy();
delete context_;
}
}
QByteArray RenderManager::Hash(const Node *n, const VideoParams &params, const rational &time)
@@ -93,19 +99,31 @@ QByteArray RenderManager::Hash(const Node *n, const VideoParams &params, const r
return hasher.result();
}
RenderTicketPtr RenderManager::RenderFrame(ViewerOutput *viewer, ColorManager *color_manager, const rational &time, RenderMode::Mode mode, FrameHashCache *cache, bool prioritize)
RenderTicketPtr RenderManager::RenderFrame(ViewerOutput* viewer, ColorManager* color_manager,
const rational& time, RenderMode::Mode mode,
FrameHashCache* cache, bool prioritize)
{
return RenderFrame(viewer,
color_manager,
time,
mode,
viewer->video_params(),
viewer->audio_params(),
QSize(0, 0),
QMatrix4x4(),
PixelFormat::PIX_FMT_INVALID,
nullptr,
cache,
prioritize);
}
RenderTicketPtr RenderManager::RenderFrame(ViewerOutput* viewer, ColorManager* color_manager, const rational &time, RenderMode::Mode mode, const QSize &force_size, const QMatrix4x4 &matrix, FrameHashCache *cache, bool prioritize)
RenderTicketPtr RenderManager::RenderFrame(ViewerOutput* viewer, ColorManager* color_manager,
const rational& time, RenderMode::Mode mode,
const VideoParams &video_params, const AudioParams &audio_params,
const QSize& force_size,
const QMatrix4x4& force_matrix, PixelFormat::Format force_format,
ColorProcessorPtr force_color_output,
FrameHashCache* cache, bool prioritize)
{
// Create ticket
RenderTicketPtr ticket = std::make_shared<RenderTicket>();
@@ -113,11 +131,18 @@ RenderTicketPtr RenderManager::RenderFrame(ViewerOutput* viewer, ColorManager* c
ticket->setProperty("viewer", Node::PtrToValue(viewer));
ticket->setProperty("time", QVariant::fromValue(time));
ticket->setProperty("size", force_size);
ticket->setProperty("matrix", matrix);
ticket->setProperty("matrix", force_matrix);
ticket->setProperty("format", force_format);
ticket->setProperty("mode", mode);
ticket->setProperty("type", kTypeVideo);
ticket->setProperty("cache", cache->GetCacheDirectory());
ticket->setProperty("colormanager", Node::PtrToValue(color_manager));
ticket->setProperty("coloroutput", QVariant::fromValue(force_color_output));
ticket->setProperty("vparam", QVariant::fromValue(video_params));
ticket->setProperty("aparam", QVariant::fromValue(audio_params));
if (cache) {
ticket->setProperty("cache", cache->GetCacheDirectory());
}
// Queue appending the ticket and running the next job on our thread to make this function thread-safe
QMetaObject::invokeMethod(this, "AddTicket", Qt::AutoConnection,
@@ -127,7 +152,12 @@ RenderTicketPtr RenderManager::RenderFrame(ViewerOutput* viewer, ColorManager* c
return ticket;
}
RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange &r, bool generate_waveforms, bool prioritize)
RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange& r, bool generate_waveforms, bool prioritize)
{
return RenderAudio(viewer, r, viewer->audio_params(), generate_waveforms, prioritize);
}
RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange &r, const AudioParams &params, bool generate_waveforms, bool prioritize)
{
// Create ticket
RenderTicketPtr ticket = std::make_shared<RenderTicket>();
@@ -136,6 +166,7 @@ RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange
ticket->setProperty("time", QVariant::fromValue(r));
ticket->setProperty("type", kTypeAudio);
ticket->setProperty("waveforms", generate_waveforms);
ticket->setProperty("aparam", QVariant::fromValue(params));
// Queue appending the ticket and running the next job on our thread to make this function thread-safe
QMetaObject::invokeMethod(this, "AddTicket", Qt::AutoConnection,
@@ -165,7 +196,7 @@ RenderTicketPtr RenderManager::SaveFrameToCache(FrameHashCache *cache, FramePtr
void RenderManager::RunTicket(RenderTicketPtr ticket) const
{
RenderProcessor::Process(ticket, context_, still_cache_, decoder_cache_, shader_cache_);
RenderProcessor::Process(ticket, context_, still_cache_, decoder_cache_, shader_cache_, default_shader_);
}
OLIVE_NAMESPACE_EXIT
+13 -2
View File
@@ -80,8 +80,16 @@ public:
*
* This function is thread-safe.
*/
RenderTicketPtr RenderFrame(ViewerOutput* viewer, ColorManager* color_manager, const rational& time, RenderMode::Mode mode, FrameHashCache* cache = nullptr, bool prioritize = false);
RenderTicketPtr RenderFrame(ViewerOutput* viewer, ColorManager* color_manager, const rational& time, RenderMode::Mode mode, const QSize& force_size, const QMatrix4x4& matrix, FrameHashCache* cache = nullptr, bool prioritize = false);
RenderTicketPtr RenderFrame(ViewerOutput* viewer, ColorManager* color_manager,
const rational& time, RenderMode::Mode mode,
FrameHashCache* cache = nullptr, bool prioritize = false);
RenderTicketPtr RenderFrame(ViewerOutput* viewer, ColorManager* color_manager,
const rational& time, RenderMode::Mode mode,
const VideoParams& video_params, const AudioParams& audio_params,
const QSize& force_size,
const QMatrix4x4& force_matrix, PixelFormat::Format force_format,
ColorProcessorPtr force_color_output,
FrameHashCache* cache = nullptr, bool prioritize = false);
/**
* @brief Asynchronously generate a chunk of audio
@@ -93,6 +101,7 @@ public:
*
* This function is thread-safe.
*/
RenderTicketPtr RenderAudio(ViewerOutput* viewer, const TimeRange& r, const AudioParams& params, bool generate_waveforms, bool prioritize = false);
RenderTicketPtr RenderAudio(ViewerOutput* viewer, const TimeRange& r, bool generate_waveforms, bool prioritize = false);
RenderTicketPtr SaveFrameToCache(FrameHashCache* cache, FramePtr frame, const QByteArray& hash, bool prioritize = false);
@@ -129,6 +138,8 @@ private:
ShaderCache* shader_cache_;
QVariant default_shader_;
};
OLIVE_NAMESPACE_EXIT
+48 -18
View File
@@ -29,12 +29,13 @@
OLIVE_NAMESPACE_ENTER
RenderProcessor::RenderProcessor(RenderTicketPtr ticket, Renderer *render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache *shader_cache) :
RenderProcessor::RenderProcessor(RenderTicketPtr ticket, Renderer *render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache *shader_cache, QVariant default_shader) :
ticket_(ticket),
render_ctx_(render_ctx),
still_image_cache_(still_image_cache),
decoder_cache_(decoder_cache),
shader_cache_(shader_cache)
shader_cache_(shader_cache),
default_shader_(default_shader)
{
}
@@ -49,14 +50,16 @@ void RenderProcessor::Run()
case RenderManager::kTypeVideo:
{
ViewerOutput* viewer = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"));
const VideoParams& video_params = ticket_->property("vparam").value<VideoParams>();
rational time = ticket_->property("time").value<rational>();
NodeValueTable table = ProcessInput(viewer->texture_input(),
TimeRange(time, time + viewer->video_params().time_base()));
TimeRange(time, time + video_params.time_base()));
TexturePtr texture = table.Get(NodeParam::kTexture).value<TexturePtr>();
VideoParams frame_params = viewer->video_params();
// Set up output frame parameters
VideoParams frame_params = ticket_->property("vparam").value<VideoParams>();
QSize frame_size = ticket_->property("size").value<QSize>();
if (!frame_size.isNull()) {
@@ -64,6 +67,11 @@ void RenderProcessor::Run()
frame_params.set_height(frame_size.height());
}
PixelFormat::Format frame_format = static_cast<PixelFormat::Format>(ticket_->property("format").toInt());
if (frame_format != PixelFormat::PIX_FMT_INVALID) {
frame_params.set_format(frame_format);
}
FramePtr frame = Frame::Create();
frame->set_timestamp(time);
frame->set_video_params(frame_params);
@@ -74,10 +82,31 @@ void RenderProcessor::Run()
memset(frame->data(), 0, frame->allocated_size());
} else {
// Dump texture contents to frame
ColorProcessorPtr output_color_transform = ticket_->property("coloroutput").value<ColorProcessorPtr>();
const VideoParams& tex_params = texture->params();
if (tex_params.width() != frame->width() || tex_params.height() != frame->height()) {
// FIXME: Blit this shit
if (tex_params.effective_width() != frame_params.effective_width()
|| tex_params.effective_height() != frame_params.effective_height()
|| tex_params.format() != frame_params.format()
|| output_color_transform) {
TexturePtr blit_tex = render_ctx_->CreateTexture(frame_params);
QMatrix4x4 matrix = ticket_->property("matrix").value<QMatrix4x4>();
if (output_color_transform) {
// Yes color transform, blit color managed
render_ctx_->BlitColorManaged(output_color_transform, texture, blit_tex.get(), matrix);
} else {
// No color transform, just blit
ShaderJob job;
job.InsertValue(QStringLiteral("ove_maintex"), {QVariant::fromValue(texture), NodeParam::kTexture});
job.InsertValue(QStringLiteral("ove_mvpmat"), {matrix, NodeParam::kMatrix});
render_ctx_->BlitToTexture(default_shader_, job, blit_tex.get());
}
// Replace texture that we're going to download in the next step
texture = blit_tex;
}
render_ctx_->DownloadFromTexture(texture.get(), frame->data(), frame->linesize_pixels());
@@ -138,9 +167,9 @@ DecoderPtr RenderProcessor::ResolveDecoderFromInput(StreamPtr stream)
return decoder;
}
void RenderProcessor::Process(RenderTicketPtr ticket, Renderer *render_ctx, StillImageCache *still_image_cache, DecoderCache *decoder_cache, ShaderCache *shader_cache)
void RenderProcessor::Process(RenderTicketPtr ticket, Renderer *render_ctx, StillImageCache *still_image_cache, DecoderCache *decoder_cache, ShaderCache *shader_cache, QVariant default_shader)
{
RenderProcessor p(ticket, render_ctx, still_image_cache, decoder_cache, shader_cache);
RenderProcessor p(ticket, render_ctx, still_image_cache, decoder_cache, shader_cache, default_shader);
p.Run();
}
@@ -148,7 +177,7 @@ NodeValueTable RenderProcessor::GenerateBlockTable(const TrackOutput *track, con
{
if (track->track_type() == Timeline::kTrackTypeAudio) {
const AudioParams& audio_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->audio_params();
const AudioParams& audio_params = ticket_->property("aparam").value<AudioParams>();
QList<Block*> active_blocks = track->BlocksAtTimeRange(range);
@@ -228,11 +257,13 @@ QVariant RenderProcessor::ProcessVideoFootage(StreamPtr stream, const rational &
// and color managing them for every frame is a waste of time, so we implement a small cache here
// to optimize such a situation
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(stream);
const VideoParams& video_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->video_params();
const VideoParams& video_params = ticket_->property("vparam").value<VideoParams>();
ColorManager* color_manager = Node::ValueToPtr<ColorManager>(ticket_->property("colormanager"));
StillImageCache::Entry want_entry = {nullptr,
stream,
ColorProcessor::GenerateID(Node::ValueToPtr<ColorManager>(ticket_->property("colormanager")), video_stream->colorspace(), ColorTransform(OCIO::ROLE_SCENE_LINEAR)),
ColorProcessor::GenerateID(color_manager, video_stream->colorspace(), color_manager->GetReferenceColorSpace()),
video_stream->premultiplied_alpha(),
video_params.divider(),
(video_stream->video_type() == VideoStream::kVideoTypeStill) ? 0 : input_time};
@@ -297,10 +328,9 @@ QVariant RenderProcessor::ProcessVideoFootage(StreamPtr stream, const rational &
qDebug() << "FIXME: Accessing video_stream->colorspace() may cause race conditions";
ColorManager* color_manager = Node::ValueToPtr<ColorManager>(ticket_->property("colormanager"));
ColorProcessorPtr processor = ColorProcessor::Create(color_manager,
video_stream->colorspace(),
ColorTransform(OCIO::ROLE_SCENE_LINEAR));
color_manager->GetReferenceColorSpace());
render_ctx_->BlitColorManaged(processor, unmanaged_texture, value.get());
@@ -327,7 +357,7 @@ QVariant RenderProcessor::ProcessAudioFootage(StreamPtr stream, const TimeRange
DecoderPtr decoder = ResolveDecoderFromInput(stream);
if (decoder) {
const AudioParams& audio_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->audio_params();
const AudioParams& audio_params = ticket_->property("aparam").value<AudioParams>();
SampleBufferPtr frame = decoder->RetrieveAudio(input_time, audio_params, &IsCancelled());
@@ -359,7 +389,7 @@ QVariant RenderProcessor::ProcessShader(const Node *node, const TimeRange &range
}
}
const VideoParams& video_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->video_params();
const VideoParams& video_params = ticket_->property("vparam").value<VideoParams>();
TexturePtr destination = render_ctx_->CreateTexture(video_params);
@@ -378,7 +408,7 @@ QVariant RenderProcessor::ProcessSamples(const Node *node, const TimeRange &rang
SampleBufferPtr output_buffer = SampleBuffer::CreateAllocated(job.samples()->audio_params(), job.samples()->sample_count());
NodeValueDatabase value_db;
const AudioParams& audio_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->audio_params();
const AudioParams& audio_params = ticket_->property("aparam").value<AudioParams>();
for (int i=0;i<job.samples()->sample_count();i++) {
// Calculate the exact rational time at this sample
@@ -416,7 +446,7 @@ QVariant RenderProcessor::ProcessFrameGeneration(const Node *node, const Generat
{
FramePtr frame = Frame::Create();
const VideoParams& video_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->video_params();
const VideoParams& video_params = ticket_->property("vparam").value<VideoParams>();
frame->set_video_params(video_params);
frame->allocate();
@@ -436,7 +466,7 @@ QVariant RenderProcessor::GetCachedFrame(const Node *node, const rational &time)
{
if (!ticket_->property("cache").toString().isEmpty()
&& node->id() == QStringLiteral("org.olivevideoeditor.Olive.videoinput")) {
const VideoParams& video_params = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"))->video_params();
const VideoParams& video_params = ticket_->property("vparam").value<VideoParams>();
QByteArray hash = RenderManager::Hash(node, video_params, time);
+4 -2
View File
@@ -32,7 +32,7 @@ OLIVE_NAMESPACE_ENTER
class RenderProcessor : public NodeTraverser
{
public:
static void Process(RenderTicketPtr ticket, Renderer* render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache* shader_cache);
static void Process(RenderTicketPtr ticket, Renderer* render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache* shader_cache, QVariant default_shader);
struct RenderedWaveform {
const TrackOutput* track;
@@ -56,7 +56,7 @@ protected:
virtual QVariant GetCachedFrame(const Node *node, const rational &time) override;
private:
RenderProcessor(RenderTicketPtr ticket, Renderer* render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache* shader_cache);
RenderProcessor(RenderTicketPtr ticket, Renderer* render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache* shader_cache, QVariant default_shader);
void Run();
@@ -72,6 +72,8 @@ private:
ShaderCache* shader_cache_;
QVariant default_shader_;
};
OLIVE_NAMESPACE_EXIT