pulse-server: pass already created module object to module_info::create()

All modules need to manually create a `module` object and check
if it was successfully created. The same with argument parsing.
To simplify modules, move the module object creation and argument
parsing into `module_create()`, and pass the already initialized
module to `module_info::create()`.

The semantics of `module_info::create()` are kept, that is,
if it fails, `module_info::unload()` will not be called.
This commit is contained in:
Barnabás Pőcze 2022-06-01 18:26:18 +02:00
parent 5ad52bb88a
commit fa3a28ab68
25 changed files with 210 additions and 548 deletions

View file

@ -59,16 +59,17 @@ void module_schedule_unload(struct module *module)
module->unloading = true; module->unloading = true;
} }
struct module *module_new(struct impl *impl, size_t user_data) static struct module *module_new(struct impl *impl, const struct module_info *info)
{ {
struct module *module; struct module *module;
module = calloc(1, sizeof(struct module) + user_data); module = calloc(1, sizeof(*module) + info->data_size);
if (module == NULL) if (module == NULL)
return NULL; return NULL;
module->index = SPA_ID_INVALID; module->index = SPA_ID_INVALID;
module->impl = impl; module->impl = impl;
module->info = info;
spa_hook_list_init(&module->listener_list); spa_hook_list_init(&module->listener_list);
module->user_data = SPA_PTROFF(module, sizeof(*module), void); module->user_data = SPA_PTROFF(module, sizeof(*module), void);
module->loaded = false; module->loaded = false;
@ -304,17 +305,34 @@ struct module *module_create(struct client *client, const char *name, const char
} }
} }
module = info->create(impl, args); module = module_new(impl, info);
if (module == NULL) if (module == NULL)
return NULL; return NULL;
module->info = info; module->props = pw_properties_new(NULL, NULL);
if (module->props == NULL) {
module_free(module);
return NULL;
}
if (args)
module_args_add_props(module->props, args);
int res = module->info->create(module);
if (res < 0) {
module_free(module);
errno = -res;
return NULL;
}
module->index = pw_map_insert_new(&impl->modules, module); module->index = pw_map_insert_new(&impl->modules, module);
if (module->index == SPA_ID_INVALID) { if (module->index == SPA_ID_INVALID) {
module_unload(module); module_unload(module);
return NULL; return NULL;
} }
module->args = args ? strdup(args) : NULL; module->args = args ? strdup(args) : NULL;
module->index |= MODULE_FLAG; module->index |= MODULE_FLAG;
return module; return module;
} }

View file

@ -40,11 +40,12 @@ struct module_info {
unsigned int load_once:1; unsigned int load_once:1;
struct module *(*create) (struct impl *impl, const char *args); int (*create) (struct module *module);
int (*load) (struct client *client, struct module *module); int (*load) (struct client *client, struct module *module);
int (*unload) (struct module *module); int (*unload) (struct module *module);
const struct spa_dict *properties; const struct spa_dict *properties;
size_t data_size;
}; };
#define DEFINE_MODULE_INFO(name) \ #define DEFINE_MODULE_INFO(name) \
@ -79,7 +80,6 @@ struct module {
struct module *module_create(struct client *client, const char *name, const char *args); struct module *module_create(struct client *client, const char *name, const char *args);
void module_free(struct module *module); void module_free(struct module *module);
struct module *module_new(struct impl *impl, size_t user_data);
int module_load(struct client *client, struct module *module); int module_load(struct client *client, struct module *module);
int module_unload(struct module *module); int module_unload(struct module *module);
void module_schedule_unload(struct module *module); void module_schedule_unload(struct module *module);

View file

@ -101,34 +101,14 @@ static const struct spa_dict_item module_always_sink_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_always_sink(struct impl *impl, const char *argument) int create_module_always_sink(struct module * const module)
{ {
struct module *module;
struct pw_properties *props = NULL;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL); struct module_always_sink_data * const data = module->user_data;
if (props == NULL) { data->module = module;
res = -EINVAL;
goto out;
}
if (argument)
module_args_add_props(props, argument);
module = module_new(impl, sizeof(struct module_always_sink_data)); return 0;
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
return module;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_always_sink) = { DEFINE_MODULE_INFO(module_always_sink) = {
@ -138,4 +118,5 @@ DEFINE_MODULE_INFO(module_always_sink) = {
.load = module_always_sink_load, .load = module_always_sink_load,
.unload = module_always_sink_unload, .unload = module_always_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_always_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_always_sink_info),
.data_size = sizeof(struct module_always_sink_data),
}; };

View file

@ -499,11 +499,10 @@ static int module_combine_sink_unload(struct module *module)
return 0; return 0;
} }
struct module *create_module_combine_sink(struct impl *impl, const char *argument) int create_module_combine_sink(struct module * const module)
{ {
struct module *module; struct module_combine_sink_data * const d = module->user_data;
struct module_combine_sink_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL;
const char *str; const char *str;
char *sink_name = NULL, **sink_names = NULL; char *sink_name = NULL, **sink_names = NULL;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
@ -512,14 +511,6 @@ struct module *create_module_combine_sink(struct impl *impl, const char *argumen
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
if (!props) {
res = -EINVAL;
goto out;
}
if (argument)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "sink_name")) != NULL) { if ((str = pw_properties_get(props, "sink_name")) != NULL) {
sink_name = strdup(str); sink_name = strdup(str);
pw_properties_set(props, "sink_name", NULL); pw_properties_set(props, "sink_name", NULL);
@ -542,19 +533,11 @@ struct module *create_module_combine_sink(struct impl *impl, const char *argumen
pw_properties_set(props, "resample_method", NULL); pw_properties_set(props, "resample_method", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->info = info; d->info = info;
d->sink_name = sink_name; d->sink_name = sink_name;
@ -565,13 +548,12 @@ struct module *create_module_combine_sink(struct impl *impl, const char *argumen
d->streams[i].cleanup = false; d->streams[i].cleanup = false;
} }
return module; return 0;
out: out:
pw_properties_free(props);
free(sink_name); free(sink_name);
pw_free_strv(sink_names); pw_free_strv(sink_names);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_combine_sink) = { DEFINE_MODULE_INFO(module_combine_sink) = {
@ -580,4 +562,5 @@ DEFINE_MODULE_INFO(module_combine_sink) = {
.load = module_combine_sink_load, .load = module_combine_sink_load,
.unload = module_combine_sink_unload, .unload = module_combine_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_combine_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_combine_sink_info),
.data_size = sizeof(struct module_combine_sink_data),
}; };

View file

@ -155,27 +155,24 @@ static const struct spa_dict_item module_echo_cancel_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_echo_cancel(struct impl *impl, const char *argument) int create_module_echo_cancel(struct module * const module)
{ {
struct module *module; struct module_echo_cancel_data * const d = module->user_data;
struct module_echo_cancel_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *aec_props = NULL, *sink_props = NULL, *source_props = NULL; struct pw_properties *aec_props = NULL, *sink_props = NULL, *source_props = NULL;
const char *str; const char *str;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
aec_props = pw_properties_new(NULL, NULL); aec_props = pw_properties_new(NULL, NULL);
source_props = pw_properties_new(NULL, NULL); source_props = pw_properties_new(NULL, NULL);
sink_props = pw_properties_new(NULL, NULL); sink_props = pw_properties_new(NULL, NULL);
if (!props ||!aec_props || !source_props || !sink_props) { if (!aec_props || !source_props || !sink_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "source_name")) != NULL) { if ((str = pw_properties_get(props, "source_name")) != NULL) {
pw_properties_set(source_props, PW_KEY_NODE_NAME, str); pw_properties_set(source_props, PW_KEY_NODE_NAME, str);
@ -208,7 +205,7 @@ struct module *create_module_echo_cancel(struct impl *impl, const char *argument
pw_properties_set(props, "sink_master", NULL); pw_properties_set(props, "sink_master", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -233,29 +230,19 @@ struct module *create_module_echo_cancel(struct impl *impl, const char *argument
pw_properties_set(props, "aec_args", NULL); pw_properties_set(props, "aec_args", NULL);
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->props = aec_props; d->props = aec_props;
d->source_props = source_props; d->source_props = source_props;
d->sink_props = sink_props; d->sink_props = sink_props;
d->info = info; d->info = info;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(aec_props); pw_properties_free(aec_props);
pw_properties_free(sink_props); pw_properties_free(sink_props);
pw_properties_free(source_props); pw_properties_free(source_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_echo_cancel) = { DEFINE_MODULE_INFO(module_echo_cancel) = {
@ -264,4 +251,5 @@ DEFINE_MODULE_INFO(module_echo_cancel) = {
.load = module_echo_cancel_load, .load = module_echo_cancel_load,
.unload = module_echo_cancel_unload, .unload = module_echo_cancel_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_echo_cancel_info), .properties = &SPA_DICT_INIT_ARRAY(module_echo_cancel_info),
.data_size = sizeof(struct module_echo_cancel_data),
}; };

View file

@ -177,11 +177,11 @@ static void position_to_props(struct spa_audio_info_raw *info, struct pw_propert
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }
struct module *create_module_ladspa_sink(struct impl *impl, const char *argument) int create_module_ladspa_sink(struct module * const module)
{ {
struct module *module; struct module_ladspa_sink_data * const d = module->user_data;
struct module_ladspa_sink_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *playback_props = NULL, *capture_props = NULL; struct pw_properties *playback_props = NULL, *capture_props = NULL;
const char *str; const char *str;
struct spa_audio_info_raw capture_info = { 0 }; struct spa_audio_info_raw capture_info = { 0 };
struct spa_audio_info_raw playback_info = { 0 }; struct spa_audio_info_raw playback_info = { 0 };
@ -189,15 +189,12 @@ struct module *create_module_ladspa_sink(struct impl *impl, const char *argument
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
capture_props = pw_properties_new(NULL, NULL); capture_props = pw_properties_new(NULL, NULL);
playback_props = pw_properties_new(NULL, NULL); playback_props = pw_properties_new(NULL, NULL);
if (!props || !capture_props || !playback_props) { if (!capture_props || !playback_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "sink_name")) != NULL) { if ((str = pw_properties_get(props, "sink_name")) != NULL) {
pw_properties_set(capture_props, PW_KEY_NODE_NAME, str); pw_properties_set(capture_props, PW_KEY_NODE_NAME, str);
@ -226,7 +223,7 @@ struct module *create_module_ladspa_sink(struct impl *impl, const char *argument
pw_properties_set(props, "master", NULL); pw_properties_set(props, "master", NULL);
} }
if (module_args_to_audioinfo(impl, props, &capture_info) < 0) { if (module_args_to_audioinfo(module->impl, props, &capture_info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -238,25 +235,16 @@ struct module *create_module_ladspa_sink(struct impl *impl, const char *argument
if (pw_properties_get(playback_props, PW_KEY_NODE_PASSIVE) == NULL) if (pw_properties_get(playback_props, PW_KEY_NODE_PASSIVE) == NULL)
pw_properties_set(playback_props, PW_KEY_NODE_PASSIVE, "true"); pw_properties_set(playback_props, PW_KEY_NODE_PASSIVE, "true");
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->capture_props = capture_props; d->capture_props = capture_props;
d->playback_props = playback_props; d->playback_props = playback_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(playback_props); pw_properties_free(playback_props);
pw_properties_free(capture_props); pw_properties_free(capture_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_ladspa_sink) = { DEFINE_MODULE_INFO(module_ladspa_sink) = {
@ -265,4 +253,5 @@ DEFINE_MODULE_INFO(module_ladspa_sink) = {
.load = module_ladspa_sink_load, .load = module_ladspa_sink_load,
.unload = module_ladspa_sink_unload, .unload = module_ladspa_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_ladspa_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_ladspa_sink_info),
.data_size = sizeof(struct module_ladspa_sink_data),
}; };

View file

@ -177,11 +177,11 @@ static void position_to_props(struct spa_audio_info_raw *info, struct pw_propert
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }
struct module *create_module_ladspa_source(struct impl *impl, const char *argument) int create_module_ladspa_source(struct module * const module)
{ {
struct module *module; struct module_ladspa_source_data * const d = module->user_data;
struct module_ladspa_source_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *playback_props = NULL, *capture_props = NULL; struct pw_properties *playback_props = NULL, *capture_props = NULL;
const char *str; const char *str;
struct spa_audio_info_raw capture_info = { 0 }; struct spa_audio_info_raw capture_info = { 0 };
struct spa_audio_info_raw playback_info = { 0 }; struct spa_audio_info_raw playback_info = { 0 };
@ -189,15 +189,12 @@ struct module *create_module_ladspa_source(struct impl *impl, const char *argume
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
capture_props = pw_properties_new(NULL, NULL); capture_props = pw_properties_new(NULL, NULL);
playback_props = pw_properties_new(NULL, NULL); playback_props = pw_properties_new(NULL, NULL);
if (!props || !capture_props || !playback_props) { if (!capture_props || !playback_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "source_name")) != NULL) { if ((str = pw_properties_get(props, "source_name")) != NULL) {
pw_properties_set(playback_props, PW_KEY_NODE_NAME, str); pw_properties_set(playback_props, PW_KEY_NODE_NAME, str);
@ -226,7 +223,7 @@ struct module *create_module_ladspa_source(struct impl *impl, const char *argume
pw_properties_set(props, "master", NULL); pw_properties_set(props, "master", NULL);
} }
if (module_args_to_audioinfo(impl, props, &playback_info) < 0) { if (module_args_to_audioinfo(module->impl, props, &playback_info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -238,25 +235,16 @@ struct module *create_module_ladspa_source(struct impl *impl, const char *argume
if (pw_properties_get(capture_props, PW_KEY_NODE_PASSIVE) == NULL) if (pw_properties_get(capture_props, PW_KEY_NODE_PASSIVE) == NULL)
pw_properties_set(capture_props, PW_KEY_NODE_PASSIVE, "true"); pw_properties_set(capture_props, PW_KEY_NODE_PASSIVE, "true");
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->capture_props = capture_props; d->capture_props = capture_props;
d->playback_props = playback_props; d->playback_props = playback_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(playback_props); pw_properties_free(playback_props);
pw_properties_free(capture_props); pw_properties_free(capture_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_ladspa_source) = { DEFINE_MODULE_INFO(module_ladspa_source) = {
@ -265,4 +253,5 @@ DEFINE_MODULE_INFO(module_ladspa_source) = {
.load = module_ladspa_source_load, .load = module_ladspa_source_load,
.unload = module_ladspa_source_unload, .unload = module_ladspa_source_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_ladspa_source_info), .properties = &SPA_DICT_INIT_ARRAY(module_ladspa_source_info),
.data_size = sizeof(struct module_ladspa_source_data),
}; };

View file

@ -143,26 +143,23 @@ static const struct spa_dict_item module_loopback_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_loopback(struct impl *impl, const char *argument) int create_module_loopback(struct module * const module)
{ {
struct module *module; struct module_loopback_data * const d = module->user_data;
struct module_loopback_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *playback_props = NULL, *capture_props = NULL; struct pw_properties *playback_props = NULL, *capture_props = NULL;
const char *str; const char *str;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
capture_props = pw_properties_new(NULL, NULL); capture_props = pw_properties_new(NULL, NULL);
playback_props = pw_properties_new(NULL, NULL); playback_props = pw_properties_new(NULL, NULL);
if (!props || !capture_props || !playback_props) { if (!capture_props || !playback_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
/* The following modargs are not implemented: /* The following modargs are not implemented:
* adjust_time, max_latency_msec, fast_adjust_threshold_msec: these are just not relevant * adjust_time, max_latency_msec, fast_adjust_threshold_msec: these are just not relevant
@ -185,7 +182,7 @@ struct module *create_module_loopback(struct impl *impl, const char *argument)
pw_properties_set(props, "sink", NULL); pw_properties_set(props, "sink", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -227,27 +224,17 @@ struct module *create_module_loopback(struct impl *impl, const char *argument)
pw_properties_set(props, "source_output_properties", NULL); pw_properties_set(props, "source_output_properties", NULL);
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->capture_props = capture_props; d->capture_props = capture_props;
d->playback_props = playback_props; d->playback_props = playback_props;
d->info = info; d->info = info;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(playback_props); pw_properties_free(playback_props);
pw_properties_free(capture_props); pw_properties_free(capture_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_loopback) = { DEFINE_MODULE_INFO(module_loopback) = {
@ -256,4 +243,5 @@ DEFINE_MODULE_INFO(module_loopback) = {
.load = module_loopback_load, .load = module_loopback_load,
.unload = module_loopback_unload, .unload = module_loopback_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_loopback_info), .properties = &SPA_DICT_INIT_ARRAY(module_loopback_info),
.data_size = sizeof(struct module_loopback_data),
}; };

View file

@ -79,27 +79,17 @@ static const struct spa_dict_item module_native_protocol_tcp_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_native_protocol_tcp(struct impl *impl, const char *argument) int create_module_native_protocol_tcp(struct module * const module)
{ {
struct module *module; struct module_native_protocol_tcp_data * const d = module->user_data;
struct module_native_protocol_tcp_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL;
const char *port, *listen, *auth; const char *port, *listen, *auth;
FILE *f; FILE *f;
char *args; char *args;
size_t size; size_t size;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
if (props == NULL) {
res = -errno;
goto out;
}
if (argument)
module_args_add_props(props, argument);
if ((port = pw_properties_get(props, "port")) == NULL) if ((port = pw_properties_get(props, "port")) == NULL)
port = SPA_STRINGIFY(PW_PROTOCOL_PULSE_DEFAULT_PORT); port = SPA_STRINGIFY(PW_PROTOCOL_PULSE_DEFAULT_PORT);
@ -108,10 +98,8 @@ struct module *create_module_native_protocol_tcp(struct impl *impl, const char *
auth = pw_properties_get(props, "auth-anonymous"); auth = pw_properties_get(props, "auth-anonymous");
f = open_memstream(&args, &size); f = open_memstream(&args, &size);
if (f == NULL) { if (f == NULL)
res = -errno; return -errno;
goto out;
}
fprintf(f, "[ { "); fprintf(f, "[ { ");
fprintf(f, " \"address\": \"tcp:%s%s%s\" ", fprintf(f, " \"address\": \"tcp:%s%s%s\" ",
@ -124,21 +112,9 @@ struct module *create_module_native_protocol_tcp(struct impl *impl, const char *
pw_properties_set(props, "pulse.tcp", args); pw_properties_set(props, "pulse.tcp", args);
free(args); free(args);
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
return module; return 0;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_native_protocol_tcp) = { DEFINE_MODULE_INFO(module_native_protocol_tcp) = {
@ -147,4 +123,5 @@ DEFINE_MODULE_INFO(module_native_protocol_tcp) = {
.load = module_native_protocol_tcp_load, .load = module_native_protocol_tcp_load,
.unload = module_native_protocol_tcp_unload, .unload = module_native_protocol_tcp_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_native_protocol_tcp_info), .properties = &SPA_DICT_INIT_ARRAY(module_native_protocol_tcp_info),
.data_size = sizeof(struct module_native_protocol_tcp_data),
}; };

View file

@ -158,25 +158,15 @@ static const struct spa_dict_item module_null_sink_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_null_sink(struct impl *impl, const char *argument) int create_module_null_sink(struct module * const module)
{ {
struct module *module; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL;
const char *str; const char *str;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
uint32_t i; uint32_t i;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
if (props == NULL) {
res = -EINVAL;
goto out;
}
if (argument)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "sink_name")) != NULL) { if ((str = pw_properties_get(props, "sink_name")) != NULL) {
pw_properties_set(props, PW_KEY_NODE_NAME, str); pw_properties_set(props, PW_KEY_NODE_NAME, str);
pw_properties_set(props, "sink_name", NULL); pw_properties_set(props, "sink_name", NULL);
@ -190,10 +180,8 @@ struct module *create_module_null_sink(struct impl *impl, const char *argument)
pw_properties_set(props, "sink_properties", NULL); pw_properties_set(props, "sink_properties", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0)
res = -EINVAL; return -EINVAL;
goto out;
}
if (info.rate) if (info.rate)
pw_properties_setf(props, SPA_KEY_AUDIO_RATE, "%u", info.rate); pw_properties_setf(props, SPA_KEY_AUDIO_RATE, "%u", info.rate);
@ -227,18 +215,7 @@ struct module *create_module_null_sink(struct impl *impl, const char *argument)
if (pw_properties_get(props, "monitor.channel-volumes") == NULL) if (pw_properties_get(props, "monitor.channel-volumes") == NULL)
pw_properties_set(props, "monitor.channel-volumes", "true"); pw_properties_set(props, "monitor.channel-volumes", "true");
module = module_new(impl, sizeof(struct module_null_sink_data)); return 0;
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
return module;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_null_sink) = { DEFINE_MODULE_INFO(module_null_sink) = {
@ -247,4 +224,5 @@ DEFINE_MODULE_INFO(module_null_sink) = {
.load = module_null_sink_load, .load = module_null_sink_load,
.unload = module_null_sink_unload, .unload = module_null_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_null_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_null_sink_info),
.data_size = sizeof(struct module_null_sink_data),
}; };

View file

@ -218,11 +218,11 @@ static const struct spa_dict_item module_pipe_sink_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_pipe_sink(struct impl *impl, const char *argument) int create_module_pipe_sink(struct module * const module)
{ {
struct module *module; struct module_pipesink_data * const d = module->user_data;
struct module_pipesink_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *capture_props = NULL; struct pw_properties *capture_props = NULL;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
struct stat st; struct stat st;
const char *str; const char *str;
@ -233,16 +233,13 @@ struct module *create_module_pipe_sink(struct impl *impl, const char *argument)
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
capture_props = pw_properties_new(NULL, NULL); capture_props = pw_properties_new(NULL, NULL);
if (!props || !capture_props) { if (!capture_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -302,14 +299,6 @@ struct module *create_module_pipe_sink(struct impl *impl, const char *argument)
pw_properties_set(capture_props, PW_KEY_NODE_VIRTUAL, "true"); pw_properties_set(capture_props, PW_KEY_NODE_VIRTUAL, "true");
pw_properties_set(capture_props, PW_KEY_MEDIA_CLASS, "Audio/Sink"); pw_properties_set(capture_props, PW_KEY_MEDIA_CLASS, "Audio/Sink");
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->capture_props = capture_props; d->capture_props = capture_props;
d->info = info; d->info = info;
@ -319,9 +308,8 @@ struct module *create_module_pipe_sink(struct impl *impl, const char *argument)
pw_log_info("Successfully loaded module-pipe-sink"); pw_log_info("Successfully loaded module-pipe-sink");
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(capture_props); pw_properties_free(capture_props);
if (filename) { if (filename) {
if (do_unlink_fifo) if (do_unlink_fifo)
@ -330,9 +318,8 @@ out:
} }
if (fd >= 0) if (fd >= 0)
close(fd); close(fd);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_pipe_sink) = { DEFINE_MODULE_INFO(module_pipe_sink) = {
@ -341,4 +328,5 @@ DEFINE_MODULE_INFO(module_pipe_sink) = {
.load = module_pipe_sink_load, .load = module_pipe_sink_load,
.unload = module_pipe_sink_unload, .unload = module_pipe_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_pipe_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_pipe_sink_info),
.data_size = sizeof(struct module_pipesink_data),
}; };

View file

@ -238,11 +238,11 @@ static const struct spa_dict_item module_pipe_source_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_pipe_source(struct impl *impl, const char *argument) int create_module_pipe_source(struct module * const module)
{ {
struct module *module; struct module_pipesrc_data * const d = module->user_data;
struct module_pipesrc_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *playback_props = NULL; struct pw_properties *playback_props = NULL;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
struct stat st; struct stat st;
const char *str; const char *str;
@ -253,16 +253,13 @@ struct module *create_module_pipe_source(struct impl *impl, const char *argument
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
playback_props = pw_properties_new(NULL, NULL); playback_props = pw_properties_new(NULL, NULL);
if (!props || !playback_props) { if (!playback_props) {
res = -errno; res = -errno;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -361,14 +358,6 @@ struct module *create_module_pipe_source(struct impl *impl, const char *argument
pw_properties_set(playback_props, PW_KEY_NODE_VIRTUAL, "true"); pw_properties_set(playback_props, PW_KEY_NODE_VIRTUAL, "true");
pw_properties_set(playback_props, PW_KEY_MEDIA_CLASS, "Audio/Source"); pw_properties_set(playback_props, PW_KEY_MEDIA_CLASS, "Audio/Source");
module = module_new(impl, sizeof(*d) + stride);
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->playback_props = playback_props; d->playback_props = playback_props;
d->info = info; d->info = info;
@ -379,18 +368,16 @@ struct module *create_module_pipe_source(struct impl *impl, const char *argument
pw_log_info("Successfully loaded module-pipe-source"); pw_log_info("Successfully loaded module-pipe-source");
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(playback_props); pw_properties_free(playback_props);
if (do_unlink) if (do_unlink)
unlink(filename); unlink(filename);
free(filename); free(filename);
if (fd >= 0) if (fd >= 0)
close(fd); close(fd);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_pipe_source) = { DEFINE_MODULE_INFO(module_pipe_source) = {
@ -399,4 +386,5 @@ DEFINE_MODULE_INFO(module_pipe_source) = {
.load = module_pipe_source_load, .load = module_pipe_source_load,
.unload = module_pipe_source_unload, .unload = module_pipe_source_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_pipe_source_info), .properties = &SPA_DICT_INIT_ARRAY(module_pipe_source_info),
.data_size = sizeof(struct module_pipesrc_data),
}; };

View file

@ -92,38 +92,14 @@ static const struct spa_dict_item module_raop_discover_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_raop_discover(struct impl *impl, const char *argument) int create_module_raop_discover(struct module * const module)
{ {
struct module *module;
struct module_raop_discover_data *d;
struct pw_properties *props = NULL;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL); struct module_raop_discover_data * const data = module->user_data;
if (props == NULL) { data->module = module;
res = -errno;
goto out;
}
if (argument != NULL)
module_args_add_props(props, argument);
module = module_new(impl, sizeof(*d)); return 0;
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module;
return module;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_raop_discover) = { DEFINE_MODULE_INFO(module_raop_discover) = {
@ -133,4 +109,5 @@ DEFINE_MODULE_INFO(module_raop_discover) = {
.load = module_raop_discover_load, .load = module_raop_discover_load,
.unload = module_raop_discover_unload, .unload = module_raop_discover_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_raop_discover_info), .properties = &SPA_DICT_INIT_ARRAY(module_raop_discover_info),
.data_size = sizeof(struct module_raop_discover_data),
}; };

View file

@ -143,11 +143,11 @@ static void position_to_props(struct spa_audio_info_raw *info, struct pw_propert
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }
struct module *create_module_remap_sink(struct impl *impl, const char *argument) int create_module_remap_sink(struct module * const module)
{ {
struct module *module; struct module_remap_sink_data * const d = module->user_data;
struct module_remap_sink_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *playback_props = NULL, *capture_props = NULL; struct pw_properties *playback_props = NULL, *capture_props = NULL;
const char *str, *master; const char *str, *master;
struct spa_audio_info_raw capture_info = { 0 }; struct spa_audio_info_raw capture_info = { 0 };
struct spa_audio_info_raw playback_info = { 0 }; struct spa_audio_info_raw playback_info = { 0 };
@ -155,15 +155,12 @@ struct module *create_module_remap_sink(struct impl *impl, const char *argument)
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
capture_props = pw_properties_new(NULL, NULL); capture_props = pw_properties_new(NULL, NULL);
playback_props = pw_properties_new(NULL, NULL); playback_props = pw_properties_new(NULL, NULL);
if (!props || !capture_props || !playback_props) { if (!capture_props || !playback_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
master = pw_properties_get(props, "master"); master = pw_properties_get(props, "master");
if (pw_properties_get(props, "sink_name") == NULL) { if (pw_properties_get(props, "sink_name") == NULL) {
@ -204,7 +201,7 @@ struct module *create_module_remap_sink(struct impl *impl, const char *argument)
pw_properties_set(props, "master", NULL); pw_properties_set(props, "master", NULL);
} }
if (module_args_to_audioinfo(impl, props, &capture_info) < 0) { if (module_args_to_audioinfo(module->impl, props, &capture_info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -235,25 +232,16 @@ struct module *create_module_remap_sink(struct impl *impl, const char *argument)
if (pw_properties_get(playback_props, PW_KEY_NODE_PASSIVE) == NULL) if (pw_properties_get(playback_props, PW_KEY_NODE_PASSIVE) == NULL)
pw_properties_set(playback_props, PW_KEY_NODE_PASSIVE, "true"); pw_properties_set(playback_props, PW_KEY_NODE_PASSIVE, "true");
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->capture_props = capture_props; d->capture_props = capture_props;
d->playback_props = playback_props; d->playback_props = playback_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(playback_props); pw_properties_free(playback_props);
pw_properties_free(capture_props); pw_properties_free(capture_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_remap_sink) = { DEFINE_MODULE_INFO(module_remap_sink) = {
@ -262,4 +250,5 @@ DEFINE_MODULE_INFO(module_remap_sink) = {
.load = module_remap_sink_load, .load = module_remap_sink_load,
.unload = module_remap_sink_unload, .unload = module_remap_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_remap_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_remap_sink_info),
.data_size = sizeof(struct module_remap_sink_data),
}; };

View file

@ -143,11 +143,11 @@ static void position_to_props(struct spa_audio_info_raw *info, struct pw_propert
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }
struct module *create_module_remap_source(struct impl *impl, const char *argument) int create_module_remap_source(struct module * const module)
{ {
struct module *module; struct module_remap_source_data * const d = module->user_data;
struct module_remap_source_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *playback_props = NULL, *capture_props = NULL; struct pw_properties *playback_props = NULL, *capture_props = NULL;
const char *str, *master; const char *str, *master;
struct spa_audio_info_raw capture_info = { 0 }; struct spa_audio_info_raw capture_info = { 0 };
struct spa_audio_info_raw playback_info = { 0 }; struct spa_audio_info_raw playback_info = { 0 };
@ -155,15 +155,12 @@ struct module *create_module_remap_source(struct impl *impl, const char *argumen
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
capture_props = pw_properties_new(NULL, NULL); capture_props = pw_properties_new(NULL, NULL);
playback_props = pw_properties_new(NULL, NULL); playback_props = pw_properties_new(NULL, NULL);
if (!props || !capture_props || !playback_props) { if (!capture_props || !playback_props) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
master = pw_properties_get(props, "master"); master = pw_properties_get(props, "master");
if (pw_properties_get(props, "source_name") == NULL) { if (pw_properties_get(props, "source_name") == NULL) {
@ -204,7 +201,7 @@ struct module *create_module_remap_source(struct impl *impl, const char *argumen
pw_properties_set(props, "master", NULL); pw_properties_set(props, "master", NULL);
} }
if (module_args_to_audioinfo(impl, props, &playback_info) < 0) { if (module_args_to_audioinfo(module->impl, props, &playback_info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -235,25 +232,16 @@ struct module *create_module_remap_source(struct impl *impl, const char *argumen
if (pw_properties_get(capture_props, PW_KEY_NODE_PASSIVE) == NULL) if (pw_properties_get(capture_props, PW_KEY_NODE_PASSIVE) == NULL)
pw_properties_set(capture_props, PW_KEY_NODE_PASSIVE, "true"); pw_properties_set(capture_props, PW_KEY_NODE_PASSIVE, "true");
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->capture_props = capture_props; d->capture_props = capture_props;
d->playback_props = playback_props; d->playback_props = playback_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(playback_props); pw_properties_free(playback_props);
pw_properties_free(capture_props); pw_properties_free(capture_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_remap_source) = { DEFINE_MODULE_INFO(module_remap_source) = {
@ -262,4 +250,5 @@ DEFINE_MODULE_INFO(module_remap_source) = {
.load = module_remap_source_load, .load = module_remap_source_load,
.unload = module_remap_source_unload, .unload = module_remap_source_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_remap_source_info), .properties = &SPA_DICT_INIT_ARRAY(module_remap_source_info),
.data_size = sizeof(struct module_remap_source_data),
}; };

View file

@ -124,27 +124,23 @@ static const struct spa_dict_item module_roc_sink_input_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_roc_sink_input(struct impl *impl, const char *argument) int create_module_roc_sink_input(struct module * const module)
{ {
struct module *module; struct module_roc_sink_input_data * const d = module->user_data;
struct module_roc_sink_input_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *source_props = NULL, *roc_props = NULL; struct pw_properties *source_props = NULL, *roc_props = NULL;
const char *str; const char *str;
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
source_props = pw_properties_new(NULL, NULL); source_props = pw_properties_new(NULL, NULL);
roc_props = pw_properties_new(NULL, NULL); roc_props = pw_properties_new(NULL, NULL);
if (!props || !source_props || !roc_props) { if (!source_props || !roc_props) {
res = -errno; res = -errno;
goto out; goto out;
} }
if (argument != NULL)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "sink")) != NULL) { if ((str = pw_properties_get(props, "sink")) != NULL) {
pw_properties_set(source_props, PW_KEY_TARGET_OBJECT, str); pw_properties_set(source_props, PW_KEY_TARGET_OBJECT, str);
pw_properties_set(props, "sink", NULL); pw_properties_set(props, "sink", NULL);
@ -184,25 +180,16 @@ struct module *create_module_roc_sink_input(struct impl *impl, const char *argum
pw_properties_set(props, "fec_code", NULL); pw_properties_set(props, "fec_code", NULL);
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->source_props = source_props; d->source_props = source_props;
d->roc_props = roc_props; d->roc_props = roc_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(source_props); pw_properties_free(source_props);
pw_properties_free(roc_props); pw_properties_free(roc_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_roc_sink_input) = { DEFINE_MODULE_INFO(module_roc_sink_input) = {
@ -211,4 +198,5 @@ DEFINE_MODULE_INFO(module_roc_sink_input) = {
.load = module_roc_sink_input_load, .load = module_roc_sink_input_load,
.unload = module_roc_sink_input_unload, .unload = module_roc_sink_input_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_roc_sink_input_info), .properties = &SPA_DICT_INIT_ARRAY(module_roc_sink_input_info),
.data_size = sizeof(struct module_roc_sink_input_data),
}; };

View file

@ -123,25 +123,22 @@ static const struct spa_dict_item module_roc_sink_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_roc_sink(struct impl *impl, const char *argument) int create_module_roc_sink(struct module * const module)
{ {
struct module *module; struct module_roc_sink_data * const d = module->user_data;
struct module_roc_sink_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *sink_props = NULL, *roc_props = NULL; struct pw_properties *sink_props = NULL, *roc_props = NULL;
const char *str; const char *str;
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
sink_props = pw_properties_new(NULL, NULL); sink_props = pw_properties_new(NULL, NULL);
roc_props = pw_properties_new(NULL, NULL); roc_props = pw_properties_new(NULL, NULL);
if (!props || !sink_props || !roc_props) { if (!sink_props || !roc_props) {
res = -errno; res = -errno;
goto out; goto out;
} }
if (argument != NULL)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "sink_name")) != NULL) { if ((str = pw_properties_get(props, "sink_name")) != NULL) {
pw_properties_set(sink_props, PW_KEY_NODE_NAME, str); pw_properties_set(sink_props, PW_KEY_NODE_NAME, str);
@ -185,25 +182,16 @@ struct module *create_module_roc_sink(struct impl *impl, const char *argument)
pw_properties_set(props, "fec_code", NULL); pw_properties_set(props, "fec_code", NULL);
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->sink_props = sink_props; d->sink_props = sink_props;
d->roc_props = roc_props; d->roc_props = roc_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(sink_props); pw_properties_free(sink_props);
pw_properties_free(roc_props); pw_properties_free(roc_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_roc_sink) = { DEFINE_MODULE_INFO(module_roc_sink) = {
@ -212,4 +200,5 @@ DEFINE_MODULE_INFO(module_roc_sink) = {
.load = module_roc_sink_load, .load = module_roc_sink_load,
.unload = module_roc_sink_unload, .unload = module_roc_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_roc_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_roc_sink_info),
.data_size = sizeof(struct module_roc_sink_data),
}; };

View file

@ -124,27 +124,23 @@ static const struct spa_dict_item module_roc_source_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_roc_source(struct impl *impl, const char *argument) int create_module_roc_source(struct module * const module)
{ {
struct module *module; struct module_roc_source_data * const d = module->user_data;
struct module_roc_source_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *source_props = NULL, *roc_props = NULL; struct pw_properties *source_props = NULL, *roc_props = NULL;
const char *str; const char *str;
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
source_props = pw_properties_new(NULL, NULL); source_props = pw_properties_new(NULL, NULL);
roc_props = pw_properties_new(NULL, NULL); roc_props = pw_properties_new(NULL, NULL);
if (!props || !source_props || !roc_props) { if (!source_props || !roc_props) {
res = -errno; res = -errno;
goto out; goto out;
} }
if (argument != NULL)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "source_name")) != NULL) { if ((str = pw_properties_get(props, "source_name")) != NULL) {
pw_properties_set(source_props, PW_KEY_NODE_NAME, str); pw_properties_set(source_props, PW_KEY_NODE_NAME, str);
pw_properties_set(props, "source_name", NULL); pw_properties_set(props, "source_name", NULL);
@ -189,25 +185,16 @@ struct module *create_module_roc_source(struct impl *impl, const char *argument)
pw_properties_set(props, "fec_code", NULL); pw_properties_set(props, "fec_code", NULL);
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->source_props = source_props; d->source_props = source_props;
d->roc_props = roc_props; d->roc_props = roc_props;
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(source_props); pw_properties_free(source_props);
pw_properties_free(roc_props); pw_properties_free(roc_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_roc_source) = { DEFINE_MODULE_INFO(module_roc_source) = {
@ -216,4 +203,5 @@ DEFINE_MODULE_INFO(module_roc_source) = {
.load = module_roc_source_load, .load = module_roc_source_load,
.unload = module_roc_source_unload, .unload = module_roc_source_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_roc_source_info), .properties = &SPA_DICT_INIT_ARRAY(module_roc_source_info),
.data_size = sizeof(struct module_roc_source_data),
}; };

View file

@ -130,25 +130,17 @@ static const struct spa_dict_item module_simple_protocol_tcp_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_simple_protocol_tcp(struct impl *impl, const char *argument) int create_module_simple_protocol_tcp(struct module * const module)
{ {
struct module *module; struct module_simple_protocol_tcp_data * const d = module->user_data;
struct module_simple_protocol_tcp_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *module_props = NULL; struct pw_properties *module_props = NULL;
const char *str, *port, *listen; const char *str, *port, *listen;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
if (props == NULL) {
res = -errno;
goto out;
}
if (argument)
module_args_add_props(props, argument);
module_props = pw_properties_new(NULL, NULL); module_props = pw_properties_new(NULL, NULL);
if (module_props == NULL) { if (module_props == NULL) {
res = -errno; res = -errno;
@ -160,7 +152,7 @@ struct module *create_module_simple_protocol_tcp(struct impl *impl, const char *
format_id2name(format_paname2id(str, strlen(str)))); format_id2name(format_paname2id(str, strlen(str))));
pw_properties_set(props, "format", NULL); pw_properties_set(props, "format", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -197,24 +189,15 @@ struct module *create_module_simple_protocol_tcp(struct impl *impl, const char *
pw_properties_setf(module_props, "server.address", "[ \"tcp:%s%s%s\" ]", pw_properties_setf(module_props, "server.address", "[ \"tcp:%s%s%s\" ]",
listen ? listen : "", listen ? ":" : "", port); listen ? listen : "", listen ? ":" : "", port);
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->module_props = module_props; d->module_props = module_props;
d->info = info; d->info = info;
return module; return 0;
out: out:
pw_properties_free(module_props); pw_properties_free(module_props);
pw_properties_free(props);
errno = -res; return res;
return NULL;
} }
DEFINE_MODULE_INFO(module_simple_protocol_tcp) = { DEFINE_MODULE_INFO(module_simple_protocol_tcp) = {
@ -223,4 +206,5 @@ DEFINE_MODULE_INFO(module_simple_protocol_tcp) = {
.load = module_simple_protocol_tcp_load, .load = module_simple_protocol_tcp_load,
.unload = module_simple_protocol_tcp_unload, .unload = module_simple_protocol_tcp_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_simple_protocol_tcp_info), .properties = &SPA_DICT_INIT_ARRAY(module_simple_protocol_tcp_info),
.data_size = sizeof(struct module_simple_protocol_tcp_data),
}; };

View file

@ -245,11 +245,10 @@ static const struct spa_dict_item module_switch_on_connect_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_switch_on_connect(struct impl *impl, const char *argument) int create_module_switch_on_connect(struct module * const module)
{ {
struct module *module; struct module_switch_on_connect_data * const d = module->user_data;
struct module_switch_on_connect_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL;
regex_t *blocklist = NULL; regex_t *blocklist = NULL;
bool only_from_unavailable = false, ignore_virtual = true; bool only_from_unavailable = false, ignore_virtual = true;
const char *str; const char *str;
@ -257,14 +256,6 @@ struct module *create_module_switch_on_connect(struct impl *impl, const char *ar
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
if (!props) {
res = -EINVAL;
goto out;
}
if (argument)
module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "only_from_unavailable")) != NULL) { if ((str = pw_properties_get(props, "only_from_unavailable")) != NULL) {
only_from_unavailable = module_args_parse_bool(str); only_from_unavailable = module_args_parse_bool(str);
pw_properties_set(props, "only_from_unavailable", NULL); pw_properties_set(props, "only_from_unavailable", NULL);
@ -292,14 +283,6 @@ struct module *create_module_switch_on_connect(struct impl *impl, const char *ar
pw_properties_set(props, "blocklist", NULL); pw_properties_set(props, "blocklist", NULL);
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->blocklist = blocklist; d->blocklist = blocklist;
d->ignore_virtual = ignore_virtual; d->ignore_virtual = ignore_virtual;
@ -310,17 +293,15 @@ struct module *create_module_switch_on_connect(struct impl *impl, const char *ar
pw_log_warn("only_from_unavailable is not implemented"); pw_log_warn("only_from_unavailable is not implemented");
} }
return module; return 0;
out: out:
pw_properties_free(props);
if (blocklist) { if (blocklist) {
regfree(blocklist); regfree(blocklist);
free(blocklist); free(blocklist);
} }
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_switch_on_connect) = { DEFINE_MODULE_INFO(module_switch_on_connect) = {
@ -330,4 +311,5 @@ DEFINE_MODULE_INFO(module_switch_on_connect) = {
.load = module_switch_on_connect_load, .load = module_switch_on_connect_load,
.unload = module_switch_on_connect_unload, .unload = module_switch_on_connect_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_switch_on_connect_info), .properties = &SPA_DICT_INIT_ARRAY(module_switch_on_connect_info),
.data_size = sizeof(struct module_switch_on_connect_data),
}; };

View file

@ -149,25 +149,22 @@ static void audio_info_to_props(struct spa_audio_info_raw *info, struct pw_prope
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }
struct module *create_module_tunnel_sink(struct impl *impl, const char *argument) int create_module_tunnel_sink(struct module * const module)
{ {
struct module *module; struct module_tunnel_sink_data * const d = module->user_data;
struct module_tunnel_sink_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *stream_props = NULL; struct pw_properties *stream_props = NULL;
const char *str, *server, *remote_sink_name; const char *str, *server, *remote_sink_name;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
stream_props = pw_properties_new(NULL, NULL); stream_props = pw_properties_new(NULL, NULL);
if (props == NULL || stream_props == NULL) { if (stream_props == NULL) {
res = -ENOMEM; res = -ENOMEM;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
remote_sink_name = pw_properties_get(props, "sink"); remote_sink_name = pw_properties_get(props, "sink");
if (remote_sink_name) if (remote_sink_name)
@ -196,7 +193,7 @@ struct module *create_module_tunnel_sink(struct impl *impl, const char *argument
module_args_add_props(stream_props, str); module_args_add_props(stream_props, str);
pw_properties_set(props, "sink_properties", NULL); pw_properties_set(props, "sink_properties", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
@ -212,25 +209,16 @@ struct module *create_module_tunnel_sink(struct impl *impl, const char *argument
pw_properties_set(stream_props, PW_KEY_AUDIO_FORMAT, format_id2name(id)); pw_properties_set(stream_props, PW_KEY_AUDIO_FORMAT, format_id2name(id));
} }
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->stream_props = stream_props; d->stream_props = stream_props;
pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec); pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec);
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(stream_props); pw_properties_free(stream_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_tunnel_sink) = { DEFINE_MODULE_INFO(module_tunnel_sink) = {
@ -239,4 +227,5 @@ DEFINE_MODULE_INFO(module_tunnel_sink) = {
.load = module_tunnel_sink_load, .load = module_tunnel_sink_load,
.unload = module_tunnel_sink_unload, .unload = module_tunnel_sink_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_tunnel_sink_info), .properties = &SPA_DICT_INIT_ARRAY(module_tunnel_sink_info),
.data_size = sizeof(struct module_tunnel_sink_data),
}; };

View file

@ -149,25 +149,22 @@ static void audio_info_to_props(struct spa_audio_info_raw *info, struct pw_prope
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s); pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
} }
struct module *create_module_tunnel_source(struct impl *impl, const char *argument) int create_module_tunnel_source(struct module * const module)
{ {
struct module *module; struct module_tunnel_source_data * const d = module->user_data;
struct module_tunnel_source_data *d; struct pw_properties * const props = module->props;
struct pw_properties *props = NULL, *stream_props = NULL; struct pw_properties *stream_props = NULL;
const char *str, *server, *remote_source_name; const char *str, *server, *remote_source_name;
struct spa_audio_info_raw info = { 0 }; struct spa_audio_info_raw info = { 0 };
int res; int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL);
stream_props = pw_properties_new(NULL, NULL); stream_props = pw_properties_new(NULL, NULL);
if (props == NULL || stream_props == NULL) { if (stream_props == NULL) {
res = -ENOMEM; res = -ENOMEM;
goto out; goto out;
} }
if (argument)
module_args_add_props(props, argument);
remote_source_name = pw_properties_get(props, "source"); remote_source_name = pw_properties_get(props, "source");
if (remote_source_name) if (remote_source_name)
@ -195,32 +192,23 @@ struct module *create_module_tunnel_source(struct impl *impl, const char *argume
module_args_add_props(stream_props, str); module_args_add_props(stream_props, str);
pw_properties_set(props, "source_properties", NULL); pw_properties_set(props, "source_properties", NULL);
} }
if (module_args_to_audioinfo(impl, props, &info) < 0) { if (module_args_to_audioinfo(module->impl, props, &info) < 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
audio_info_to_props(&info, stream_props); audio_info_to_props(&info, stream_props);
module = module_new(impl, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module; d->module = module;
d->stream_props = stream_props; d->stream_props = stream_props;
pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec); pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec);
return module; return 0;
out: out:
pw_properties_free(props);
pw_properties_free(stream_props); pw_properties_free(stream_props);
errno = -res;
return NULL; return res;
} }
DEFINE_MODULE_INFO(module_tunnel_source) = { DEFINE_MODULE_INFO(module_tunnel_source) = {
@ -229,4 +217,5 @@ DEFINE_MODULE_INFO(module_tunnel_source) = {
.load = module_tunnel_source_load, .load = module_tunnel_source_load,
.unload = module_tunnel_source_unload, .unload = module_tunnel_source_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_tunnel_source_info), .properties = &SPA_DICT_INIT_ARRAY(module_tunnel_source_info),
.data_size = sizeof(struct module_tunnel_source_data),
}; };

View file

@ -110,38 +110,14 @@ static const struct spa_dict_item module_x11_bell_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_x11_bell(struct impl *impl, const char *argument) int create_module_x11_bell(struct module * const module)
{ {
struct pw_properties *props = NULL;
struct module_x11_bell_data *data;
struct module *module;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL); struct module_x11_bell_data * const data = module->user_data;
if (props == NULL) {
res = -EINVAL;
goto out;
}
if (argument)
module_args_add_props(props, argument);
module = module_new(impl, sizeof(struct module_x11_bell_data));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
data = module->user_data;
data->module = module; data->module = module;
return module; return 0;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_x11_bell) = { DEFINE_MODULE_INFO(module_x11_bell) = {
@ -150,4 +126,5 @@ DEFINE_MODULE_INFO(module_x11_bell) = {
.load = module_x11_bell_load, .load = module_x11_bell_load,
.unload = module_x11_bell_unload, .unload = module_x11_bell_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_x11_bell_info), .properties = &SPA_DICT_INIT_ARRAY(module_x11_bell_info),
.data_size = sizeof(struct module_x11_bell_data),
}; };

View file

@ -92,38 +92,14 @@ static const struct spa_dict_item module_zeroconf_discover_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_zeroconf_discover(struct impl *impl, const char *argument) int create_module_zeroconf_discover(struct module * const module)
{ {
struct module *module;
struct module_zeroconf_discover_data *d;
struct pw_properties *props = NULL;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL); struct module_zeroconf_discover_data * const data = module->user_data;
if (props == NULL) { data->module = module;
res = -errno;
goto out;
}
if (argument != NULL)
module_args_add_props(props, argument);
module = module_new(impl, sizeof(*d)); return 0;
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module;
return module;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_zeroconf_discover) = { DEFINE_MODULE_INFO(module_zeroconf_discover) = {
@ -133,4 +109,5 @@ DEFINE_MODULE_INFO(module_zeroconf_discover) = {
.load = module_zeroconf_discover_load, .load = module_zeroconf_discover_load,
.unload = module_zeroconf_discover_unload, .unload = module_zeroconf_discover_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_zeroconf_discover_info), .properties = &SPA_DICT_INIT_ARRAY(module_zeroconf_discover_info),
.data_size = sizeof(struct module_zeroconf_discover_data),
}; };

View file

@ -647,41 +647,17 @@ static const struct spa_dict_item module_zeroconf_publish_info[] = {
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct module *create_module_zeroconf_publish(struct impl *impl, const char *argument) int create_module_zeroconf_publish(struct module * const module)
{ {
struct module *module;
struct module_zeroconf_publish_data *d;
struct pw_properties *props = NULL;
int res;
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
props = pw_properties_new(NULL, NULL); struct module_zeroconf_publish_data * const data = module->user_data;
if (!props) { data->module = module;
res = -errno; data->port = pw_properties_get_uint32(module->props, "port", PW_PROTOCOL_PULSE_DEFAULT_PORT);
goto out; spa_list_init(&data->pending);
} spa_list_init(&data->published);
if (argument)
module_args_add_props(props, argument);
module = module_new(impl, sizeof(*d)); return 0;
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module;
d->port = pw_properties_get_uint32(props, "port", PW_PROTOCOL_PULSE_DEFAULT_PORT);
spa_list_init(&d->pending);
spa_list_init(&d->published);
return module;
out:
pw_properties_free(props);
errno = -res;
return NULL;
} }
DEFINE_MODULE_INFO(module_zeroconf_publish) = { DEFINE_MODULE_INFO(module_zeroconf_publish) = {
@ -690,4 +666,5 @@ DEFINE_MODULE_INFO(module_zeroconf_publish) = {
.load = module_zeroconf_publish_load, .load = module_zeroconf_publish_load,
.unload = module_zeroconf_publish_unload, .unload = module_zeroconf_publish_unload,
.properties = &SPA_DICT_INIT_ARRAY(module_zeroconf_publish_info), .properties = &SPA_DICT_INIT_ARRAY(module_zeroconf_publish_info),
.data_size = sizeof(struct module_zeroconf_publish_data),
}; };