videoconvert: Enable loading external converter plugins

Load the converter from the video.adapt.converter property.
This commit is contained in:
columbarius 2023-09-24 18:30:54 +02:00 committed by Wim Taymans
parent d6c1b6470a
commit 7d97e47e28
3 changed files with 57 additions and 25 deletions

View file

@ -2,7 +2,9 @@
/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */ /* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
/* SPDX-License-Identifier: MIT */ /* SPDX-License-Identifier: MIT */
#include "spa/utils/dict.h"
#include <spa/support/plugin.h> #include <spa/support/plugin.h>
#include <spa/support/plugin-loader.h>
#include <spa/support/log.h> #include <spa/support/log.h>
#include <spa/support/cpu.h> #include <spa/support/cpu.h>
@ -41,6 +43,7 @@ struct impl {
struct spa_log *log; struct spa_log *log;
struct spa_cpu *cpu; struct spa_cpu *cpu;
struct spa_plugin_loader *ploader;
uint32_t max_align; uint32_t max_align;
enum spa_direction direction; enum spa_direction direction;
@ -58,6 +61,7 @@ struct impl {
struct spa_node *convert; struct spa_node *convert;
struct spa_hook convert_listener; struct spa_hook convert_listener;
uint64_t convert_flags; uint64_t convert_flags;
char *convertname;
uint32_t n_buffers; uint32_t n_buffers;
struct spa_buffer **buffers; struct spa_buffer **buffers;
@ -552,8 +556,6 @@ static int configure_convert(struct impl *this, uint32_t mode)
return spa_node_set_param(this->convert, SPA_PARAM_PortConfig, 0, param); return spa_node_set_param(this->convert, SPA_PARAM_PortConfig, 0, param);
} }
extern const struct spa_handle_factory spa_videoconvert_factory;
static const struct spa_node_events follower_node_events; static const struct spa_node_events follower_node_events;
static int recalc_latency(struct impl *this, struct spa_node *src, enum spa_direction direction, static int recalc_latency(struct impl *this, struct spa_node *src, enum spa_direction direction,
@ -1712,6 +1714,45 @@ static const struct spa_node_methods impl_node = {
.process = impl_node_process, .process = impl_node_process,
}; };
static int load_plugin_from(struct impl *this, const struct spa_dict *info,
const char *convertname, struct spa_handle **handle, struct spa_node **iface)
{
struct spa_handle *hnd_convert = NULL;
void *iface_conv = NULL;
hnd_convert = spa_plugin_loader_load(this->ploader, convertname, NULL);
if (!hnd_convert)
return -EINVAL;
spa_handle_get_interface(hnd_convert, SPA_TYPE_INTERFACE_Node, &iface_conv);
if (iface_conv == NULL) {
spa_plugin_loader_unload(this->ploader, hnd_convert);
return -EINVAL;
}
*handle = hnd_convert;
*iface = iface_conv;
return 0;
}
static int load_converter(struct impl *this, const struct spa_dict *info)
{
int ret;
if (!this->ploader || !info)
return -EINVAL;
const char* factory_name = spa_dict_lookup(info, "video.adapt.converter");
if (factory_name) {
ret = load_plugin_from(this, info, factory_name, &this->hnd_convert, &this->convert);
if (ret >= 0) {
this->convertname = strdup(factory_name);
return ret;
}
}
return 0;
}
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface) static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
{ {
struct impl *this; struct impl *this;
@ -1740,8 +1781,10 @@ static int impl_clear(struct spa_handle *handle)
spa_hook_remove(&this->follower_listener); spa_hook_remove(&this->follower_listener);
spa_node_set_callbacks(this->follower, NULL, NULL); spa_node_set_callbacks(this->follower, NULL, NULL);
if (this->hnd_convert) if (this->hnd_convert) {
spa_handle_clear(this->hnd_convert); spa_plugin_loader_unload(this->ploader, this->hnd_convert);
free(this->convertname);
}
if (this->buffers) if (this->buffers)
free(this->buffers); free(this->buffers);
@ -1755,12 +1798,7 @@ static size_t
impl_get_size(const struct spa_handle_factory *factory, impl_get_size(const struct spa_handle_factory *factory,
const struct spa_dict *params) const struct spa_dict *params)
{ {
size_t size = 0; size_t size = sizeof(struct impl);
#if 0
size += spa_handle_factory_get_size(&spa_videoconvert_factory, params);
#endif
size += sizeof(struct impl);
return size; return size;
} }
@ -1773,10 +1811,8 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t n_support) uint32_t n_support)
{ {
struct impl *this; struct impl *this;
#if 0
void *iface;
#endif
const char *str; const char *str;
int ret;
spa_return_val_if_fail(factory != NULL, -EINVAL); spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL); spa_return_val_if_fail(handle != NULL, -EINVAL);
@ -1791,6 +1827,8 @@ impl_init(const struct spa_handle_factory *factory,
this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU);
this->ploader = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_PluginLoader);
if (info == NULL || if (info == NULL ||
(str = spa_dict_lookup(info, "video.adapt.follower")) == NULL) (str = spa_dict_lookup(info, "video.adapt.follower")) == NULL)
return -EINVAL; return -EINVAL;
@ -1809,18 +1847,10 @@ impl_init(const struct spa_handle_factory *factory,
SPA_VERSION_NODE, SPA_VERSION_NODE,
&impl_node, this); &impl_node, this);
#if 0 ret = load_converter(this, info);
this->hnd_convert = SPA_PTROFF(this, sizeof(struct impl), struct spa_handle); spa_log_debug(this->log, "%p: loaded converter %s, hnd %p, convert %p", this, this->convertname, this->hnd_convert, this->convert);
spa_handle_factory_init(&spa_videoconvert_factory, if (ret < 0)
this->hnd_convert, return ret;
info, support, n_support);
spa_handle_get_interface(this->hnd_convert, SPA_TYPE_INTERFACE_Node, &iface);
if (iface == NULL)
return -EINVAL;
this->convert = iface;
#endif
this->target = this->convert; this->target = this->convert;
this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | this->info_all = SPA_NODE_CHANGE_MASK_FLAGS |

View file

@ -30,6 +30,7 @@ context.spa-libs = {
# #
api.vulkan.* = vulkan/libspa-vulkan api.vulkan.* = vulkan/libspa-vulkan
support.* = support/libspa-support support.* = support/libspa-support
video.convert.* = videoconvert/libspa-videoconvert
} }
context.modules = [ context.modules = [

View file

@ -70,6 +70,7 @@ context.spa-libs = {
api.vulkan.* = vulkan/libspa-vulkan api.vulkan.* = vulkan/libspa-vulkan
api.jack.* = jack/libspa-jack api.jack.* = jack/libspa-jack
support.* = support/libspa-support support.* = support/libspa-support
video.convert.* = videoconvert/libspa-videoconvert
#videotestsrc = videotestsrc/libspa-videotestsrc #videotestsrc = videotestsrc/libspa-videotestsrc
#audiotestsrc = audiotestsrc/libspa-audiotestsrc #audiotestsrc = audiotestsrc/libspa-audiotestsrc
} }