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 <stddef.h>
#include <unistd.h>
#include <string.h>
@ -137,8 +138,8 @@ 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(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
@ -148,7 +149,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,
@ -156,14 +157,14 @@ static int impl_node_enum_params(struct spa_node *node,
}
else if (id == t->param.idProps) {
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
param = spa_pod_builder_object(builder,
id, t->props,
":", t->prop_live, "b", this->props.live);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
(*index)++;
@ -171,7 +172,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,
@ -180,7 +181,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;
@ -188,7 +189,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
if (id == t->param.idProps) {
if (param == NULL) {
reset_props(this, &this->props);
return SPA_RESULT_OK;
return 0;
}
spa_pod_object_parse(param,
":", t->prop_live, "?b", &this->props.live, NULL);
@ -199,9 +200,9 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE;
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static void set_timer(struct impl *this, bool enabled)
@ -247,13 +248,13 @@ static int consume_buffer(struct impl *this)
read_timer(this);
if (spa_list_is_empty(&this->ready)) {
io->status = SPA_RESULT_NEED_BUFFER;
io->status = SPA_STATUS_NEED_BUFFER;
if (this->callbacks->need_input)
this->callbacks->need_input(this->callbacks_data);
}
if (spa_list_is_empty(&this->ready)) {
spa_log_error(this->log, NAME " %p: no buffers", this);
return SPA_RESULT_NEED_BUFFER;
return -EPIPE;
}
b = spa_list_first(&this->ready, struct buffer, link);
@ -280,10 +281,10 @@ static int consume_buffer(struct impl *this)
set_timer(this, true);
io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_NEED_BUFFER;
io->status = SPA_STATUS_NEED_BUFFER;
b->outstanding = true;
return SPA_RESULT_NEED_BUFFER;
return SPA_STATUS_NEED_BUFFER;
}
static void on_input(struct spa_source *source)
@ -297,8 +298,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
{
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);
@ -306,13 +307,12 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
struct timespec now;
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (this->n_buffers == 0)
return SPA_RESULT_NO_BUFFERS;
return -EIO;
if (this->started)
return SPA_RESULT_OK;
return 0;
clock_gettime(CLOCK_MONOTONIC, &now);
if (this->props.live)
@ -326,20 +326,19 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
set_timer(this, true);
} 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;
if (!this->started)
return SPA_RESULT_OK;
return 0;
this->started = false;
set_timer(this, false);
} else
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
return SPA_RESULT_OK;
return 0;
}
static int
@ -349,18 +348,18 @@ 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);
if (this->data_loop == NULL && callbacks != NULL && callbacks->need_input != NULL) {
spa_log_error(this->log, "a data_loop is needed for async operation");
return SPA_RESULT_ERROR;
return -EINVAL;
}
this->callbacks = callbacks;
this->callbacks_data = data;
return SPA_RESULT_OK;
return 0;
}
static int
@ -370,7 +369,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;
@ -381,7 +380,7 @@ impl_node_get_n_ports(struct spa_node *node,
if (max_output_ports)
*max_output_ports = 0;
return SPA_RESULT_OK;
return 0;
}
static int
@ -391,23 +390,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_input_ports > 0 && input_ids != NULL)
input_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
@ -418,16 +417,16 @@ impl_node_port_get_info(struct spa_node *node,
{
struct impl *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 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);
*info = &this->info;
return SPA_RESULT_OK;
return 0;
}
static int port_enum_formats(struct spa_node *node,
@ -437,7 +436,7 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder,
struct spa_pod **param)
{
return SPA_RESULT_ENUM_END;
return 0;
}
static int port_get_format(struct spa_node *node,
@ -450,14 +449,14 @@ static int port_get_format(struct spa_node *node,
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
*param = SPA_MEMBER(this->format_buffer, 0, struct spa_pod);
return SPA_RESULT_OK;
return 1;
}
static int
@ -473,14 +472,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);
offset = builder->offset;
@ -495,19 +494,19 @@ 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 (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
param = spa_pod_builder_object(builder,
id, t->param_buffers.Buffers,
@ -526,11 +525,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)++;
@ -538,7 +537,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)
@ -550,7 +549,7 @@ static int clear_buffers(struct impl *this)
this->started = false;
set_timer(this, false);
}
return SPA_RESULT_OK;
return 0;
}
static int port_set_format(struct spa_node *node,
@ -565,11 +564,11 @@ static int port_set_format(struct spa_node *node,
clear_buffers(this);
} else {
if (SPA_POD_SIZE(format) > sizeof(this->format_buffer))
return SPA_RESULT_ERROR;
return -ENOSPC;
memcpy(this->format_buffer, format, SPA_POD_SIZE(format));
this->have_format = true;
}
return SPA_RESULT_OK;
return 0;
}
static int
@ -581,18 +580,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
@ -605,14 +604,14 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
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);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
clear_buffers(this);
@ -634,7 +633,7 @@ impl_node_port_use_buffers(struct spa_node *node,
}
this->n_buffers = n_buffers;
return SPA_RESULT_OK;
return 0;
}
static int
@ -648,16 +647,16 @@ impl_node_port_alloc_buffers(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);
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;
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -668,20 +667,20 @@ impl_node_port_set_io(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);
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)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -690,7 +689,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 int impl_node_process_input(struct spa_node *node)
@ -698,20 +697,20 @@ static int impl_node_process_input(struct spa_node *node)
struct impl *this;
struct spa_port_io *input;
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);
input = this->io;
spa_return_val_if_fail(input != NULL, SPA_RESULT_UNEXPECTED);
spa_return_val_if_fail(input != NULL, -EIO);
if (input->status == SPA_RESULT_HAVE_BUFFER && input->buffer_id < this->n_buffers) {
if (input->status == SPA_STATUS_HAVE_BUFFER && input->buffer_id < this->n_buffers) {
struct buffer *b = &this->buffers[input->buffer_id];
if (!b->outstanding) {
spa_log_warn(this->log, NAME " %p: buffer %u in use", this,
input->buffer_id);
input->status = SPA_RESULT_INVALID_BUFFER_ID;
return SPA_RESULT_ERROR;
input->status = -EINVAL;
return -EINVAL;
}
spa_log_trace(this->log, NAME " %p: queue buffer %u", this, input->buffer_id);
@ -720,17 +719,17 @@ static int impl_node_process_input(struct spa_node *node)
b->outstanding = false;
input->buffer_id = SPA_ID_INVALID;
input->status = SPA_RESULT_OK;
input->status = SPA_STATUS_OK;
}
if (this->callbacks == NULL || this->callbacks->need_input == NULL)
return consume_buffer(this);
else
return SPA_RESULT_OK;
return SPA_STATUS_OK;
}
static int impl_node_process_output(struct spa_node *node)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static const struct spa_node impl_node = {
@ -759,13 +758,13 @@ 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
@ -777,7 +776,7 @@ impl_clock_get_time(struct spa_clock *clock,
struct timespec now;
uint64_t tnow;
spa_return_val_if_fail(clock != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(clock != NULL, -EINVAL);
if (rate)
*rate = SPA_NSEC_PER_SEC;
@ -790,7 +789,7 @@ impl_clock_get_time(struct spa_clock *clock,
if (monotonic_time)
*monotonic_time = tnow;
return SPA_RESULT_OK;
return 0;
}
static const struct spa_clock impl_clock = {
@ -806,8 +805,8 @@ 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;
@ -816,16 +815,16 @@ 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)
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
this = (struct impl *) handle;
@ -833,7 +832,7 @@ static int impl_clear(struct spa_handle *handle)
spa_loop_remove_source(this->data_loop, &this->timer_source);
close(this->timer_source.fd);
return SPA_RESULT_OK;
return 0;
}
static int
@ -846,8 +845,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;
@ -864,7 +863,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);
@ -893,7 +892,7 @@ impl_init(const struct spa_handle_factory *factory,
spa_log_info(this->log, NAME " %p: initialized", this);
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -904,19 +903,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_fakesink_factory = {

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
@ -143,9 +144,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;
@ -155,7 +156,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,
@ -165,7 +166,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,
@ -174,7 +175,7 @@ static int impl_node_enum_params(struct spa_node *node,
1, p->pattern);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
(*index)++;
@ -182,7 +183,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,
@ -191,7 +192,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;
@ -201,7 +202,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
if (param == NULL) {
reset_props(this, p);
return SPA_RESULT_OK;
return 0;
}
spa_pod_object_parse(param,
":", t->prop_live, "?b", &p->live,
@ -213,14 +214,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE;
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
return SPA_RESULT_OK;
return 0;
}
static int fill_buffer(struct impl *this, struct buffer *b)
{
return SPA_RESULT_OK;
return 0;
}
static void set_timer(struct impl *this, bool enabled)
@ -265,7 +266,7 @@ static int make_buffer(struct impl *this)
set_timer(this, false);
this->underrun = true;
spa_log_error(this->log, NAME " %p: out of buffers", this);
return SPA_RESULT_OUT_OF_BUFFERS;
return -EPIPE;
}
b = spa_list_first(&this->empty, struct buffer, link);
spa_list_remove(&b->link);
@ -292,9 +293,9 @@ static int make_buffer(struct impl *this)
set_timer(this, true);
io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_HAVE_BUFFER;
io->status = SPA_STATUS_HAVE_BUFFER;
return SPA_RESULT_HAVE_BUFFER;
return SPA_STATUS_HAVE_BUFFER;
}
static void on_output(struct spa_source *source)
@ -304,7 +305,7 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
if (res == SPA_RESULT_HAVE_BUFFER && this->callbacks && this->callbacks->have_output)
if (res == SPA_STATUS_HAVE_BUFFER && this->callbacks && this->callbacks->have_output)
this->callbacks->have_output(this->callbacks_data);
}
@ -312,8 +313,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
{
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);
@ -321,13 +322,13 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
struct timespec now;
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (this->n_buffers == 0)
return SPA_RESULT_NO_BUFFERS;
return -EIO;
if (this->started)
return SPA_RESULT_OK;
return 0;
clock_gettime(CLOCK_MONOTONIC, &now);
if (this->props.live)
@ -341,20 +342,19 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
set_timer(this, true);
} 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;
if (!this->started)
return SPA_RESULT_OK;
return 0;
this->started = false;
set_timer(this, false);
} else
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
return SPA_RESULT_OK;
return 0;
}
static int
@ -364,18 +364,18 @@ 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);
if (this->data_loop == NULL && (callbacks != NULL && callbacks->have_output != NULL)) {
spa_log_error(this->log, "a data_loop is needed for async operation");
return SPA_RESULT_ERROR;
return -EINVAL;
}
this->callbacks = callbacks;
this->callbacks_data = data;
return SPA_RESULT_OK;
return 0;
}
static int
@ -385,7 +385,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;
@ -396,7 +396,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
@ -406,23 +406,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
@ -433,16 +433,16 @@ impl_node_port_get_info(struct spa_node *node,
{
struct impl *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 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);
*info = &this->info;
return SPA_RESULT_OK;
return 0;
}
static int port_enum_formats(struct spa_node *node,
@ -452,7 +452,7 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder,
struct spa_pod **param)
{
return SPA_RESULT_ENUM_END;
return 0;
}
static int port_get_format(struct spa_node *node,
@ -465,13 +465,13 @@ static int port_get_format(struct spa_node *node,
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
*param = SPA_MEMBER(this->format_buffer, 0, struct spa_pod);
return SPA_RESULT_OK;
return 1;
}
static int
@ -487,14 +487,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);
offset = builder->offset;
@ -509,19 +509,19 @@ 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 (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
param = spa_pod_builder_object(builder,
id, t->param_buffers.Buffers,
@ -540,11 +540,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)++;
@ -552,7 +552,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)
@ -564,7 +564,7 @@ static int clear_buffers(struct impl *this)
this->started = false;
set_timer(this, false);
}
return SPA_RESULT_OK;
return 0;
}
static int port_set_format(struct spa_node *node,
@ -579,11 +579,11 @@ static int port_set_format(struct spa_node *node,
clear_buffers(this);
} else {
if (SPA_POD_SIZE(format) > sizeof(this->format_buffer))
return SPA_RESULT_ERROR;
return -ENOSPC;
memcpy(this->format_buffer, format, SPA_POD_SIZE(format));
this->have_format = true;
}
return SPA_RESULT_OK;
return 0;
}
static int
@ -595,18 +595,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
@ -619,14 +619,14 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
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);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
clear_buffers(this);
@ -650,7 +650,7 @@ impl_node_port_use_buffers(struct spa_node *node,
this->n_buffers = n_buffers;
this->underrun = false;
return SPA_RESULT_OK;
return 0;
}
static int
@ -664,16 +664,16 @@ impl_node_port_alloc_buffers(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);
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;
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -684,15 +684,15 @@ impl_node_port_set_io(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);
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 inline void reuse_buffer(struct impl *this, uint32_t id)
@ -715,17 +715,16 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id,
{
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);
spa_return_val_if_fail(port_id == 0, SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail(this->n_buffers > 0, SPA_RESULT_NO_BUFFERS);
spa_return_val_if_fail(buffer_id < this->n_buffers, SPA_RESULT_INVALID_BUFFER_ID);
spa_return_val_if_fail(port_id == 0, -EINVAL);
spa_return_val_if_fail(buffer_id < this->n_buffers, -EINVAL);
reuse_buffer(this, buffer_id);
return SPA_RESULT_OK;
return 0;
}
static int
@ -734,12 +733,12 @@ 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 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)
@ -747,14 +746,14 @@ static int impl_node_process_output(struct spa_node *node)
struct impl *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 impl, 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) {
reuse_buffer(this, this->io->buffer_id);
@ -762,10 +761,10 @@ static int impl_node_process_output(struct spa_node *node)
}
if ((this->callbacks == NULL || this->callbacks->have_output == NULL) &&
(io->status == SPA_RESULT_NEED_BUFFER))
(io->status == SPA_STATUS_NEED_BUFFER))
return make_buffer(this);
else
return SPA_RESULT_OK;
return SPA_STATUS_OK;
}
static const struct spa_node impl_node = {
@ -794,13 +793,13 @@ 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
@ -812,7 +811,7 @@ impl_clock_get_time(struct spa_clock *clock,
struct timespec now;
uint64_t tnow;
spa_return_val_if_fail(clock != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(clock != NULL, -EINVAL);
if (rate)
*rate = SPA_NSEC_PER_SEC;
@ -825,7 +824,7 @@ impl_clock_get_time(struct spa_clock *clock,
if (monotonic_time)
*monotonic_time = tnow;
return SPA_RESULT_OK;
return 0;
}
static const struct spa_clock impl_clock = {
@ -841,8 +840,8 @@ 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;
@ -851,16 +850,16 @@ 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)
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(handle != NULL, -EINVAL);
this = (struct impl *) handle;
@ -868,7 +867,7 @@ static int impl_clear(struct spa_handle *handle)
spa_loop_remove_source(this->data_loop, &this->timer_source);
close(this->timer_source.fd);
return SPA_RESULT_OK;
return 0;
}
static int
@ -881,8 +880,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;
@ -899,7 +898,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);
@ -928,7 +927,7 @@ impl_init(const struct spa_handle_factory *factory,
spa_log_info(this->log, NAME " %p: initialized", this);
return SPA_RESULT_OK;
return 0;
}
static const struct spa_interface_info impl_interfaces[] = {
@ -939,19 +938,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_fakesrc_factory = {

View file

@ -17,17 +17,20 @@
* Boston, MA 02110-1301, USA.
*/
#include <errno.h>
#include <spa/support/plugin.h>
extern const struct spa_handle_factory spa_fakesrc_factory;
extern const struct spa_handle_factory spa_fakesink_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index)
{
spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL, -EINVAL);
spa_return_val_if_fail(index != NULL, -EINVAL);
switch (index) {
switch (*index) {
case 0:
*factory = &spa_fakesrc_factory;
break;
@ -35,7 +38,8 @@ spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t inde
*factory = &spa_fakesink_factory;
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
return SPA_RESULT_OK;
(*index)++;
return 1;
}