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

@ -187,20 +187,20 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
return SPA_RESULT_ERROR;
return -errno;
}
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
printf("can't find enum function\n");
return SPA_RESULT_ERROR;
return -errno;
}
for (i = 0;; i++) {
for (i = 0;;) {
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
if ((res = enum_func(&factory, &i)) <= 0) {
if (res != 0)
printf("can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, name))
@ -218,9 +218,9 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
return res;
}
*node = iface;
return SPA_RESULT_OK;
return 0;
}
return SPA_RESULT_ERROR;
return -EBADF;
}
static void on_sink_done(void *data, int seq, int res)
@ -263,12 +263,12 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source)
data->n_sources++;
data->rebuild_fds = true;
return SPA_RESULT_OK;
return 0;
}
static int do_update_source(struct spa_source *source)
{
return SPA_RESULT_OK;
return 0;
}
static void do_remove_source(struct spa_source *source)
@ -392,8 +392,8 @@ static int negotiate_formats(struct data *data)
if ((res = spa_node_port_enum_params(data->sink,
SPA_DIRECTION_INPUT, 0,
data->type.param.idEnumFormat, &state,
filter, &b)) < 0)
return res;
filter, &b)) <= 0)
return -EBADF;
format = spa_pod_builder_deref(&b, ref);
spa_debug_pod(&format->pod, 0);
@ -439,7 +439,7 @@ static int negotiate_formats(struct data *data)
1)) < 0)
return res;
return SPA_RESULT_OK;
return 0;
}
static void *loop(void *user_data)

View file

@ -198,20 +198,20 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
return SPA_RESULT_ERROR;
return -errno;
}
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
printf("can't find enum function\n");
return SPA_RESULT_ERROR;
return -errno;
}
for (i = 0;; i++) {
for (i = 0;;) {
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
if ((res = enum_func(&factory, &i)) <= 0) {
if (res != 0)
printf("can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, name))
@ -229,9 +229,9 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
return res;
}
*node = iface;
return SPA_RESULT_OK;
return 0;
}
return SPA_RESULT_ERROR;
return -EBADF;
}
static void on_sink_done(void *data, int seq, int res)
@ -253,26 +253,26 @@ static void on_sink_need_input(void *_data)
int res;
res = spa_node_process_output(data->mix);
if (res == SPA_RESULT_NEED_BUFFER) {
if (data->source1_mix_io[0].status == SPA_RESULT_NEED_BUFFER) {
if (res == SPA_STATUS_NEED_BUFFER) {
if (data->source1_mix_io[0].status == SPA_STATUS_NEED_BUFFER) {
res = spa_node_process_output(data->source1);
if (res != SPA_RESULT_HAVE_BUFFER)
if (res != SPA_STATUS_HAVE_BUFFER)
printf("got process_output error from source1 %d\n", res);
}
if (data->source2_mix_io[0].status == SPA_RESULT_NEED_BUFFER) {
if (data->source2_mix_io[0].status == SPA_STATUS_NEED_BUFFER) {
res = spa_node_process_output(data->source2);
if (res != SPA_RESULT_HAVE_BUFFER)
if (res != SPA_STATUS_HAVE_BUFFER)
printf("got process_output error from source2 %d\n", res);
}
res = spa_node_process_input(data->mix);
if (res == SPA_RESULT_HAVE_BUFFER)
if (res == SPA_STATUS_HAVE_BUFFER)
goto push;
else
printf("got process_input error from mixer %d\n", res);
} else if (res == SPA_RESULT_HAVE_BUFFER) {
} else if (res == SPA_STATUS_HAVE_BUFFER) {
push:
if ((res = spa_node_process_input(data->sink)) < 0)
printf("got process_input error from sink %d\n", res);
@ -307,12 +307,12 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source)
data->n_sources++;
data->rebuild_fds = true;
return SPA_RESULT_OK;
return 0;
}
static int do_update_source(struct spa_source *source)
{
return SPA_RESULT_OK;
return 0;
}
static void do_remove_source(struct spa_source *source)
@ -474,8 +474,8 @@ static int negotiate_formats(struct data *data)
spa_node_port_enum_params(data->sink,
SPA_DIRECTION_INPUT, 0,
data->type.param.idEnumFormat, &state,
filter, &b)) < 0)
return res;
filter, &b)) <= 0)
return -EBADF;
format = spa_pod_builder_deref(&b, ref);
@ -547,7 +547,7 @@ static int negotiate_formats(struct data *data)
data->source2_buffers, 2)) < 0)
return res;
return SPA_RESULT_OK;
return 0;
}
static void *loop(void *user_data)

View file

@ -183,21 +183,21 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
if (data->hnd == NULL) {
if ((data->hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
return SPA_RESULT_ERROR;
return -errno;
}
}
if ((enum_func = dlsym(data->hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
printf("can't find enum function\n");
return SPA_RESULT_ERROR;
return -errno;
}
for (i = 0;; i++) {
for (i = 0;;) {
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
if ((res = enum_func(&factory, &i)) <= 0) {
if (res != 0)
printf("can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, name))
@ -215,15 +215,15 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
return res;
}
*node = iface;
return SPA_RESULT_OK;
return 0;
}
return SPA_RESULT_ERROR;
return -EBADF;
}
static void on_sink_pull(struct data *data)
{
spa_log_trace(data->log, "do sink pull");
data->sink_node.state = SPA_RESULT_NEED_BUFFER;
data->sink_node.state = SPA_STATUS_NEED_BUFFER;
if (data->mode & MODE_DIRECT) {
spa_node_process_output(data->source);
spa_node_process_input(data->sink);
@ -317,12 +317,12 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source)
data->n_sources++;
data->rebuild_fds = true;
return SPA_RESULT_OK;
return 0;
}
static int do_update_source(struct spa_source *source)
{
return SPA_RESULT_OK;
return 0;
}
static void do_remove_source(struct spa_source *source)
@ -359,7 +359,7 @@ static int make_nodes(struct data *data)
spa_node_set_callbacks(data->source, &source_callbacks, data);
data->source_sink_io[0] = SPA_PORT_IO_INIT;
data->source_sink_io[0].status = SPA_RESULT_NEED_BUFFER;
data->source_sink_io[0].status = SPA_STATUS_NEED_BUFFER;
spa_node_port_set_io(data->source, SPA_DIRECTION_OUTPUT, 0, &data->source_sink_io[0]);
spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, &data->source_sink_io[0]);
@ -421,7 +421,7 @@ static int negotiate_formats(struct data *data)
1)) < 0)
return res;
return SPA_RESULT_OK;
return 0;
}
static void *loop(void *user_data)

View file

@ -171,20 +171,20 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
return SPA_RESULT_ERROR;
return -errno;
}
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
printf("can't find enum function\n");
return SPA_RESULT_ERROR;
return -errno;
}
for (i = 0;; i++) {
for (i = 0;;) {
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
if ((res = enum_func(&factory, &i)) <= 0) {
if (res != 0)
printf("can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, name))
@ -202,9 +202,9 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
return res;
}
*node = iface;
return SPA_RESULT_OK;
return 0;
}
return SPA_RESULT_ERROR;
return -EBADF;
}
static void on_sink_done(void *data, int seq, int res)
@ -223,7 +223,7 @@ static void on_sink_need_input(void *_data)
int res;
res = spa_node_process_output(data->source);
if (res != SPA_RESULT_HAVE_BUFFER)
if (res != SPA_STATUS_HAVE_BUFFER)
printf("got process_output error from source %d\n", res);
if ((res = spa_node_process_input(data->sink)) < 0)
@ -255,12 +255,12 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source)
data->n_sources++;
data->rebuild_fds = true;
return SPA_RESULT_OK;
return 0;
}
static int do_update_source(struct spa_source *source)
{
return SPA_RESULT_OK;
return 0;
}
static void do_remove_source(struct spa_source *source)
@ -338,8 +338,8 @@ static int negotiate_formats(struct data *data)
if ((res = spa_node_port_enum_params(data->sink,
SPA_DIRECTION_INPUT, 0,
data->type.param.idEnumFormat, &state,
filter, &b)) < 0)
return res;
filter, &b)) <= 0)
return -EBADF;
format = spa_pod_builder_deref(&b, ref);
@ -370,7 +370,7 @@ static int negotiate_formats(struct data *data)
1)) < 0)
return res;
return SPA_RESULT_OK;
return 0;
}
static void *loop(void *user_data)

View file

@ -132,20 +132,20 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
return SPA_RESULT_ERROR;
return -errno;
}
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
printf("can't find enum function\n");
return SPA_RESULT_ERROR;
return -errno;
}
for (i = 0;; i++) {
for (i = 0;;) {
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
if ((res = enum_func(&factory, &i)) <= 0) {
if (res != 0)
printf("can't enumerate factories: %s\n", spa_strerror(res));
break;
}
if (strcmp(factory->name, name))
@ -163,9 +163,9 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
return res;
}
*node = iface;
return SPA_RESULT_OK;
return 0;
}
return SPA_RESULT_ERROR;
return -EBADF;
}
static void handle_events(struct data *data)
@ -258,7 +258,7 @@ static void on_source_have_output(void *_data)
SDL_RenderPresent(data->renderer);
}
io->status = SPA_RESULT_NEED_BUFFER;
io->status = SPA_STATUS_NEED_BUFFER;
if ((res = spa_node_process_output(data->source)) < 0)
printf("got pull error %d\n", res);
@ -279,12 +279,12 @@ static int do_add_source(struct spa_loop *loop, struct spa_source *source)
data->n_sources++;
data->rebuild_fds = true;
return SPA_RESULT_OK;
return 0;
}
static int do_update_source(struct spa_source *source)
{
return SPA_RESULT_OK;
return 0;
}
static void do_remove_source(struct spa_source *source)
@ -342,11 +342,11 @@ static int alloc_buffers(struct data *data)
SDL_TEXTUREACCESS_STREAMING, 320, 240);
if (!texture) {
printf("can't create texture: %s\n", SDL_GetError());
return SPA_RESULT_ERROR;
return -ENOMEM;
}
if (SDL_LockTexture(texture, NULL, &ptr, &stride) < 0) {
fprintf(stderr, "Couldn't lock texture: %s\n", SDL_GetError());
return SPA_RESULT_ERROR;
return -EIO;
}
b->buffer.id = i;
@ -404,8 +404,8 @@ static int negotiate_formats(struct data *data)
#if 0
void *state = NULL;
if ((res = spa_node_port_enum_formats(data->source, 0, &format, NULL, &state)) < 0)
return res;
if ((res = spa_node_port_enum_formats(data->source, 0, &format, NULL, &state)) <= 0)
return -EBADF;
#else
format = spa_pod_builder_object(&b,
@ -448,7 +448,7 @@ static int negotiate_formats(struct data *data)
}
data->n_buffers = n_buffers;
}
return SPA_RESULT_OK;
return 0;
}
static void *loop(void *user_data)