Skip to content

Commit 0a3a033

Browse files
author
mr.fantastic
committed
Addressing @ddennedy review comments
- handle the Microsoft Visual C++ compiler in module CMakeLists.txt - Change every copyright to the year 2025 - Use C99 variables in the for loop initializer declare style - Clang format and include <stdbool.h> explicitly - specify which versions of OpenFX supported - mention OpenFX header files URL in mlt_openfx.c - using mlt_image and its functions in src/modules/openfx/filter_openfx.c
1 parent afae53b commit 0a3a033

6 files changed

Lines changed: 450 additions & 433 deletions

File tree

src/modules/openfx/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ add_custom_target(Other_openfx_Files SOURCES
88
filter_openfx.yml
99
)
1010

11+
include(GenerateExportHeader)
12+
generate_export_header(mltopenfx)
1113
target_compile_options(mltopenfx PRIVATE ${MLT_COMPILE_OPTIONS})
12-
13-
target_link_libraries(mltopenfx PRIVATE mlt m PkgConfig::glib ${CMAKE_DL_LIBS})
14+
target_include_directories(mltopenfx PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
15+
target_link_libraries(mltopenfx PRIVATE mlt PkgConfig::glib ${CMAKE_DL_LIBS})
16+
if(NOT MSVC)
17+
target_link_libraries(mltopenfx PRIVATE m)
18+
endif()
1419

1520
set_target_properties(mltopenfx PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${MLT_MODULE_OUTPUT_DIRECTORY}")
1621

src/modules/openfx/factory.c

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* factory.c -- the factory method interfaces
3-
* Copyright (C) 2024 Meltytech, LLC
3+
* Copyright (C) 2025 Meltytech, LLC
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
1919

2020
#include "mlt_openfx.h"
2121
#include <glib.h>
22+
#include <stdbool.h>
2223
extern OfxHost MltOfxHost;
2324
static OfxSetHostFn ofx_set_host;
2425
static OfxGetPluginFn ofx_get_plugin;
@@ -63,7 +64,8 @@ static const char *getArchStr()
6364
#define OFX_DIRSEP "/"
6465
#include <dirent.h>
6566

66-
#elif defined(WINDOWS) || defined(WIN32) || defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
67+
#elif defined(WINDOWS) || defined(WIN32) || defined(_WIN32) || defined(__MINGW32__) \
68+
|| defined(__MINGW64__)
6769
#define OFX_DIRLIST_SEP_CHARS ";"
6870
#if defined(_WIN64) || defined(__MINGW64__)
6971
#define OFX_ARCHSTR "Win64"
@@ -89,8 +91,7 @@ static void plugin_mgr_destroy(mlt_properties p)
8991
{
9092
int cN = mlt_properties_count(mltofx_context);
9193

92-
int j;
93-
for (j = 0; j < cN; ++j) {
94+
for (int j = 0; j < cN; ++j) {
9495
char *id = mlt_properties_get_name(mltofx_context, j);
9596
mlt_properties pb = (mlt_properties) mlt_properties_get_data(mltofx_context, id, NULL);
9697

@@ -110,8 +111,7 @@ static void plugin_mgr_destroy(mlt_properties p)
110111

111112
int N = mlt_properties_get_int(p, "N");
112113

113-
int i;
114-
for (i = 0; i < N; ++i) {
114+
for (int i = 0; i < N; ++i) {
115115
char tstr[12] = {
116116
'\0',
117117
};
@@ -161,14 +161,15 @@ MLT_REPOSITORY
161161
MltOfxHost.host = (OfxPropertySetHandle) mlt_properties_new();
162162
mltofx_init_host_properties(MltOfxHost.host);
163163

164-
char *dir, *openfx_path = getenv("OFX_PLUGIN_PATH"),
165-
*load_unsupported_plugins = getenv("MLT_OFX_LOAD_UNSUPPORTED_PLUGINS"); /* Load unsupported plugins for debugging purposes */
164+
char *dir,
165+
*openfx_path = getenv("OFX_PLUGIN_PATH"),
166+
*load_unsupported_plugins = getenv(
167+
"MLT_OFX_LOAD_UNSUPPORTED_PLUGINS"); /* Load unsupported plugins for debugging purposes */
166168

167169
bool is_load_unsupported_plugins = false;
168-
if (load_unsupported_plugins)
169-
{
170-
is_load_unsupported_plugins = strcmp(load_unsupported_plugins, "true") == 0 ? true : false;
171-
}
170+
if (load_unsupported_plugins) {
171+
is_load_unsupported_plugins = strcmp(load_unsupported_plugins, "true") == 0;
172+
}
172173

173174
size_t archstr_len = strlen(OFX_ARCHSTR);
174175

@@ -177,9 +178,9 @@ MLT_REPOSITORY
177178

178179
if (openfx_path) {
179180
int dli = 0;
180-
char *saveptr, *strptr;
181+
char *saveptr;
181182

182-
for (strptr = openfx_path;; strptr = NULL) {
183+
for (char *strptr = openfx_path;; strptr = NULL) {
183184
dir = strtok_r(strptr, MLT_DIRLIST_DELIMITER, &saveptr);
184185
if (dir == NULL)
185186
break;
@@ -247,25 +248,23 @@ MLT_REPOSITORY
247248
if (ofx_get_plugin == NULL)
248249
goto parse_error;
249250

250-
int i;
251-
for (i = 0; i < NumberOfPlugins; ++i) {
251+
for (int i = 0; i < NumberOfPlugins; ++i) {
252252
OfxPlugin *plugin_ptr = ofx_get_plugin(i);
253253

254254
char *s = NULL;
255255
size_t pluginIdentifier_len = strlen(plugin_ptr->pluginIdentifier);
256256
s = malloc(pluginIdentifier_len + 8);
257257
sprintf(s, "openfx.%s", plugin_ptr->pluginIdentifier);
258258

259-
/* if colon `:` exists in plugin identifier
259+
/* if colon `:` exists in plugin identifier
260260
change it to accent sign `^` because `:`
261261
can cause issues with mlt if put in filter
262262
name */
263-
char *str_ptr = strchr(s, ':');
264-
while (str_ptr != NULL) {
265-
*str_ptr++ = '^';
266-
str_ptr = strchr(str_ptr, ':');
267-
}
268-
263+
char *str_ptr = strchr(s, ':');
264+
while (str_ptr != NULL) {
265+
*str_ptr++ = '^';
266+
str_ptr = strchr(str_ptr, ':');
267+
}
269268

270269
mlt_properties p;
271270
p = mlt_properties_new();
@@ -279,20 +278,20 @@ MLT_REPOSITORY
279278
mlt_properties_set(p, "dli", dl_n);
280279
mlt_properties_set_int(p, "index", i);
281280

282-
/* Sometimes error codes other than kOfxStatErrMissingHostFeature
281+
/* Sometimes error codes other than kOfxStatErrMissingHostFeature
283282
returned from kOfxActionDescribe like kOfxStatErrMemory, kOfxStatFailed, kOfxStatErrFatal */
284-
bool plugin_supported = mltofx_is_plugin_supported(plugin_ptr) == kOfxStatOK;
283+
bool plugin_supported = mltofx_is_plugin_supported(plugin_ptr)
284+
== kOfxStatOK;
285285
/* WIP: this is only creating them as filter I should find a way to see howto detect producers
286286
if they exists in OpenFX plugins
287287
*/
288-
if (plugin_supported || is_load_unsupported_plugins)
289-
{
290-
MLT_REGISTER(mlt_service_filter_type, s, filter_openfx_init);
291-
MLT_REGISTER_METADATA(mlt_service_filter_type,
292-
s,
293-
metadata,
294-
"filter_openfx.yml");
295-
}
288+
if (plugin_supported || is_load_unsupported_plugins) {
289+
MLT_REGISTER(mlt_service_filter_type, s, filter_openfx_init);
290+
MLT_REGISTER_METADATA(mlt_service_filter_type,
291+
s,
292+
metadata,
293+
"filter_openfx.yml");
294+
}
296295
}
297296

298297
parse_error:
@@ -304,7 +303,7 @@ MLT_REPOSITORY
304303
de = readdir(d);
305304
}
306305

307-
closedir(d);
306+
closedir(d);
308307
}
309308

310309
mlt_properties_set_int(mltofx_dl, "N", dli);

src/modules/openfx/filter_openfx.c

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* filter_openfx.c -- filter Video through OpenFX plugins
3-
* Copyright (C) 2024 Meltytech, LLC
3+
* Copyright (C) 2025 Meltytech, LLC
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -41,16 +41,15 @@ static int filter_get_image(mlt_frame frame,
4141
mlt_properties params = mlt_properties_get_data(image_effect, "mltofx_params", NULL);
4242
mlt_properties image_effect_params = mlt_properties_get_data(image_effect, "params", NULL);
4343

44-
*format = mlt_image_rgba;
44+
format = mlt_image_rgba;
4545
int error = mlt_frame_get_image(frame, image, format, width, height, 1);
4646

4747
if (error == 0) {
4848
mlt_position position = mlt_filter_get_position(filter, frame);
4949
mlt_position length = mlt_filter_get_length2(filter, frame);
5050
int params_count = mlt_properties_count(params);
5151

52-
int i;
53-
for (i = 0; i < params_count; ++i) {
52+
for (int i = 0; i < params_count; ++i) {
5453
char *iprop_name = mlt_properties_get_name(params, i);
5554

5655
char *mlt_value = mlt_properties_get(properties, iprop_name);
@@ -59,19 +58,21 @@ static int filter_get_image(mlt_frame frame,
5958
mlt_properties param = mlt_properties_get_data_at(params, i, NULL);
6059

6160
char *type = mlt_properties_get(param, "type");
62-
char *widget = mlt_properties_get(param, "widget");
61+
char *widget = mlt_properties_get(param, "widget");
6362

6463
if (type != NULL) {
65-
if (widget != NULL && (strcmp(widget, "2dpoint") == 0 || strcmp(widget, "2dsize") == 0) && strcmp(type, "double") == 0) {
66-
mlt_rect value = mlt_properties_anim_get_rect(properties,
67-
iprop_name,
68-
position,
69-
length);
70-
mltofx_param_set_value(image_effect_params,
64+
if (widget != NULL
65+
&& (strcmp(widget, "2dpoint") == 0 || strcmp(widget, "2dsize") == 0)
66+
&& strcmp(type, "double") == 0) {
67+
mlt_rect value = mlt_properties_anim_get_rect(properties,
68+
iprop_name,
69+
position,
70+
length);
71+
mltofx_param_set_value(image_effect_params,
7172
iprop_name,
7273
mltofx_prop_double2d,
7374
value);
74-
} else if (strcmp(type, "double") == 0) {
75+
} else if (strcmp(type, "double") == 0) {
7576
double value = mlt_properties_anim_get_double(properties,
7677
iprop_name,
7778
position,
@@ -88,12 +89,13 @@ static int filter_get_image(mlt_frame frame,
8889
mltofx_prop_int,
8990
value);
9091
} else if (strcmp(type, "string") == 0) {
91-
int value
92-
= mlt_properties_anim_get_int(properties, iprop_name, position, length);
93-
mltofx_param_set_value(image_effect_params,
94-
iprop_name,
95-
mltofx_prop_int, /* for handling option choice TODO: do something better */
96-
value);
92+
int value
93+
= mlt_properties_anim_get_int(properties, iprop_name, position, length);
94+
mltofx_param_set_value(
95+
image_effect_params,
96+
iprop_name,
97+
mltofx_prop_int, /* for handling option choice TODO: do something better */
98+
value);
9799
} else if (strcmp(type, "boolean") == 0) {
98100
int value
99101
= mlt_properties_anim_get_int(properties, iprop_name, position, length);
@@ -102,41 +104,52 @@ static int filter_get_image(mlt_frame frame,
102104
mltofx_prop_int,
103105
value);
104106
} else if (strcmp(type, "color") == 0) {
105-
mlt_color value
106-
= mlt_properties_anim_get_color(properties, iprop_name, position, length);
107-
mltofx_param_set_value(image_effect_params,
108-
iprop_name,
109-
mltofx_prop_color,
110-
value);
111-
}
107+
mlt_color value = mlt_properties_anim_get_color(properties,
108+
iprop_name,
109+
position,
110+
length);
111+
mltofx_param_set_value(image_effect_params,
112+
iprop_name,
113+
mltofx_prop_color,
114+
value);
115+
}
112116
}
113117
}
114118
}
115119

116120
mltofx_begin_sequence_render(plugin, image_effect);
117121

118-
/* According to OpenFX documentation: Note that hosts that
122+
/* According to OpenFX documentation: Note that hosts that
119123
have constant sized imagery need not call this action, only
120124
hosts that allow image sizes to vary need call this. */
121-
/* mltofx_get_region_of_definition(plugin, image_effect); */
125+
/* mltofx_get_region_of_definition(plugin, image_effect); */
122126

123127
mltofx_get_regions_of_interest(plugin, image_effect, (double) *width, (double) *height);
124128
mltofx_get_clip_preferences(plugin, image_effect);
125129

126-
uint8_t *src_copy = malloc(*width * *height * 4);
127-
if (src_copy == NULL)
128-
goto out;
129-
memcpy(src_copy, *image, *width * *height * 4);
130+
struct mlt_image_s src_img;
131+
mlt_image_set_values(&src_img, *image, *format, *width, *height);
132+
133+
struct mlt_image_s src_img_copy;
134+
mlt_image_set_values(&src_img_copy, NULL, *format, *width, *height);
135+
136+
mlt_image_alloc_data(&src_img_copy);
137+
138+
uint8_t *src_copy = src_img_copy.data;
139+
140+
memcpy(src_copy, *image, mlt_image_calculate_size(&src_img));
130141
mltofx_set_source_clip_data(plugin, image_effect, src_copy, *width, *height);
131142
mltofx_set_output_clip_data(plugin, image_effect, *image, *width, *height);
132143

144+
mlt_service_lock(MLT_FILTER_SERVICE(filter));
133145
mltofx_action_render(plugin, image_effect, *width, *height);
146+
mlt_service_unlock(MLT_FILTER_SERVICE(filter));
134147

135-
free(src_copy);
148+
mlt_image_close(&src_img_copy);
136149

137150
mltofx_end_sequence_render(plugin, image_effect);
138151
}
139-
out:
152+
140153
return error;
141154
}
142155

src/modules/openfx/filter_openfx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ url: https://openeffects.org/
99
creator: mr.fantastic <mrfantastic@firemail.cc>
1010
tags:
1111
- Video
12-
description: Process videos using OpenFX plugins.
12+
description: Process videos using OpenFX 1.5 plugins.

0 commit comments

Comments
 (0)