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 <sys/types.h>
#include <sys/stat.h>
@ -92,13 +93,13 @@ static int spa_ffmpeg_enc_node_enum_params(struct spa_node *node,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int spa_ffmpeg_enc_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int spa_ffmpeg_enc_node_send_command(struct spa_node *node, const struct spa_command *command)
@ -106,7 +107,7 @@ static int spa_ffmpeg_enc_node_send_command(struct spa_node *node, const struct
struct impl *this;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
this = SPA_CONTAINER_OF(node, struct impl, node);
@ -115,9 +116,9 @@ static int spa_ffmpeg_enc_node_send_command(struct spa_node *node, const struct
} 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
@ -128,14 +129,14 @@ spa_ffmpeg_enc_node_set_callbacks(struct spa_node *node,
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
return 0;
}
static int
@ -146,7 +147,7 @@ spa_ffmpeg_enc_node_get_n_ports(struct spa_node *node,
uint32_t *max_output_ports)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
if (n_input_ports)
*n_input_ports = 1;
@ -157,7 +158,7 @@ spa_ffmpeg_enc_node_get_n_ports(struct spa_node *node,
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
return 0;
}
static int
@ -168,28 +169,28 @@ spa_ffmpeg_enc_node_get_port_ids(struct spa_node *node,
uint32_t *output_ids)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
return SPA_RESULT_OK;
return 0;
}
static int
spa_ffmpeg_enc_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
spa_ffmpeg_enc_node_remove_port(struct spa_node *node,
enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -201,18 +202,18 @@ spa_ffmpeg_enc_node_port_get_info(struct spa_node *node,
struct port *port;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
return -EINVAL;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info;
return SPA_RESULT_OK;
return 0;
}
static int port_enum_formats(struct spa_node *node,
@ -232,9 +233,9 @@ static int port_enum_formats(struct spa_node *node,
*param = NULL;
break;
default:
return SPA_RESULT_ENUM_END;
return 0;
}
return SPA_RESULT_OK;
return 1;
}
static int port_get_format(struct spa_node *node,
@ -251,14 +252,14 @@ static int port_get_format(struct spa_node *node,
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
return -EIO;
if (*index > 0)
return SPA_RESULT_ENUM_END;
return 0;
*param = NULL;
return SPA_RESULT_OK;
return 1;
}
static int
@ -285,18 +286,18 @@ spa_ffmpeg_enc_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
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
(*index)++;
@ -304,7 +305,7 @@ spa_ffmpeg_enc_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 port_set_format(struct spa_node *node,
@ -319,7 +320,7 @@ static int port_set_format(struct spa_node *node,
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
return 0;
} else {
struct spa_video_info info = { 0 };
@ -329,17 +330,17 @@ static int port_set_format(struct spa_node *node,
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
return -EINVAL;
if (spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video) < 0)
return SPA_RESULT_INVALID_MEDIA_TYPE;
return -EINVAL;
if (!(flags & SPA_NODE_PARAM_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
return 0;
}
static int
@ -355,7 +356,7 @@ spa_ffmpeg_enc_node_port_set_param(struct spa_node *node,
return port_set_format(node, direction, port_id, flags, param);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return -ENOENT;
}
static int
@ -365,12 +366,12 @@ spa_ffmpeg_enc_node_port_use_buffers(struct spa_node *node,
struct spa_buffer **buffers, uint32_t n_buffers)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
if (!IS_VALID_PORT(node, direction, port_id))
return SPA_RESULT_INVALID_PORT;
return -EINVAL;
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -382,7 +383,7 @@ spa_ffmpeg_enc_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
@ -394,30 +395,30 @@ spa_ffmpeg_enc_node_port_set_io(struct spa_node *node,
struct port *port;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
return -EINVAL;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io;
return SPA_RESULT_OK;
return 0;
}
static int
spa_ffmpeg_enc_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
return -EINVAL;
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int
@ -425,12 +426,12 @@ spa_ffmpeg_enc_node_port_send_command(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, const struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
return -ENOTSUP;
}
static int spa_ffmpeg_enc_node_process_input(struct spa_node *node)
{
return SPA_RESULT_INVALID_PORT;
return -EINVAL;
}
static int spa_ffmpeg_enc_node_process_output(struct spa_node *node)
@ -440,22 +441,22 @@ static int spa_ffmpeg_enc_node_process_output(struct spa_node *node)
struct spa_port_io *output;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -EINVAL;
this = SPA_CONTAINER_OF(node, struct impl, node);
if ((output = this->out_ports[0].io) == NULL)
return SPA_RESULT_OK;
return -EIO;
port = &this->out_ports[0];
if (!port->have_format) {
output->status = SPA_RESULT_NO_FORMAT;
return SPA_RESULT_ERROR;
output->status = -EIO;
return -EIO;
}
output->status = SPA_RESULT_OK;
output->status = SPA_STATUS_OK;
return SPA_RESULT_OK;
return SPA_STATUS_OK;
}
static const struct spa_node ffmpeg_enc_node = {
@ -487,16 +488,16 @@ spa_ffmpeg_enc_get_interface(struct spa_handle *handle, uint32_t interface_id, v
struct impl *this;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
return -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;
}
int
@ -519,7 +520,7 @@ spa_ffmpeg_enc_init(struct spa_handle *handle,
}
if (this->map == NULL) {
spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
return -EINVAL;
}
this->node = ffmpeg_enc_node;
@ -527,5 +528,5 @@ spa_ffmpeg_enc_init(struct spa_handle *handle,
this->in_ports[0].info.flags = 0;
this->out_ports[0].info.flags = 0;
return SPA_RESULT_OK;
return 0;
}