modules: add usage to factories

Improve audio-dsp properties
Fix some keys
This commit is contained in:
Wim Taymans 2019-05-31 16:41:07 +02:00
parent d4def56bcb
commit a672a9ee67
9 changed files with 44 additions and 29 deletions

View file

@ -98,9 +98,7 @@ static void *create_object(void *_data,
struct factory_data *d = _data;
struct pw_client *client;
struct pw_node *dsp;
int res, maxbuffer;
const char *str;
enum pw_direction direction;
int res;
struct node_data *nd;
struct pw_resource *bound_resource;
@ -109,24 +107,16 @@ static void *create_object(void *_data,
client = pw_resource_get_client(resource);
if ((str = pw_properties_get(properties, "audio-dsp.direction")) == NULL)
goto no_props;
direction = pw_properties_parse_int(str);
if ((str = pw_properties_get(properties, "audio-dsp.maxbuffer")) == NULL)
goto no_props;
maxbuffer = pw_properties_parse_int(str);
dsp = pw_audio_dsp_new(pw_module_get_core(d->module),
properties,
direction,
maxbuffer,
sizeof(struct node_data));
if (dsp == NULL)
if (dsp == NULL) {
if (errno == ENOMEM)
goto no_mem;
else
goto usage;
}
nd = pw_audio_dsp_get_user_data(dsp);
nd->data = d;
@ -157,9 +147,9 @@ static void *create_object(void *_data,
pw_log_error("audio-dsp needs a resource");
pw_resource_error(resource, -EINVAL, "no resource");
goto done;
no_props:
pw_log_error("audio-dsp needs a property");
pw_resource_error(resource, -EINVAL, "no property");
usage:
pw_log_error("usage: "AUDIO_DSP_USAGE);
pw_resource_error(resource, -EINVAL, "usage: "AUDIO_DSP_USAGE);
goto done;
no_mem:
pw_log_error("can't create node");
@ -210,7 +200,9 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
"audio-dsp",
PW_TYPE_INTERFACE_Node,
PW_VERSION_NODE_PROXY,
NULL,
pw_properties_new(
PW_KEY_FACTORY_USAGE, AUDIO_DSP_USAGE,
NULL),
sizeof(*data));
if (factory == NULL)
return -ENOMEM;

View file

@ -258,8 +258,6 @@ static const struct pw_node_events node_events = {
struct pw_node *pw_audio_dsp_new(struct pw_core *core,
const struct pw_properties *props,
enum pw_direction direction,
uint32_t max_buffer_size,
size_t user_data_size)
{
struct pw_node *node;
@ -267,10 +265,24 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
const char *api, *alias, *str, *factory;
char node_name[128];
struct pw_properties *pr;
enum pw_direction direction;
uint32_t max_buffer_size;
int i;
pr = pw_properties_copy(props);
if ((str = pw_properties_get(pr, "audio-dsp.direction")) == NULL) {
pw_log_error("missing audio-dsp.direction property");
goto error;
}
direction = pw_properties_parse_int(str);
if ((str = pw_properties_get(pr, "audio-dsp.maxbuffer")) == NULL) {
pw_log_error("missing audio-dsp.maxbuffer property");
goto error;
}
max_buffer_size = pw_properties_parse_int(str);
if ((api = pw_properties_get(pr, PW_KEY_DEVICE_API)) == NULL) {
pw_log_error("missing "PW_KEY_DEVICE_API" property");
goto error;

View file

@ -32,11 +32,15 @@
extern "C" {
#endif
#define AUDIO_DSP_USAGE "audio-dsp.direction=<enum spa_direction> " \
"audio-dsp.maxbuffer=<int> " \
"audio-dsp.name=<string> " \
PW_KEY_DEVICE_API"=<string> " \
"["PW_KEY_NODE_ID"=<int>]"
struct pw_node *
pw_audio_dsp_new(struct pw_core *core,
const struct pw_properties *properties,
enum pw_direction direction,
uint32_t max_buffer_size,
size_t user_data_size);
void *pw_audio_dsp_get_user_data(struct pw_node *node);

View file

@ -123,7 +123,9 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
"client-device",
SPA_TYPE_INTERFACE_Device,
SPA_VERSION_DEVICE,
NULL,
pw_properties_new(
PW_KEY_FACTORY_USAGE, CLIENT_DEVICE_USAGE,
NULL),
sizeof(*data));
if (factory == NULL)
return -ENOMEM;

View file

@ -31,6 +31,8 @@
extern "C" {
#endif
#define CLIENT_DEVICE_USAGE "["PW_KEY_DEVICE_NAME"=<string>]"
struct pw_device *
pw_client_device_new(struct pw_resource *resource,
struct pw_global *parent,

View file

@ -320,7 +320,9 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
"link-factory",
PW_TYPE_INTERFACE_Link,
PW_VERSION_LINK_PROXY,
NULL,
pw_properties_new(
PW_KEY_FACTORY_USAGE, FACTORY_USAGE,
NULL),
sizeof(*data));
if (factory == NULL)
return -ENOMEM;

View file

@ -91,7 +91,7 @@ static void *create_object(void *_data,
if (factory_name == NULL)
goto no_properties;
name = pw_properties_get(properties, "name");
name = pw_properties_get(properties, PW_KEY_DEVICE_NAME);
if (name == NULL)
name = "spa-device";

View file

@ -91,7 +91,7 @@ static void *create_object(void *_data,
if (factory_name == NULL)
goto no_properties;
name = pw_properties_get(properties, "name");
name = pw_properties_get(properties, PW_KEY_NODE_NAME);
if (name == NULL)
name = "spa-node";

View file

@ -180,6 +180,7 @@ extern "C" {
/** Factory properties */
#define PW_KEY_FACTORY_NAME "factory.name" /**< the name of the factory */
#define PW_KEY_FACTORY_USAGE "factory.usage" /**< the usage of the factory */
#define PW_KEY_FACTORY_TYPE_NAME "factory.type.name" /**< the name of the type created by a factory */
#define PW_KEY_FACTORY_TYPE_VERSION "factory.type.version" /**< the version of the type created by a factory */