Use errno for result errors

Make new enumeration for data transport status and use errno
style error numbers for errors.
This commit is contained in:
Wim Taymans 2017-11-13 09:41:41 +01:00
parent dda28b1589
commit 6fb0f580ea
86 changed files with 2019 additions and 1988 deletions

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <errno.h>
#include <string.h>
#include <stddef.h>
@ -147,9 +148,9 @@ static int impl_node_enum_params(struct spa_node *node,
uint32_t offset;
struct spa_pod *param;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
@ -159,7 +160,7 @@ static int impl_node_enum_params(struct spa_node *node,
next:
if (id == t->param.idList) {
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
param = spa_pod_builder_object(builder,
id, t->param.List,
@ -169,7 +170,7 @@ static int impl_node_enum_params(struct spa_node *node,
struct props *p = &this->props;
if(*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
param = spa_pod_builder_object(builder,
id, t->props,
@ -177,7 +178,7 @@ static int impl_node_enum_params(struct spa_node *node,
":", t->prop_mute, "b", p->mute);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
(*index)++;
@ -185,7 +186,7 @@ static int impl_node_enum_params(struct spa_node *node,
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
goto next;
return SPA_RESULT_OK;
return 1;
}
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
@ -194,7 +195,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
@ -204,24 +205,24 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
if (param == NULL) {
reset_props(p);
return SPA_RESULT_OK;
return 0;
}
spa_pod_object_parse(param,
":", t->prop_volume, "?d", &p->volume,
":", t->prop_mute, "?b", &p->mute, NULL);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
{
struct impl *this;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(command != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -230,9 +231,9 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
this->started = false;
} else
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
return SPA_RESULT_OK;
return 0;
}
static int
@ -242,14 +243,14 @@ impl_node_set_callbacks(struct spa_node *node,
{
struct impl *this;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->callbacks_data = data;
return SPA_RESULT_OK;
return 0;
}
static int
@ -259,7 +260,7 @@ impl_node_get_n_ports(struct spa_node *node,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
if (n_input_ports)
*n_input_ports = 1;
@ -270,7 +271,7 @@ impl_node_get_n_ports(struct spa_node *node,
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
return 0;
}
static int
@ -280,26 +281,26 @@ impl_node_get_port_ids(struct spa_node *node,
uint32_t n_output_ports,
uint32_t *output_ids)
{
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
if (n_input_ports > 0 && input_ids)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids)
output_ids[0] = 0;
return SPA_RESULT_OK;
return 0;
}
static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -311,17 +312,17 @@ impl_node_port_get_info(struct spa_node *node,
struct impl *this;
struct port *port;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(info != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
*info = &port->info;
return SPA_RESULT_OK;
return 0;
}
static int port_enum_formats(struct spa_node *node,
@ -347,9 +348,9 @@ static int port_enum_formats(struct spa_node *node,
":", t->format_audio.channels,"iru", 2, 2, 1, INT32_MAX);
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
return SPA_RESULT_OK;
return 1;
}
static int port_get_format(struct spa_node *node,
@ -366,9 +367,9 @@ static int port_get_format(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
@ -378,7 +379,7 @@ static int port_get_format(struct spa_node *node,
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
return SPA_RESULT_OK;
return 1;
}
static int
@ -395,14 +396,14 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod *param;
int res;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
@ -419,21 +420,21 @@ impl_node_port_enum_params(struct spa_node *node,
param = spa_pod_builder_object(builder, id, t->param.List,
":", t->param.listId, "I", list[*index]);
else
return SPA_RESULT_ENUM_END;
return 0;
}
else if (id == t->param.idEnumFormat) {
if ((res = port_enum_formats(node, direction, port_id, index, filter, builder, &param)) < 0)
if ((res = port_enum_formats(node, direction, port_id, index, filter, builder, &param)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
if ((res = port_get_format(node, direction, port_id, index, filter, builder, &param)) < 0)
if ((res = port_get_format(node, direction, port_id, index, filter, builder, &param)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
param = spa_pod_builder_object(builder,
id, t->param_buffers.Buffers,
@ -454,11 +455,11 @@ impl_node_port_enum_params(struct spa_node *node,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
(*index)++;
@ -466,7 +467,7 @@ impl_node_port_enum_params(struct spa_node *node,
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
goto next;
return SPA_RESULT_OK;
return 1;
}
static int clear_buffers(struct impl *this, struct port *port)
@ -476,7 +477,7 @@ static int clear_buffers(struct impl *this, struct port *port)
port->n_buffers = 0;
spa_list_init(&port->empty);
}
return SPA_RESULT_OK;
return 0;
}
static int port_set_format(struct spa_node *node,
@ -501,17 +502,17 @@ static int port_set_format(struct spa_node *node,
if (info.media_type != this->type.media_type.audio ||
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &this->type.format_audio) < 0)
return SPA_RESULT_INVALID_MEDIA_TYPE;
return -EINVAL;
this->bpf = 2 * info.info.raw.channels;
this->current_format = info;
port->have_format = true;
}
return SPA_RESULT_OK;
return 0;
}
static int
@ -523,18 +524,18 @@ impl_node_port_set_param(struct spa_node *node,
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
return port_set_format(node, direction, port_id, flags, param);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
}
static int
@ -548,16 +549,16 @@ impl_node_port_use_buffers(struct spa_node *node,
struct port *port;
uint32_t i;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
clear_buffers(this, port);
@ -578,14 +579,14 @@ impl_node_port_use_buffers(struct spa_node *node,
} else {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
buffers[i]);
return SPA_RESULT_ERROR;
return -EINVAL;
}
if (!b->outstanding)
spa_list_append(&port->empty, &b->link);
}
port->n_buffers = n_buffers;
return SPA_RESULT_OK;
return 0;
}
static int
@ -597,7 +598,7 @@ impl_node_port_alloc_buffers(struct spa_node *node,
struct spa_buffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -609,16 +610,16 @@ impl_node_port_set_io(struct spa_node *node,
struct impl *this;
struct port *port;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
port->io = io;
return SPA_RESULT_OK;
return 0;
}
static void recycle_buffer(struct impl *this, uint32_t id)
@ -641,24 +642,21 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id,
struct impl *this;
struct port *port;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id),
SPA_RESULT_INVALID_PORT);
-EINVAL);
port = GET_OUT_PORT(this, port_id);
if (port->n_buffers == 0)
return SPA_RESULT_NO_BUFFERS;
if (buffer_id >= port->n_buffers)
return SPA_RESULT_INVALID_BUFFER_ID;
return -EINVAL;
recycle_buffer(this, buffer_id);
return SPA_RESULT_OK;
return 0;
}
static int
@ -667,7 +665,7 @@ impl_node_port_send_command(struct spa_node *node,
uint32_t port_id,
const struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static struct spa_buffer *find_free_buffer(struct impl *this, struct port *port)
@ -737,40 +735,40 @@ static int impl_node_process_input(struct spa_node *node)
struct port *in_port, *out_port;
struct spa_buffer *dbuf, *sbuf;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
out_port = GET_OUT_PORT(this, 0);
output = out_port->io;
spa_return_val_if_fail(output != NULL, SPA_RESULT_ERROR);
spa_return_val_if_fail(output != NULL, -EIO);
if (output->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER;
if (output->status == SPA_STATUS_HAVE_BUFFER)
return SPA_STATUS_HAVE_BUFFER;
in_port = GET_IN_PORT(this, 0);
input = in_port->io;
spa_return_val_if_fail(input != NULL, SPA_RESULT_ERROR);
spa_return_val_if_fail(input != NULL, -EIO);
if (input->buffer_id >= in_port->n_buffers)
return SPA_RESULT_NEED_BUFFER;
return SPA_STATUS_NEED_BUFFER;
if ((dbuf = find_free_buffer(this, out_port)) == NULL) {
spa_log_error(this->log, NAME " %p: out of buffers", this);
return SPA_RESULT_OUT_OF_BUFFERS;
return -EPIPE;
}
sbuf = in_port->buffers[input->buffer_id].outbuf;
input->status = SPA_RESULT_OK;
input->status = SPA_STATUS_OK;
spa_log_trace(this->log, NAME " %p: do volume %d -> %d", this, sbuf->id, dbuf->id);
do_volume(this, dbuf, sbuf);
output->buffer_id = dbuf->id;
output->status = SPA_RESULT_HAVE_BUFFER;
output->status = SPA_STATUS_HAVE_BUFFER;
return SPA_RESULT_HAVE_BUFFER;
return SPA_STATUS_HAVE_BUFFER;
}
static int impl_node_process_output(struct spa_node *node)
@ -779,16 +777,16 @@ static int impl_node_process_output(struct spa_node *node)
struct port *in_port, *out_port;
struct spa_port_io *input, *output;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
out_port = GET_OUT_PORT(this, 0);
output = out_port->io;
spa_return_val_if_fail(output != NULL, SPA_RESULT_ERROR);
spa_return_val_if_fail(output != NULL, -EIO);
if (output->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER;
if (output->status == SPA_STATUS_HAVE_BUFFER)
return SPA_STATUS_HAVE_BUFFER;
/* recycle */
if (output->buffer_id < out_port->n_buffers) {
@ -798,12 +796,12 @@ static int impl_node_process_output(struct spa_node *node)
in_port = GET_IN_PORT(this, 0);
input = in_port->io;
spa_return_val_if_fail(input != NULL, SPA_RESULT_ERROR);
spa_return_val_if_fail(input != NULL, -EIO);
input->range = output->range;
input->status = SPA_RESULT_NEED_BUFFER;
input->status = SPA_STATUS_NEED_BUFFER;
return SPA_RESULT_NEED_BUFFER;
return SPA_STATUS_NEED_BUFFER;
}
static const struct spa_node impl_node = {
@ -833,22 +831,22 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
spa_return_val_if_fail(interface != NULL, -EINVAL);
this = (struct impl *) handle;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int impl_clear(struct spa_handle *handle)
{
return SPA_RESULT_OK;
return 0;
}
static int
@ -861,8 +859,8 @@ impl_init(const struct spa_handle_factory *factory,
struct impl *this;
uint32_t i;
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(handle != NULL, -EINVAL);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear;
@ -877,7 +875,7 @@ impl_init(const struct spa_handle_factory *factory,
}
if (this->map == NULL) {
spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
return -EINVAL;
}
init_type(&this->type, this->map);
@ -892,7 +890,7 @@ impl_init(const struct spa_handle_factory *factory,
SPA_PORT_INFO_FLAG_NO_REF;
spa_list_init(&this->out_ports[0].empty);
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -902,19 +900,21 @@ static const struct spa_interface_info impl_interfaces[] = {
static int
impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
uint32_t *index)
{
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(info != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
switch (index) {
switch (*index) {
case 0:
*info = &impl_interfaces[index];
*info = &impl_interfaces[*index];
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
return SPA_RESULT_OK;
(*index)++;
return 1;
}
const struct spa_handle_factory spa_volume_factory = {