Commit 8b0a5ea5 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix possible crash working with placeholder clips with speed effect

parent d5a972b0
Pipeline #108323 passed with stage
in 5 minutes and 21 seconds
......@@ -856,12 +856,27 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int trackId, int
chain->attach(link);
warpProducer.reset(chain);
} else {
QString url = QString("timewarp:%1:%2").arg(QString::fromStdString(std::to_string(speed)), resource);
QString url;
QString original_resource;
if (m_clipStatus == FileStatus::StatusMissing) {
url = QString("timewarp:%1:%2").arg(QString::fromStdString(std::to_string(speed)), QString("qtext"));
original_resource = originalProducer()->get("resource");
} else {
if (resource.endsWith(QLatin1String(":qtext"))) {
resource.replace(QLatin1String("qtext"), originalProducer()->get("warp_resource"));
}
url = QString("timewarp:%1:%2").arg(QString::fromStdString(std::to_string(speed)), resource);
}
warpProducer.reset(new Mlt::Producer(*originalProducer()->profile(), url.toUtf8().constData()));
int original_length = originalProducer()->get_length();
warpProducer->set("length", int(original_length / std::abs(speed) + 0.5));
qDebug() << "new producer: " << url;
qDebug() << "warp LENGTH before" << warpProducer->get_length();
int updated_length = int(original_length / std::abs(speed) + 0.5);
warpProducer->set("length", updated_length);
if (!original_resource.isEmpty()) {
// Don't lose original resource for placeholder clips
//warpProducer->set("warp_resource", original_resource.toUtf8().constData());
warpProducer->set("text", i18n("Invalid").toUtf8().constData());
}
}
// this is a workaround to cope with Mlt erroneous rounding
Mlt::Properties original(m_masterProducer->get_properties());
......@@ -901,7 +916,7 @@ std::pair<std::shared_ptr<Mlt::Producer>, bool> ProjectClip::giveMasterAndGetTim
// check whether it's a timewarp
double speed = 1.0;
bool timeWarp = false;
if (QString::fromUtf8(master->parent().get("mlt_service")) == QLatin1String("timewarp")) {
if (master->parent().property_exists("warp_speed")) {
speed = master->parent().get_double("warp_speed");
timeWarp = true;
} else if (master->parent().type() == mlt_service_chain_type) {
......@@ -927,6 +942,12 @@ std::pair<std::shared_ptr<Mlt::Producer>, bool> ProjectClip::giveMasterAndGetTim
master->parent().set("_loaded", 1);
if (timeWarp) {
m_timewarpProducers[clipId] = std::make_shared<Mlt::Producer>(&master->parent());
QString resource = m_timewarpProducers[clipId]->get("resource");
if (resource.endsWith(QLatin1String("qtext"))) {
// This was a placeholder clip, reset producer
std::shared_ptr<Mlt::Producer> prod(getTimelineProducer(tid, clipId, state, master->parent().get_int("audio_index"), speed));
m_timewarpProducers[clipId] = prod;
}
m_effectStack->loadService(m_timewarpProducers[clipId]);
return {master, true};
}
......
......@@ -1365,7 +1365,6 @@ void DocumentChecker::fixClipItem(QTreeWidgetItem *child, const QDomNodeList &pr
// Fix clip
setProperty(e, QStringLiteral("_placeholder"), QStringLiteral("1"));
setProperty(e, QStringLiteral("kdenlive:orig_service"), getProperty(e, QStringLiteral("mlt_service")));
break;
}
}
} else if (child->data(0, statusRole).toInt() == LUMAOK) {
......
......@@ -110,7 +110,7 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
double speed = 1.0;
bool warp_pitch = false;
if (QString::fromUtf8(producer->parent().get("mlt_service")) == QLatin1String("timewarp")) {
if (producer->parent().property_exists("warp_speed")) {
speed = producer->parent().get_double("warp_speed");
warp_pitch = producer->parent().get_int("warp_pitch");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment