Skip to content

Commit

Permalink
backwards compatible support for rename frei0r plugins
Browse files Browse the repository at this point in the history
frei0r v2.3.1 changed the name of some plugins. That breaks existing
apps, scripts, and MLT XML using the old names. This change fixes that.
  • Loading branch information
ddennedy committed Oct 31, 2023
1 parent 8d978aa commit 65d34ed
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/modules/frei0r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_library(mltfrei0r MODULE
file(GLOB YML "*.yml")
add_custom_target(Other_frei0r_Files SOURCES
${YML}
aliases.yaml
blacklist.txt
not_thread_safe.txt
param_name_map.yaml
Expand All @@ -28,6 +29,7 @@ set_target_properties(mltfrei0r PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${MLT_MODUL
install(TARGETS mltfrei0r LIBRARY DESTINATION ${MLT_INSTALL_MODULE_DIR})

install(FILES
aliases.yaml
filter_cairoblend_mode.yml
resolution_scale.yml
param_name_map.yaml
Expand Down
17 changes: 17 additions & 0 deletions src/modules/frei0r/aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# MLT frei0r plugin name mapping from new name to old ones
# new:
# - old
frei0r.measure_pr0be:
- frei0r.pr0be
frei0r.measure_pr0file:
- frei0r.pr0file
frei0r.tehroxx0r:
- frei0r.tehRoxx0r
frei0r.alpha0ps_alpha0ps:
- frei0r.alpha0ps
frei0r.alpha0ps_alphagrad:
- frei0r.alphagrad
frei0r.alpha0ps_alphaspot:
- frei0r.alphaspot
frei0r.denoise_hqdn3d:
- frei0r.hqdn3d
53 changes: 48 additions & 5 deletions src/modules/frei0r/factory.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* factory.c -- the factory method interfaces
* Copyright (c) 2008 Marco Gittler <[email protected]>
* Copyright (C) 2009-2022 Meltytech, LLC
* Copyright (C) 2009-2023 Meltytech, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -453,7 +453,11 @@ static void *create_frei0r_item(mlt_profile profile,
firstname);

if (firstname) {
void *handle = dlopen(soname, RTLD_LAZY);
const char *alias = mlt_properties_get(mlt_properties_get_data(mlt_global_properties(),
"frei0r.aliases",
NULL),
id);
void *handle = dlopen(alias ? alias : soname, RTLD_LAZY);

if (handle) {
ret = load_lib(profile, type, handle, firstname);
Expand All @@ -477,7 +481,6 @@ static mlt_properties metadata(mlt_service_type type, const char *id, void *data

MLT_REPOSITORY
{
int i = 0;
mlt_tokeniser tokeniser = mlt_tokeniser_init();
char *frei0r_path = get_frei0r_path();
int dircount = mlt_tokeniser_parse_new(tokeniser, frei0r_path, MLT_DIRLIST_DELIMITER);
Expand All @@ -504,6 +507,17 @@ MLT_REPOSITORY
(mlt_destructor) mlt_properties_close,
NULL);

// Load a list of plugin alias names.
snprintf(dirname, PATH_MAX, "%s/frei0r/aliases.yaml", mlt_environment("MLT_DATA"));
mlt_properties aliases = mlt_properties_parse_yaml(dirname);
mlt_properties reverse_aliases = mlt_properties_new();
mlt_properties_set_data(mlt_global_properties(),
"frei0r.aliases",
reverse_aliases,
0,
(mlt_destructor) mlt_properties_close,
NULL);

while (dircount--) {
mlt_properties direntries = mlt_properties_new();
char *directory = mlt_tokeniser_get_string(tokeniser, dircount);
Expand All @@ -514,7 +528,7 @@ MLT_REPOSITORY
snprintf(dirname, PATH_MAX, "%s%s", getenv("HOME"), strchr(directory, '/'));
mlt_properties_dir_list(direntries, dirname, "*" LIBSUF, 1);

for (i = 0; i < mlt_properties_count(direntries); i++) {
for (int i = 0; i < mlt_properties_count(direntries); i++) {
char *name = mlt_properties_get_value(direntries, i);
char *shortname = name + strlen(dirname) + 1;
#ifdef _WIN32
Expand All @@ -527,9 +541,11 @@ MLT_REPOSITORY
if (firstname)
strncat(pluginname, firstname, sizeof(pluginname) - strlen(pluginname) - 1);

if (firstname && mlt_properties_get(blacklist, firstname))
if (firstname && mlt_properties_exists(blacklist, firstname))
continue;

mlt_properties plugin_aliases = mlt_properties_get_data(aliases, pluginname, NULL);

void *handle = dlopen(strcat(name, LIBSUF), RTLD_LAZY);
if (handle) {
void (*plginfo)(f0r_plugin_info_t *) = dlsym(handle, "f0r_get_plugin_info");
Expand All @@ -547,6 +563,15 @@ MLT_REPOSITORY
pluginname,
fill_param_info,
name);
for (int j = 0; j < mlt_properties_count(plugin_aliases); j++) {
const char *alias = mlt_properties_get_value(plugin_aliases, j);
mlt_properties_set(reverse_aliases, alias, name);
MLT_REGISTER(mlt_service_producer_type, alias, create_frei0r_item);
MLT_REGISTER_METADATA(mlt_service_producer_type,
alias,
fill_param_info,
name);
}
} else if (firstname && info.plugin_type == F0R_PLUGIN_TYPE_FILTER) {
if (mlt_properties_get(mlt_repository_filters(repository), pluginname)) {
dlclose(handle);
Expand All @@ -557,6 +582,15 @@ MLT_REPOSITORY
pluginname,
fill_param_info,
name);
for (int j = 0; j < mlt_properties_count(plugin_aliases); j++) {
const char *alias = mlt_properties_get_value(plugin_aliases, j);
mlt_properties_set(reverse_aliases, alias, name);
MLT_REGISTER(mlt_service_filter_type, alias, create_frei0r_item);
MLT_REGISTER_METADATA(mlt_service_filter_type,
alias,
fill_param_info,
name);
}
} else if (firstname && info.plugin_type == F0R_PLUGIN_TYPE_MIXER2) {
if (mlt_properties_get(mlt_repository_transitions(repository), pluginname)) {
dlclose(handle);
Expand All @@ -567,6 +601,15 @@ MLT_REPOSITORY
pluginname,
fill_param_info,
name);
for (int j = 0; j < mlt_properties_count(plugin_aliases); j++) {
const char *alias = mlt_properties_get_value(plugin_aliases, j);
mlt_properties_set(reverse_aliases, alias, name);
MLT_REGISTER(mlt_service_transition_type, alias, create_frei0r_item);
MLT_REGISTER_METADATA(mlt_service_transition_type,
alias,
fill_param_info,
name);
}
}
}
dlclose(handle);
Expand Down

0 comments on commit 65d34ed

Please sign in to comment.