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

@ -52,9 +52,9 @@ static int impl_node_enum_params(struct spa_node *node,
struct spa_pod *param;
uint32_t offset;
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 state, node);
t = &this->type;
@ -64,7 +64,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,
@ -74,7 +74,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,
@ -85,7 +85,7 @@ static int impl_node_enum_params(struct spa_node *node,
2, 1, INT32_MAX);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
(*index)++;
@ -93,7 +93,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,
@ -102,7 +102,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
struct state *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 state, node);
t = &this->type;
@ -112,16 +112,16 @@ 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_device, "?S", p->device, sizeof(p->device),
":", t->prop_min_latency, "?i", &p->min_latency, NULL);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int do_send_done(struct spa_loop *loop, bool async, uint32_t seq, size_t size, const void *data, void *user_data)
@ -130,7 +130,7 @@ static int do_send_done(struct spa_loop *loop, bool async, uint32_t seq, size_t
this->callbacks->done(this->callbacks_data, seq, *(int*)data);
return SPA_RESULT_OK;
return 0;
}
static int do_start(struct spa_loop *loop, bool async, uint32_t seq, size_t size, const void *data, void *user_data)
@ -175,31 +175,29 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
{
struct state *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 state, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (this->n_buffers == 0)
return SPA_RESULT_NO_BUFFERS;
return -EIO;
return spa_loop_invoke(this->data_loop, do_start, ++this->seq, 0, NULL, false, this);
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (this->n_buffers == 0)
return SPA_RESULT_NO_BUFFERS;
return -EIO;
return spa_loop_invoke(this->data_loop, do_pause, ++this->seq, 0, NULL, false, this);
} else
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
return SPA_RESULT_OK;
return 0;
}
static int
@ -209,14 +207,14 @@ impl_node_set_callbacks(struct spa_node *node,
{
struct state *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 state, node);
this->callbacks = callbacks;
this->callbacks_data = data;
return SPA_RESULT_OK;
return 0;
}
static int
@ -226,7 +224,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 = 0;
@ -237,7 +235,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
@ -247,23 +245,23 @@ 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_output_ports > 0 && output_ids != NULL)
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
@ -272,16 +270,16 @@ impl_node_port_get_info(struct spa_node *node,
{
struct state *this;
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 state, 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);
*info = &this->info;
return SPA_RESULT_OK;
return 0;
}
static void recycle_buffer(struct state *this, uint32_t buffer_id)
@ -307,9 +305,9 @@ static int port_get_format(struct spa_node *node,
struct type *t = &this->type;
if (!this->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,
@ -319,7 +317,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
@ -335,14 +333,14 @@ impl_node_port_enum_params(struct spa_node *node,
uint32_t offset;
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 state, 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);
offset = builder->offset;
@ -357,20 +355,20 @@ 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) {
return spa_alsa_enum_format(this, index, filter, builder);
}
else if (id == t->param.idFormat) {
if ((res = port_get_format(node, direction, port_id, index, &param, builder)) < 0)
if ((res = port_get_format(node, direction, port_id, index, &param, builder)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
if (!this->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,
@ -382,7 +380,7 @@ impl_node_port_enum_params(struct spa_node *node,
}
else if (id == t->param.idMeta) {
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
switch (*index) {
case 0:
@ -392,11 +390,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)++;
@ -404,7 +402,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 state *this)
@ -414,7 +412,7 @@ static int clear_buffers(struct state *this)
spa_list_init(&this->ready);
this->n_buffers = 0;
}
return SPA_RESULT_OK;
return 0;
}
static int port_set_format(struct spa_node *node,
@ -438,10 +436,10 @@ 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;
if ((err = spa_alsa_set_format(this, &info, flags)) < 0)
return err;
@ -455,7 +453,7 @@ static int port_set_format(struct spa_node *node,
this->info.rate = this->rate;
}
return SPA_RESULT_OK;
return 0;
}
static int
@ -467,18 +465,18 @@ impl_node_port_set_param(struct spa_node *node,
struct state *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 state, 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
@ -490,14 +488,14 @@ impl_node_port_use_buffers(struct spa_node *node,
int res;
int 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 state, 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);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (this->n_buffers > 0) {
spa_alsa_pause(this, false);
@ -517,13 +515,13 @@ impl_node_port_use_buffers(struct spa_node *node,
d[0].type == this->type.data.DmaBuf ||
d[0].type == this->type.data.MemPtr) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: need mapped memory", this);
return SPA_RESULT_ERROR;
return -EINVAL;
}
spa_list_append(&this->free, &b->link);
}
this->n_buffers = n_buffers;
return SPA_RESULT_OK;
return 0;
}
@ -538,17 +536,17 @@ impl_node_port_alloc_buffers(struct spa_node *node,
{
struct state *this;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(buffers != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(buffers != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, 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);
if (this->n_buffers == 0)
return SPA_RESULT_NO_FORMAT;
return -EIO;
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -556,36 +554,36 @@ impl_node_port_set_io(struct spa_node *node, enum spa_direction direction, uint3
{
struct state *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 state, 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);
this->io = io;
return SPA_RESULT_OK;
return 0;
}
static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
{
struct state *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 state, node);
spa_return_val_if_fail(port_id == 0, SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(port_id == 0, -EINVAL);
if (this->n_buffers == 0)
return SPA_RESULT_NO_BUFFERS;
return -EIO;
if (buffer_id >= this->n_buffers)
return SPA_RESULT_INVALID_BUFFER_ID;
return -EINVAL;
recycle_buffer(this, buffer_id);
return SPA_RESULT_OK;
return 0;
}
static int
@ -595,25 +593,25 @@ impl_node_port_send_command(struct spa_node *node,
struct state *this;
int res;
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 state, 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);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
res = spa_alsa_pause(this, false);
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
res = spa_alsa_start(this, false);
} else
res = SPA_RESULT_NOT_IMPLEMENTED;
res = -ENOTSUP;
return res;
}
static int impl_node_process_input(struct spa_node *node)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int impl_node_process_output(struct spa_node *node)
@ -621,20 +619,20 @@ static int impl_node_process_output(struct spa_node *node)
struct state *this;
struct spa_port_io *io;
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 state, node);
io = this->io;
spa_return_val_if_fail(io != NULL, SPA_RESULT_UNEXPECTED);
spa_return_val_if_fail(io != NULL, -EIO);
if (io->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER;
if (io->status == SPA_STATUS_HAVE_BUFFER)
return SPA_STATUS_HAVE_BUFFER;
if (io->buffer_id < this->n_buffers) {
recycle_buffer(this, io->buffer_id);
io->buffer_id = SPA_ID_INVALID;
}
return SPA_RESULT_OK;
return 0;
}
static const struct spa_dict_item node_info_items[] = {
@ -672,14 +670,14 @@ static const struct spa_node impl_node = {
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod_builder *builder)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock,
uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int impl_clock_get_time(struct spa_clock *clock,
@ -689,7 +687,7 @@ static int impl_clock_get_time(struct spa_clock *clock,
{
struct state *this;
spa_return_val_if_fail(clock != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(clock != NULL, -EINVAL);
this = SPA_CONTAINER_OF(clock, struct state, clock);
@ -700,7 +698,7 @@ static int impl_clock_get_time(struct spa_clock *clock,
if (monotonic_time)
*monotonic_time = this->last_monotonic;
return SPA_RESULT_OK;
return 0;
}
static const struct spa_clock impl_clock = {
@ -716,8 +714,8 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
{
struct state *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 state *) handle;
@ -726,14 +724,14 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
else if (interface_id == this->type.clock)
*interface = &this->clock;
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
@ -746,8 +744,8 @@ impl_init(const struct spa_handle_factory *factory,
struct state *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;
@ -766,15 +764,15 @@ impl_init(const struct spa_handle_factory *factory,
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
return -EINVAL;
}
if (this->data_loop == NULL) {
spa_log_error(this->log, "a data loop is needed");
return SPA_RESULT_ERROR;
return -EINVAL;
}
if (this->main_loop == NULL) {
spa_log_error(this->log, "a main loop is needed");
return SPA_RESULT_ERROR;
return -EINVAL;
}
init_type(&this->type, this->map);
@ -791,7 +789,7 @@ impl_init(const struct spa_handle_factory *factory,
snprintf(this->props.device, 63, "%s", info->items[i].value);
}
}
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -802,17 +800,18 @@ 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);
if (index >= SPA_N_ELEMENTS(impl_interfaces))
return SPA_RESULT_ENUM_END;
if (*index >= SPA_N_ELEMENTS(impl_interfaces))
return 0;
*info = &impl_interfaces[index];
*info = &impl_interfaces[(*index)++];
return SPA_RESULT_OK;
return 1;
}
static const struct spa_dict_item info_items[] = {