mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
improve error handling
This commit is contained in:
parent
c4f35825fe
commit
00ea15dc1f
30 changed files with 465 additions and 228 deletions
|
|
@ -527,7 +527,7 @@ builder_overflow (void *event_data, uint32_t size)
|
||||||
b->size = SPA_ROUND_UP_N (size, 512);
|
b->size = SPA_ROUND_UP_N (size, 512);
|
||||||
b->data = realloc (b->data, b->size);
|
b->data = realloc (b->data, b->size);
|
||||||
if (b->data == NULL)
|
if (b->data == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl));
|
impl = calloc(1, sizeof(struct impl));
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
pw_log_debug("module %p: new %s", impl, args);
|
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),
|
NULL),
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (factory == NULL)
|
if (factory == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
data = pw_factory_get_user_data(factory);
|
data = pw_factory_get_user_data(factory);
|
||||||
data->this = factory;
|
data->this = factory;
|
||||||
|
|
|
||||||
|
|
@ -66,26 +66,37 @@ static void *create_object(void *_data,
|
||||||
struct pw_resource *device_resource;
|
struct pw_resource *device_resource;
|
||||||
struct pw_global *parent;
|
struct pw_global *parent;
|
||||||
struct pw_client *client = pw_resource_get_client(resource);
|
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);
|
device_resource = pw_resource_new(client, new_id, PW_PERM_RWX, type, version, 0);
|
||||||
if (device_resource == NULL)
|
if (device_resource == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error_resource;
|
||||||
|
}
|
||||||
|
|
||||||
parent = pw_client_get_global(client);
|
parent = pw_client_get_global(client);
|
||||||
|
|
||||||
result = pw_client_device_new(device_resource, parent, properties);
|
result = pw_client_device_new(device_resource, parent, properties);
|
||||||
if (result == NULL)
|
if (result == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error_device;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create device");
|
pw_log_error("can't create resource: %s", spa_strerror(res));
|
||||||
pw_resource_error(resource, -ENOMEM, "can't create device: no memory");
|
pw_resource_error(resource, res, "can't create resource: %s", spa_strerror(res));
|
||||||
goto done;
|
goto error_exit;
|
||||||
done:
|
error_device:
|
||||||
if (properties)
|
pw_log_error("can't create device: %s", spa_strerror(res));
|
||||||
pw_properties_free(properties);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +139,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
NULL),
|
NULL),
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (factory == NULL)
|
if (factory == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
data = pw_factory_get_user_data(factory);
|
data = pw_factory_get_user_data(factory);
|
||||||
data->this = factory;
|
data->this = factory;
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,13 @@ static void *create_object(void *_data,
|
||||||
struct pw_resource *node_resource;
|
struct pw_resource *node_resource;
|
||||||
struct pw_global *parent;
|
struct pw_global *parent;
|
||||||
struct pw_client *client = pw_resource_get_client(resource);
|
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);
|
node_resource = pw_resource_new(client, new_id, PW_PERM_RWX, type, version, 0);
|
||||||
if (node_resource == NULL)
|
if (node_resource == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error_resource;
|
||||||
|
}
|
||||||
|
|
||||||
parent = pw_client_get_global(client);
|
parent = pw_client_get_global(client);
|
||||||
|
|
||||||
|
|
@ -82,18 +85,24 @@ static void *create_object(void *_data,
|
||||||
else {
|
else {
|
||||||
result = pw_client_node_new(node_resource, parent, properties, true);
|
result = pw_client_node_new(node_resource, parent, properties, true);
|
||||||
}
|
}
|
||||||
if (result == NULL)
|
if (result == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error_node;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create node");
|
pw_log_error("can't create resource: %s", spa_strerror(res));
|
||||||
pw_resource_error(resource, -ENOMEM, "can't create node: no memory");
|
pw_resource_error(resource, res, "can't create resource: %s", spa_strerror(res));
|
||||||
goto done;
|
goto error_exit;
|
||||||
done:
|
error_node:
|
||||||
if (properties)
|
pw_log_error("can't create node: %s", spa_strerror(res));
|
||||||
pw_properties_free(properties);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +144,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
NULL,
|
NULL,
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (factory == NULL)
|
if (factory == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
data = pw_factory_get_user_data(factory);
|
data = pw_factory_get_user_data(factory);
|
||||||
data->this = 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) {
|
if (f == NULL) {
|
||||||
m = pw_array_add(&impl->mems, sizeof(struct mem));
|
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;
|
m->id = pw_array_get_len(&impl->mems, struct mem) - 1;
|
||||||
}
|
}
|
||||||
else {
|
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_offset += mem->offset;
|
||||||
mem_size = size;
|
mem_size = size;
|
||||||
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
||||||
|
if (m == NULL)
|
||||||
|
return -errno;
|
||||||
memid = m->id;
|
memid = m->id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -776,6 +780,8 @@ static int do_port_set_io(struct impl *impl,
|
||||||
|
|
||||||
mem_offset += mem->offset;
|
mem_offset += mem->offset;
|
||||||
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
||||||
|
if (m == NULL)
|
||||||
|
return -errno;
|
||||||
memid = m->id;
|
memid = m->id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -879,6 +885,8 @@ do_port_use_buffers(struct impl *impl,
|
||||||
}
|
}
|
||||||
|
|
||||||
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
||||||
|
if (m == NULL)
|
||||||
|
return -errno;
|
||||||
b->memid = m->id;
|
b->memid = m->id;
|
||||||
|
|
||||||
mb[i].buffer = &b->buffer;
|
mb[i].buffer = &b->buffer;
|
||||||
|
|
@ -900,6 +908,8 @@ do_port_use_buffers(struct impl *impl,
|
||||||
if (d->type == SPA_DATA_DmaBuf ||
|
if (d->type == SPA_DATA_DmaBuf ||
|
||||||
d->type == SPA_DATA_MemFd) {
|
d->type == SPA_DATA_MemFd) {
|
||||||
m = ensure_mem(impl, d->fd, d->type, d->flags);
|
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);
|
b->buffer.datas[j].data = SPA_UINT32_TO_PTR(m->id);
|
||||||
} else if (d->type == SPA_DATA_MemPtr) {
|
} else if (d->type == SPA_DATA_MemPtr) {
|
||||||
spa_log_debug(this->log, "mem %d %zd", j, SPA_PTRDIFF(d->data, baseptr));
|
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]);
|
impl->other_fds[1]);
|
||||||
|
|
||||||
m = ensure_mem(impl, node->activation->fd, SPA_DATA_MemFd, node->activation->flags);
|
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,
|
pw_client_node_resource_set_activation(this->resource,
|
||||||
node_id,
|
node_id,
|
||||||
|
|
@ -1362,6 +1376,8 @@ static int port_init_mix(void *data, struct pw_port_mix *mix)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
mix->id = pw_map_insert_new(&impl->io_map, NULL);
|
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->io = SPA_MEMBER(impl->io_areas->ptr,
|
||||||
mix->id * sizeof(struct spa_io_buffers), void);
|
mix->id * sizeof(struct spa_io_buffers), void);
|
||||||
|
|
@ -1577,6 +1593,10 @@ static void node_peer_added(void *data, struct pw_node *peer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m = ensure_mem(impl, peer->activation->fd, SPA_DATA_MemFd, peer->activation->flags);
|
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,
|
pw_log_debug("client-node %p: peer %p %u added %u", &impl->this, peer,
|
||||||
peer->info.id, m->id);
|
peer->info.id, m->id);
|
||||||
|
|
|
||||||
|
|
@ -609,13 +609,13 @@ static int negotiate_buffers(struct impl *impl)
|
||||||
in_alloc = false;
|
in_alloc = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spa_pod_parse_object(param,
|
if ((res = spa_pod_parse_object(param,
|
||||||
SPA_TYPE_OBJECT_ParamBuffers, NULL,
|
SPA_TYPE_OBJECT_ParamBuffers, NULL,
|
||||||
SPA_PARAM_BUFFERS_buffers, SPA_POD_Int(&buffers),
|
SPA_PARAM_BUFFERS_buffers, SPA_POD_Int(&buffers),
|
||||||
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(&blocks),
|
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(&blocks),
|
||||||
SPA_PARAM_BUFFERS_size, SPA_POD_Int(&size),
|
SPA_PARAM_BUFFERS_size, SPA_POD_Int(&size),
|
||||||
SPA_PARAM_BUFFERS_align, SPA_POD_Int(&align)) < 0)
|
SPA_PARAM_BUFFERS_align, SPA_POD_Int(&align))) < 0)
|
||||||
return -EINVAL;
|
return res;
|
||||||
|
|
||||||
spa_log_debug(this->log, "%p: buffers %d, blocks %d, size %d, align %d",
|
spa_log_debug(this->log, "%p: buffers %d, blocks %d, size %d, align %d",
|
||||||
impl, buffers, blocks, size, align);
|
impl, buffers, blocks, size, align);
|
||||||
|
|
@ -635,7 +635,7 @@ static int negotiate_buffers(struct impl *impl)
|
||||||
free(impl->buffers);
|
free(impl->buffers);
|
||||||
impl->buffers = calloc(buffers, sizeof(struct spa_buffer *) + info.skel_size);
|
impl->buffers = calloc(buffers, sizeof(struct spa_buffer *) + info.skel_size);
|
||||||
if (impl->buffers == NULL)
|
if (impl->buffers == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
skel = SPA_MEMBER(impl->buffers, sizeof(struct spa_buffer *) * buffers, void);
|
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));
|
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);
|
pw_log_debug("add mem %u, fd %d, flags %d", mem_id, memfd, flags);
|
||||||
|
|
||||||
m->id = mem_id;
|
m->id = mem_id;
|
||||||
|
|
@ -720,6 +723,11 @@ client_node_port_use_buffers(void *object,
|
||||||
}
|
}
|
||||||
|
|
||||||
bid = pw_array_add(&mix->buffers, sizeof(struct buffer));
|
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;
|
bid->id = i;
|
||||||
|
|
||||||
bmem.mem_id = m->id;
|
bmem.mem_id = m->id;
|
||||||
|
|
@ -745,7 +753,7 @@ client_node_port_use_buffers(void *object,
|
||||||
|
|
||||||
b = bid->buf = malloc(size);
|
b = bid->buf = malloc(size);
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
res = -ENOMEM;
|
res = -errno;
|
||||||
pw_proxy_error(proxy, res, "can't alloc memory: %s", spa_strerror(res));
|
pw_proxy_error(proxy, res, "can't alloc memory: %s", spa_strerror(res));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
@ -962,6 +970,8 @@ client_node_set_activation(void *object,
|
||||||
|
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
link = pw_array_add(&data->links, sizeof(struct link));
|
link = pw_array_add(&data->links, sizeof(struct link));
|
||||||
|
if (link == NULL)
|
||||||
|
return -errno;
|
||||||
link->node_id = node_id;
|
link->node_id = node_id;
|
||||||
link->mem_id = memid;
|
link->mem_id = memid;
|
||||||
link->target.activation = ptr;
|
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) {
|
if ((res = pw_port_add(p, node)) < 0) {
|
||||||
pw_log_warn("can't add port: %s", spa_strerror(res));
|
pw_log_warn("can't add port: %s", spa_strerror(res));
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,15 +159,15 @@ static void *create_object(void *_data,
|
||||||
core = pw_client_get_core(client);
|
core = pw_client_get_core(client);
|
||||||
|
|
||||||
if (properties == NULL)
|
if (properties == NULL)
|
||||||
goto no_properties;
|
goto error_properties;
|
||||||
|
|
||||||
if ((str = pw_properties_get(properties, PW_KEY_LINK_OUTPUT_NODE)) == NULL)
|
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);
|
output_node_id = pw_properties_parse_int(str);
|
||||||
|
|
||||||
if ((str = pw_properties_get(properties, PW_KEY_LINK_INPUT_NODE)) == NULL)
|
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);
|
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);
|
global = pw_core_find_global(core, output_node_id);
|
||||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node)
|
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);
|
output_node = pw_global_get_object(global);
|
||||||
|
|
||||||
global = pw_core_find_global(core, input_node_id);
|
global = pw_core_find_global(core, input_node_id);
|
||||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Node)
|
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);
|
input_node = pw_global_get_object(global);
|
||||||
|
|
||||||
|
|
@ -194,31 +195,34 @@ static void *create_object(void *_data,
|
||||||
else {
|
else {
|
||||||
global = pw_core_find_global(core, output_port_id);
|
global = pw_core_find_global(core, output_port_id);
|
||||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Port)
|
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);
|
outport = pw_global_get_object(global);
|
||||||
}
|
}
|
||||||
if (outport == NULL)
|
if (outport == NULL)
|
||||||
goto no_output_port;
|
goto error_output_port;
|
||||||
|
|
||||||
if (input_port_id == SPA_ID_INVALID)
|
if (input_port_id == SPA_ID_INVALID)
|
||||||
inport = get_port(input_node, SPA_DIRECTION_INPUT);
|
inport = get_port(input_node, SPA_DIRECTION_INPUT);
|
||||||
else {
|
else {
|
||||||
global = pw_core_find_global(core, input_port_id);
|
global = pw_core_find_global(core, input_port_id);
|
||||||
if (global == NULL || pw_global_get_type(global) != PW_TYPE_INTERFACE_Port)
|
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);
|
inport = pw_global_get_object(global);
|
||||||
}
|
}
|
||||||
if (inport == NULL)
|
if (inport == NULL)
|
||||||
goto no_input_port;
|
goto error_input_port;
|
||||||
|
|
||||||
str = pw_properties_get(properties, PW_KEY_OBJECT_LINGER);
|
str = pw_properties_get(properties, PW_KEY_OBJECT_LINGER);
|
||||||
linger = str ? pw_properties_parse_bool(str) : false;
|
linger = str ? pw_properties_parse_bool(str) : false;
|
||||||
|
|
||||||
link = pw_link_new(core, outport, inport, NULL, properties, sizeof(struct link_data));
|
link = pw_link_new(core, outport, inport, NULL, properties, sizeof(struct link_data));
|
||||||
if (link == NULL)
|
properties = NULL;
|
||||||
goto no_mem;
|
if (link == NULL) {
|
||||||
|
res = -errno;
|
||||||
|
goto error_create_link;
|
||||||
|
}
|
||||||
|
|
||||||
ld = pw_link_get_user_data(link);
|
ld = pw_link_get_user_data(link);
|
||||||
ld->data = d;
|
ld->data = d;
|
||||||
|
|
@ -226,61 +230,71 @@ static void *create_object(void *_data,
|
||||||
spa_list_append(&d->link_list, &ld->l);
|
spa_list_append(&d->link_list, &ld->l);
|
||||||
|
|
||||||
pw_link_add_listener(link, &ld->link_listener, &link_events, ld);
|
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 : client,
|
||||||
linger ? NULL : pw_client_get_global(client),
|
linger ? NULL : pw_client_get_global(client),
|
||||||
NULL);
|
NULL)) < 0)
|
||||||
|
goto error_link_register;
|
||||||
properties = NULL;
|
|
||||||
|
|
||||||
ld->global = pw_link_get_global(link);
|
ld->global = pw_link_get_global(link);
|
||||||
pw_global_add_listener(ld->global, &ld->global_listener, &global_events, ld);
|
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);
|
res = pw_global_bind(ld->global, client, PW_PERM_RWX, PW_VERSION_LINK_PROXY, new_id);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
goto no_bind;
|
goto error_bind;
|
||||||
|
|
||||||
if (!linger) {
|
if (!linger) {
|
||||||
ld->resource = pw_client_find_resource(client, new_id);
|
ld->resource = pw_client_find_resource(client, new_id);
|
||||||
if (ld->resource == NULL)
|
if (ld->resource == NULL) {
|
||||||
goto no_bind;
|
res = -ENOENT;
|
||||||
|
goto error_bind;
|
||||||
|
}
|
||||||
|
|
||||||
pw_resource_add_listener(ld->resource, &ld->resource_listener, &resource_events, ld);
|
pw_resource_add_listener(ld->resource, &ld->resource_listener, &resource_events, ld);
|
||||||
}
|
}
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
|
|
||||||
no_properties:
|
error_properties:
|
||||||
|
res = -EINVAL;
|
||||||
pw_log_error("link-factory usage:" FACTORY_USAGE);
|
pw_log_error("link-factory usage:" FACTORY_USAGE);
|
||||||
pw_resource_error(resource, -EINVAL, "no properties");
|
pw_resource_error(resource, res, "no properties");
|
||||||
goto done;
|
goto error_exit;
|
||||||
no_output:
|
error_output:
|
||||||
|
res = -EINVAL;
|
||||||
pw_log_error("link-factory unknown output node %u", output_node_id);
|
pw_log_error("link-factory unknown output node %u", output_node_id);
|
||||||
pw_resource_error(resource, -EINVAL, "unknown output node %u", output_node_id);
|
pw_resource_error(resource, res, "unknown output node %u", output_node_id);
|
||||||
goto done;
|
goto error_exit;
|
||||||
no_input:
|
error_input:
|
||||||
|
res = -EINVAL;
|
||||||
pw_log_error("link-factory unknown input node %u", input_node_id);
|
pw_log_error("link-factory unknown input node %u", input_node_id);
|
||||||
pw_resource_error(resource, -EINVAL, "unknown input node %u", input_node_id);
|
pw_resource_error(resource, res, "unknown input node %u", input_node_id);
|
||||||
goto done;
|
goto error_exit;
|
||||||
no_output_port:
|
error_output_port:
|
||||||
|
res = -EINVAL;
|
||||||
pw_log_error("link-factory unknown output port %u", output_port_id);
|
pw_log_error("link-factory unknown output port %u", output_port_id);
|
||||||
pw_resource_error(resource, -EINVAL, "unknown output port %u", output_port_id);
|
pw_resource_error(resource, res, "unknown output port %u", output_port_id);
|
||||||
goto done;
|
goto error_exit;
|
||||||
no_input_port:
|
error_input_port:
|
||||||
|
res = -EINVAL;
|
||||||
pw_log_error("link-factory unknown input port %u", input_port_id);
|
pw_log_error("link-factory unknown input port %u", input_port_id);
|
||||||
pw_resource_error(resource, -EINVAL, "unknown input port %u", input_port_id);
|
pw_resource_error(resource, res, "unknown input port %u", input_port_id);
|
||||||
goto done;
|
goto error_exit;
|
||||||
no_mem:
|
error_create_link:
|
||||||
res = -errno;
|
|
||||||
pw_log_error("can't create link: %s", spa_strerror(res));
|
pw_log_error("can't create link: %s", spa_strerror(res));
|
||||||
pw_resource_error(resource, res, "can't create link: %s", spa_strerror(res));
|
pw_resource_error(resource, res, "can't create link: %s", spa_strerror(res));
|
||||||
goto done;
|
goto error_exit;
|
||||||
no_bind:
|
error_link_register:
|
||||||
pw_resource_error(resource, res, "can't bind link");
|
pw_log_error("can't register link: %s", spa_strerror(res));
|
||||||
goto done;
|
pw_resource_error(resource, res, "can't register link: %s", spa_strerror(res));
|
||||||
done:
|
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)
|
if (properties)
|
||||||
pw_properties_free(properties);
|
pw_properties_free(properties);
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
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_core *core = pw_module_get_core(module);
|
||||||
struct pw_factory *factory;
|
struct pw_factory *factory;
|
||||||
struct factory_data *data;
|
struct factory_data *data;
|
||||||
|
int res;
|
||||||
|
|
||||||
factory = pw_factory_new(core,
|
factory = pw_factory_new(core,
|
||||||
"link-factory",
|
"link-factory",
|
||||||
|
|
@ -324,8 +339,10 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
PW_KEY_FACTORY_USAGE, FACTORY_USAGE,
|
PW_KEY_FACTORY_USAGE, FACTORY_USAGE,
|
||||||
NULL),
|
NULL),
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (factory == NULL)
|
if (factory == NULL) {
|
||||||
return -ENOMEM;
|
res = -errno;
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
data = pw_factory_get_user_data(factory);
|
data = pw_factory_get_user_data(factory);
|
||||||
data->this = factory;
|
data->this = factory;
|
||||||
|
|
@ -338,13 +355,21 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
&impl_factory,
|
&impl_factory,
|
||||||
data);
|
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_add_listener(module, &data->module_listener, &module_events, data);
|
||||||
|
|
||||||
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error_register:
|
||||||
|
pw_factory_destroy(factory);
|
||||||
|
error_cleanup:
|
||||||
|
if (properties)
|
||||||
|
pw_properties_free(properties);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
|
|
@ -79,12 +79,12 @@ struct client {
|
||||||
struct pw_properties *properties;
|
struct pw_properties *properties;
|
||||||
struct spa_source *source;
|
struct spa_source *source;
|
||||||
|
|
||||||
struct pw_protocol_native_connection *connection;
|
struct pw_protocol_native_connection *connection;
|
||||||
struct spa_hook conn_listener;
|
struct spa_hook conn_listener;
|
||||||
|
|
||||||
bool disconnecting;
|
struct spa_source *flush_event;
|
||||||
bool flush_signaled;
|
unsigned int disconnecting:1;
|
||||||
struct spa_source *flush_event;
|
unsigned int flush_signaled:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct server {
|
struct server {
|
||||||
|
|
@ -93,11 +93,11 @@ struct server {
|
||||||
int fd_lock;
|
int fd_lock;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
||||||
bool activated;
|
|
||||||
|
|
||||||
struct pw_loop *loop;
|
struct pw_loop *loop;
|
||||||
struct spa_source *source;
|
struct spa_source *source;
|
||||||
struct spa_hook hook;
|
struct spa_hook hook;
|
||||||
|
unsigned int activated:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct client_data {
|
struct client_data {
|
||||||
|
|
@ -105,7 +105,7 @@ struct client_data {
|
||||||
struct spa_hook client_listener;
|
struct spa_hook client_listener;
|
||||||
struct spa_source *source;
|
struct spa_source *source;
|
||||||
struct pw_protocol_native_connection *connection;
|
struct pw_protocol_native_connection *connection;
|
||||||
bool busy;
|
unsigned int busy:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
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)
|
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) {
|
if (buf->buffer_size + size > buf->buffer_maxsize) {
|
||||||
buf->buffer_maxsize = SPA_ROUND_UP_N(buf->buffer_size + size, MAX_BUFFER_SIZE);
|
buf->buffer_maxsize = SPA_ROUND_UP_N(buf->buffer_size + size, MAX_BUFFER_SIZE);
|
||||||
buf->buffer_data = realloc(buf->buffer_data, buf->buffer_maxsize);
|
buf->buffer_data = realloc(buf->buffer_data, buf->buffer_maxsize);
|
||||||
if (buf->buffer_data == NULL) {
|
if (buf->buffer_data == NULL) {
|
||||||
|
res = -errno;
|
||||||
buf->buffer_maxsize = 0;
|
buf->buffer_maxsize = 0;
|
||||||
spa_hook_list_call(&conn->listener_list,
|
spa_hook_list_call(&conn->listener_list,
|
||||||
struct pw_protocol_native_connection_events,
|
struct pw_protocol_native_connection_events,
|
||||||
error, 0, -ENOMEM);
|
error, 0, -res);
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pw_log_warn("connection %p: resize buffer to %zd %zd %zd",
|
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;
|
break;
|
||||||
|
|
||||||
if (connection_ensure_size(conn, buf, len) == NULL)
|
if (connection_ensure_size(conn, buf, len) == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
if ((res = refill_buffer(conn, buf)) < 0)
|
if ((res = refill_buffer(conn, buf)) < 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +366,7 @@ static int builder_overflow(void *data, uint32_t size)
|
||||||
|
|
||||||
b->size = SPA_ROUND_UP_N(size, 4096);
|
b->size = SPA_ROUND_UP_N(size, 4096);
|
||||||
if ((b->data = begin_write(&impl->this, b->size)) == NULL)
|
if ((b->data = begin_write(&impl->this, b->size)) == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,7 +405,7 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if ((p = connection_ensure_size(conn, buf, HDR_SIZE + size)) == NULL)
|
if ((p = connection_ensure_size(conn, buf, HDR_SIZE + size)) == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
p[0] = buf->msg.id;
|
p[0] = buf->msg.id;
|
||||||
p[1] = (buf->msg.opcode << 24) | (size & 0xffffff);
|
p[1] = (buf->msg.opcode << 24) | (size & 0xffffff);
|
||||||
|
|
|
||||||
|
|
@ -83,13 +83,14 @@ static void *create_object(void *_data,
|
||||||
struct pw_device *device;
|
struct pw_device *device;
|
||||||
const char *factory_name, *name;
|
const char *factory_name, *name;
|
||||||
struct device_data *nd;
|
struct device_data *nd;
|
||||||
|
int res;
|
||||||
|
|
||||||
if (properties == NULL)
|
if (properties == NULL)
|
||||||
goto no_properties;
|
goto error_properties;
|
||||||
|
|
||||||
factory_name = pw_properties_get(properties, SPA_KEY_FACTORY_NAME);
|
factory_name = pw_properties_get(properties, SPA_KEY_FACTORY_NAME);
|
||||||
if (factory_name == NULL)
|
if (factory_name == NULL)
|
||||||
goto no_properties;
|
goto error_properties;
|
||||||
|
|
||||||
name = pw_properties_get(properties, PW_KEY_DEVICE_NAME);
|
name = pw_properties_get(properties, PW_KEY_DEVICE_NAME);
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
|
|
@ -103,8 +104,10 @@ static void *create_object(void *_data,
|
||||||
0,
|
0,
|
||||||
properties,
|
properties,
|
||||||
sizeof(struct device_data));
|
sizeof(struct device_data));
|
||||||
if (device == NULL)
|
if (device == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error_device;
|
||||||
|
}
|
||||||
|
|
||||||
nd = pw_spa_device_get_user_data(device);
|
nd = pw_spa_device_get_user_data(device);
|
||||||
nd->device = device;
|
nd->device = device;
|
||||||
|
|
@ -120,17 +123,19 @@ static void *create_object(void *_data,
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
|
|
||||||
no_properties:
|
error_properties:
|
||||||
|
res = -EINVAL;
|
||||||
pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
|
pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
|
||||||
if (resource) {
|
if (resource)
|
||||||
pw_resource_error(resource, -EINVAL, "usage: " FACTORY_USAGE);
|
pw_resource_error(resource, res, "usage: " FACTORY_USAGE);
|
||||||
}
|
goto error_exit;
|
||||||
return NULL;
|
error_device:
|
||||||
no_mem:
|
pw_log_error("can't create device: %s", spa_strerror(res));
|
||||||
pw_log_error("can't create device: no memory");
|
if (resource)
|
||||||
if (resource) {
|
pw_resource_error(resource, res, "can't create device: %s", spa_strerror(res));
|
||||||
pw_resource_error(resource, -ENOMEM, "no memory");
|
goto error_exit;
|
||||||
}
|
error_exit:
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
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_core *core = pw_module_get_core(module);
|
||||||
struct pw_factory *factory;
|
struct pw_factory *factory;
|
||||||
struct factory_data *data;
|
struct factory_data *data;
|
||||||
|
int res;
|
||||||
|
|
||||||
factory = pw_factory_new(core,
|
factory = pw_factory_new(core,
|
||||||
"spa-device-factory",
|
"spa-device-factory",
|
||||||
|
|
@ -182,7 +188,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
NULL,
|
NULL,
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (factory == NULL)
|
if (factory == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
data = pw_factory_get_user_data(factory);
|
data = pw_factory_get_user_data(factory);
|
||||||
data->this = 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_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;
|
return 0;
|
||||||
|
|
||||||
|
error_register:
|
||||||
|
pw_factory_destroy(factory);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
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_core *core = pw_module_get_core(module);
|
||||||
struct pw_factory *factory;
|
struct pw_factory *factory;
|
||||||
struct factory_data *data;
|
struct factory_data *data;
|
||||||
|
int res;
|
||||||
|
|
||||||
factory = pw_factory_new(core,
|
factory = pw_factory_new(core,
|
||||||
"spa-node-factory",
|
"spa-node-factory",
|
||||||
|
|
@ -182,7 +183,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
|
||||||
NULL,
|
NULL,
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (factory == NULL)
|
if (factory == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
|
|
||||||
data = pw_factory_get_user_data(factory);
|
data = pw_factory_get_user_data(factory);
|
||||||
data->this = 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_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;
|
return 0;
|
||||||
|
|
||||||
|
error_register:
|
||||||
|
pw_factory_destroy(factory);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ struct impl {
|
||||||
void *unload;
|
void *unload;
|
||||||
struct spa_handle *handle;
|
struct spa_handle *handle;
|
||||||
struct spa_device *device;
|
struct spa_device *device;
|
||||||
char *factory_name;
|
|
||||||
|
|
||||||
struct spa_hook device_listener;
|
struct spa_hook device_listener;
|
||||||
|
|
||||||
|
|
@ -69,7 +68,6 @@ static void device_destroy(void *data)
|
||||||
spa_hook_remove(&impl->device_listener);
|
spa_hook_remove(&impl->device_listener);
|
||||||
if (impl->handle)
|
if (impl->handle)
|
||||||
pw_unload_spa_handle(impl->handle);
|
pw_unload_spa_handle(impl->handle);
|
||||||
free(impl->factory_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct pw_device_events device_events = {
|
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 pw_device *this;
|
||||||
struct impl *impl;
|
struct impl *impl;
|
||||||
|
int res;
|
||||||
|
|
||||||
this = pw_device_new(core, name, properties, sizeof(struct impl) + user_data_size);
|
this = pw_device_new(core, name, properties, sizeof(struct impl) + user_data_size);
|
||||||
if (this == NULL)
|
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_add_listener(this, &impl->device_listener, &device_events, impl);
|
||||||
pw_device_set_implementation(this, impl->device);
|
pw_device_set_implementation(this, impl->device);
|
||||||
|
|
||||||
if (!SPA_FLAG_CHECK(impl->flags, PW_SPA_DEVICE_FLAG_NO_REGISTER))
|
if (!SPA_FLAG_CHECK(impl->flags, PW_SPA_DEVICE_FLAG_NO_REGISTER)) {
|
||||||
pw_device_register(this, impl->owner, impl->parent, NULL);
|
if ((res = pw_device_register(this, impl->owner, impl->parent, NULL)) < 0)
|
||||||
|
goto error_register;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
error_register:
|
||||||
|
pw_device_destroy(this);
|
||||||
|
errno = -res;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pw_spa_device_get_user_data(struct pw_device *device)
|
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)
|
size_t user_data_size)
|
||||||
{
|
{
|
||||||
struct pw_device *this;
|
struct pw_device *this;
|
||||||
struct impl *impl;
|
|
||||||
struct spa_handle *handle;
|
struct spa_handle *handle;
|
||||||
void *iface;
|
void *iface;
|
||||||
int res;
|
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,
|
handle = pw_core_load_spa_handle(core, factory_name,
|
||||||
properties ? &properties->dict : NULL);
|
properties ? &properties->dict : NULL);
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
|
res = -errno;
|
||||||
pw_log_error("can't load device handle: %m");
|
pw_log_error("can't load device handle: %m");
|
||||||
goto exit;
|
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,
|
this = pw_spa_device_new(core, owner, parent, name, flags,
|
||||||
iface, handle, properties, user_data_size);
|
iface, handle, properties, user_data_size);
|
||||||
if (this == NULL) {
|
if (this == NULL) {
|
||||||
|
res = -errno;
|
||||||
pw_log_error("can't create device: %m");
|
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;
|
return this;
|
||||||
|
|
||||||
exit_unload:
|
exit_unload:
|
||||||
pw_unload_spa_handle(handle);
|
pw_unload_spa_handle(handle);
|
||||||
exit:
|
exit:
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,9 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
||||||
else
|
else
|
||||||
props = pw_properties_new(NULL, NULL);
|
props = pw_properties_new(NULL, NULL);
|
||||||
|
|
||||||
|
if (props == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if ((name = pw_properties_get(props, PW_KEY_DEVICE_NAME)) == NULL)
|
if ((name = pw_properties_get(props, PW_KEY_DEVICE_NAME)) == NULL)
|
||||||
name = "unknown";
|
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,
|
handle = pw_core_load_spa_handle(core, info->factory_name,
|
||||||
&props->dict);
|
&props->dict);
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
|
res = -errno;
|
||||||
pw_log_error("can't make factory instance: %m");
|
pw_log_error("can't make factory instance: %m");
|
||||||
goto error_free_props;
|
goto error_free_props;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
|
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;
|
goto error_free_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = calloc(1, sizeof(struct monitor_object));
|
obj = calloc(1, sizeof(struct monitor_object));
|
||||||
|
if (obj == NULL) {
|
||||||
|
res = -errno;
|
||||||
|
goto error_free_handle;
|
||||||
|
}
|
||||||
obj->id = id;
|
obj->id = id;
|
||||||
obj->name = strdup(name);
|
obj->name = strdup(name);
|
||||||
obj->handle = handle;
|
obj->handle = handle;
|
||||||
|
|
@ -139,6 +147,7 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
res = -ENOTSUP;
|
||||||
pw_log_error("interface %d not implemented", obj->type);
|
pw_log_error("interface %d not implemented", obj->type);
|
||||||
goto error_free_object;
|
goto error_free_object;
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +163,7 @@ error_free_handle:
|
||||||
pw_unload_spa_handle(handle);
|
pw_unload_spa_handle(handle);
|
||||||
error_free_props:
|
error_free_props:
|
||||||
pw_properties_free(props);
|
pw_properties_free(props);
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,7 +223,7 @@ static int on_monitor_object_info(void *data, uint32_t id,
|
||||||
} else if (obj == NULL) {
|
} else if (obj == NULL) {
|
||||||
obj = add_object(this, id, info, now_nsec);
|
obj = add_object(this, id, info, now_nsec);
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
return -ENOMEM;
|
return -errno;
|
||||||
} else {
|
} else {
|
||||||
change_object(this, obj, info, now_nsec);
|
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,
|
handle = pw_core_load_spa_handle(core,
|
||||||
factory_name,
|
factory_name,
|
||||||
properties ? &properties->dict : NULL);
|
properties ? &properties->dict : NULL);
|
||||||
if (handle == NULL)
|
if (handle == NULL) {
|
||||||
|
res = -errno;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
|
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;
|
goto exit_unload;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
if (impl == NULL)
|
if (impl == NULL) {
|
||||||
|
res = -errno;
|
||||||
goto exit_unload;
|
goto exit_unload;
|
||||||
|
}
|
||||||
|
|
||||||
impl->core = core;
|
impl->core = core;
|
||||||
impl->parent = parent;
|
impl->parent = parent;
|
||||||
|
|
@ -302,6 +316,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
||||||
exit_unload:
|
exit_unload:
|
||||||
pw_unload_spa_handle(handle);
|
pw_unload_spa_handle(handle);
|
||||||
exit:
|
exit:
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,7 @@ pw_spa_node_new(struct pw_core *core,
|
||||||
impl->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
|
impl->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
|
||||||
|
|
||||||
pw_node_add_listener(this, &impl->node_listener, &node_events, impl);
|
pw_node_add_listener(this, &impl->node_listener, &node_events, impl);
|
||||||
res = pw_node_set_implementation(this, impl->node);
|
if ((res = pw_node_set_implementation(this, impl->node)) < 0)
|
||||||
|
|
||||||
if (res < 0)
|
|
||||||
goto clean_node;
|
goto clean_node;
|
||||||
|
|
||||||
if (flags & PW_SPA_NODE_FLAG_ASYNC) {
|
if (flags & PW_SPA_NODE_FLAG_ASYNC) {
|
||||||
|
|
@ -153,6 +151,7 @@ pw_spa_node_new(struct pw_core *core,
|
||||||
|
|
||||||
clean_node:
|
clean_node:
|
||||||
pw_node_destroy(this);
|
pw_node_destroy(this);
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +179,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
|
||||||
&b);
|
&b);
|
||||||
if (res != 1) {
|
if (res != 1) {
|
||||||
if (res < 0)
|
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;
|
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) {
|
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 res;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -256,8 +255,10 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
||||||
handle = pw_core_load_spa_handle(core,
|
handle = pw_core_load_spa_handle(core,
|
||||||
factory_name,
|
factory_name,
|
||||||
properties ? &properties->dict : NULL);
|
properties ? &properties->dict : NULL);
|
||||||
if (handle == NULL)
|
if (handle == NULL) {
|
||||||
|
res = -errno;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
|
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
|
||||||
pw_log_error("can't get node interface %d", res);
|
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 (properties != NULL) {
|
||||||
if (setup_props(core, spa_node, properties) < 0) {
|
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,
|
this = pw_spa_node_new(core, owner, parent, name, flags,
|
||||||
spa_node, handle, properties, user_data_size);
|
spa_node, handle, properties, user_data_size);
|
||||||
if (this == NULL)
|
if (this == NULL) {
|
||||||
|
res = -errno;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
impl = this->user_data;
|
impl = this->user_data;
|
||||||
impl->handle = handle;
|
impl->handle = handle;
|
||||||
|
|
@ -288,5 +291,6 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
|
||||||
exit_unload:
|
exit_unload:
|
||||||
pw_unload_spa_handle(handle);
|
pw_unload_spa_handle(handle);
|
||||||
exit:
|
exit:
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto out;
|
goto error_resource;
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
data->client = this;
|
data->client = this;
|
||||||
|
|
@ -219,7 +219,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out:
|
error_resource:
|
||||||
pw_log_error("can't create client resource: %m");
|
pw_log_error("can't create client resource: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -259,10 +259,13 @@ struct pw_client *pw_client_new(struct pw_core *core,
|
||||||
struct pw_client *this;
|
struct pw_client *this;
|
||||||
struct impl *impl;
|
struct impl *impl;
|
||||||
struct pw_permission *p;
|
struct pw_permission *p;
|
||||||
|
int res;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
if (impl == NULL)
|
if (impl == NULL) {
|
||||||
return NULL;
|
res = -errno;
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
this = &impl->this;
|
this = &impl->this;
|
||||||
pw_log_debug("client %p: new", this);
|
pw_log_debug("client %p: new", this);
|
||||||
|
|
@ -271,11 +274,18 @@ struct pw_client *pw_client_new(struct pw_core *core,
|
||||||
|
|
||||||
if (properties == NULL)
|
if (properties == NULL)
|
||||||
properties = pw_properties_new(NULL, NULL);
|
properties = pw_properties_new(NULL, NULL);
|
||||||
if (properties == NULL)
|
if (properties == NULL) {
|
||||||
return NULL;
|
res = -errno;
|
||||||
|
goto error_free;
|
||||||
|
}
|
||||||
|
|
||||||
pw_array_init(&impl->permissions, 1024);
|
pw_array_init(&impl->permissions, 1024);
|
||||||
p = pw_array_add(&impl->permissions, sizeof(struct pw_permission));
|
p = pw_array_add(&impl->permissions, sizeof(struct pw_permission));
|
||||||
|
if (p == NULL) {
|
||||||
|
res = -errno;
|
||||||
|
goto error_clear_array;
|
||||||
|
}
|
||||||
|
|
||||||
p->id = SPA_ID_INVALID;
|
p->id = SPA_ID_INVALID;
|
||||||
p->permissions = 0;
|
p->permissions = 0;
|
||||||
|
|
||||||
|
|
@ -297,6 +307,16 @@ struct pw_client *pw_client_new(struct pw_core *core,
|
||||||
pw_core_emit_check_access(core, this);
|
pw_core_emit_check_access(core, this);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
error_clear_array:
|
||||||
|
pw_array_clear(&impl->permissions);
|
||||||
|
error_free:
|
||||||
|
free(impl);
|
||||||
|
error_cleanup:
|
||||||
|
if (properties)
|
||||||
|
pw_properties_free(properties);
|
||||||
|
errno = -res;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void global_destroy(void *object)
|
static void global_destroy(void *object)
|
||||||
|
|
@ -522,6 +542,10 @@ int pw_client_update_permissions(struct pw_client *client,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
p = ensure_permissions(client, permissions[i].id);
|
p = ensure_permissions(client, permissions[i].id);
|
||||||
|
if (p == NULL) {
|
||||||
|
pw_log_warn("client %p: can't ensure permission: %m", client);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
old_perm = p->permissions == SPA_ID_INVALID ? def->permissions : p->permissions;
|
old_perm = p->permissions == SPA_ID_INVALID ? def->permissions : p->permissions;
|
||||||
new_perm = permissions[i].permissions;
|
new_perm = permissions[i].permissions;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,33 +74,33 @@ static void * registry_bind(void *object, uint32_t id,
|
||||||
uint32_t permissions, new_id = user_data_size;
|
uint32_t permissions, new_id = user_data_size;
|
||||||
|
|
||||||
if ((global = pw_core_find_global(core, id)) == NULL)
|
if ((global = pw_core_find_global(core, id)) == NULL)
|
||||||
goto no_id;
|
goto error_no_id;
|
||||||
|
|
||||||
permissions = pw_global_get_permissions(global, client);
|
permissions = pw_global_get_permissions(global, client);
|
||||||
|
|
||||||
if (!PW_PERM_IS_R(permissions))
|
if (!PW_PERM_IS_R(permissions))
|
||||||
goto no_id;
|
goto error_no_id;
|
||||||
|
|
||||||
if (global->type != type)
|
if (global->type != type)
|
||||||
goto wrong_interface;
|
goto error_wrong_interface;
|
||||||
|
|
||||||
pw_log_debug("global %p: bind global id %d, iface %s/%d to %d", global, id,
|
pw_log_debug("global %p: bind global id %d, iface %s/%d to %d", global, id,
|
||||||
spa_debug_type_find_name(pw_type_info(), type), version, new_id);
|
spa_debug_type_find_name(pw_type_info(), type), version, new_id);
|
||||||
|
|
||||||
if (pw_global_bind(global, client, permissions, version, new_id) < 0)
|
if (pw_global_bind(global, client, permissions, version, new_id) < 0)
|
||||||
goto exit;
|
goto error_exit_clean;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
no_id:
|
error_no_id:
|
||||||
pw_log_debug("registry %p: no global with id %u to bind to %u", resource, id, new_id);
|
pw_log_debug("registry %p: no global with id %u to bind to %u", resource, id, new_id);
|
||||||
pw_resource_error(resource, -ENOENT, "no such global %u", id);
|
pw_resource_error(resource, -ENOENT, "no such global %u", id);
|
||||||
goto exit;
|
goto error_exit_clean;
|
||||||
wrong_interface:
|
error_wrong_interface:
|
||||||
pw_log_debug("registry %p: global with id %u has no interface %u", resource, id, type);
|
pw_log_debug("registry %p: global with id %u has no interface %u", resource, id, type);
|
||||||
pw_resource_error(resource, -ENOENT, "no such interface %u", type);
|
pw_resource_error(resource, -ENOENT, "no such interface %u", type);
|
||||||
goto exit;
|
goto error_exit_clean;
|
||||||
exit:
|
error_exit_clean:
|
||||||
/* unmark the new_id the map, the client does not yet know about the failed
|
/* unmark the new_id the map, the client does not yet know about the failed
|
||||||
* bind and will choose the next id, which we would refuse when we don't mark
|
* bind and will choose the next id, which we would refuse when we don't mark
|
||||||
* new_id as 'used and freed' */
|
* new_id as 'used and freed' */
|
||||||
|
|
@ -116,25 +116,34 @@ static int registry_destroy(void *object, uint32_t id)
|
||||||
struct pw_core *core = resource->core;
|
struct pw_core *core = resource->core;
|
||||||
struct pw_global *global;
|
struct pw_global *global;
|
||||||
uint32_t permissions;
|
uint32_t permissions;
|
||||||
|
int res;
|
||||||
|
|
||||||
if ((global = pw_core_find_global(core, id)) == NULL)
|
if ((global = pw_core_find_global(core, id)) == NULL)
|
||||||
goto no_id;
|
goto error_no_id;
|
||||||
|
|
||||||
permissions = pw_global_get_permissions(global, client);
|
permissions = pw_global_get_permissions(global, client);
|
||||||
|
|
||||||
|
if (!PW_PERM_IS_R(permissions))
|
||||||
|
goto error_no_id;
|
||||||
|
|
||||||
if (!PW_PERM_IS_X(permissions))
|
if (!PW_PERM_IS_X(permissions))
|
||||||
goto no_id;
|
goto error_not_allowed;
|
||||||
|
|
||||||
pw_log_debug("global %p: destroy global id %d", global, id);
|
pw_log_debug("global %p: destroy global id %d", global, id);
|
||||||
|
|
||||||
pw_global_destroy(global);
|
pw_global_destroy(global);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_id:
|
error_no_id:
|
||||||
pw_log_debug("registry %p: no global with id %u to destroy", resource, id);
|
pw_log_debug("registry %p: no global with id %u to destroy", resource, id);
|
||||||
goto exit;
|
res = -ENOENT;
|
||||||
exit:
|
goto error_exit;
|
||||||
return -EFAULT;
|
error_not_allowed:
|
||||||
|
pw_log_debug("registry %p: destroy of id %u not allowed", resource, id);
|
||||||
|
res = -EPERM;
|
||||||
|
goto error_exit;
|
||||||
|
error_exit:
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct pw_registry_proxy_methods registry_methods = {
|
static const struct pw_registry_proxy_methods registry_methods = {
|
||||||
|
|
@ -228,6 +237,7 @@ static struct pw_registry_proxy * core_get_registry(void *object, uint32_t versi
|
||||||
struct pw_resource *registry_resource;
|
struct pw_resource *registry_resource;
|
||||||
struct resource_data *data;
|
struct resource_data *data;
|
||||||
uint32_t new_id = user_data_size;
|
uint32_t new_id = user_data_size;
|
||||||
|
int res;
|
||||||
|
|
||||||
registry_resource = pw_resource_new(client,
|
registry_resource = pw_resource_new(client,
|
||||||
new_id,
|
new_id,
|
||||||
|
|
@ -235,8 +245,10 @@ static struct pw_registry_proxy * core_get_registry(void *object, uint32_t versi
|
||||||
PW_TYPE_INTERFACE_Registry,
|
PW_TYPE_INTERFACE_Registry,
|
||||||
version,
|
version,
|
||||||
sizeof(*data));
|
sizeof(*data));
|
||||||
if (registry_resource == NULL)
|
if (registry_resource == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error_resource;
|
||||||
|
}
|
||||||
|
|
||||||
data = pw_resource_get_user_data(registry_resource);
|
data = pw_resource_get_user_data(registry_resource);
|
||||||
pw_resource_add_listener(registry_resource,
|
pw_resource_add_listener(registry_resource,
|
||||||
|
|
@ -266,13 +278,14 @@ static struct pw_registry_proxy * core_get_registry(void *object, uint32_t versi
|
||||||
|
|
||||||
return (struct pw_registry_proxy *)registry_resource;
|
return (struct pw_registry_proxy *)registry_resource;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create registry resource");
|
pw_log_error("can't create registry resource: %m");
|
||||||
pw_core_resource_error(client->core_resource, new_id,
|
pw_core_resource_errorf(client->core_resource, new_id,
|
||||||
client->recv_seq, -ENOMEM, "no memory");
|
client->recv_seq, res,
|
||||||
|
"can't create registry resource: %s", spa_strerror(res));
|
||||||
pw_map_insert_at(&client->objects, new_id, NULL);
|
pw_map_insert_at(&client->objects, new_id, NULL);
|
||||||
pw_core_resource_remove_id(client->core_resource, new_id);
|
pw_core_resource_remove_id(client->core_resource, new_id);
|
||||||
errno = ENOMEM;
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,12 +346,13 @@ core_create_object(void *object,
|
||||||
no_properties:
|
no_properties:
|
||||||
res = -errno;
|
res = -errno;
|
||||||
pw_log_error("can't create properties");
|
pw_log_error("can't create properties");
|
||||||
pw_resource_error(resource, res, "no memory");
|
pw_resource_error(resource, res, "can't create properties: %s", spa_strerror(res));
|
||||||
create_failed:
|
create_failed:
|
||||||
res = -errno;
|
res = -errno;
|
||||||
error:
|
error:
|
||||||
pw_map_insert_at(&client->objects, new_id, NULL);
|
pw_map_insert_at(&client->objects, new_id, NULL);
|
||||||
pw_core_resource_remove_id(client->core_resource, new_id);
|
pw_core_resource_remove_id(client->core_resource, new_id);
|
||||||
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -387,12 +401,16 @@ global_bind(void *_data,
|
||||||
struct pw_global *global = this->global;
|
struct pw_global *global = this->global;
|
||||||
struct pw_resource *resource;
|
struct pw_resource *resource;
|
||||||
struct resource_data *data;
|
struct resource_data *data;
|
||||||
|
int res;
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
|
|
||||||
pw_resource_add_listener(resource,
|
pw_resource_add_listener(resource,
|
||||||
&data->resource_listener,
|
&data->resource_listener,
|
||||||
&core_resource_events,
|
&core_resource_events,
|
||||||
|
|
@ -410,9 +428,9 @@ global_bind(void *_data,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error:
|
||||||
pw_log_error("can't create core resource");
|
pw_log_error("core %p: can't create resource: %m", this);
|
||||||
return -ENOMEM;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void global_destroy(void *object)
|
static void global_destroy(void *object)
|
||||||
|
|
@ -449,8 +467,10 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop,
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
if (impl == NULL)
|
if (impl == NULL) {
|
||||||
return NULL;
|
res = -errno;
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
this = &impl->this;
|
this = &impl->this;
|
||||||
|
|
||||||
|
|
@ -463,7 +483,7 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop,
|
||||||
properties = pw_properties_new(NULL, NULL);
|
properties = pw_properties_new(NULL, NULL);
|
||||||
if (properties == NULL) {
|
if (properties == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto out_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->properties = properties;
|
this->properties = properties;
|
||||||
|
|
@ -471,16 +491,13 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop,
|
||||||
this->data_loop_impl = pw_data_loop_new(pw_properties_copy(properties));
|
this->data_loop_impl = pw_data_loop_new(pw_properties_copy(properties));
|
||||||
if (this->data_loop_impl == NULL) {
|
if (this->data_loop_impl == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto out_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->data_loop = pw_data_loop_get_loop(this->data_loop_impl);
|
this->data_loop = pw_data_loop_get_loop(this->data_loop_impl);
|
||||||
this->data_system = this->data_loop->system;
|
this->data_system = this->data_loop->system;
|
||||||
this->main_loop = main_loop;
|
this->main_loop = main_loop;
|
||||||
|
|
||||||
pw_array_init(&this->factory_lib, 32);
|
|
||||||
pw_map_init(&this->globals, 128, 32);
|
|
||||||
|
|
||||||
n_support = pw_get_support(this->support, SPA_N_ELEMENTS(this->support));
|
n_support = pw_get_support(this->support, SPA_N_ELEMENTS(this->support));
|
||||||
this->support[n_support++] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_System, this->main_loop->system);
|
this->support[n_support++] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_System, this->main_loop->system);
|
||||||
this->support[n_support++] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_Loop, this->main_loop->loop);
|
this->support[n_support++] = SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_Loop, this->main_loop->loop);
|
||||||
|
|
@ -502,7 +519,11 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop,
|
||||||
}
|
}
|
||||||
this->n_support = n_support;
|
this->n_support = n_support;
|
||||||
|
|
||||||
pw_data_loop_start(this->data_loop_impl);
|
if ((res = pw_data_loop_start(this->data_loop_impl)) < 0)
|
||||||
|
goto error_free_loop;
|
||||||
|
|
||||||
|
pw_array_init(&this->factory_lib, 32);
|
||||||
|
pw_map_init(&this->globals, 128, 32);
|
||||||
|
|
||||||
spa_list_init(&this->protocol_list);
|
spa_list_init(&this->protocol_list);
|
||||||
spa_list_init(&this->remote_list);
|
spa_list_init(&this->remote_list);
|
||||||
|
|
@ -551,18 +572,23 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop,
|
||||||
this);
|
this);
|
||||||
if (this->global == NULL) {
|
if (this->global == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto out_cleanup;
|
goto error_free_loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_global_add_listener(this->global, &this->global_listener, &global_events, this);
|
pw_global_add_listener(this->global, &this->global_listener, &global_events, this);
|
||||||
pw_global_register(this->global, NULL, NULL);
|
pw_global_register(this->global, NULL, NULL);
|
||||||
|
|
||||||
this->info.id = this->global->id;
|
this->info.id = this->global->id;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
out_cleanup:
|
error_free_loop:
|
||||||
out_free:
|
pw_data_loop_destroy(this->data_loop_impl);
|
||||||
|
error_free:
|
||||||
free(this);
|
free(this);
|
||||||
|
error_cleanup:
|
||||||
|
if (properties)
|
||||||
|
pw_properties_free(properties);
|
||||||
errno = -res;
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,33 +67,39 @@ struct pw_data_loop *pw_data_loop_new(struct pw_properties *properties)
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
this = calloc(1, sizeof(struct pw_data_loop));
|
this = calloc(1, sizeof(struct pw_data_loop));
|
||||||
if (this == NULL)
|
if (this == NULL) {
|
||||||
return NULL;
|
res = -errno;
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
pw_log_debug("data-loop %p: new", this);
|
pw_log_debug("data-loop %p: new", this);
|
||||||
|
|
||||||
this->loop = pw_loop_new(properties);
|
this->loop = pw_loop_new(properties);
|
||||||
|
properties = NULL;
|
||||||
if (this->loop == NULL) {
|
if (this->loop == NULL) {
|
||||||
pw_log_debug("data-loop %p: can't create loop: %m", this);
|
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto no_loop;
|
pw_log_debug("data-loop %p: can't create loop: %m", this);
|
||||||
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->event = pw_loop_add_event(this->loop, do_stop, this);
|
this->event = pw_loop_add_event(this->loop, do_stop, this);
|
||||||
if (this->event == NULL) {
|
if (this->event == NULL) {
|
||||||
pw_log_debug("data-loop %p: can't add event: %m", this);
|
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto no_event;
|
pw_log_debug("data-loop %p: can't add event: %m", this);
|
||||||
|
goto error_loop_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
no_event:
|
error_loop_destroy:
|
||||||
pw_loop_destroy(this->loop);
|
pw_loop_destroy(this->loop);
|
||||||
no_loop:
|
error_free:
|
||||||
free(this);
|
free(this);
|
||||||
|
error_cleanup:
|
||||||
|
if (properties)
|
||||||
|
pw_properties_free(properties);
|
||||||
errno = -res;
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,10 @@ struct pw_device *pw_device_new(struct pw_core *core,
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
if (impl == NULL)
|
if (impl == NULL) {
|
||||||
return NULL;
|
res = -errno;
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
this = &impl->this;
|
this = &impl->this;
|
||||||
|
|
||||||
|
|
@ -91,7 +93,7 @@ struct pw_device *pw_device_new(struct pw_core *core,
|
||||||
properties = pw_properties_new(NULL, NULL);
|
properties = pw_properties_new(NULL, NULL);
|
||||||
if (properties == NULL) {
|
if (properties == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto no_mem;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->core = core;
|
this->core = core;
|
||||||
|
|
@ -111,8 +113,11 @@ struct pw_device *pw_device_new(struct pw_core *core,
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
no_mem:
|
error_free:
|
||||||
free(impl);
|
free(impl);
|
||||||
|
error_cleanup:
|
||||||
|
if (properties)
|
||||||
|
pw_properties_free(properties);
|
||||||
errno = -res;
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -296,7 +301,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto no_mem;
|
goto error_resource;
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
data->device = this;
|
data->device = this;
|
||||||
|
|
@ -319,8 +324,8 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create device resource");
|
pw_log_error("can't create device resource: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto no_mem;
|
goto error_resource;
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
|
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
|
||||||
|
|
@ -126,7 +126,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create factory resource: %m");
|
pw_log_error("can't create factory resource: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ pw_global_new(struct pw_core *core,
|
||||||
{
|
{
|
||||||
struct impl *impl;
|
struct impl *impl;
|
||||||
struct pw_global *this;
|
struct pw_global *this;
|
||||||
|
int res;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl));
|
impl = calloc(1, sizeof(struct impl));
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
|
|
@ -103,6 +104,11 @@ pw_global_new(struct pw_core *core,
|
||||||
this->object = object;
|
this->object = object;
|
||||||
this->properties = properties;
|
this->properties = properties;
|
||||||
this->id = pw_map_insert_new(&core->globals, this);
|
this->id = pw_map_insert_new(&core->globals, this);
|
||||||
|
if (this->id == SPA_ID_INVALID) {
|
||||||
|
res = -errno;
|
||||||
|
pw_log_error("global %p: can't allocate new id: %m", this);
|
||||||
|
goto error_clean;
|
||||||
|
}
|
||||||
|
|
||||||
spa_list_init(&this->child_list);
|
spa_list_init(&this->child_list);
|
||||||
spa_list_init(&this->resource_list);
|
spa_list_init(&this->resource_list);
|
||||||
|
|
@ -113,6 +119,11 @@ pw_global_new(struct pw_core *core,
|
||||||
this->id);
|
this->id);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
error_clean:
|
||||||
|
free(impl);
|
||||||
|
errno = -res;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** register a global to the core registry
|
/** register a global to the core registry
|
||||||
|
|
|
||||||
|
|
@ -1050,7 +1050,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto no_mem;
|
goto error_resource;
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
|
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
|
||||||
|
|
@ -1065,8 +1065,8 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create link resource");
|
pw_log_error("can't create link resource: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto no_mem;
|
goto error_resource;
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
|
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
|
||||||
|
|
@ -144,8 +144,8 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create module resource");
|
pw_log_error("can't create module resource: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
|
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
goto no_mem;
|
goto error_resource;
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
data->node = this;
|
data->node = this;
|
||||||
|
|
@ -460,8 +460,8 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
this->info.change_mask = 0;
|
this->info.change_mask = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create node resource");
|
pw_log_error("can't create node resource: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1336,6 +1336,7 @@ uint32_t pw_node_get_free_port_id(struct pw_node *node, enum pw_direction direct
|
||||||
uint32_t n_ports, max_ports;
|
uint32_t n_ports, max_ports;
|
||||||
struct pw_map *portmap;
|
struct pw_map *portmap;
|
||||||
uint32_t port_id;
|
uint32_t port_id;
|
||||||
|
int res;
|
||||||
|
|
||||||
if (direction == PW_DIRECTION_INPUT) {
|
if (direction == PW_DIRECTION_INPUT) {
|
||||||
max_ports = node->info.max_input_ports;
|
max_ports = node->info.max_input_ports;
|
||||||
|
|
@ -1349,19 +1350,24 @@ uint32_t pw_node_get_free_port_id(struct pw_node *node, enum pw_direction direct
|
||||||
pw_log_debug("node %p: direction %s n_ports:%u max_ports:%u",
|
pw_log_debug("node %p: direction %s n_ports:%u max_ports:%u",
|
||||||
node, pw_direction_as_string(direction), n_ports, max_ports);
|
node, pw_direction_as_string(direction), n_ports, max_ports);
|
||||||
|
|
||||||
if (n_ports >= max_ports)
|
if (n_ports >= max_ports) {
|
||||||
goto no_mem;
|
res = -ENOSPC;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
port_id = pw_map_insert_new(portmap, NULL);
|
port_id = pw_map_insert_new(portmap, NULL);
|
||||||
if (port_id == SPA_ID_INVALID)
|
if (port_id == SPA_ID_INVALID) {
|
||||||
goto no_mem;
|
res = -errno;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
pw_log_debug("node %p: free port %d", node, port_id);
|
pw_log_debug("node %p: free port %d", node, port_id);
|
||||||
|
|
||||||
return port_id;
|
return port_id;
|
||||||
|
|
||||||
no_mem:
|
error:
|
||||||
pw_log_warn("no more port available");
|
pw_log_warn("node %p: no more port available: %s", node, spa_strerror(res));
|
||||||
|
errno = -res;
|
||||||
return SPA_ID_INVALID;
|
return SPA_ID_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,8 @@ int pw_port_init_mix(struct pw_port *port, struct pw_port_mix *mix)
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
port_id = pw_map_insert_new(&port->mix_port_map, mix);
|
port_id = pw_map_insert_new(&port->mix_port_map, mix);
|
||||||
|
if (port_id == SPA_ID_INVALID)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
mix->port.direction = port->direction;
|
mix->port.direction = port->direction;
|
||||||
mix->port.port_id = port_id;
|
mix->port.port_id = port_id;
|
||||||
|
|
@ -602,7 +604,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
|
||||||
if (resource == NULL) {
|
if (resource == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto no_mem;
|
goto error_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = pw_resource_get_user_data(resource);
|
data = pw_resource_get_user_data(resource);
|
||||||
|
|
@ -625,8 +627,8 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
|
||||||
this->info.change_mask = 0;
|
this->info.change_mask = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_mem:
|
error_resource:
|
||||||
pw_log_error("can't create port resource: %s", spa_strerror(res));
|
pw_log_error("can't create port resource: %m");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -674,6 +676,7 @@ int pw_port_add(struct pw_port *port, struct pw_node *node)
|
||||||
struct pw_port *find;
|
struct pw_port *find;
|
||||||
bool control;
|
bool control;
|
||||||
const char *str, *dir;
|
const char *str, *dir;
|
||||||
|
int res;
|
||||||
|
|
||||||
if (port->node != NULL)
|
if (port->node != NULL)
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
|
@ -690,6 +693,9 @@ int pw_port_add(struct pw_port *port, struct pw_node *node)
|
||||||
if (find != NULL)
|
if (find != NULL)
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
|
||||||
|
if ((res = pw_map_insert_at(portmap, port_id, port)) < 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
port->node = node;
|
port->node = node;
|
||||||
|
|
||||||
pw_node_emit_port_init(node, port);
|
pw_node_emit_port_init(node, port);
|
||||||
|
|
@ -734,7 +740,6 @@ int pw_port_add(struct pw_port *port, struct pw_node *node)
|
||||||
pw_log_debug("port %p: %d add to node %p", port, port_id, node);
|
pw_log_debug("port %p: %d add to node %p", port, port_id, node);
|
||||||
|
|
||||||
spa_list_append(ports, &port->link);
|
spa_list_append(ports, &port->link);
|
||||||
pw_map_insert_at(portmap, port_id, port);
|
|
||||||
|
|
||||||
if (port->direction == PW_DIRECTION_INPUT) {
|
if (port->direction == PW_DIRECTION_INPUT) {
|
||||||
node->info.n_input_ports++;
|
node->info.n_input_ports++;
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ static int add_func(struct pw_properties *this, char *key, char *value)
|
||||||
struct properties *impl = SPA_CONTAINER_OF(this, struct properties, this);
|
struct properties *impl = SPA_CONTAINER_OF(this, struct properties, this);
|
||||||
|
|
||||||
item = pw_array_add(&impl->items, sizeof(struct spa_dict_item));
|
item = pw_array_add(&impl->items, sizeof(struct spa_dict_item));
|
||||||
|
if (item == NULL)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
item->key = key;
|
item->key = key;
|
||||||
item->value = value;
|
item->value = value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ struct pw_proxy *pw_proxy_new(struct pw_proxy *factory,
|
||||||
struct proxy *impl;
|
struct proxy *impl;
|
||||||
struct pw_proxy *this;
|
struct pw_proxy *this;
|
||||||
struct pw_remote *remote = factory->remote;
|
struct pw_remote *remote = factory->remote;
|
||||||
|
int res;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct proxy) + user_data_size);
|
impl = calloc(1, sizeof(struct proxy) + user_data_size);
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
|
|
@ -68,16 +69,26 @@ struct pw_proxy *pw_proxy_new(struct pw_proxy *factory,
|
||||||
this = &impl->this;
|
this = &impl->this;
|
||||||
this->remote = remote;
|
this->remote = remote;
|
||||||
|
|
||||||
|
this->marshal = pw_protocol_get_marshal(remote->conn->protocol, type);
|
||||||
|
if (this->marshal == NULL) {
|
||||||
|
pw_log_error("proxy %p: no marshal for type %d", this, type);
|
||||||
|
res = -EPROTO;
|
||||||
|
goto error_clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->id = pw_map_insert_new(&remote->objects, this);
|
||||||
|
if (this->id == SPA_ID_INVALID) {
|
||||||
|
res = -errno;
|
||||||
|
pw_log_error("proxy %p: can't allocate new id: %m", this);
|
||||||
|
goto error_clean;
|
||||||
|
}
|
||||||
|
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
spa_hook_list_init(&this->object_listener_list);
|
spa_hook_list_init(&this->object_listener_list);
|
||||||
|
|
||||||
this->id = pw_map_insert_new(&remote->objects, this);
|
|
||||||
|
|
||||||
if (user_data_size > 0)
|
if (user_data_size > 0)
|
||||||
this->user_data = SPA_MEMBER(impl, sizeof(struct proxy), void);
|
this->user_data = SPA_MEMBER(impl, sizeof(struct proxy), void);
|
||||||
|
|
||||||
this->marshal = pw_protocol_get_marshal(remote->conn->protocol, type);
|
|
||||||
|
|
||||||
this->impl = SPA_INTERFACE_INIT(
|
this->impl = SPA_INTERFACE_INIT(
|
||||||
type,
|
type,
|
||||||
this->marshal->version,
|
this->marshal->version,
|
||||||
|
|
@ -91,6 +102,11 @@ struct pw_proxy *pw_proxy_new(struct pw_proxy *factory,
|
||||||
remote, this->marshal);
|
remote, this->marshal);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
error_clean:
|
||||||
|
free(impl);
|
||||||
|
errno = -res;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
|
|
@ -327,14 +327,14 @@ static int do_connect(struct pw_remote *remote)
|
||||||
PW_TYPE_INTERFACE_Core, 0);
|
PW_TYPE_INTERFACE_Core, 0);
|
||||||
if (remote->core_proxy == NULL) {
|
if (remote->core_proxy == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto no_proxy;
|
goto error_disconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
remote->client_proxy = (struct pw_client_proxy*)pw_proxy_new(&dummy,
|
remote->client_proxy = (struct pw_client_proxy*)pw_proxy_new(&dummy,
|
||||||
PW_TYPE_INTERFACE_Client, 0);
|
PW_TYPE_INTERFACE_Client, 0);
|
||||||
if (remote->client_proxy == NULL) {
|
if (remote->client_proxy == NULL) {
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto clean_core_proxy;
|
goto error_clean_core_proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_core_proxy_add_listener(remote->core_proxy, &impl->core_listener, &core_proxy_events, remote);
|
pw_core_proxy_add_listener(remote->core_proxy, &impl->core_listener, &core_proxy_events, remote);
|
||||||
|
|
@ -345,12 +345,12 @@ static int do_connect(struct pw_remote *remote)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
clean_core_proxy:
|
error_clean_core_proxy:
|
||||||
((struct pw_proxy*)remote->core_proxy)->removed = true;
|
((struct pw_proxy*)remote->core_proxy)->removed = true;
|
||||||
pw_proxy_destroy((struct pw_proxy*)remote->core_proxy);
|
pw_proxy_destroy((struct pw_proxy*)remote->core_proxy);
|
||||||
no_proxy:
|
error_disconnect:
|
||||||
pw_protocol_client_disconnect(remote->conn);
|
pw_protocol_client_disconnect(remote->conn);
|
||||||
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR, "can't connect: no memory");
|
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR, "can't connect: %s", spa_strerror(res));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -421,8 +421,8 @@ int pw_remote_steal_fd(struct pw_remote *remote)
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = pw_protocol_client_steal_fd(remote->conn);
|
fd = pw_protocol_client_steal_fd(remote->conn);
|
||||||
pw_remote_update_state(remote, PW_REMOTE_STATE_UNCONNECTED, NULL);
|
if (fd >= 0)
|
||||||
|
pw_remote_update_state(remote, PW_REMOTE_STATE_UNCONNECTED, NULL);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ struct pw_resource *pw_resource_new(struct pw_client *client,
|
||||||
{
|
{
|
||||||
struct impl *impl;
|
struct impl *impl;
|
||||||
struct pw_resource *this;
|
struct pw_resource *this;
|
||||||
|
int res;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
|
|
@ -63,18 +64,30 @@ struct pw_resource *pw_resource_new(struct pw_client *client,
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
spa_hook_list_init(&this->object_listener_list);
|
spa_hook_list_init(&this->object_listener_list);
|
||||||
|
|
||||||
|
this->marshal = pw_protocol_get_marshal(client->protocol, type);
|
||||||
|
if (this->marshal == NULL) {
|
||||||
|
pw_log_error("resource %p: no marshal for type %d", this, type);
|
||||||
|
res = -EPROTO;
|
||||||
|
goto error_clean;
|
||||||
|
}
|
||||||
|
|
||||||
if (id == SPA_ID_INVALID) {
|
if (id == SPA_ID_INVALID) {
|
||||||
id = pw_map_insert_new(&client->objects, this);
|
res = -EINVAL;
|
||||||
} else if (pw_map_insert_at(&client->objects, id, this) < 0)
|
goto error_clean;
|
||||||
goto in_use;
|
}
|
||||||
|
|
||||||
|
if ((res = pw_map_insert_at(&client->objects, id, this)) < 0) {
|
||||||
|
res = -errno;
|
||||||
|
pw_log_error("resource %p: can't add id %u for client %p: %m",
|
||||||
|
this, id, client);
|
||||||
|
goto error_clean;
|
||||||
|
}
|
||||||
|
|
||||||
this->id = id;
|
this->id = id;
|
||||||
|
|
||||||
if (user_data_size > 0)
|
if (user_data_size > 0)
|
||||||
this->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
|
this->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
|
||||||
|
|
||||||
this->marshal = pw_protocol_get_marshal(client->protocol, type);
|
|
||||||
|
|
||||||
this->impl = SPA_INTERFACE_INIT(
|
this->impl = SPA_INTERFACE_INIT(
|
||||||
type,
|
type,
|
||||||
this->marshal->version,
|
this->marshal->version,
|
||||||
|
|
@ -88,10 +101,9 @@ struct pw_resource *pw_resource_new(struct pw_client *client,
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
in_use:
|
error_clean:
|
||||||
pw_log_debug("resource %p: id %u in use for client %p", this, id, client);
|
|
||||||
free(impl);
|
free(impl);
|
||||||
errno = -EEXIST;
|
errno = -res;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue