Try to fix plugin issue

This commit is contained in:
2026-01-05 21:31:35 +08:00
parent 8ed5660faf
commit e37972b227
13 changed files with 858 additions and 31 deletions
+4
View File
@@ -162,7 +162,9 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt,
case PixelFormat::U16:
return AV_PIX_FMT_RGB48;
case PixelFormat::F16:
return AV_PIX_FMT_RGBF16;
case PixelFormat::F32:
return AV_PIX_FMT_RGBF32;
case PixelFormat::INVALID:
case PixelFormat::COUNT:
break;
@@ -174,7 +176,9 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt,
case PixelFormat::U16:
return AV_PIX_FMT_RGBA64;
case PixelFormat::F16:
return AV_PIX_FMT_RGBAF16;
case PixelFormat::F32:
return AV_PIX_FMT_RGBAF32;
case PixelFormat::INVALID:
case PixelFormat::COUNT:
break;
+27 -1
View File
@@ -204,6 +204,25 @@ olive::plugin::OliveClipInstance::getImage(OfxTime time,
return image;
}
}
std::shared_ptr<OFX::Host::ImageEffect::Image>
olive::plugin::OliveClipInstance::getOutputImage(OfxTime time)
{
if (images_.contains(time)) {
return images_.value(time);
}
OfxRectD rod_d = getRegionOfDefinition(time);
OfxRectI rod = { static_cast<int>(std::floor(rod_d.x1)),
static_cast<int>(std::floor(rod_d.y1)),
static_cast<int>(std::ceil(rod_d.x2)),
static_cast<int>(std::ceil(rod_d.y2)) };
OfxRectI bounds = rod;
auto image = std::make_shared<Image>(*this, params_, bounds, rod, true);
images_.insert(time, image);
return image;
}
OfxRectD
olive::plugin::OliveClipInstance::getRegionOfDefinition(OfxTime time) const
{
@@ -231,7 +250,14 @@ void olive::plugin::OliveClipInstance::setInputTexture(TexturePtr texture, OfxTi
if (!texture) {
return;
}
this->params_ = texture->params();
VideoParams incoming = texture->params();
if (params_.format() != PixelFormat::INVALID &&
params_.channel_count() > 0) {
incoming.set_format(params_.format());
incoming.set_channel_count(params_.channel_count());
incoming.set_premultiplied_alpha(params_.premultiplied_alpha());
}
this->params_ = incoming;
#ifdef OFX_SUPPORTS_OPENGLRENDER
input_textures_.insert(time, texture);
#endif
+1 -4
View File
@@ -44,10 +44,7 @@ public:
{
params_ = params;
}
std::shared_ptr<OFX::Host::ImageEffect::Image> getOutputImage(OfxTime time)
{
return images_[time];
}
std::shared_ptr<OFX::Host::ImageEffect::Image> getOutputImage(OfxTime time);
const std::string &getUnmappedBitDepth() const override;
const std::string &getUnmappedComponents() const override;
+10
View File
@@ -191,6 +191,16 @@ OfxStatus olive::plugin::OliveHost::vmessage(const char *type, const char *id, c
vsnprintf(buffer, sizeof(buffer), format, args);
QString message(buffer);
auto *app = qobject_cast<QApplication *>(QCoreApplication::instance());
if (!app) {
qWarning().noquote()
<< "OFX message:" << type << message;
if (strcmp(type, kOfxMessageQuestion) == 0) {
return kOfxStatReplyNo;
}
return kOfxStatOK;
}
if (strcmp(type, kOfxMessageQuestion) == 0) {
auto ret = QMessageBox::question(nullptr, "", message,
QMessageBox::Ok, QMessageBox::Cancel);
+14 -3
View File
@@ -32,6 +32,7 @@
#include <cstdio>
#include <QMessageBox>
#include <QCoreApplication>
#include <QApplication>
#include <qmessagebox.h>
#include <qobject.h>
#include <QtGlobal>
@@ -254,9 +255,6 @@ OFX::Host::Param::Instance *
OlivePluginInstance::newParam(const std::string &name,
OFX::Host::Param::Descriptor &desc)
{
if (!node_) {
return nullptr;
}
const std::string &type = desc.getType();
if (type == kOfxParamTypeInteger) {
@@ -372,6 +370,11 @@ void OlivePluginInstance::progressStart(const std::string &message,
progress_cancelled_ = false;
progress_active_ = true;
auto *app = qobject_cast<QApplication *>(QCoreApplication::instance());
if (!app) {
return;
}
if (progress_dialog_) {
progress_dialog_->close();
progress_dialog_->deleteLater();
@@ -482,5 +485,13 @@ OFX::Host::ImageEffect::ClipInstance *OlivePluginInstance::newClipInstance(
return clipInstance;
}
OlivePluginInstance::~OlivePluginInstance()
{
if (!QCoreApplication::instance() ||
qEnvironmentVariableIsSet("OAK_OFX_ITEST")) {
_created = false;
}
}
}
}
+5 -1
View File
@@ -67,7 +67,7 @@ public:
}
explicit OlivePluginInstance(Instance & instance):Instance(instance){};
~OlivePluginInstance() override = default;
~OlivePluginInstance() override;
const std::string &getDefaultOutputFielding() const override;
void setVideoParam(VideoParams params)
@@ -82,6 +82,10 @@ public:
{
open_gl_enabled_ = enabled;
}
bool isCreated() const
{
return _created;
}
OFX::Host::ImageEffect::ClipInstance *newClipInstance(
OFX::Host::ImageEffect::Instance *plugin,
OFX::Host::ImageEffect::ClipDescriptor *descriptor,
+332
View File
@@ -61,12 +61,18 @@ protected:
std::shared_ptr<PluginNode> _node;
OFX::Host::Param::Descriptor& _descriptor;
QString id;
bool has_value_ = false;
int value_ = 0;
public:
IntegerInstance(std::shared_ptr<PluginNode>node, OFX::Host::Param::Descriptor &descriptor)
: _node(node), _descriptor(descriptor),
OFX::Host::Param::IntegerInstance(_descriptor){}
OfxStatus get(int &a)
{
if (!_node) {
a = has_value_ ? value_ : 0;
return kOfxStatOK;
}
if (id.isEmpty()) {
return kOfxStatErrBadHandle;
}
@@ -81,6 +87,10 @@ public:
}
OfxStatus get(OfxTime time, int &data)
{
if (!_node) {
data = has_value_ ? value_ : 0;
return kOfxStatOK;
}
if (id.isEmpty()) {
return kOfxStatErrBadHandle;
}
@@ -94,6 +104,11 @@ public:
}
OfxStatus set(int data)
{
if (!_node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kInt, data);
@@ -105,6 +120,11 @@ public:
}
OfxStatus set(OfxTime time, int data)
{
if (!_node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
Node::SetValueAtTime(
NodeInput(_node.get(), _descriptor.getName().c_str()),
@@ -119,6 +139,8 @@ class DoubleInstance : public OFX::Host::Param::DoubleInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
double value_ = 0.0;
public:
DoubleInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::DoubleInstance(descriptor)
@@ -129,6 +151,10 @@ public:
}
OfxStatus get(double& data)
{
if (!node) {
data = has_value_ ? value_ : 0.0;
return kOfxStatOK;
}
QVariant variant = node->GetStandardValue(_descriptor.getName().c_str());
if (variant.canConvert<double>()) {
data = variant.toDouble();
@@ -139,6 +165,10 @@ public:
}
OfxStatus get(OfxTime time, double& data)
{
if (!node) {
data = has_value_ ? value_ : 0.0;
return kOfxStatOK;
}
QVariant variant =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time));
@@ -151,6 +181,11 @@ public:
}
OfxStatus set(double data)
{
if (!node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kFloat, data);
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -160,6 +195,11 @@ public:
}
OfxStatus set(OfxTime time, double data)
{
if (!node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
Node::SetValueAtTime(
NodeInput(node.get(), _descriptor.getName().c_str()),
@@ -181,6 +221,8 @@ class BooleanInstance : public OFX::Host::Param::BooleanInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
bool value_ = false;
public:
BooleanInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::BooleanInstance(descriptor)
@@ -191,6 +233,10 @@ public:
}
OfxStatus get(bool& data)
{
if (!node) {
data = has_value_ ? value_ : false;
return kOfxStatOK;
}
QVariant variant = node->GetStandardValue(_descriptor.getName().c_str());
if (variant.canConvert<bool>()) {
data = variant.toBool();
@@ -201,6 +247,10 @@ public:
}
OfxStatus get(OfxTime time, bool& data)
{
if (!node) {
data = has_value_ ? value_ : false;
return kOfxStatOK;
}
QVariant variant =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time));
@@ -213,6 +263,11 @@ public:
}
OfxStatus set(bool data)
{
if (!node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kBoolean, data);
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -222,6 +277,11 @@ public:
}
OfxStatus set(OfxTime time, bool data)
{
if (!node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
Node::SetValueAtTime(
NodeInput(node.get(), _descriptor.getName().c_str()),
@@ -235,6 +295,8 @@ class ChoiceInstance : public OFX::Host::Param::ChoiceInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
int value_ = 0;
public:
ChoiceInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::ChoiceInstance(descriptor)
@@ -245,6 +307,10 @@ public:
}
OfxStatus get(int& data)
{
if (!node) {
data = has_value_ ? value_ : 0;
return kOfxStatOK;
}
QVariant variant = node->GetStandardValue(_descriptor.getName().c_str());
if (variant.canConvert<int>()) {
data = variant.toInt();
@@ -255,6 +321,10 @@ public:
}
OfxStatus get(OfxTime time, int& data)
{
if (!node) {
data = has_value_ ? value_ : 0;
return kOfxStatOK;
}
QVariant variant =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time));
@@ -267,6 +337,11 @@ public:
}
OfxStatus set(int data)
{
if (!node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kCombo, data);
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -276,6 +351,11 @@ public:
}
OfxStatus set(OfxTime time, int data)
{
if (!node) {
value_ = data;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
Node::SetValueAtTime(
NodeInput(node.get(), _descriptor.getName().c_str()),
@@ -289,6 +369,8 @@ class RGBAInstance : public OFX::Host::Param::RGBAInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
double value_[4] = {0.0, 0.0, 0.0, 0.0};
public:
RGBAInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::RGBAInstance(descriptor)
@@ -299,6 +381,17 @@ public:
}
OfxStatus get(double& r,double& g,double& b,double& a)
{
if (!node) {
if (has_value_) {
r = value_[0];
g = value_[1];
b = value_[2];
a = value_[3];
} else {
r = g = b = a = 0.0;
}
return kOfxStatOK;
}
olive::core::Color c =
node->GetStandardValue(_descriptor.getName().c_str())
.value<olive::core::Color>();
@@ -311,6 +404,17 @@ public:
}
OfxStatus get(OfxTime time, double& r,double& g,double& b,double& a)
{
if (!node) {
if (has_value_) {
r = value_[0];
g = value_[1];
b = value_[2];
a = value_[3];
} else {
r = g = b = a = 0.0;
}
return kOfxStatOK;
}
olive::core::Color c =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time))
@@ -324,6 +428,14 @@ public:
}
OfxStatus set(double r,double g,double b,double a)
{
if (!node) {
value_[0] = r;
value_[1] = g;
value_[2] = b;
value_[3] = a;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kColor,
QVariant::fromValue(olive::core::Color(r, g, b, a)));
@@ -334,6 +446,14 @@ public:
}
OfxStatus set(OfxTime time, double r,double g,double b,double a)
{
if (!node) {
value_[0] = r;
value_[1] = g;
value_[2] = b;
value_[3] = a;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
const QString name = _descriptor.getName().c_str();
Node::SetValueAtTime(NodeInput(node.get(), name), rational::fromDouble(time),
@@ -354,6 +474,8 @@ class RGBInstance : public OFX::Host::Param::RGBInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
double value_[3] = {0.0, 0.0, 0.0};
public:
RGBInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::RGBInstance(descriptor)
@@ -364,6 +486,16 @@ public:
}
OfxStatus get(double& r,double& g,double& b)
{
if (!node) {
if (has_value_) {
r = value_[0];
g = value_[1];
b = value_[2];
} else {
r = g = b = 0.0;
}
return kOfxStatOK;
}
olive::core::Color c =
node->GetStandardValue(_descriptor.getName().c_str())
.value<olive::core::Color>();
@@ -375,6 +507,16 @@ public:
}
OfxStatus get(OfxTime time, double& r,double& g,double& b)
{
if (!node) {
if (has_value_) {
r = value_[0];
g = value_[1];
b = value_[2];
} else {
r = g = b = 0.0;
}
return kOfxStatOK;
}
olive::core::Color c =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time))
@@ -387,6 +529,13 @@ public:
}
OfxStatus set(double r,double g,double b)
{
if (!node) {
value_[0] = r;
value_[1] = g;
value_[2] = b;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kColor,
QVariant::fromValue(olive::core::Color(r, g, b)));
@@ -397,6 +546,13 @@ public:
}
OfxStatus set(OfxTime time, double r,double g,double b)
{
if (!node) {
value_[0] = r;
value_[1] = g;
value_[2] = b;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
const QString name = _descriptor.getName().c_str();
Node::SetValueAtTime(NodeInput(node.get(), name), rational::fromDouble(time),
@@ -414,6 +570,8 @@ class Double2DInstance : public OFX::Host::Param::Double2DInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
double value_[2] = {0.0, 0.0};
public:
Double2DInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::Double2DInstance(descriptor)
@@ -424,6 +582,15 @@ public:
}
OfxStatus get(double& x,double& y)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
} else {
x = y = 0.0;
}
return kOfxStatOK;
}
QVector2D vec =
node->GetStandardValue(_descriptor.getName().c_str())
.value<QVector2D>();
@@ -433,6 +600,15 @@ public:
}
OfxStatus get(OfxTime time,double& x,double& y)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
} else {
x = y = 0.0;
}
return kOfxStatOK;
}
QVector2D vec =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time))
@@ -443,6 +619,12 @@ public:
}
OfxStatus set(double x,double y)
{
if (!node) {
value_[0] = x;
value_[1] = y;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kVec2, QVector2D(x, y));
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -452,6 +634,12 @@ public:
}
OfxStatus set(OfxTime time,double x,double y)
{
if (!node) {
value_[0] = x;
value_[1] = y;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
const QString name = _descriptor.getName().c_str();
Node::SetValueAtTime(NodeInput(node.get(), name), rational::fromDouble(time),
@@ -467,6 +655,8 @@ class Integer2DInstance : public OFX::Host::Param::Integer2DInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
int value_[2] = {0, 0};
public:
Integer2DInstance(std::shared_ptr<PluginNode> effect, const std::string& name, OFX::Host::Param::Descriptor& descriptor)
: OFX::Host::Param::Integer2DInstance(descriptor)
@@ -477,6 +667,15 @@ public:
}
OfxStatus get(int& x,int& y)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
} else {
x = y = 0;
}
return kOfxStatOK;
}
QVector2D vec =
node->GetStandardValue(_descriptor.getName().c_str())
.value<QVector2D>();
@@ -486,6 +685,15 @@ public:
}
OfxStatus get(OfxTime time,int& x,int& y)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
} else {
x = y = 0;
}
return kOfxStatOK;
}
QVector2D vec =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time))
@@ -496,6 +704,12 @@ public:
}
OfxStatus set(int x,int y)
{
if (!node) {
value_[0] = x;
value_[1] = y;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kVec2, QVector2D(x, y));
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -505,6 +719,12 @@ public:
}
OfxStatus set(OfxTime time,int x,int y)
{
if (!node) {
value_[0] = x;
value_[1] = y;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
const QString name = _descriptor.getName().c_str();
Node::SetValueAtTime(NodeInput(node.get(), name), rational::fromDouble(time),
@@ -520,6 +740,8 @@ class Double3DInstance : public OFX::Host::Param::Double3DInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
double value_[3] = {0.0, 0.0, 0.0};
public:
Double3DInstance(std::shared_ptr<PluginNode> effect, const std::string& name,
OFX::Host::Param::Descriptor& descriptor)
@@ -531,6 +753,16 @@ public:
}
OfxStatus get(double& x,double& y,double& z)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
z = value_[2];
} else {
x = y = z = 0.0;
}
return kOfxStatOK;
}
QVector3D vec =
node->GetStandardValue(_descriptor.getName().c_str())
.value<QVector3D>();
@@ -541,6 +773,16 @@ public:
}
OfxStatus get(OfxTime time,double& x,double& y,double& z)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
z = value_[2];
} else {
x = y = z = 0.0;
}
return kOfxStatOK;
}
QVector3D vec =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time))
@@ -552,6 +794,13 @@ public:
}
OfxStatus set(double x,double y,double z)
{
if (!node) {
value_[0] = x;
value_[1] = y;
value_[2] = z;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kVec3, QVector3D(x, y, z));
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -561,6 +810,13 @@ public:
}
OfxStatus set(OfxTime time,double x,double y,double z)
{
if (!node) {
value_[0] = x;
value_[1] = y;
value_[2] = z;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
const QString name = _descriptor.getName().c_str();
Node::SetValueAtTime(NodeInput(node.get(), name),
@@ -578,6 +834,8 @@ class Integer3DInstance : public OFX::Host::Param::Integer3DInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
int value_[3] = {0, 0, 0};
public:
Integer3DInstance(std::shared_ptr<PluginNode> effect, const std::string& name,
OFX::Host::Param::Descriptor& descriptor)
@@ -589,6 +847,16 @@ public:
}
OfxStatus get(int& x,int& y,int& z)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
z = value_[2];
} else {
x = y = z = 0;
}
return kOfxStatOK;
}
QVector3D vec =
node->GetStandardValue(_descriptor.getName().c_str())
.value<QVector3D>();
@@ -599,6 +867,16 @@ public:
}
OfxStatus get(OfxTime time,int& x,int& y,int& z)
{
if (!node) {
if (has_value_) {
x = value_[0];
y = value_[1];
z = value_[2];
} else {
x = y = z = 0;
}
return kOfxStatOK;
}
QVector3D vec =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time))
@@ -610,6 +888,13 @@ public:
}
OfxStatus set(int x,int y,int z)
{
if (!node) {
value_[0] = x;
value_[1] = y;
value_[2] = z;
has_value_ = true;
return kOfxStatOK;
}
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kVec3, QVector3D(x, y, z));
auto command = new NodeParamSetSplitStandardValueCommand(
@@ -619,6 +904,13 @@ public:
}
OfxStatus set(OfxTime time,int x,int y,int z)
{
if (!node) {
value_[0] = x;
value_[1] = y;
value_[2] = z;
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
const QString name = _descriptor.getName().c_str();
Node::SetValueAtTime(NodeInput(node.get(), name),
@@ -636,6 +928,8 @@ class StringInstance : public OFX::Host::Param::StringInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
std::string value_;
public:
StringInstance(std::shared_ptr<PluginNode> effect, const std::string& name,
OFX::Host::Param::Descriptor& descriptor)
@@ -647,6 +941,10 @@ public:
}
OfxStatus get(std::string &data)
{
if (!node) {
data = has_value_ ? value_ : std::string();
return kOfxStatOK;
}
QVariant variant = node->GetStandardValue(_descriptor.getName().c_str());
if (variant.canConvert<QString>()) {
data = variant.toString().toStdString();
@@ -657,6 +955,10 @@ public:
}
OfxStatus get(OfxTime time, std::string &data)
{
if (!node) {
data = has_value_ ? value_ : std::string();
return kOfxStatOK;
}
QVariant variant =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time));
@@ -669,6 +971,11 @@ public:
}
OfxStatus set(const char *data)
{
if (!node) {
value_ = data ? data : "";
has_value_ = true;
return kOfxStatOK;
}
QString v = QString::fromUtf8(data);
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kText, v);
@@ -679,6 +986,11 @@ public:
}
OfxStatus set(OfxTime time, const char *data)
{
if (!node) {
value_ = data ? data : "";
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
Node::SetValueAtTime(
NodeInput(node.get(), _descriptor.getName().c_str()),
@@ -692,6 +1004,8 @@ class CustomInstance : public OFX::Host::Param::CustomInstance {
protected:
std::shared_ptr<PluginNode> node;
OFX::Host::Param::Descriptor& _descriptor;
bool has_value_ = false;
std::string value_;
public:
CustomInstance(std::shared_ptr<PluginNode> effect, const std::string& name,
OFX::Host::Param::Descriptor& descriptor)
@@ -703,6 +1017,10 @@ public:
}
OfxStatus get(std::string &data)
{
if (!node) {
data = has_value_ ? value_ : std::string();
return kOfxStatOK;
}
QVariant variant = node->GetStandardValue(_descriptor.getName().c_str());
if (variant.canConvert<QByteArray>()) {
data = variant.toByteArray().toStdString();
@@ -717,6 +1035,10 @@ public:
}
OfxStatus get(OfxTime time, std::string &data)
{
if (!node) {
data = has_value_ ? value_ : std::string();
return kOfxStatOK;
}
QVariant variant =
node->GetValueAtTime(_descriptor.getName().c_str(),
rational::fromDouble(time));
@@ -733,6 +1055,11 @@ public:
}
OfxStatus set(const char *data)
{
if (!node) {
value_ = data ? data : "";
has_value_ = true;
return kOfxStatOK;
}
QByteArray v = QByteArray(data);
SplitValue split = NodeValue::split_normal_value_into_track_values(
NodeValue::kBinary, v);
@@ -743,6 +1070,11 @@ public:
}
OfxStatus set(OfxTime time, const char *data)
{
if (!node) {
value_ = data ? data : "";
has_value_ = true;
return kOfxStatOK;
}
auto command = new MultiUndoCommand();
Node::SetValueAtTime(
NodeInput(node.get(), _descriptor.getName().c_str()),
+242 -22
View File
@@ -23,12 +23,14 @@
#include <cstdint>
#include <cstring>
#include <qtypes.h>
#include <QDebug>
#define GL_PREAMBLE //QMutexLocker __l(&global_opengl_mutex);
#include "pluginrenderer.h"
#include "pluginSupport/OliveClip.h"
#include "pluginSupport/OlivePluginInstance.h"
#include "common/ffmpegutils.h"
#include "ofxImageEffect.h"
#include "ofxhUtilities.h"
extern "C"{
#include <libavutil/pixfmt.h>
#include <libavutil/pixdesc.h>
@@ -67,6 +69,10 @@ static AVPixelFormat GetOfxAVPixelFormat(const OFX::Host::ImageEffect::Image &im
pix_fmt = AV_PIX_FMT_GRAY8;
} else if (pixel_format == olive::core::PixelFormat::U16) {
pix_fmt = AV_PIX_FMT_GRAY16LE;
} else if (pixel_format == olive::core::PixelFormat::F16) {
pix_fmt = AV_PIX_FMT_GRAYF16;
} else if (pixel_format == olive::core::PixelFormat::F32) {
pix_fmt = AV_PIX_FMT_GRAYF32;
}
}
@@ -88,7 +94,109 @@ static AVPixelFormat GetOfxAVPixelFormat(const OFX::Host::ImageEffect::Image &im
return pix_fmt;
}
static AVPixelFormat GetDestinationAVPixelFormat(const olive::VideoParams &params);
static bool ApplyClipPreferencesToParams(
const OFX::Host::ImageEffect::ClipInstance &clip,
olive::VideoParams *params)
{
if (!params) {
return false;
}
olive::core::PixelFormat format = olive::core::PixelFormat::INVALID;
const std::string &depth = clip.getPixelDepth();
if (depth == kOfxBitDepthByte) {
format = olive::core::PixelFormat::U8;
} else if (depth == kOfxBitDepthShort) {
format = olive::core::PixelFormat::U16;
} else if (depth == kOfxBitDepthHalf) {
format = olive::core::PixelFormat::F16;
} else if (depth == kOfxBitDepthFloat) {
format = olive::core::PixelFormat::F32;
}
int channels = 0;
const std::string &components = clip.getComponents();
if (components == kOfxImageComponentRGBA) {
channels = 4;
} else if (components == kOfxImageComponentRGB) {
channels = 3;
} else if (components == kOfxImageComponentAlpha) {
channels = 1;
}
if (format == olive::core::PixelFormat::INVALID || channels == 0) {
return false;
}
params->set_format(format);
params->set_channel_count(channels);
return true;
}
static olive::AVFramePtr create_avframe_from_ofx_image(OFX::Host::ImageEffect::Image &image)
{
void *data_ptr = image.getPointerProperty(kOfxImagePropData);
if (!data_ptr) {
qWarning().noquote() << "OFX output image missing data pointer";
return nullptr;
}
int bounds[4] = {0, 0, 0, 0};
image.getIntPropertyN(kOfxImagePropBounds, bounds, 4);
int width = bounds[2] - bounds[0];
int height = bounds[3] - bounds[1];
if (width <= 0 || height <= 0) {
qWarning().noquote()
<< "OFX output image has invalid bounds"
<< bounds[0] << bounds[1] << bounds[2] << bounds[3];
return nullptr;
}
int bytes_per_pixel = 0;
AVPixelFormat pix_fmt = GetOfxAVPixelFormat(image, &bytes_per_pixel);
if (pix_fmt == AV_PIX_FMT_NONE || bytes_per_pixel <= 0) {
qWarning().noquote()
<< "OFX output image has unsupported pixel format depth="
<< QString::fromStdString(image.getStringProperty(
kOfxImageEffectPropPixelDepth))
<< "components="
<< QString::fromStdString(
image.getStringProperty(kOfxImageEffectPropComponents));
return nullptr;
}
int row_bytes = image.getIntProperty(kOfxImagePropRowBytes);
if (row_bytes <= 0) {
row_bytes = width * bytes_per_pixel;
}
uint8_t *src = static_cast<uint8_t *>(data_ptr);
src += bounds[1] * row_bytes + bounds[0] * bytes_per_pixel;
olive::AVFramePtr frame = olive::CreateAVFramePtr();
frame->width = width;
frame->height = height;
frame->format = pix_fmt;
if (av_frame_get_buffer(frame.get(), 0) < 0) {
return nullptr;
}
const int copy_bytes = width * bytes_per_pixel;
for (int y = 0; y < height; ++y) {
std::memcpy(frame->data[0] + y * frame->linesize[0],
src + y * row_bytes,
copy_bytes);
}
return frame;
}
static olive::AVFramePtr create_avframe_from_ofx_image_with_params(
OFX::Host::ImageEffect::Image &image,
const olive::VideoParams &params)
{
void *data_ptr = image.getPointerProperty(kOfxImagePropData);
if (!data_ptr) {
@@ -103,9 +211,14 @@ static olive::AVFramePtr create_avframe_from_ofx_image(OFX::Host::ImageEffect::I
return nullptr;
}
int bytes_per_pixel = 0;
AVPixelFormat pix_fmt = GetOfxAVPixelFormat(image, &bytes_per_pixel);
if (pix_fmt == AV_PIX_FMT_NONE || bytes_per_pixel <= 0) {
AVPixelFormat pix_fmt = GetDestinationAVPixelFormat(params);
if (pix_fmt == AV_PIX_FMT_NONE) {
return nullptr;
}
const int bytes_per_pixel =
params.channel_count() * params.format().byte_count();
if (bytes_per_pixel <= 0) {
return nullptr;
}
@@ -146,6 +259,10 @@ static AVPixelFormat GetDestinationAVPixelFormat(const olive::VideoParams &param
pix_fmt = AV_PIX_FMT_GRAY8;
} else if (params.format() == olive::core::PixelFormat::U16) {
pix_fmt = AV_PIX_FMT_GRAY16LE;
} else if (params.format() == olive::core::PixelFormat::F16) {
pix_fmt = AV_PIX_FMT_GRAYF16;
} else if (params.format() == olive::core::PixelFormat::F32) {
pix_fmt = AV_PIX_FMT_GRAYF32;
}
}
return pix_fmt;
@@ -280,6 +397,48 @@ static olive::AVFramePtr ConvertFrameIfNeeded(olive::AVFramePtr src,
return dst;
}
static int LinesizeToPixels(const olive::VideoParams &params, int linesize_bytes)
{
const int bytes_per_pixel =
params.channel_count() * params.format().byte_count();
if (bytes_per_pixel <= 0) {
return 0;
}
return linesize_bytes / bytes_per_pixel;
}
static QString PluginIdForInstance(const OFX::Host::ImageEffect::Instance *instance)
{
if (!instance) {
return QStringLiteral("<null>");
}
auto *plugin = instance->getPlugin();
if (!plugin) {
return QStringLiteral("<unknown>");
}
return QString::fromStdString(plugin->getIdentifier());
}
static void LogOfxFailure(const char *action, OfxStatus stat,
const OFX::Host::ImageEffect::Instance *instance)
{
if (stat == kOfxStatOK || stat == kOfxStatReplyDefault) {
return;
}
qWarning().noquote()
<< "OFX action failed:" << action
<< "plugin=" << PluginIdForInstance(instance)
<< "status=" << OFX::StatStr(stat)
<< "(" << stat << ")";
}
static void MarkRenderFailure(olive::Texture *destination)
{
if (destination && destination->renderer()) {
destination->renderer()->ClearDestination(destination, 1.0, 0.0, 1.0, 1.0);
}
}
void olive::plugin::PluginRenderer::RenderPlugin(TexturePtr src, olive::plugin::PluginJob& job,
olive::Texture *destination,
olive::VideoParams destination_params,
@@ -295,6 +454,7 @@ void olive::plugin::PluginRenderer::RenderPlugin(TexturePtr src, olive::plugin::
destination && destination->renderer() && destination->id().isValid();
if (olive_instance) {
olive_instance->setOpenGLEnabled(use_opengl);
olive_instance->setVideoParam(destination_params);
}
// current render scale of 1
@@ -330,36 +490,40 @@ void olive::plugin::PluginRenderer::RenderPlugin(TexturePtr src, olive::plugin::
}
clip->setParams(destination_params);
OfxStatus stat;
stat = instance->createInstanceAction();
if(stat != kOfxStatOK && stat != kOfxStatReplyDefault) {
return;
OfxStatus stat = kOfxStatOK;
if (olive_instance && !olive_instance->isCreated()) {
stat = instance->createInstanceAction();
if(stat != kOfxStatOK && stat != kOfxStatReplyDefault) {
LogOfxFailure("createInstance", stat, instance);
MarkRenderFailure(destination);
return;
}
}
// call get region of interest on each of the inputs
OfxTime frame = 0;
clip->setRegionOfDefinition(regionOfDefinition, frame);
clip->setOutputTexture(destination, frame);
const NodeValueRow &values = job.GetValues();
const auto &clips = instance->getDescriptor().getClips();
std::map<std::string, TexturePtr> input_textures;
for (const auto &entry : clips) {
if (entry.first == kOfxImageEffectOutputClipName) {
continue;
}
OliveClipInstance *input_clip =
dynamic_cast<OliveClipInstance *>(instance->getClip(entry.first));
if (input_clip) {
QString clip_key = QString::fromStdString(entry.first);
TexturePtr input_tex = values.value(clip_key).toTexture();
if (!input_tex &&
entry.first == kOfxImageEffectSimpleSourceClipName) {
input_tex = values.value(kTextureInput).toTexture();
}
if (input_tex) {
input_clip->setInputTexture(input_tex, frame);
}
if (!input_clip) {
continue;
}
QString clip_key = QString::fromStdString(entry.first);
TexturePtr input_tex = values.value(clip_key).toTexture();
if (!input_tex &&
entry.first == kOfxImageEffectSimpleSourceClipName) {
input_tex = values.value(kTextureInput).toTexture();
}
if (input_tex) {
input_textures[entry.first] = input_tex;
input_clip->setInputTexture(input_tex, frame);
}
}
@@ -367,13 +531,40 @@ void olive::plugin::PluginRenderer::RenderPlugin(TexturePtr src, olive::plugin::
// the clip component/depth logic and caches away the components and depth.
bool ok = instance->getClipPreferences();
if (!ok) {
qWarning().noquote()
<< "OFX getClipPreferences failed for plugin="
<< PluginIdForInstance(instance);
MarkRenderFailure(destination);
return;
}
olive::VideoParams output_params = destination_params;
if (ApplyClipPreferencesToParams(*clip, &output_params)) {
clip->setParams(output_params);
}
for (const auto &entry : input_textures) {
OliveClipInstance *input_clip =
dynamic_cast<OliveClipInstance *>(instance->getClip(entry.first));
if (!input_clip) {
continue;
}
olive::VideoParams input_params = entry.second->params();
if (ApplyClipPreferencesToParams(*input_clip, &input_params)) {
input_clip->setParams(input_params);
}
input_clip->setInputTexture(entry.second, frame);
}
clip->setRegionOfDefinition(regionOfDefinition, frame);
clip->setOutputTexture(destination, frame);
stat = instance->beginRenderAction(0, numFramesToRender,
1.0, false, renderScale, true,
interactive);
if (stat != kOfxStatOK && stat != kOfxStatReplyDefault) {
LogOfxFailure("beginRender", stat, instance);
MarkRenderFailure(destination);
return;
}
@@ -392,19 +583,33 @@ void olive::plugin::PluginRenderer::RenderPlugin(TexturePtr src, olive::plugin::
std::map<OFX::Host::ImageEffect::ClipInstance *, OfxRectD> rois;
stat = instance->getRegionOfInterestAction(frame, renderScale,
regionOfInterest, rois);
assert(stat == kOfxStatOK || stat == kOfxStatReplyDefault);
if (stat != kOfxStatOK && stat != kOfxStatReplyDefault) {
LogOfxFailure("getRegionOfInterest", stat, instance);
MarkRenderFailure(destination);
return;
}
// render a frame
const char *render_field = GetRenderFieldForParams(destination_params);
stat = instance->renderAction(0, render_field, renderWindow, renderScale,
true, interactive, interactive);
assert(stat == kOfxStatOK);
if (stat != kOfxStatOK && stat != kOfxStatReplyDefault) {
LogOfxFailure("render", stat, instance);
MarkRenderFailure(destination);
instance->endRenderAction(0, numFramesToRender, 1.0, interactive,
renderScale, true, interactive);
return;
}
// get the output image buffer (CPU path only)
std::shared_ptr<OFX::Host::ImageEffect::Image> output_image;
if (!use_opengl) {
output_image = clip->getOutputImage(frame);
if (!output_image) {
qWarning().noquote()
<< "OFX getOutputImage returned null for plugin="
<< PluginIdForInstance(instance);
MarkRenderFailure(destination);
instance->endRenderAction(frame, numFramesToRender, 1.0, interactive,
renderScale, true, interactive);
return;
@@ -424,12 +629,27 @@ void olive::plugin::PluginRenderer::RenderPlugin(TexturePtr src, olive::plugin::
if (!use_opengl) {
AVFramePtr frame_ptr = create_avframe_from_ofx_image(*output_image);
if (!frame_ptr) {
frame_ptr = create_avframe_from_ofx_image_with_params(
*output_image, output_params);
}
if (!frame_ptr) {
qWarning().noquote()
<< "OFX output image conversion failed for plugin="
<< PluginIdForInstance(instance);
instance->endRenderAction(0, numFramesToRender, 1.0, interactive,
renderScale, true, interactive);
return;
}
AVFramePtr converted = ConvertFrameIfNeeded(frame_ptr, destination_params);
destination->handleFrame(converted);
if (destination->renderer() && converted && converted->data[0]) {
int linesize_pixels =
LinesizeToPixels(destination_params, converted->linesize[0]);
if (linesize_pixels <= 0) {
linesize_pixels = destination_params.effective_width();
}
destination->Upload(converted->data[0], linesize_pixels);
}
} else {
AVFramePtr frame_ptr =
ReadbackTextureToFrame(destination, destination_params);