static_assert(sizeof(effect_path_list) / sizeof(char *) == AUDIO_EFFECT_METHOD_MAX);
-static struct plugin_list {
- void *handle;
- int refcnt;
- audio_effect_plugin_info_s *plugin_info;
-} plugin_list[AUDIO_EFFECT_METHOD_MAX];
+static void *dl_handles[AUDIO_EFFECT_METHOD_MAX];
static const char *get_plugin_name(const char *name)
{
{
audio_effect_plugin_info_s *plugin_info;
entry_point_t entry_point;
- void *handle = NULL;
+ void *handle;
assert(method < AUDIO_EFFECT_METHOD_MAX);
- LOG_INFO("Trying to create the plugin %s. plugin_info(%p), refcnt(%d)",
- get_plugin_name(effect_path_list[method]), plugin_list[method].plugin_info, plugin_list[method].refcnt);
+ LOG_INFO("Trying to create the plugin. method(%s)", get_plugin_name(effect_path_list[method]));
+
+ if (dl_handles[method]) {
+ LOG_ERROR("Failed to load plugin. It's already loaded. method(%s)", get_plugin_name(effect_path_list[method]));
+ return NULL;
+ }
- if (!plugin_list[method].plugin_info && plugin_list[method].refcnt == 0) {
- handle = dlopen(effect_path_list[method], RTLD_LAZY);
- if (!handle) {
- LOG_ERROR("Failed to open handle. path(%s) dlerror(%s)", get_plugin_name(effect_path_list[method]), dlerror());
- return NULL;
- }
+ handle = dlopen(effect_path_list[method], RTLD_LAZY);
+ if (!handle) {
+ LOG_ERROR("Failed to open handle. path(%s) dlerror(%s)", get_plugin_name(effect_path_list[method]), dlerror());
+ return NULL;
}
entry_point = dlsym(handle, PLUGIN_ENTRY_POINT_STRING);
if (plugin_info->constraint.frames != 0 && plugin_info->constraint.frames != frames)
LOG_WARN("This plugin uses fixed frames size. Check frames size with audio_effect_get_process_framesize api");
- plugin_list[method].handle = handle;
- /* TODO handle lock */
- plugin_list[method].refcnt += 1;
+ dl_handles[method] = handle;
- LOG_INFO("plugin(%s) was created successfully. handle(%p) ref(%d)",
- get_plugin_name(effect_path_list[method]), plugin_list[method].handle, plugin_list[method].refcnt);
+ LOG_INFO("plugin(%s) was created successfully. handle(%p)", get_plugin_name(effect_path_list[method]), dl_handles[method]);
return &plugin_info->interface;
fail:
- if (handle)
- dlclose(handle);
-
- plugin_list[method].plugin_info = NULL;
+ dlclose(handle);
return NULL;
}
void audio_effect_interface_free(audio_effect_interface_s *intf)
{
audio_effect_method_e method;
+ int ret;
assert(intf);
+ assert(dl_handles[intf->method]);
+ assert(intf->method < AUDIO_EFFECT_METHOD_MAX);
method = intf->method;
- plugin_list[method].refcnt -= 1;
+ LOG_INFO("unloading the plugin. (%s). handle(%p)", get_plugin_name(effect_path_list[method]), dl_handles[method]);
- if (plugin_list[method].refcnt == 0) {
- int ret;
- LOG_INFO("unloading the plugin. (%s). handle(%p)",
- get_plugin_name(effect_path_list[method]), plugin_list[method].handle);
-
- if ((ret = dlclose(plugin_list[method].handle)) != 0)
- LOG_ERROR("Failed to close plugin. ret(%d), dlerror(%s)", ret, dlerror());
- }
+ if ((ret = dlclose(dl_handles[method])) != 0)
+ LOG_ERROR("Failed to close plugin. ret(%d), dlerror(%s)", ret, dlerror());
- plugin_list[method].handle = NULL;
- plugin_list[method].plugin_info = NULL;
+ dl_handles[method] = NULL;
LOG_INFO("unloaded the plugin. (%s)", get_plugin_name(effect_path_list[method]));
}