Skip to content

Commit 21f51fd

Browse files
committed
Add more detection logic to filter out unsuported plugins
1 parent 4cc5e4f commit 21f51fd

File tree

3 files changed

+59
-73
lines changed

3 files changed

+59
-73
lines changed

src/modules/openfx/factory.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,8 @@ MLT_REPOSITORY
168168
setenv("OCIO", "ocio://ocio://default", 1);
169169
}
170170

171-
char *dir,
172-
*openfx_path = getenv("OFX_PLUGIN_PATH"),
173-
*load_unsupported_plugins = getenv(
174-
"MLT_OFX_LOAD_UNSUPPORTED_PLUGINS"); /* Load unsupported plugins for debugging purposes */
175-
176-
bool is_load_unsupported_plugins = false;
177-
if (load_unsupported_plugins) {
178-
is_load_unsupported_plugins = strcmp(load_unsupported_plugins, "true") == 0;
179-
}
180-
171+
char *dir;
172+
char *openfx_path = getenv("OFX_PLUGIN_PATH");
181173
size_t archstr_len = strlen(OFX_ARCHSTR);
182174

183175
mltofx_context = mlt_properties_new();
@@ -216,6 +208,8 @@ MLT_REPOSITORY
216208

217209
ofx_get_plugin = dlsym(dlhandle, "OfxGetPlugin");
218210
ofx_get_number_of_plugins = dlsym(dlhandle, "OfxGetNumberOfPlugins");
211+
if (!ofx_get_plugin || !ofx_get_number_of_plugins)
212+
goto parse_error;
219213
NumberOfPlugins = ofx_get_number_of_plugins();
220214

221215
char dl_n[16] = {
@@ -257,16 +251,22 @@ MLT_REPOSITORY
257251

258252
for (int i = 0; i < NumberOfPlugins; ++i) {
259253
OfxPlugin *plugin_ptr = ofx_get_plugin(i);
254+
if (!plugin_ptr)
255+
goto parse_error;
256+
257+
int detected = mltofx_detect_plugin(plugin_ptr);
258+
if (!detected) {
259+
continue;
260+
}
260261

261262
char *s = NULL;
262263
size_t pluginIdentifier_len = strlen(plugin_ptr->pluginIdentifier);
263264
s = malloc(pluginIdentifier_len + 8);
264265
sprintf(s, "openfx.%s", plugin_ptr->pluginIdentifier);
265266

266-
/* if colon `:` exists in plugin identifier
267-
change it to accent sign `^` because `:`
268-
can cause issues with mlt if put in filter
269-
name */
267+
// If colon `:` exists in plugin identifier change it to
268+
// accent sign `^` because `:` can cause issues with mlt
269+
// if put in filter name
270270
char *str_ptr = strchr(s, ':');
271271
while (str_ptr != NULL) {
272272
*str_ptr++ = '^';
@@ -285,20 +285,12 @@ MLT_REPOSITORY
285285
mlt_properties_set(p, "dli", dl_n);
286286
mlt_properties_set_int(p, "index", i);
287287

288-
/* Sometimes error codes other than kOfxStatErrMissingHostFeature
289-
returned from kOfxActionDescribe like kOfxStatErrMemory, kOfxStatFailed, kOfxStatErrFatal */
290-
bool plugin_supported = mltofx_is_plugin_supported(plugin_ptr)
291-
== kOfxStatOK;
292-
/* WIP: this is only creating them as filter I should find a way to see howto detect producers
293-
if they exists in OpenFX plugins
294-
*/
295-
if (plugin_supported || is_load_unsupported_plugins) {
296-
MLT_REGISTER(mlt_service_filter_type, s, filter_openfx_init);
297-
MLT_REGISTER_METADATA(mlt_service_filter_type,
298-
s,
299-
metadata,
300-
"filter_openfx.yml");
301-
}
288+
MLT_REGISTER(mlt_service_filter_type, s, filter_openfx_init);
289+
MLT_REGISTER_METADATA(mlt_service_filter_type,
290+
s,
291+
metadata,
292+
"filter_openfx.yml");
293+
free(s);
302294
}
303295

304296
parse_error:

src/modules/openfx/mlt_openfx.c

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,30 +1493,12 @@ OfxHost MltOfxHost = {NULL, MltOfxfetchSuite};
14931493
void mltofx_init_host_properties(OfxPropertySetHandle host_properties)
14941494
{
14951495
propSetString(host_properties, kOfxPropName, 0, "MLT");
1496-
propSetString(host_properties, kOfxImageEffectPropContext, 0, kOfxImageEffectContextGeneral);
1497-
propSetString(host_properties,
1498-
kOfxImageEffectPropSupportedPixelDepths,
1499-
0,
1500-
kOfxBitDepthByte); /* kOfxBitDepthByte is hardcoded */
1496+
propSetString(host_properties, kOfxImageEffectPropSupportedContexts, 0, kOfxImageEffectContextFilter);
1497+
propSetString(host_properties, kOfxImageEffectPropSupportedPixelDepths, 0, kOfxBitDepthByte);
15011498
propSetString(host_properties, kOfxImageEffectPropSupportedPixelDepths, 1, kOfxBitDepthShort);
1502-
propSetString(host_properties, kOfxImageEffectPropSupportedPixelDepths, 2, kOfxBitDepthHalf);
1503-
propSetString(host_properties, kOfxImageEffectPropSupportedPixelDepths, 3, kOfxBitDepthFloat);
1504-
1505-
propSetString(host_properties,
1506-
kOfxImageEffectPropSupportedComponents,
1507-
0,
1508-
kOfxImageComponentNone);
1509-
propSetString(host_properties,
1510-
kOfxImageEffectPropSupportedComponents,
1511-
1,
1512-
kOfxImageComponentRGBA);
1513-
propSetString(host_properties, kOfxImageEffectPropSupportedComponents, 2, kOfxImageComponentRGB);
1514-
propSetString(host_properties,
1515-
kOfxImageEffectPropSupportedComponents,
1516-
3,
1517-
kOfxImageComponentAlpha);
1518-
1519-
propSetInt(host_properties, kOfxImageEffectPropSupportsMultipleClipDepths, 0, 1);
1499+
propSetString(host_properties, kOfxImageEffectPropSupportedComponents, 0, kOfxImageComponentRGBA);
1500+
propSetString(host_properties, kOfxImageEffectPropSupportedComponents, 1, kOfxImageComponentRGB);
1501+
propSetInt(host_properties, kOfxImageEffectPropSupportsMultipleClipDepths, 0, 0);
15201502

15211503
/* TODO: add support for OpenGL plugins */
15221504
propSetString(host_properties, kOfxImageEffectPropOpenGLRenderSupported, 0, "false");
@@ -1753,7 +1735,7 @@ void mltofx_set_output_clip_data(OfxPlugin *plugin,
17531735
(double) width / (double) height);
17541736
}
17551737

1756-
OfxStatus mltofx_is_plugin_supported(OfxPlugin *plugin)
1738+
int mltofx_detect_plugin(OfxPlugin *plugin)
17571739
{
17581740
mlt_properties image_effect = mlt_properties_new();
17591741
mlt_properties clips = mlt_properties_new();
@@ -1792,39 +1774,56 @@ OfxStatus mltofx_is_plugin_supported(OfxPlugin *plugin)
17921774
(mlt_destructor) mlt_properties_close,
17931775
NULL);
17941776

1795-
propSetString((OfxPropertySetHandle) props,
1796-
kOfxImageEffectPropContext,
1797-
0,
1798-
kOfxImageEffectContextGeneral);
1799-
18001777
plugin->setHost(&MltOfxHost);
18011778

18021779
OfxStatus status_code = kOfxStatErrUnknown;
18031780
status_code = plugin->mainEntry(kOfxActionLoad, NULL, NULL, NULL);
18041781
mltofx_log_status_code(status_code, "kOfxActionLoad");
1782+
if (status_code != kOfxStatOK) {
1783+
return 0;
1784+
}
18051785
status_code
18061786
= plugin->mainEntry(kOfxActionDescribe, (OfxImageEffectHandle) image_effect, NULL, NULL);
18071787
mltofx_log_status_code(status_code, "kOfxActionDescribe");
18081788

18091789
if (status_code != kOfxStatOK) {
18101790
plugin->mainEntry(kOfxActionUnload, NULL, NULL, NULL);
1811-
return status_code;
1791+
return 0;
18121792
}
18131793

1814-
/* test describe in context action because some plugins say they are unsupported at this stage */
1815-
status_code = plugin->mainEntry(kOfxImageEffectActionDescribeInContext,
1816-
(OfxImageEffectHandle) image_effect,
1817-
(OfxPropertySetHandle) MltOfxHost.host,
1818-
NULL);
1794+
int i = 0;
1795+
int count = 0;
18191796

1820-
mltofx_log_status_code(status_code, "kOfxImageEffectActionDescribeInContext");
1821-
if (status_code != kOfxStatErrMissingHostFeature) {
1797+
propGetDimension((OfxPropertySetHandle) props, kOfxImageEffectPropSupportedContexts, &count);
1798+
for (i = 0; i < count; i++) {
1799+
char *context;
1800+
propGetString((OfxPropertySetHandle) props, kOfxImageEffectPropSupportedContexts, i, &context);
1801+
if (!strcmp(context, kOfxImageEffectContextFilter)) {
1802+
break;
1803+
}
1804+
}
1805+
if (i == count) {
1806+
mlt_log_debug(NULL, "[ofx] Plugin not a filter: %s\n", plugin->pluginIdentifier);
18221807
plugin->mainEntry(kOfxActionUnload, NULL, NULL, NULL);
1823-
return kOfxStatOK;
1808+
return 0;
1809+
}
1810+
1811+
propGetDimension((OfxPropertySetHandle) props, kOfxImageEffectPropSupportedPixelDepths, &count);
1812+
for (i = 0; i < count; i++) {
1813+
char *depth;
1814+
propGetString((OfxPropertySetHandle) props, kOfxImageEffectPropSupportedPixelDepths, i, &depth);
1815+
if (!strcmp(depth, kOfxBitDepthByte) || !strcmp(depth, kOfxBitDepthShort)) {
1816+
break;
1817+
}
1818+
}
1819+
if (i == count) {
1820+
mlt_log_debug(NULL, "[ofx] Plugin not byte/short: %s\n", plugin->pluginIdentifier);
1821+
plugin->mainEntry(kOfxActionUnload, NULL, NULL, NULL);
1822+
return 0;
18241823
}
18251824

18261825
plugin->mainEntry(kOfxActionUnload, NULL, NULL, NULL);
1827-
return status_code;
1826+
return 1;
18281827
}
18291828

18301829
void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params)
@@ -1865,11 +1864,6 @@ void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params)
18651864
(mlt_destructor) mlt_properties_close,
18661865
NULL);
18671866

1868-
propSetString((OfxPropertySetHandle) props,
1869-
kOfxImageEffectPropContext,
1870-
0,
1871-
kOfxImageEffectContextGeneral);
1872-
18731867
plugin->setHost(&MltOfxHost);
18741868

18751869
OfxStatus status_code = kOfxStatErrUnknown;

src/modules/openfx/mlt_openfx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void mltofx_set_output_clip_data(OfxPlugin *plugin,
7575
int height,
7676
mlt_image_format format);
7777

78-
OfxStatus mltofx_is_plugin_supported(OfxPlugin *plugin);
78+
int mltofx_detect_plugin(OfxPlugin *plugin);
7979

8080
void *mltofx_fetch_params(OfxPlugin *plugin, mlt_properties params);
8181

0 commit comments

Comments
 (0)