mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-22 08:56:59 -05:00
improve error handling
This commit is contained in:
parent
c4f35825fe
commit
00ea15dc1f
30 changed files with 465 additions and 228 deletions
|
|
@ -222,7 +222,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
|
||||
impl = calloc(1, sizeof(struct impl));
|
||||
if (impl == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
pw_log_debug("module %p: new %s", impl, args);
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
NULL),
|
||||
sizeof(*data));
|
||||
if (factory == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
data = pw_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
|
|
|
|||
|
|
@ -66,26 +66,37 @@ static void *create_object(void *_data,
|
|||
struct pw_resource *device_resource;
|
||||
struct pw_global *parent;
|
||||
struct pw_client *client = pw_resource_get_client(resource);
|
||||
int res;
|
||||
|
||||
device_resource = pw_resource_new(client, new_id, PW_PERM_RWX, type, version, 0);
|
||||
if (device_resource == NULL)
|
||||
goto no_mem;
|
||||
if (device_resource == NULL) {
|
||||
res = -errno;
|
||||
goto error_resource;
|
||||
}
|
||||
|
||||
parent = pw_client_get_global(client);
|
||||
|
||||
result = pw_client_device_new(device_resource, parent, properties);
|
||||
if (result == NULL)
|
||||
goto no_mem;
|
||||
if (result == NULL) {
|
||||
res = -errno;
|
||||
goto error_device;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
no_mem:
|
||||
pw_log_error("can't create device");
|
||||
pw_resource_error(resource, -ENOMEM, "can't create device: no memory");
|
||||
goto done;
|
||||
done:
|
||||
if (properties)
|
||||
pw_properties_free(properties);
|
||||
error_resource:
|
||||
pw_log_error("can't create resource: %s", spa_strerror(res));
|
||||
pw_resource_error(resource, res, "can't create resource: %s", spa_strerror(res));
|
||||
goto error_exit;
|
||||
error_device:
|
||||
pw_log_error("can't create device: %s", spa_strerror(res));
|
||||
pw_resource_error(resource, res, "can't create device: %s", spa_strerror(res));
|
||||
goto error_exit_free;
|
||||
|
||||
error_exit_free:
|
||||
pw_resource_destroy(device_resource);
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +139,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
NULL),
|
||||
sizeof(*data));
|
||||
if (factory == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
data = pw_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
|
|
|
|||
|
|
@ -69,10 +69,13 @@ static void *create_object(void *_data,
|
|||
struct pw_resource *node_resource;
|
||||
struct pw_global *parent;
|
||||
struct pw_client *client = pw_resource_get_client(resource);
|
||||
int res;
|
||||
|
||||
node_resource = pw_resource_new(client, new_id, PW_PERM_RWX, type, version, 0);
|
||||
if (node_resource == NULL)
|
||||
goto no_mem;
|
||||
if (node_resource == NULL) {
|
||||
res = -errno;
|
||||
goto error_resource;
|
||||
}
|
||||
|
||||
parent = pw_client_get_global(client);
|
||||
|
||||
|
|
@ -82,18 +85,24 @@ static void *create_object(void *_data,
|
|||
else {
|
||||
result = pw_client_node_new(node_resource, parent, properties, true);
|
||||
}
|
||||
if (result == NULL)
|
||||
goto no_mem;
|
||||
|
||||
if (result == NULL) {
|
||||
res = -errno;
|
||||
goto error_node;
|
||||
}
|
||||
return result;
|
||||
|
||||
no_mem:
|
||||
pw_log_error("can't create node");
|
||||
pw_resource_error(resource, -ENOMEM, "can't create node: no memory");
|
||||
goto done;
|
||||
done:
|
||||
if (properties)
|
||||
pw_properties_free(properties);
|
||||
error_resource:
|
||||
pw_log_error("can't create resource: %s", spa_strerror(res));
|
||||
pw_resource_error(resource, res, "can't create resource: %s", spa_strerror(res));
|
||||
goto error_exit;
|
||||
error_node:
|
||||
pw_log_error("can't create node: %s", spa_strerror(res));
|
||||
pw_resource_error(resource, res, "can't create node: %s", spa_strerror(res));
|
||||
goto error_exit_free;
|
||||
error_exit_free:
|
||||
pw_resource_destroy(node_resource);
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +144,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
NULL,
|
||||
sizeof(*data));
|
||||
if (factory == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
data = pw_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
|
|
|
|||
|
|
@ -225,6 +225,8 @@ static struct mem *ensure_mem(struct impl *impl, int fd, uint32_t type, uint32_t
|
|||
|
||||
if (f == NULL) {
|
||||
m = pw_array_add(&impl->mems, sizeof(struct mem));
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
m->id = pw_array_get_len(&impl->mems, struct mem) - 1;
|
||||
}
|
||||
else {
|
||||
|
|
@ -469,6 +471,8 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
|
|||
mem_offset += mem->offset;
|
||||
mem_size = size;
|
||||
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
||||
if (m == NULL)
|
||||
return -errno;
|
||||
memid = m->id;
|
||||
}
|
||||
else {
|
||||
|
|
@ -776,6 +780,8 @@ static int do_port_set_io(struct impl *impl,
|
|||
|
||||
mem_offset += mem->offset;
|
||||
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
||||
if (m == NULL)
|
||||
return -errno;
|
||||
memid = m->id;
|
||||
}
|
||||
else {
|
||||
|
|
@ -879,6 +885,8 @@ do_port_use_buffers(struct impl *impl,
|
|||
}
|
||||
|
||||
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
||||
if (m == NULL)
|
||||
return -errno;
|
||||
b->memid = m->id;
|
||||
|
||||
mb[i].buffer = &b->buffer;
|
||||
|
|
@ -900,6 +908,8 @@ do_port_use_buffers(struct impl *impl,
|
|||
if (d->type == SPA_DATA_DmaBuf ||
|
||||
d->type == SPA_DATA_MemFd) {
|
||||
m = ensure_mem(impl, d->fd, d->type, d->flags);
|
||||
if (m == NULL)
|
||||
return -errno;
|
||||
b->buffer.datas[j].data = SPA_UINT32_TO_PTR(m->id);
|
||||
} else if (d->type == SPA_DATA_MemPtr) {
|
||||
spa_log_debug(this->log, "mem %d %zd", j, SPA_PTRDIFF(d->data, baseptr));
|
||||
|
|
@ -1278,6 +1288,10 @@ void pw_client_node_registered(struct pw_client_node *this, struct pw_global *gl
|
|||
impl->other_fds[1]);
|
||||
|
||||
m = ensure_mem(impl, node->activation->fd, SPA_DATA_MemFd, node->activation->flags);
|
||||
if (m == NULL) {
|
||||
pw_log_debug("client-node %p: can't ensure mem: %m", this);
|
||||
return;
|
||||
}
|
||||
|
||||
pw_client_node_resource_set_activation(this->resource,
|
||||
node_id,
|
||||
|
|
@ -1362,6 +1376,8 @@ static int port_init_mix(void *data, struct pw_port_mix *mix)
|
|||
return -ENOMEM;
|
||||
|
||||
mix->id = pw_map_insert_new(&impl->io_map, NULL);
|
||||
if (mix->id == SPA_ID_INVALID)
|
||||
return -errno;
|
||||
|
||||
mix->io = SPA_MEMBER(impl->io_areas->ptr,
|
||||
mix->id * sizeof(struct spa_io_buffers), void);
|
||||
|
|
@ -1577,6 +1593,10 @@ static void node_peer_added(void *data, struct pw_node *peer)
|
|||
return;
|
||||
|
||||
m = ensure_mem(impl, peer->activation->fd, SPA_DATA_MemFd, peer->activation->flags);
|
||||
if (m == NULL) {
|
||||
pw_log_debug("client-node %p: can't ensure mem: %m", this);
|
||||
return;
|
||||
}
|
||||
|
||||
pw_log_debug("client-node %p: peer %p %u added %u", &impl->this, peer,
|
||||
peer->info.id, m->id);
|
||||
|
|
|
|||
|
|
@ -609,13 +609,13 @@ static int negotiate_buffers(struct impl *impl)
|
|||
in_alloc = false;
|
||||
}
|
||||
|
||||
if (spa_pod_parse_object(param,
|
||||
if ((res = spa_pod_parse_object(param,
|
||||
SPA_TYPE_OBJECT_ParamBuffers, NULL,
|
||||
SPA_PARAM_BUFFERS_buffers, SPA_POD_Int(&buffers),
|
||||
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(&blocks),
|
||||
SPA_PARAM_BUFFERS_size, SPA_POD_Int(&size),
|
||||
SPA_PARAM_BUFFERS_align, SPA_POD_Int(&align)) < 0)
|
||||
return -EINVAL;
|
||||
SPA_PARAM_BUFFERS_align, SPA_POD_Int(&align))) < 0)
|
||||
return res;
|
||||
|
||||
spa_log_debug(this->log, "%p: buffers %d, blocks %d, size %d, align %d",
|
||||
impl, buffers, blocks, size, align);
|
||||
|
|
@ -635,7 +635,7 @@ static int negotiate_buffers(struct impl *impl)
|
|||
free(impl->buffers);
|
||||
impl->buffers = calloc(buffers, sizeof(struct spa_buffer *) + info.skel_size);
|
||||
if (impl->buffers == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
skel = SPA_MEMBER(impl->buffers, sizeof(struct spa_buffer *) * buffers, void);
|
||||
|
||||
|
|
|
|||
|
|
@ -342,6 +342,9 @@ static int client_node_add_mem(void *object,
|
|||
}
|
||||
|
||||
m = pw_array_add(&data->mems, sizeof(struct mem));
|
||||
if (m == NULL)
|
||||
return -errno;
|
||||
|
||||
pw_log_debug("add mem %u, fd %d, flags %d", mem_id, memfd, flags);
|
||||
|
||||
m->id = mem_id;
|
||||
|
|
@ -720,6 +723,11 @@ client_node_port_use_buffers(void *object,
|
|||
}
|
||||
|
||||
bid = pw_array_add(&mix->buffers, sizeof(struct buffer));
|
||||
if (bid == NULL) {
|
||||
res = -errno;
|
||||
pw_proxy_error(proxy, res, "error allocating buffers : %m");
|
||||
goto cleanup;
|
||||
}
|
||||
bid->id = i;
|
||||
|
||||
bmem.mem_id = m->id;
|
||||
|
|
@ -745,7 +753,7 @@ client_node_port_use_buffers(void *object,
|
|||
|
||||
b = bid->buf = malloc(size);
|
||||
if (b == NULL) {
|
||||
res = -ENOMEM;
|
||||
res = -errno;
|
||||
pw_proxy_error(proxy, res, "can't alloc memory: %s", spa_strerror(res));
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -962,6 +970,8 @@ client_node_set_activation(void *object,
|
|||
|
||||
if (ptr) {
|
||||
link = pw_array_add(&data->links, sizeof(struct link));
|
||||
if (link == NULL)
|
||||
return -errno;
|
||||
link->node_id = node_id;
|
||||
link->mem_id = memid;
|
||||
link->target.activation = ptr;
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ static struct pw_port *get_port(struct pw_node *node, enum spa_direction directi
|
|||
|
||||
if ((res = pw_port_add(p, node)) < 0) {
|
||||
pw_log_warn("can't add port: %s", spa_strerror(res));
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -158,15 +159,15 @@ static void *create_object(void *_data,
|
|||
core = pw_client_get_core(client);
|
||||
|
||||
if (properties == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
if ((str = pw_properties_get(properties, PW_KEY_LINK_OUTPUT_NODE)) == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
output_node_id = pw_properties_parse_int(str);
|
||||
|
||||
if ((str = pw_properties_get(properties, PW_KEY_LINK_INPUT_NODE)) == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
input_node_id = pw_properties_parse_int(str);
|
||||
|
||||
|
|
@ -178,13 +179,13 @@ static void *create_object(void *_data,
|
|||
|
||||
global = pw_core_find_global(core, output_node_id);
|
||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node)
|
||||
goto no_output;
|
||||
goto error_output;
|
||||
|
||||
output_node = pw_global_get_object(global);
|
||||
|
||||
global = pw_core_find_global(core, input_node_id);
|
||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node)
|
||||
goto no_input;
|
||||
goto error_input;
|
||||
|
||||
input_node = pw_global_get_object(global);
|
||||
|
||||
|
|
@ -194,31 +195,34 @@ static void *create_object(void *_data,
|
|||
else {
|
||||
global = pw_core_find_global(core, output_port_id);
|
||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Port)
|
||||
goto no_output_port;
|
||||
goto error_output_port;
|
||||
|
||||
outport = pw_global_get_object(global);
|
||||
}
|
||||
if (outport == NULL)
|
||||
goto no_output_port;
|
||||
goto error_output_port;
|
||||
|
||||
if (input_port_id == SPA_ID_INVALID)
|
||||
inport = get_port(input_node, SPA_DIRECTION_INPUT);
|
||||
else {
|
||||
global = pw_core_find_global(core, input_port_id);
|
||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Port)
|
||||
goto no_input_port;
|
||||
goto error_input_port;
|
||||
|
||||
inport = pw_global_get_object(global);
|
||||
}
|
||||
if (inport == NULL)
|
||||
goto no_input_port;
|
||||
goto error_input_port;
|
||||
|
||||
str = pw_properties_get(properties, PW_KEY_OBJECT_LINGER);
|
||||
linger = str ? pw_properties_parse_bool(str) : false;
|
||||
|
||||
link = pw_link_new(core, outport, inport, NULL, properties, sizeof(struct link_data));
|
||||
if (link == NULL)
|
||||
goto no_mem;
|
||||
properties = NULL;
|
||||
if (link == NULL) {
|
||||
res = -errno;
|
||||
goto error_create_link;
|
||||
}
|
||||
|
||||
ld = pw_link_get_user_data(link);
|
||||
ld->data = d;
|
||||
|
|
@ -226,61 +230,71 @@ static void *create_object(void *_data,
|
|||
spa_list_append(&d->link_list, &ld->l);
|
||||
|
||||
pw_link_add_listener(link, &ld->link_listener, &link_events, ld);
|
||||
pw_link_register(link,
|
||||
if ((res = pw_link_register(link,
|
||||
linger ? NULL : client,
|
||||
linger ? NULL : pw_client_get_global(client),
|
||||
NULL);
|
||||
|
||||
properties = NULL;
|
||||
NULL)) < 0)
|
||||
goto error_link_register;
|
||||
|
||||
ld->global = pw_link_get_global(link);
|
||||
pw_global_add_listener(ld->global, &ld->global_listener, &global_events, ld);
|
||||
|
||||
res = pw_global_bind(ld->global, client, PW_PERM_RWX, PW_VERSION_LINK_PROXY, new_id);
|
||||
if (res < 0)
|
||||
goto no_bind;
|
||||
goto error_bind;
|
||||
|
||||
if (!linger) {
|
||||
ld->resource = pw_client_find_resource(client, new_id);
|
||||
if (ld->resource == NULL)
|
||||
goto no_bind;
|
||||
if (ld->resource == NULL) {
|
||||
res = -ENOENT;
|
||||
goto error_bind;
|
||||
}
|
||||
|
||||
pw_resource_add_listener(ld->resource, &ld->resource_listener, &resource_events, ld);
|
||||
}
|
||||
|
||||
return link;
|
||||
|
||||
no_properties:
|
||||
error_properties:
|
||||
res = -EINVAL;
|
||||
pw_log_error("link-factory usage:" FACTORY_USAGE);
|
||||
pw_resource_error(resource, -EINVAL, "no properties");
|
||||
goto done;
|
||||
no_output:
|
||||
pw_resource_error(resource, res, "no properties");
|
||||
goto error_exit;
|
||||
error_output:
|
||||
res = -EINVAL;
|
||||
pw_log_error("link-factory unknown output node %u", output_node_id);
|
||||
pw_resource_error(resource, -EINVAL, "unknown output node %u", output_node_id);
|
||||
goto done;
|
||||
no_input:
|
||||
pw_resource_error(resource, res, "unknown output node %u", output_node_id);
|
||||
goto error_exit;
|
||||
error_input:
|
||||
res = -EINVAL;
|
||||
pw_log_error("link-factory unknown input node %u", input_node_id);
|
||||
pw_resource_error(resource, -EINVAL, "unknown input node %u", input_node_id);
|
||||
goto done;
|
||||
no_output_port:
|
||||
pw_resource_error(resource, res, "unknown input node %u", input_node_id);
|
||||
goto error_exit;
|
||||
error_output_port:
|
||||
res = -EINVAL;
|
||||
pw_log_error("link-factory unknown output port %u", output_port_id);
|
||||
pw_resource_error(resource, -EINVAL, "unknown output port %u", output_port_id);
|
||||
goto done;
|
||||
no_input_port:
|
||||
pw_resource_error(resource, res, "unknown output port %u", output_port_id);
|
||||
goto error_exit;
|
||||
error_input_port:
|
||||
res = -EINVAL;
|
||||
pw_log_error("link-factory unknown input port %u", input_port_id);
|
||||
pw_resource_error(resource, -EINVAL, "unknown input port %u", input_port_id);
|
||||
goto done;
|
||||
no_mem:
|
||||
res = -errno;
|
||||
pw_resource_error(resource, res, "unknown input port %u", input_port_id);
|
||||
goto error_exit;
|
||||
error_create_link:
|
||||
pw_log_error("can't create link: %s", spa_strerror(res));
|
||||
pw_resource_error(resource, res, "can't create link: %s", spa_strerror(res));
|
||||
goto done;
|
||||
no_bind:
|
||||
pw_resource_error(resource, res, "can't bind link");
|
||||
goto done;
|
||||
done:
|
||||
goto error_exit;
|
||||
error_link_register:
|
||||
pw_log_error("can't register link: %s", spa_strerror(res));
|
||||
pw_resource_error(resource, res, "can't register link: %s", spa_strerror(res));
|
||||
goto error_exit;
|
||||
error_bind:
|
||||
pw_resource_error(resource, res, "can't bind link: %s", spa_strerror(res));
|
||||
goto error_exit;
|
||||
error_exit:
|
||||
if (properties)
|
||||
pw_properties_free(properties);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -315,6 +329,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
struct pw_core *core = pw_module_get_core(module);
|
||||
struct pw_factory *factory;
|
||||
struct factory_data *data;
|
||||
int res;
|
||||
|
||||
factory = pw_factory_new(core,
|
||||
"link-factory",
|
||||
|
|
@ -324,8 +339,10 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
PW_KEY_FACTORY_USAGE, FACTORY_USAGE,
|
||||
NULL),
|
||||
sizeof(*data));
|
||||
if (factory == NULL)
|
||||
return -ENOMEM;
|
||||
if (factory == NULL) {
|
||||
res = -errno;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
data = pw_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
|
|
@ -338,13 +355,21 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
&impl_factory,
|
||||
data);
|
||||
|
||||
pw_factory_register(factory, NULL, pw_module_get_global(module), NULL);
|
||||
if ((res = pw_factory_register(factory, NULL, pw_module_get_global(module), NULL)) < 0)
|
||||
goto error_register;
|
||||
|
||||
pw_module_add_listener(module, &data->module_listener, &module_events, data);
|
||||
|
||||
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
||||
|
||||
return 0;
|
||||
|
||||
error_register:
|
||||
pw_factory_destroy(factory);
|
||||
error_cleanup:
|
||||
if (properties)
|
||||
pw_properties_free(properties);
|
||||
return res;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
|
|||
|
|
@ -79,12 +79,12 @@ struct client {
|
|||
struct pw_properties *properties;
|
||||
struct spa_source *source;
|
||||
|
||||
struct pw_protocol_native_connection *connection;
|
||||
struct spa_hook conn_listener;
|
||||
struct pw_protocol_native_connection *connection;
|
||||
struct spa_hook conn_listener;
|
||||
|
||||
bool disconnecting;
|
||||
bool flush_signaled;
|
||||
struct spa_source *flush_event;
|
||||
struct spa_source *flush_event;
|
||||
unsigned int disconnecting:1;
|
||||
unsigned int flush_signaled:1;
|
||||
};
|
||||
|
||||
struct server {
|
||||
|
|
@ -93,11 +93,11 @@ struct server {
|
|||
int fd_lock;
|
||||
struct sockaddr_un addr;
|
||||
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
||||
bool activated;
|
||||
|
||||
struct pw_loop *loop;
|
||||
struct spa_source *source;
|
||||
struct spa_hook hook;
|
||||
unsigned int activated:1;
|
||||
};
|
||||
|
||||
struct client_data {
|
||||
|
|
@ -105,7 +105,7 @@ struct client_data {
|
|||
struct spa_hook client_listener;
|
||||
struct spa_source *source;
|
||||
struct pw_protocol_native_connection *connection;
|
||||
bool busy;
|
||||
unsigned int busy:1;
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -123,14 +123,18 @@ uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connecti
|
|||
|
||||
static void *connection_ensure_size(struct pw_protocol_native_connection *conn, struct buffer *buf, size_t size)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (buf->buffer_size + size > buf->buffer_maxsize) {
|
||||
buf->buffer_maxsize = SPA_ROUND_UP_N(buf->buffer_size + size, MAX_BUFFER_SIZE);
|
||||
buf->buffer_data = realloc(buf->buffer_data, buf->buffer_maxsize);
|
||||
if (buf->buffer_data == NULL) {
|
||||
res = -errno;
|
||||
buf->buffer_maxsize = 0;
|
||||
spa_hook_list_call(&conn->listener_list,
|
||||
struct pw_protocol_native_connection_events,
|
||||
error, 0, -ENOMEM);
|
||||
error, 0, -res);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
pw_log_warn("connection %p: resize buffer to %zd %zd %zd",
|
||||
|
|
@ -335,7 +339,7 @@ pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *con
|
|||
break;
|
||||
|
||||
if (connection_ensure_size(conn, buf, len) == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
if ((res = refill_buffer(conn, buf)) < 0)
|
||||
return res;
|
||||
}
|
||||
|
|
@ -362,7 +366,7 @@ static int builder_overflow(void *data, uint32_t size)
|
|||
|
||||
b->size = SPA_ROUND_UP_N(size, 4096);
|
||||
if ((b->data = begin_write(&impl->this, b->size)) == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -401,7 +405,7 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
|
|||
int res;
|
||||
|
||||
if ((p = connection_ensure_size(conn, buf, HDR_SIZE + size)) == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
p[0] = buf->msg.id;
|
||||
p[1] = (buf->msg.opcode << 24) | (size & 0xffffff);
|
||||
|
|
|
|||
|
|
@ -83,13 +83,14 @@ static void *create_object(void *_data,
|
|||
struct pw_device *device;
|
||||
const char *factory_name, *name;
|
||||
struct device_data *nd;
|
||||
int res;
|
||||
|
||||
if (properties == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
factory_name = pw_properties_get(properties, SPA_KEY_FACTORY_NAME);
|
||||
if (factory_name == NULL)
|
||||
goto no_properties;
|
||||
goto error_properties;
|
||||
|
||||
name = pw_properties_get(properties, PW_KEY_DEVICE_NAME);
|
||||
if (name == NULL)
|
||||
|
|
@ -103,8 +104,10 @@ static void *create_object(void *_data,
|
|||
0,
|
||||
properties,
|
||||
sizeof(struct device_data));
|
||||
if (device == NULL)
|
||||
goto no_mem;
|
||||
if (device == NULL) {
|
||||
res = -errno;
|
||||
goto error_device;
|
||||
}
|
||||
|
||||
nd = pw_spa_device_get_user_data(device);
|
||||
nd->device = device;
|
||||
|
|
@ -120,17 +123,19 @@ static void *create_object(void *_data,
|
|||
|
||||
return device;
|
||||
|
||||
no_properties:
|
||||
error_properties:
|
||||
res = -EINVAL;
|
||||
pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
|
||||
if (resource) {
|
||||
pw_resource_error(resource, -EINVAL, "usage: " FACTORY_USAGE);
|
||||
}
|
||||
return NULL;
|
||||
no_mem:
|
||||
pw_log_error("can't create device: no memory");
|
||||
if (resource) {
|
||||
pw_resource_error(resource, -ENOMEM, "no memory");
|
||||
}
|
||||
if (resource)
|
||||
pw_resource_error(resource, res, "usage: " FACTORY_USAGE);
|
||||
goto error_exit;
|
||||
error_device:
|
||||
pw_log_error("can't create device: %s", spa_strerror(res));
|
||||
if (resource)
|
||||
pw_resource_error(resource, res, "can't create device: %s", spa_strerror(res));
|
||||
goto error_exit;
|
||||
error_exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -174,6 +179,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
struct pw_core *core = pw_module_get_core(module);
|
||||
struct pw_factory *factory;
|
||||
struct factory_data *data;
|
||||
int res;
|
||||
|
||||
factory = pw_factory_new(core,
|
||||
"spa-device-factory",
|
||||
|
|
@ -182,7 +188,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
NULL,
|
||||
sizeof(*data));
|
||||
if (factory == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
data = pw_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
|
|
@ -198,9 +204,17 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
|
||||
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
||||
|
||||
pw_factory_register(factory, NULL, pw_module_get_global(module), NULL);
|
||||
if ((res = pw_factory_register(factory,
|
||||
NULL,
|
||||
pw_module_get_global(module),
|
||||
NULL)) < 0)
|
||||
goto error_register;
|
||||
|
||||
return 0;
|
||||
|
||||
error_register:
|
||||
pw_factory_destroy(factory);
|
||||
return res;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
struct pw_core *core = pw_module_get_core(module);
|
||||
struct pw_factory *factory;
|
||||
struct factory_data *data;
|
||||
int res;
|
||||
|
||||
factory = pw_factory_new(core,
|
||||
"spa-node-factory",
|
||||
|
|
@ -182,7 +183,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
NULL,
|
||||
sizeof(*data));
|
||||
if (factory == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
|
||||
data = pw_factory_get_user_data(factory);
|
||||
data->this = factory;
|
||||
|
|
@ -198,9 +199,15 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
|||
|
||||
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
||||
|
||||
pw_factory_register(factory, NULL, pw_module_get_global(module), NULL);
|
||||
if ((res = pw_factory_register(factory,
|
||||
NULL, pw_module_get_global(module), NULL)) < 0)
|
||||
goto error_register;
|
||||
|
||||
return 0;
|
||||
|
||||
error_register:
|
||||
pw_factory_destroy(factory);
|
||||
return res;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ struct impl {
|
|||
void *unload;
|
||||
struct spa_handle *handle;
|
||||
struct spa_device *device;
|
||||
char *factory_name;
|
||||
|
||||
struct spa_hook device_listener;
|
||||
|
||||
|
|
@ -69,7 +68,6 @@ static void device_destroy(void *data)
|
|||
spa_hook_remove(&impl->device_listener);
|
||||
if (impl->handle)
|
||||
pw_unload_spa_handle(impl->handle);
|
||||
free(impl->factory_name);
|
||||
}
|
||||
|
||||
static const struct pw_device_events device_events = {
|
||||
|
|
@ -90,6 +88,7 @@ pw_spa_device_new(struct pw_core *core,
|
|||
{
|
||||
struct pw_device *this;
|
||||
struct impl *impl;
|
||||
int res;
|
||||
|
||||
this = pw_device_new(core, name, properties, sizeof(struct impl) + user_data_size);
|
||||
if (this == NULL)
|
||||
|
|
@ -109,10 +108,16 @@ pw_spa_device_new(struct pw_core *core,
|
|||
pw_device_add_listener(this, &impl->device_listener, &device_events, impl);
|
||||
pw_device_set_implementation(this, impl->device);
|
||||
|
||||
if (!SPA_FLAG_CHECK(impl->flags, PW_SPA_DEVICE_FLAG_NO_REGISTER))
|
||||
pw_device_register(this, impl->owner, impl->parent, NULL);
|
||||
|
||||
if (!SPA_FLAG_CHECK(impl->flags, PW_SPA_DEVICE_FLAG_NO_REGISTER)) {
|
||||
if ((res = pw_device_register(this, impl->owner, impl->parent, NULL)) < 0)
|
||||
goto error_register;
|
||||
}
|
||||
return this;
|
||||
|
||||
error_register:
|
||||
pw_device_destroy(this);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pw_spa_device_get_user_data(struct pw_device *device)
|
||||
|
|
@ -131,7 +136,6 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
|
|||
size_t user_data_size)
|
||||
{
|
||||
struct pw_device *this;
|
||||
struct impl *impl;
|
||||
struct spa_handle *handle;
|
||||
void *iface;
|
||||
int res;
|
||||
|
|
@ -139,6 +143,7 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
|
|||
handle = pw_core_load_spa_handle(core, factory_name,
|
||||
properties ? &properties->dict : NULL);
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't load device handle: %m");
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -151,17 +156,16 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
|
|||
this = pw_spa_device_new(core, owner, parent, name, flags,
|
||||
iface, handle, properties, user_data_size);
|
||||
if (this == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't create device: %m");
|
||||
goto exit;
|
||||
goto exit_unload;
|
||||
}
|
||||
|
||||
impl = this->user_data;
|
||||
impl->factory_name = strdup(factory_name);
|
||||
|
||||
return this;
|
||||
|
||||
exit_unload:
|
||||
pw_unload_spa_handle(handle);
|
||||
exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,9 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
else
|
||||
props = pw_properties_new(NULL, NULL);
|
||||
|
||||
if (props == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((name = pw_properties_get(props, PW_KEY_DEVICE_NAME)) == NULL)
|
||||
name = "unknown";
|
||||
|
||||
|
|
@ -112,16 +115,21 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
handle = pw_core_load_spa_handle(core, info->factory_name,
|
||||
&props->dict);
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't make factory instance: %m");
|
||||
goto error_free_props;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
|
||||
pw_log_error("can't get %d interface: %d", info->type, res);
|
||||
pw_log_error("can't get %d interface: %s", info->type, spa_strerror(res));
|
||||
goto error_free_handle;
|
||||
}
|
||||
|
||||
obj = calloc(1, sizeof(struct monitor_object));
|
||||
if (obj == NULL) {
|
||||
res = -errno;
|
||||
goto error_free_handle;
|
||||
}
|
||||
obj->id = id;
|
||||
obj->name = strdup(name);
|
||||
obj->handle = handle;
|
||||
|
|
@ -139,6 +147,7 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
break;
|
||||
}
|
||||
default:
|
||||
res = -ENOTSUP;
|
||||
pw_log_error("interface %d not implemented", obj->type);
|
||||
goto error_free_object;
|
||||
}
|
||||
|
|
@ -154,6 +163,7 @@ error_free_handle:
|
|||
pw_unload_spa_handle(handle);
|
||||
error_free_props:
|
||||
pw_properties_free(props);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -213,7 +223,7 @@ static int on_monitor_object_info(void *data, uint32_t id,
|
|||
} else if (obj == NULL) {
|
||||
obj = add_object(this, id, info, now_nsec);
|
||||
if (obj == NULL)
|
||||
return -ENOMEM;
|
||||
return -errno;
|
||||
} else {
|
||||
change_object(this, obj, info, now_nsec);
|
||||
}
|
||||
|
|
@ -267,17 +277,21 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
|||
handle = pw_core_load_spa_handle(core,
|
||||
factory_name,
|
||||
properties ? &properties->dict : NULL);
|
||||
if (handle == NULL)
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
|
||||
pw_log_error("can't get MONITOR interface: %d", res);
|
||||
pw_log_error("can't get MONITOR interface: %s", spa_strerror(res));
|
||||
goto exit_unload;
|
||||
}
|
||||
|
||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||
if (impl == NULL)
|
||||
if (impl == NULL) {
|
||||
res = -errno;
|
||||
goto exit_unload;
|
||||
}
|
||||
|
||||
impl->core = core;
|
||||
impl->parent = parent;
|
||||
|
|
@ -302,6 +316,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
|||
exit_unload:
|
||||
pw_unload_spa_handle(handle);
|
||||
exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,9 +139,7 @@ pw_spa_node_new(struct pw_core *core,
|
|||
impl->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
|
||||
|
||||
pw_node_add_listener(this, &impl->node_listener, &node_events, impl);
|
||||
res = pw_node_set_implementation(this, impl->node);
|
||||
|
||||
if (res < 0)
|
||||
if ((res = pw_node_set_implementation(this, impl->node)) < 0)
|
||||
goto clean_node;
|
||||
|
||||
if (flags & PW_SPA_NODE_FLAG_ASYNC) {
|
||||
|
|
@ -153,6 +151,7 @@ pw_spa_node_new(struct pw_core *core,
|
|||
|
||||
clean_node:
|
||||
pw_node_destroy(this);
|
||||
errno = -res;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
|
@ -180,7 +179,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
|
|||
&b);
|
||||
if (res != 1) {
|
||||
if (res < 0)
|
||||
pw_log_debug("spa_node_get_props failed: %d", res);
|
||||
pw_log_debug("spa_node_get_props failed: %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +229,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
|
|||
}
|
||||
|
||||
if ((res = spa_node_set_param(spa_node, SPA_PARAM_Props, 0, props)) < 0) {
|
||||
pw_log_debug("spa_node_set_props failed: %d", res);
|
||||
pw_log_debug("spa_node_set_props failed: %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -256,8 +255,10 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
|||
handle = pw_core_load_spa_handle(core,
|
||||
factory_name,
|
||||
properties ? &properties->dict : NULL);
|
||||
if (handle == NULL)
|
||||
if (handle == NULL) {
|
||||
res = -errno;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
|
||||
pw_log_error("can't get node interface %d", res);
|
||||
|
|
@ -270,14 +271,16 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
|||
|
||||
if (properties != NULL) {
|
||||
if (setup_props(core, spa_node, properties) < 0) {
|
||||
pw_log_debug("Unrecognized properties");
|
||||
pw_log_warn("can't setup properties: %s", spa_strerror(res));
|
||||
}
|
||||
}
|
||||
|
||||
this = pw_spa_node_new(core, owner, parent, name, flags,
|
||||
spa_node, handle, properties, user_data_size);
|
||||
if (this == NULL)
|
||||
if (this == NULL) {
|
||||
res = -errno;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
impl = this->user_data;
|
||||
impl->handle = handle;
|
||||
|
|
@ -288,5 +291,6 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
|||
exit_unload:
|
||||
pw_unload_spa_handle(handle);
|
||||
exit:
|
||||
errno = -res;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue