Skip to content

Commit

Permalink
fix GPU filters paste below non-GPU filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Sep 25, 2024
1 parent 7cef7e7 commit e8442c7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/mltcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,30 @@ QUuid Controller::ensureHasUuid(Mlt::Properties &properties) const
return newUid;
}

static int indexOfFirstNonGpu(Producer &toProducer)
{
for (int i = 0; i < toProducer.filter_count(); i++) {
QScopedPointer<Mlt::Filter> filter(toProducer.filter(i));
if (filter && filter->is_valid() && !filter->get_int("_loader")
&& !filter->get_int(kShotcutHiddenProperty)
&& filter->get("mlt_service")) {
if (!QString::fromLatin1(filter->get("mlt_service")).startsWith("movit."))
return i;
}
}
Mlt::Chain toChain(toProducer);
for (int i = 0; i < toChain.link_count(); i++) {
QScopedPointer<Mlt::Link> link(toChain.link(i));
if (link && link->is_valid() && !link->get_int("_loader")
&& !link->get_int(kShotcutHiddenProperty)
&& link->get("mlt_service")) {
if (!QString::fromLatin1(link->get("mlt_service")).startsWith("movit."))
return i;
}
}
return -1;
}

void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool fromClipboard,
bool includeDisabled)
{
Expand All @@ -1112,6 +1136,9 @@ void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool
kFilterOutProperty) : fromProducer.get_out();
int count = fromProducer.filter_count();

// Get the index of the first non-GPU filter or link in toProducer
int firstNonGpuService = fromClipboard ? indexOfFirstNonGpu(toProducer) : -1;

for (int i = 0; i < count; i++) {
QScopedPointer<Mlt::Filter> fromFilter(fromProducer.filter(i));
if (fromFilter && fromFilter->is_valid() && !fromFilter->get_int("_loader")
Expand Down Expand Up @@ -1140,6 +1167,8 @@ void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool
// Force any 2-pass filters to require re-analysis
toFilter.clear("results");
toProducer.attach(toFilter);
if (firstNonGpuService >= 0 && metadata->needsGPU())
toProducer.move_filter(toProducer.filter_count(), firstNonGpuService++);

if (!fromClipboard) {
toFilter.set(kFilterInProperty, fromFilter->get_in() - in);
Expand All @@ -1163,6 +1192,9 @@ void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool
if (toLink.is_valid()) {
toLink.inherit(*fromLink);
toChain.attach(toLink);
if (firstNonGpuService >= 0
&& QString::fromLatin1(fromLink->get("mlt_service")).startsWith("movit."))
toChain.move_link(toChain.link_count(), firstNonGpuService++);
}
}
}
Expand Down

0 comments on commit e8442c7

Please sign in to comment.