indent -kr -i8 -l100

This commit is contained in:
Wim Taymans 2017-05-25 16:23:13 +02:00
parent 11f23a3ffa
commit d1a06ae247
28 changed files with 7034 additions and 10381 deletions

View file

@ -66,18 +66,17 @@ struct type {
struct spa_type_data data; struct spa_type_data data;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->node = spa_type_map_get_id (map, SPA_TYPE__Node); type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
type->format = spa_type_map_get_id (map, SPA_TYPE__Format); type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
spa_type_media_type_map (map, &type->media_type); spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype); spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map (map, &type->format_audio); spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map (map, &type->audio_format); spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map (map, &type->command_node); spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map (map, &type->meta); spa_type_meta_map(map, &type->meta);
spa_type_data_map (map, &type->data); spa_type_data_map(map, &type->data);
} }
struct impl { struct impl {
@ -123,54 +122,46 @@ struct impl {
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \ SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__) SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
static int static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
impl_node_get_props (struct spa_node *node,
struct spa_props **props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int impl_node_set_props(struct spa_node *node, const struct spa_props *props)
impl_node_set_props (struct spa_node *node,
const struct spa_props *props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int impl_node_send_command(struct spa_node *node, struct spa_command *command)
impl_node_send_command (struct spa_node *node,
struct spa_command *command)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) { if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
this->started = true; this->started = true;
} } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
this->started = false; this->started = false;
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_set_callbacks (struct spa_node *node, impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, const struct spa_node_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size,
void *user_data) void *user_data)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks; this->callbacks = *callbacks;
this->user_data = user_data; this->user_data = user_data;
@ -179,13 +170,13 @@ impl_node_set_callbacks (struct spa_node *node,
} }
static int static int
impl_node_get_n_ports (struct spa_node *node, impl_node_get_n_ports(struct spa_node *node,
uint32_t *n_input_ports, uint32_t *n_input_ports,
uint32_t *max_input_ports, uint32_t *max_input_ports,
uint32_t *n_output_ports, uint32_t *n_output_ports,
uint32_t *max_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, SPA_RESULT_INVALID_ARGUMENTS);
if (n_input_ports) if (n_input_ports)
*n_input_ports = 0; *n_input_ports = 0;
@ -200,7 +191,7 @@ impl_node_get_n_ports (struct spa_node *node,
} }
static int static int
impl_node_get_port_ids (struct spa_node *node, impl_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports, uint32_t n_input_ports,
uint32_t *input_ids, uint32_t *input_ids,
uint32_t n_output_ports, uint32_t n_output_ports,
@ -209,9 +200,9 @@ impl_node_get_port_ids (struct spa_node *node,
struct impl *this; struct impl *this;
int i, idx; int i, idx;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (input_ids) { if (input_ids) {
for (i = 0, idx = 0; i < MAX_PORTS && idx < n_input_ports; i++) { for (i = 0, idx = 0; i < MAX_PORTS && idx < n_input_ports; i++) {
@ -225,42 +216,37 @@ impl_node_get_port_ids (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
impl_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail (CHECK_FREE_IN_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT); spa_return_val_if_fail(CHECK_FREE_IN_PORT(this, direction, port_id),
SPA_RESULT_INVALID_PORT);
this->port_count++; this->port_count++;
spa_list_init (&this->in_ports[port_id].queue); spa_list_init(&this->in_ports[port_id].queue);
this->in_ports[port_id].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | this->in_ports[port_id].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
SPA_PORT_INFO_FLAG_REMOVABLE | SPA_PORT_INFO_FLAG_REMOVABLE |
SPA_PORT_INFO_FLAG_OPTIONAL | SPA_PORT_INFO_FLAG_OPTIONAL | SPA_PORT_INFO_FLAG_IN_PLACE;
SPA_PORT_INFO_FLAG_IN_PLACE;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_remove_port (struct spa_node *node, impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction,
uint32_t port_id)
{ {
struct impl *this; struct impl *this;
struct spa_port_io *io; struct spa_port_io *io;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail (CHECK_IN_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT); spa_return_val_if_fail(CHECK_IN_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
io = this->in_ports[port_id].io; io = this->in_ports[port_id].io;
if (io && io->buffer_id) if (io && io->buffer_id)
@ -274,7 +260,7 @@ impl_node_remove_port (struct spa_node *node,
static int static int
impl_node_port_enum_formats (struct spa_node *node, impl_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_format **format, struct spa_format **format,
@ -289,54 +275,59 @@ impl_node_port_enum_formats (struct spa_node *node,
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
uint32_t count, match; uint32_t count, match;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
count = match = filter ? 0 : index; count = match = filter ? 0 : index;
next: next:
spa_pod_builder_init (&b, buffer, sizeof (buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (count++) { switch (count++) {
case 0: case 0:
spa_pod_builder_format (&b, &f[0], this->type.format, spa_pod_builder_format(&b, &f[0], this->type.format,
this->type.media_type.audio, this->type.media_subtype.raw, this->type.media_type.audio,
PROP (&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID, this->type.audio_format.S16), this->type.media_subtype.raw,
PROP_U_MM (&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX), PROP(&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID,
PROP_U_MM (&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX)); this->type.audio_format.S16),
PROP_U_MM(&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT,
44100,
1, INT32_MAX),
PROP_U_MM(&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT,
2,
1, INT32_MAX));
break; break;
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
fmt = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_format); fmt = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer)); spa_pod_builder_init(&b, this->format_buffer, sizeof(this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index) if ((res = spa_format_filter(fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next; goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, struct spa_format); *format = SPA_POD_BUILDER_DEREF(&b, 0, struct spa_format);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int clear_buffers(struct impl *this, struct port *port)
clear_buffers (struct impl *this, struct port *port)
{ {
if (port->n_buffers > 0) { if (port->n_buffers > 0) {
spa_log_info (this->log, "audio-mixer %p: clear buffers %p", this, port); spa_log_info(this->log, NAME " %p: clear buffers %p", this, port);
port->n_buffers = 0; port->n_buffers = 0;
spa_list_init (&port->queue); spa_list_init(&port->queue);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_format (struct spa_node *node, impl_node_port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t flags, uint32_t flags,
@ -345,26 +336,27 @@ impl_node_port_set_format (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
if (format == NULL) { if (format == NULL) {
port->have_format = false; port->have_format = false;
clear_buffers (this, port); clear_buffers(this, port);
} else { } else {
struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE (format), struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE (format), }; SPA_FORMAT_MEDIA_SUBTYPE(format),
};
if (info.media_type != this->type.media_type.audio || if (info.media_type != this->type.media_type.audio ||
info.media_subtype != this->type.media_subtype.raw) info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio)) if (!spa_format_audio_raw_parse(format, &info.info.raw, &this->type.format_audio))
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
this->format = info; this->format = info;
@ -375,7 +367,7 @@ impl_node_port_set_format (struct spa_node *node,
} }
static int static int
impl_node_port_get_format (struct spa_node *node, impl_node_port_get_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_format **format) const struct spa_format **format)
@ -385,31 +377,35 @@ impl_node_port_get_format (struct spa_node *node,
struct spa_pod_builder b = { NULL, }; struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
if (!port->have_format) if (!port->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer)); spa_pod_builder_init(&b, this->format_buffer, sizeof(this->format_buffer));
spa_pod_builder_format (&b, &f[0], this->type.format, spa_pod_builder_format(&b, &f[0], this->type.format,
this->type.media_type.audio, this->type.media_subtype.raw, this->type.media_type.audio,
PROP (&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID, this->format.info.raw.format), this->type.media_subtype.raw,
PROP (&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT, this->format.info.raw.rate), PROP(&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID,
PROP (&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT, this->format.info.raw.channels)); this->format.info.raw.format),
*format = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_format); PROP(&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT,
this->format.info.raw.rate),
PROP(&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT,
this->format.info.raw.channels));
*format = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_get_info (struct spa_node *node, impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_port_info **info) const struct spa_port_info **info)
@ -417,12 +413,12 @@ impl_node_port_get_info (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
*info = &port->info; *info = &port->info;
@ -431,7 +427,7 @@ impl_node_port_get_info (struct spa_node *node,
} }
static int static int
impl_node_port_enum_params (struct spa_node *node, impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t index, uint32_t index,
@ -441,7 +437,7 @@ impl_node_port_enum_params (struct spa_node *node,
} }
static int static int
impl_node_port_set_param (struct spa_node *node, impl_node_port_set_param(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_param *param) const struct spa_param *param)
@ -450,7 +446,7 @@ impl_node_port_set_param (struct spa_node *node,
} }
static int static int
impl_node_port_use_buffers (struct spa_node *node, impl_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_buffer **buffers, struct spa_buffer **buffers,
@ -460,17 +456,18 @@ impl_node_port_use_buffers (struct spa_node *node,
struct port *port; struct port *port;
uint32_t i; uint32_t i;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
spa_return_val_if_fail (port->have_format, SPA_RESULT_NO_FORMAT); spa_return_val_if_fail(port->have_format, SPA_RESULT_NO_FORMAT);
clear_buffers (this, port); clear_buffers(this, port);
for (i = 0; i < n_buffers; i++) { for (i = 0; i < n_buffers; i++) {
struct buffer *b; struct buffer *b;
@ -479,17 +476,17 @@ impl_node_port_use_buffers (struct spa_node *node,
b = &port->buffers[i]; b = &port->buffers[i];
b->outbuf = buffers[i]; b->outbuf = buffers[i];
b->outstanding = direction == SPA_DIRECTION_INPUT ? true : false; b->outstanding = direction == SPA_DIRECTION_INPUT ? true : false;
b->h = spa_buffer_find_meta (buffers[i], this->type.meta.Header); b->h = spa_buffer_find_meta(buffers[i], this->type.meta.Header);
if (!((d[0].type == this->type.data.MemPtr || if (!((d[0].type == this->type.data.MemPtr ||
d[0].type == this->type.data.MemFd || d[0].type == this->type.data.MemFd ||
d[0].type == this->type.data.DmaBuf) && d[0].type == this->type.data.DmaBuf) && d[0].data != NULL)) {
d[0].data != NULL)) { spa_log_error(this->log, "volume %p: invalid memory on buffer %p", this,
spa_log_error (this->log, "volume %p: invalid memory on buffer %p", this, buffers[i]); buffers[i]);
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
if (!b->outstanding) if (!b->outstanding)
spa_list_insert (port->queue.prev, &b->link); spa_list_insert(port->queue.prev, &b->link);
} }
port->n_buffers = n_buffers; port->n_buffers = n_buffers;
@ -497,19 +494,19 @@ impl_node_port_use_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_alloc_buffers (struct spa_node *node, impl_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_param **params, struct spa_param **params,
uint32_t n_params, uint32_t n_params,
struct spa_buffer **buffers, struct spa_buffer **buffers,
uint32_t *n_buffers) uint32_t * n_buffers)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_port_set_io (struct spa_node *node, impl_node_port_set_io(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_port_io *io) struct spa_port_io *io)
@ -517,54 +514,52 @@ impl_node_port_set_io (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT_NUM (this, direction, port_id), SPA_RESULT_INVALID_PORT); spa_return_val_if_fail(CHECK_PORT_NUM(this, direction, port_id), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io; port->io = io;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static void static void recycle_buffer(struct impl *this, uint32_t id)
recycle_buffer (struct impl *this, uint32_t id)
{ {
struct port *port = &this->out_ports[0]; struct port *port = &this->out_ports[0];
struct buffer *b = &port->buffers[id]; struct buffer *b = &port->buffers[id];
if (!b->outstanding) { if (!b->outstanding) {
spa_log_warn (this->log, NAME "%p: buffer %d not outstanding", this, id); spa_log_warn(this->log, NAME "%p: buffer %d not outstanding", this, id);
return; return;
} }
spa_list_insert (port->queue.prev, &b->link); spa_list_insert(port->queue.prev, &b->link);
b->outstanding = false; b->outstanding = false;
spa_log_trace (this->log, NAME " %p: recycle buffer %d", this, id); spa_log_trace(this->log, NAME " %p: recycle buffer %d", this, id);
} }
static int static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id),
SPA_RESULT_INVALID_PORT);
recycle_buffer (this, buffer_id); recycle_buffer(this, buffer_id);
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_port_send_command (struct spa_node *node, impl_node_port_send_command(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_command *command) struct spa_command *command)
@ -573,30 +568,29 @@ impl_node_port_send_command (struct spa_node *node,
} }
static inline void static inline void
add_port_data (struct impl *this, void *out, size_t outsize, struct port *port, int layer) add_port_data(struct impl *this, void *out, size_t outsize, struct port *port, int layer)
{ {
void *in; void *in;
size_t insize; size_t insize;
struct buffer *b; struct buffer *b;
struct spa_data *id; struct spa_data *id;
b = spa_list_first (&port->queue, struct buffer, link); b = spa_list_first(&port->queue, struct buffer, link);
id = b->outbuf->datas; id = b->outbuf->datas;
in = SPA_MEMBER (id[0].data, port->queued_offset + id[0].chunk->offset, void); in = SPA_MEMBER(id[0].data, port->queued_offset + id[0].chunk->offset, void);
insize = id[0].chunk->size - port->queued_offset; insize = id[0].chunk->size - port->queued_offset;
outsize = SPA_MIN (outsize, insize); outsize = SPA_MIN(outsize, insize);
{ {
int i, size = outsize / 2; int i, size = outsize / 2;
int16_t *op = out, *ip = in; int16_t *op = out, *ip = in;
if (layer == 0) { if (layer == 0) {
memcpy (op, ip, outsize); memcpy(op, ip, outsize);
} } else {
else {
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
op[i] = SPA_CLAMP (op[i] + ip[i], INT16_MIN, INT16_MAX); op[i] = SPA_CLAMP(op[i] + ip[i], INT16_MIN, INT16_MAX);
} }
} }
@ -604,20 +598,19 @@ add_port_data (struct impl *this, void *out, size_t outsize, struct port *port,
port->queued_bytes -= outsize; port->queued_bytes -= outsize;
if (outsize == insize) { if (outsize == insize) {
spa_log_trace (this->log, NAME " %p: return buffer %d on port %p %zd", spa_log_trace(this->log, NAME " %p: return buffer %d on port %p %zd",
this, b->outbuf->id, port, outsize); this, b->outbuf->id, port, outsize);
port->io->buffer_id = b->outbuf->id; port->io->buffer_id = b->outbuf->id;
spa_list_remove (&b->link); spa_list_remove(&b->link);
b->outstanding = true; b->outstanding = true;
port->queued_offset = 0; port->queued_offset = 0;
} else { } else {
spa_log_trace (this->log, NAME " %p: keeping buffer %d on port %p %zd %zd", spa_log_trace(this->log, NAME " %p: keeping buffer %d on port %p %zd %zd",
this, b->outbuf->id, port, port->queued_bytes, outsize); this, b->outbuf->id, port, port->queued_bytes, outsize);
} }
} }
static int static int mix_output(struct impl *this, size_t n_bytes)
mix_output (struct impl *this, size_t n_bytes)
{ {
struct buffer *outbuf; struct buffer *outbuf;
int i, layer; int i, layer;
@ -628,20 +621,20 @@ mix_output (struct impl *this, size_t n_bytes)
outport = &this->out_ports[0]; outport = &this->out_ports[0];
output = outport->io; output = outport->io;
if (spa_list_is_empty (&outport->queue)) if (spa_list_is_empty(&outport->queue))
return SPA_RESULT_OUT_OF_BUFFERS; return SPA_RESULT_OUT_OF_BUFFERS;
outbuf = spa_list_first (&outport->queue, struct buffer, link); outbuf = spa_list_first(&outport->queue, struct buffer, link);
spa_list_remove (&outbuf->link); spa_list_remove(&outbuf->link);
outbuf->outstanding = true; outbuf->outstanding = true;
od = outbuf->outbuf->datas; od = outbuf->outbuf->datas;
n_bytes = SPA_MIN (n_bytes, od[0].maxsize); n_bytes = SPA_MIN(n_bytes, od[0].maxsize);
od[0].chunk->offset = 0; od[0].chunk->offset = 0;
od[0].chunk->size = n_bytes; od[0].chunk->size = n_bytes;
od[0].chunk->stride = 0; od[0].chunk->stride = 0;
spa_log_trace (this->log, NAME " %p: dequeue output buffer %d %zd", spa_log_trace(this->log, NAME " %p: dequeue output buffer %d %zd",
this, outbuf->outbuf->id, n_bytes); this, outbuf->outbuf->id, n_bytes);
for (layer = 0, i = 0; i < MAX_PORTS; i++) { for (layer = 0, i = 0; i < MAX_PORTS; i++) {
struct port *port = &this->in_ports[i]; struct port *port = &this->in_ports[i];
@ -649,13 +642,13 @@ mix_output (struct impl *this, size_t n_bytes)
if (port->io == NULL || port->n_buffers == 0) if (port->io == NULL || port->n_buffers == 0)
continue; continue;
if (spa_list_is_empty (&port->queue)) { if (spa_list_is_empty(&port->queue)) {
spa_log_warn (this->log, NAME " %p: underrun stream %d", this, i); spa_log_warn(this->log, NAME " %p: underrun stream %d", this, i);
port->queued_bytes = 0; port->queued_bytes = 0;
port->queued_offset = 0; port->queued_offset = 0;
continue; continue;
} }
add_port_data (this, od[0].data, n_bytes, port, layer++); add_port_data(this, od[0].data, n_bytes, port, layer++);
} }
output->buffer_id = outbuf->outbuf->id; output->buffer_id = outbuf->outbuf->id;
output->status = SPA_RESULT_HAVE_BUFFER; output->status = SPA_RESULT_HAVE_BUFFER;
@ -663,8 +656,7 @@ mix_output (struct impl *this, size_t n_bytes)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
} }
static int static int impl_node_process_input(struct spa_node *node)
impl_node_process_input (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
@ -672,13 +664,13 @@ impl_node_process_input (struct spa_node *node)
size_t min_queued = SIZE_MAX; size_t min_queued = SIZE_MAX;
struct spa_port_io *output; struct spa_port_io *output;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
outport = &this->out_ports[0]; outport = &this->out_ports[0];
output = outport->io; output = outport->io;
spa_return_val_if_fail (output != NULL, SPA_RESULT_ERROR); spa_return_val_if_fail(output != NULL, SPA_RESULT_ERROR);
if (output->status == SPA_RESULT_HAVE_BUFFER) if (output->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
@ -691,12 +683,12 @@ impl_node_process_input (struct spa_node *node)
continue; continue;
if (port->queued_bytes == 0 && if (port->queued_bytes == 0 &&
input->status == SPA_RESULT_HAVE_BUFFER && input->status == SPA_RESULT_HAVE_BUFFER && input->buffer_id != SPA_ID_INVALID) {
input->buffer_id != SPA_ID_INVALID) {
struct buffer *b = &port->buffers[input->buffer_id]; struct buffer *b = &port->buffers[input->buffer_id];
if (!b->outstanding) { if (!b->outstanding) {
spa_log_warn (this->log, NAME " %p: buffer %u in use", this, input->buffer_id); spa_log_warn(this->log, NAME " %p: buffer %u in use", this,
input->buffer_id);
input->status = SPA_RESULT_INVALID_BUFFER_ID; input->status = SPA_RESULT_INVALID_BUFFER_ID;
continue; continue;
} }
@ -705,10 +697,10 @@ impl_node_process_input (struct spa_node *node)
input->buffer_id = SPA_ID_INVALID; input->buffer_id = SPA_ID_INVALID;
input->status = SPA_RESULT_OK; input->status = SPA_RESULT_OK;
spa_list_insert (port->queue.prev, &b->link); spa_list_insert(port->queue.prev, &b->link);
port->queued_bytes += b->outbuf->datas[0].chunk->size; port->queued_bytes += b->outbuf->datas[0].chunk->size;
spa_log_trace (this->log, NAME " %p: queue buffer %d on port %d %zd %zd", spa_log_trace(this->log, NAME " %p: queue buffer %d on port %d %zd %zd",
this, b->outbuf->id, i, port->queued_bytes, min_queued); this, b->outbuf->id, i, port->queued_bytes, min_queued);
} }
if (port->queued_bytes > 0 && port->queued_bytes < min_queued) if (port->queued_bytes > 0 && port->queued_bytes < min_queued)
@ -716,15 +708,14 @@ impl_node_process_input (struct spa_node *node)
} }
if (min_queued != SIZE_MAX && min_queued > 0) { if (min_queued != SIZE_MAX && min_queued > 0) {
output->status = mix_output (this, min_queued); output->status = mix_output(this, min_queued);
} else { } else {
output->status = SPA_RESULT_NEED_BUFFER; output->status = SPA_RESULT_NEED_BUFFER;
} }
return output->status; return output->status;
} }
static int static int impl_node_process_output(struct spa_node *node)
impl_node_process_output (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -732,20 +723,20 @@ impl_node_process_output (struct spa_node *node)
int i; int i;
size_t min_queued = SIZE_MAX; size_t min_queued = SIZE_MAX;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
port = &this->out_ports[0]; port = &this->out_ports[0];
output = port->io; output = port->io;
spa_return_val_if_fail (output != NULL, SPA_RESULT_ERROR); spa_return_val_if_fail(output != NULL, SPA_RESULT_ERROR);
if (output->status == SPA_RESULT_HAVE_BUFFER) if (output->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
/* recycle */ /* recycle */
if (output->buffer_id != SPA_ID_INVALID) { if (output->buffer_id != SPA_ID_INVALID) {
recycle_buffer (this, output->buffer_id); recycle_buffer(this, output->buffer_id);
output->buffer_id = SPA_ID_INVALID; output->buffer_id = SPA_ID_INVALID;
} }
/* produce more output if possible */ /* produce more output if possible */
@ -759,9 +750,8 @@ impl_node_process_output (struct spa_node *node)
min_queued = port->queued_bytes; min_queued = port->queued_bytes;
} }
if (min_queued != SIZE_MAX && min_queued > 0) { if (min_queued != SIZE_MAX && min_queued > 0) {
output->status = mix_output (this, min_queued); output->status = mix_output(this, min_queued);
} } else {
else {
/* take requested output range and apply to input */ /* take requested output range and apply to input */
for (i = 0; i < MAX_PORTS; i++) { for (i = 0; i < MAX_PORTS; i++) {
struct port *port = &this->in_ports[i]; struct port *port = &this->in_ports[i];
@ -773,11 +763,10 @@ impl_node_process_output (struct spa_node *node)
if (port->queued_bytes == 0) { if (port->queued_bytes == 0) {
input->range = output->range; input->range = output->range;
input->status = SPA_RESULT_NEED_BUFFER; input->status = SPA_RESULT_NEED_BUFFER;
} } else {
else {
input->status = SPA_RESULT_OK; input->status = SPA_RESULT_OK;
} }
spa_log_trace (this->log, NAME " %p: port %d %d queued %zd, res %d", this, spa_log_trace(this->log, NAME " %p: port %d %d queued %zd, res %d", this,
i, output->range.min_size, port->queued_bytes, input->status); i, output->range.min_size, port->queued_bytes, input->status);
} }
} }
@ -785,7 +774,7 @@ impl_node_process_output (struct spa_node *node)
} }
static const struct spa_node impl_node = { static const struct spa_node impl_node = {
sizeof (struct spa_node), sizeof(struct spa_node),
NULL, NULL,
impl_node_get_props, impl_node_get_props,
impl_node_set_props, impl_node_set_props,
@ -810,15 +799,12 @@ static const struct spa_node impl_node = {
impl_node_process_output, impl_node_process_output,
}; };
static int static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
@ -830,14 +816,13 @@ impl_get_interface (struct spa_handle *handle,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_clear(struct spa_handle *handle)
impl_clear (struct spa_handle *handle)
{ {
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_init (const struct spa_handle_factory *factory, impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -846,8 +831,8 @@ impl_init (const struct spa_handle_factory *factory,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface; handle->get_interface = impl_get_interface;
handle->clear = impl_clear; handle->clear = impl_clear;
@ -855,39 +840,38 @@ impl_init (const struct spa_handle_factory *factory,
this = (struct impl *) handle; this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "an id-map is needed"); spa_log_error(this->log, "an id-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
init_type (&this->type, this->map); init_type(&this->type, this->map);
this->node = impl_node; this->node = impl_node;
this->out_ports[0].io = NULL; this->out_ports[0].io = NULL;
this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
SPA_PORT_INFO_FLAG_NO_REF; SPA_PORT_INFO_FLAG_NO_REF;
spa_list_init (&this->out_ports[0].queue); spa_list_init(&this->out_ports[0].queue);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static const struct spa_interface_info impl_interfaces[] = static const struct spa_interface_info impl_interfaces[] = {
{ {SPA_TYPE__Node,},
{ SPA_TYPE__Node, },
}; };
static int static int
impl_enum_interface_info (const struct spa_handle_factory *factory, impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info, 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(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:
@ -899,10 +883,10 @@ impl_enum_interface_info (const struct spa_handle_factory *factory,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
const struct spa_handle_factory spa_audiomixer_factory = const struct spa_handle_factory spa_audiomixer_factory = {
{ NAME, NAME,
NULL, NULL,
sizeof (struct impl), sizeof(struct impl),
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };

View file

@ -23,11 +23,9 @@
extern const struct spa_handle_factory spa_audiomixer_factory; extern const struct spa_handle_factory spa_audiomixer_factory;
int int
spa_handle_factory_enum(const struct spa_handle_factory **factory, spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
uint32_t index)
{ {
spa_return_val_if_fail(factory != NULL, spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:

File diff suppressed because it is too large Load diff

View file

@ -23,11 +23,9 @@
extern const struct spa_handle_factory spa_audiotestsrc_factory; extern const struct spa_handle_factory spa_audiotestsrc_factory;
int int
spa_handle_factory_enum(const struct spa_handle_factory **factory, spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
uint32_t index)
{ {
spa_return_val_if_fail(factory != NULL, spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:

View file

@ -54,14 +54,13 @@ struct type {
struct spa_type_command_node command_node; struct spa_type_command_node command_node;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->node = spa_type_map_get_id (map, SPA_TYPE__Node); type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
spa_type_media_type_map (map, &type->media_type); spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype); spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map (map, &type->format_video); spa_type_format_video_map(map, &type->format_video);
spa_type_command_node_map (map, &type->command_node); spa_type_command_node_map(map, &type->command_node);
} }
struct impl { struct impl {
@ -81,45 +80,37 @@ struct impl {
bool started; bool started;
}; };
static int static int spa_ffmpeg_dec_node_get_props(struct spa_node *node, struct spa_props **props)
spa_ffmpeg_dec_node_get_props (struct spa_node *node,
struct spa_props **props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int spa_ffmpeg_dec_node_set_props(struct spa_node *node, const struct spa_props *props)
spa_ffmpeg_dec_node_set_props (struct spa_node *node,
const struct spa_props *props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int spa_ffmpeg_dec_node_send_command(struct spa_node *node, struct spa_command *command)
spa_ffmpeg_dec_node_send_command (struct spa_node *node,
struct spa_command *command)
{ {
struct impl *this; struct impl *this;
if (node == NULL || command == NULL) if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) { if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
this->started = true; this->started = true;
} } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
this->started = false; this->started = false;
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
spa_ffmpeg_dec_node_set_callbacks (struct spa_node *node, spa_ffmpeg_dec_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, const struct spa_node_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size,
void *user_data) void *user_data)
@ -129,7 +120,7 @@ spa_ffmpeg_dec_node_set_callbacks (struct spa_node *node,
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks; this->callbacks = *callbacks;
this->user_data = user_data; this->user_data = user_data;
@ -138,11 +129,11 @@ spa_ffmpeg_dec_node_set_callbacks (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_get_n_ports (struct spa_node *node, spa_ffmpeg_dec_node_get_n_ports(struct spa_node *node,
uint32_t *n_input_ports, uint32_t * n_input_ports,
uint32_t *max_input_ports, uint32_t * max_input_ports,
uint32_t *n_output_ports, uint32_t * n_output_ports,
uint32_t *max_output_ports) uint32_t * max_output_ports)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -160,11 +151,11 @@ spa_ffmpeg_dec_node_get_n_ports (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_get_port_ids (struct spa_node *node, spa_ffmpeg_dec_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports, uint32_t n_input_ports,
uint32_t *input_ids, uint32_t * input_ids,
uint32_t n_output_ports, uint32_t n_output_ports,
uint32_t *output_ids) uint32_t * output_ids)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -179,7 +170,13 @@ spa_ffmpeg_dec_node_get_port_ids (struct spa_node *node,
static int static int
spa_ffmpeg_dec_node_add_port (struct spa_node *node, spa_ffmpeg_dec_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_remove_port(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id) uint32_t port_id)
{ {
@ -187,15 +184,7 @@ spa_ffmpeg_dec_node_add_port (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_remove_port (struct spa_node *node, spa_ffmpeg_dec_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_ffmpeg_dec_node_port_enum_formats (struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_format **format, struct spa_format **format,
@ -209,7 +198,7 @@ spa_ffmpeg_dec_node_port_enum_formats (struct spa_node *node,
//this = SPA_CONTAINER_OF (node, struct impl, node); //this = SPA_CONTAINER_OF (node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
switch (index) { switch (index) {
@ -224,7 +213,7 @@ spa_ffmpeg_dec_node_port_enum_formats (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_port_set_format (struct spa_node *node, spa_ffmpeg_dec_node_port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t flags, uint32_t flags,
@ -236,25 +225,27 @@ spa_ffmpeg_dec_node_port_set_format (struct spa_node *node,
if (node == NULL || format == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (format == NULL) { if (format == NULL) {
port->have_format = false; port->have_format = false;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} else { } else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format), struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE (format), }; SPA_FORMAT_MEDIA_SUBTYPE(format),
};
if (info.media_type != this->type.media_type.video && if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw) info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video)) if (!spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
@ -266,7 +257,7 @@ spa_ffmpeg_dec_node_port_set_format (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_port_get_format (struct spa_node *node, spa_ffmpeg_dec_node_port_get_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_format **format) const struct spa_format **format)
@ -277,12 +268,13 @@ spa_ffmpeg_dec_node_port_get_format (struct spa_node *node,
if (node == NULL || format == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format) if (!port->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -293,7 +285,7 @@ spa_ffmpeg_dec_node_port_get_format (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_port_get_info (struct spa_node *node, spa_ffmpeg_dec_node_port_get_info(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_port_info **info) const struct spa_port_info **info)
@ -304,19 +296,20 @@ spa_ffmpeg_dec_node_port_get_info (struct spa_node *node,
if (node == NULL || info == NULL) if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info; *info = &port->info;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
spa_ffmpeg_dec_node_port_enum_params (struct spa_node *node, spa_ffmpeg_dec_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t index, uint32_t index,
@ -326,7 +319,7 @@ spa_ffmpeg_dec_node_port_enum_params (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_port_set_param (struct spa_node *node, spa_ffmpeg_dec_node_port_set_param(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_param *param) const struct spa_param *param)
@ -335,7 +328,7 @@ spa_ffmpeg_dec_node_port_set_param (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_port_use_buffers (struct spa_node *node, spa_ffmpeg_dec_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_buffer **buffers, struct spa_buffer **buffers,
@ -344,26 +337,26 @@ spa_ffmpeg_dec_node_port_use_buffers (struct spa_node *node,
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (node, direction, port_id)) if (!IS_VALID_PORT(node, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_dec_node_port_alloc_buffers (struct spa_node *node, spa_ffmpeg_dec_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_param **params, struct spa_param **params,
uint32_t n_params, uint32_t n_params,
struct spa_buffer **buffers, struct spa_buffer **buffers,
uint32_t *n_buffers) uint32_t * n_buffers)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_dec_node_port_set_io (struct spa_node *node, spa_ffmpeg_dec_node_port_set_io(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_port_io *io) struct spa_port_io *io)
@ -374,25 +367,24 @@ spa_ffmpeg_dec_node_port_set_io (struct spa_node *node,
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io; port->io = io;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int spa_ffmpeg_dec_node_process_input(struct spa_node *node)
spa_ffmpeg_dec_node_process_input (struct spa_node *node)
{ {
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
} }
static int static int spa_ffmpeg_dec_node_process_output(struct spa_node *node)
spa_ffmpeg_dec_node_process_output (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -401,7 +393,7 @@ spa_ffmpeg_dec_node_process_output (struct spa_node *node)
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
port = &this->out_ports[0]; port = &this->out_ports[0];
@ -418,9 +410,7 @@ spa_ffmpeg_dec_node_process_output (struct spa_node *node)
} }
static int static int
spa_ffmpeg_dec_node_port_reuse_buffer (struct spa_node *node, spa_ffmpeg_dec_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
uint32_t port_id,
uint32_t buffer_id)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -432,7 +422,7 @@ spa_ffmpeg_dec_node_port_reuse_buffer (struct spa_node *node,
} }
static int static int
spa_ffmpeg_dec_node_port_send_command (struct spa_node *node, spa_ffmpeg_dec_node_port_send_command(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_command *command) struct spa_command *command)
@ -442,7 +432,7 @@ spa_ffmpeg_dec_node_port_send_command (struct spa_node *node,
static const struct spa_node ffmpeg_dec_node = { static const struct spa_node ffmpeg_dec_node = {
sizeof (struct spa_node), sizeof(struct spa_node),
NULL, NULL,
spa_ffmpeg_dec_node_get_props, spa_ffmpeg_dec_node_get_props,
spa_ffmpeg_dec_node_set_props, spa_ffmpeg_dec_node_set_props,
@ -468,9 +458,7 @@ static const struct spa_node ffmpeg_dec_node = {
}; };
static int static int
spa_ffmpeg_dec_get_interface (struct spa_handle *handle, spa_ffmpeg_dec_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
@ -488,7 +476,7 @@ spa_ffmpeg_dec_get_interface (struct spa_handle *handle,
} }
int int
spa_ffmpeg_dec_init (struct spa_handle *handle, spa_ffmpeg_dec_init(struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
uint32_t n_support) uint32_t n_support)
@ -501,16 +489,16 @@ spa_ffmpeg_dec_init (struct spa_handle *handle,
this = (struct impl *) handle; this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed"); spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
init_type (&this->type, this->map); init_type(&this->type, this->map);
this->node = ffmpeg_dec_node; this->node = ffmpeg_dec_node;

View file

@ -58,14 +58,13 @@ struct type {
struct spa_type_command_node command_node; struct spa_type_command_node command_node;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->node = spa_type_map_get_id (map, SPA_TYPE__Node); type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
spa_type_media_type_map (map, &type->media_type); spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype); spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map (map, &type->format_video); spa_type_format_video_map(map, &type->format_video);
spa_type_command_node_map (map, &type->command_node); spa_type_command_node_map(map, &type->command_node);
} }
struct impl { struct impl {
@ -85,55 +84,46 @@ struct impl {
bool started; bool started;
}; };
static int static int spa_ffmpeg_enc_node_get_props(struct spa_node *node, struct spa_props **props)
spa_ffmpeg_enc_node_get_props (struct spa_node *node,
struct spa_props **props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int spa_ffmpeg_enc_node_set_props(struct spa_node *node, const struct spa_props *props)
spa_ffmpeg_enc_node_set_props (struct spa_node *node,
const struct spa_props *props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int spa_ffmpeg_enc_node_send_command(struct spa_node *node, struct spa_command *command)
spa_ffmpeg_enc_node_send_command (struct spa_node *node,
struct spa_command *command)
{ {
struct impl *this; struct impl *this;
if (node == NULL || command == NULL) if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) { if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
this->started = true; this->started = true;
} } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
this->started = false; this->started = false;
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
spa_ffmpeg_enc_node_set_callbacks (struct spa_node *node, spa_ffmpeg_enc_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, const struct spa_node_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size, void *user_data)
void *user_data)
{ {
struct impl *this; struct impl *this;
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks; this->callbacks = *callbacks;
this->user_data = user_data; this->user_data = user_data;
@ -142,11 +132,10 @@ spa_ffmpeg_enc_node_set_callbacks (struct spa_node *node,
} }
static int static int
spa_ffmpeg_enc_node_get_n_ports (struct spa_node *node, spa_ffmpeg_enc_node_get_n_ports(struct spa_node *node,
uint32_t *n_input_ports, uint32_t * n_input_ports,
uint32_t *max_input_ports, uint32_t * max_input_ports,
uint32_t *n_output_ports, uint32_t * n_output_ports, uint32_t * max_output_ports)
uint32_t *max_output_ports)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -164,11 +153,10 @@ spa_ffmpeg_enc_node_get_n_ports (struct spa_node *node,
} }
static int static int
spa_ffmpeg_enc_node_get_port_ids (struct spa_node *node, spa_ffmpeg_enc_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports, uint32_t n_input_ports,
uint32_t *input_ids, uint32_t * input_ids,
uint32_t n_output_ports, uint32_t n_output_ports, uint32_t * output_ids)
uint32_t *output_ids)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -183,28 +171,24 @@ spa_ffmpeg_enc_node_get_port_ids (struct spa_node *node,
static int static int
spa_ffmpeg_enc_node_add_port (struct spa_node *node, spa_ffmpeg_enc_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_enc_node_remove_port (struct spa_node *node, spa_ffmpeg_enc_node_remove_port(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction, uint32_t port_id)
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_enc_node_port_enum_formats (struct spa_node *node, spa_ffmpeg_enc_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_format **format, struct spa_format **format,
const struct spa_format *filter, const struct spa_format *filter, uint32_t index)
uint32_t index)
{ {
//struct impl *this; //struct impl *this;
//struct port *port; //struct port *port;
@ -214,7 +198,7 @@ spa_ffmpeg_enc_node_port_enum_formats (struct spa_node *node,
//this = SPA_CONTAINER_OF (node, struct impl, node); //this = SPA_CONTAINER_OF (node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
//port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; //port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
@ -231,11 +215,10 @@ spa_ffmpeg_enc_node_port_enum_formats (struct spa_node *node,
} }
static int static int
spa_ffmpeg_enc_node_port_set_format (struct spa_node *node, spa_ffmpeg_enc_node_port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t flags, uint32_t flags, const struct spa_format *format)
const struct spa_format *format)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -243,25 +226,27 @@ spa_ffmpeg_enc_node_port_set_format (struct spa_node *node,
if (node == NULL || format == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (format == NULL) { if (format == NULL) {
port->have_format = false; port->have_format = false;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} else { } else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format), struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE (format), }; SPA_FORMAT_MEDIA_SUBTYPE(format),
};
if (info.media_type != this->type.media_type.video && if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw) info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video)) if (!spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
@ -273,10 +258,9 @@ spa_ffmpeg_enc_node_port_set_format (struct spa_node *node,
} }
static int static int
spa_ffmpeg_enc_node_port_get_format (struct spa_node *node, spa_ffmpeg_enc_node_port_get_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id, const struct spa_format **format)
const struct spa_format **format)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -284,12 +268,13 @@ spa_ffmpeg_enc_node_port_get_format (struct spa_node *node,
if (node == NULL || format == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format) if (!port->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -300,10 +285,9 @@ spa_ffmpeg_enc_node_port_get_format (struct spa_node *node,
} }
static int static int
spa_ffmpeg_enc_node_port_get_info (struct spa_node *node, spa_ffmpeg_enc_node_port_get_info(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id, const struct spa_port_info **info)
const struct spa_port_info **info)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -311,69 +295,64 @@ spa_ffmpeg_enc_node_port_get_info (struct spa_node *node,
if (node == NULL || info == NULL) if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info; *info = &port->info;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
spa_ffmpeg_enc_node_port_enum_params (struct spa_node *node, spa_ffmpeg_enc_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id, uint32_t index, struct spa_param **param)
uint32_t index,
struct spa_param **param)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_enc_node_port_set_param (struct spa_node *node, spa_ffmpeg_enc_node_port_set_param(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id, const struct spa_param *param)
const struct spa_param *param)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_enc_node_port_use_buffers (struct spa_node *node, spa_ffmpeg_enc_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_buffer **buffers, struct spa_buffer **buffers, uint32_t n_buffers)
uint32_t n_buffers)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (node, direction, port_id)) if (!IS_VALID_PORT(node, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_enc_node_port_alloc_buffers (struct spa_node *node, spa_ffmpeg_enc_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_param **params, struct spa_param **params,
uint32_t n_params, uint32_t n_params,
struct spa_buffer **buffers, struct spa_buffer **buffers, uint32_t * n_buffers)
uint32_t *n_buffers)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
spa_ffmpeg_enc_node_port_set_io (struct spa_node *node, spa_ffmpeg_enc_node_port_set_io(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id, struct spa_port_io *io)
struct spa_port_io *io)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -381,21 +360,20 @@ spa_ffmpeg_enc_node_port_set_io (struct spa_node *node,
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (!IS_VALID_PORT (this, direction, port_id)) if (!IS_VALID_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io; port->io = io;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
spa_ffmpeg_enc_node_port_reuse_buffer (struct spa_node *node, spa_ffmpeg_enc_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
uint32_t port_id,
uint32_t buffer_id)
{ {
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -407,22 +385,19 @@ spa_ffmpeg_enc_node_port_reuse_buffer (struct spa_node *node,
} }
static int static int
spa_ffmpeg_enc_node_port_send_command (struct spa_node *node, spa_ffmpeg_enc_node_port_send_command(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id, struct spa_command *command)
struct spa_command *command)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int spa_ffmpeg_enc_node_process_input(struct spa_node *node)
spa_ffmpeg_enc_node_process_input (struct spa_node *node)
{ {
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
} }
static int static int spa_ffmpeg_enc_node_process_output(struct spa_node *node)
spa_ffmpeg_enc_node_process_output (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
@ -431,7 +406,7 @@ spa_ffmpeg_enc_node_process_output (struct spa_node *node)
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if ((output = this->out_ports[0].io) == NULL) if ((output = this->out_ports[0].io) == NULL)
return SPA_RESULT_OK; return SPA_RESULT_OK;
@ -448,7 +423,7 @@ spa_ffmpeg_enc_node_process_output (struct spa_node *node)
} }
static const struct spa_node ffmpeg_enc_node = { static const struct spa_node ffmpeg_enc_node = {
sizeof (struct spa_node), sizeof(struct spa_node),
NULL, NULL,
spa_ffmpeg_enc_node_get_props, spa_ffmpeg_enc_node_get_props,
spa_ffmpeg_enc_node_set_props, spa_ffmpeg_enc_node_set_props,
@ -474,9 +449,7 @@ static const struct spa_node ffmpeg_enc_node = {
}; };
static int static int
spa_ffmpeg_enc_get_interface (struct spa_handle *handle, spa_ffmpeg_enc_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
@ -494,10 +467,9 @@ spa_ffmpeg_enc_get_interface (struct spa_handle *handle,
} }
int int
spa_ffmpeg_enc_init (struct spa_handle *handle, spa_ffmpeg_enc_init(struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support, uint32_t n_support)
uint32_t n_support)
{ {
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
@ -507,13 +479,13 @@ spa_ffmpeg_enc_init (struct spa_handle *handle,
this = (struct impl *) handle; this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed"); spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }

View file

@ -25,11 +25,13 @@
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
int spa_ffmpeg_dec_init (struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support); int spa_ffmpeg_dec_init(struct spa_handle *handle, const struct spa_dict *info,
int spa_ffmpeg_enc_init (struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support); const struct spa_support *support, uint32_t n_support);
int spa_ffmpeg_enc_init(struct spa_handle *handle, const struct spa_dict *info,
const struct spa_support *support, uint32_t n_support);
static int static int
ffmpeg_dec_init (const struct spa_handle_factory *factory, ffmpeg_dec_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -38,11 +40,11 @@ ffmpeg_dec_init (const struct spa_handle_factory *factory,
if (factory == NULL || handle == NULL) if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
return spa_ffmpeg_dec_init (handle, info, support, n_support); return spa_ffmpeg_dec_init(handle, info, support, n_support);
} }
static int static int
ffmpeg_enc_init (const struct spa_handle_factory *factory, ffmpeg_enc_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -51,17 +53,15 @@ ffmpeg_enc_init (const struct spa_handle_factory *factory,
if (factory == NULL || handle == NULL) if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
return spa_ffmpeg_enc_init (handle, info, support, n_support); return spa_ffmpeg_enc_init(handle, info, support, n_support);
} }
static const struct spa_interface_info ffmpeg_interfaces[] = static const struct spa_interface_info ffmpeg_interfaces[] = {
{ {SPA_TYPE__Node, },
{ SPA_TYPE__Node,
},
}; };
static int static int
ffmpeg_enum_interface_info (const struct spa_handle_factory *factory, ffmpeg_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info, const struct spa_interface_info **info,
uint32_t index) uint32_t index)
{ {
@ -76,9 +76,7 @@ ffmpeg_enum_interface_info (const struct spa_handle_factory *factory,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
int 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)
{ {
static const AVCodec *c = NULL; static const AVCodec *c = NULL;
static int ci = 0; static int ci = 0;
@ -88,22 +86,21 @@ spa_handle_factory_enum (const struct spa_handle_factory **factory,
av_register_all(); av_register_all();
if (index == 0) { if (index == 0) {
c = av_codec_next (NULL); c = av_codec_next(NULL);
ci = 0; ci = 0;
} }
while (index > ci && c) { while (index > ci && c) {
c = av_codec_next (c); c = av_codec_next(c);
ci++; ci++;
} }
if (c == NULL) if (c == NULL)
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
if (av_codec_is_encoder (c)) { if (av_codec_is_encoder(c)) {
snprintf (name, 128, "ffenc_%s", c->name); snprintf(name, 128, "ffenc_%s", c->name);
f.init = ffmpeg_enc_init; f.init = ffmpeg_enc_init;
} } else {
else { snprintf(name, 128, "ffdec_%s", c->name);
snprintf (name, 128, "ffdec_%s", c->name);
f.init = ffmpeg_dec_init; f.init = ffmpeg_dec_init;
} }
f.name = name; f.name = name;

View file

@ -1,528 +0,0 @@
/* Spa Libva Decoder
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <spa/node.h>
#include <spa/video/format.h>
typedef struct _SpaLibvaDec SpaLibvaDec;
typedef struct {
SpaProps props;
} SpaLibvaDecProps;
static void
reset_libva_dec_props (SpaLibvaDecProps *props)
{
}
#define INPUT_PORT_ID 0
#define OUTPUT_PORT_ID 1
#define IS_VALID_PORT(id) ((id) < 2)
#define MAX_BUFFERS 32
typedef struct _LibvaBuffer LibvaBuffer;
struct _LibvaBuffer {
SpaBuffer buffer;
SpaMeta metas[1];
SpaMetaHeader header;
SpaData datas[1];
SpaLibvaDec *dec;
SpaBuffer *imported;
bool outstanding;
LibvaBuffer *next;
};
typedef struct {
SpaVideoRawFormat raw_format[2];
SpaFormat *current_format;
bool have_buffers;
LibvaBuffer buffers[MAX_BUFFERS];
SpaPortInfo info;
SpaPortStatus status;
} SpaLibvaState;
struct _SpaLibvaDec {
SpaHandle handle;
SpaLibvaDecProps props[2];
SpaNodeEventCallback event_cb;
void *user_data;
SpaLibvaState state[2];
};
enum {
PROP_ID_LAST,
};
static const SpaPropInfo prop_info[] =
{
{ 0, },
};
static int
spa_libva_dec_node_get_props (SpaHandle *handle,
SpaProps **props)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_set_props (SpaHandle *handle,
const SpaProps *props)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaDecProps *p = &this->props[1];
int res;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (props == NULL) {
reset_libva_dec_props (p);
return SPA_RESULT_OK;
}
res = spa_props_copy_values (props, &p->props);
return res;
}
static int
spa_libva_dec_node_send_command (SpaHandle *handle,
SpaCommand *command)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (command->type) {
case SPA_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
case SPA_COMMAND_START:
if (this->event_cb) {
SpaNodeEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_NODE_EVENT_TYPE_STARTED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_STOP:
if (this->event_cb) {
SpaNodeEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_NODE_EVENT_TYPE_STOPPED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_FLUSH:
case SPA_COMMAND_DRAIN:
case SPA_COMMAND_MARKER:
return SPA_RESULT_NOT_IMPLEMENTED;
}
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_set_event_callback (SpaHandle *handle,
SpaNodeEventCallback event,
void *user_data)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this->event_cb = event;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_get_n_ports (SpaHandle *handle,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_get_port_ids (SpaHandle *handle,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_add_port (SpaHandle *handle,
SpaDirection direction,
uint32_t *port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_remove_port (SpaHandle *handle,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_enum_formats (SpaHandle *handle,
uint32_t port_id,
uint32_t index,
SpaFormat **format)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
switch (index) {
case 0:
spa_video_raw_format_init (&state->raw_format[0]);
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = &state->raw_format[0].format;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_set_format (SpaHandle *handle,
uint32_t port_id,
bool test_only,
const SpaFormat *format)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
int res;
SpaFormat *f, *tf;
size_t fs;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (format == NULL) {
state->current_format = NULL;
return SPA_RESULT_OK;
}
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
if ((res = spa_video_raw_format_parse (format, &state->raw_format[0]) < 0))
return res;
f = &state->raw_format[0].format;
tf = &state->raw_format[1].format;
fs = sizeof (SpaVideoRawFormat);
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!test_only) {
memcpy (tf, f, fs);
state->current_format = tf;
}
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_get_format (SpaHandle *handle,
uint32_t port_id,
const SpaFormat **format)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (state->current_format == NULL)
return SPA_RESULT_NO_FORMAT;
*format = state->current_format;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_get_info (SpaHandle *handle,
uint32_t port_id,
const SpaPortInfo **info)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*info = &this->state[port_id].info;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_get_props (SpaHandle *handle,
uint32_t port_id,
SpaProps **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_set_props (SpaHandle *handle,
uint32_t port_id,
const SpaProps *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_get_status (SpaHandle *handle,
uint32_t port_id,
const SpaPortStatus **status)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
if (handle == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*status = &this->state[port_id].status;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_use_buffers (SpaHandle *handle,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_OK;
}
static int
spa_libva_dec_node_port_alloc_buffers (SpaHandle *handle,
uint32_t port_id,
SpaParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_dec_node_port_push_input (SpaHandle *handle,
uint32_t n_info,
SpaInputInfo *info)
{
return SPA_RESULT_INVALID_PORT;
}
static int
spa_libva_dec_node_port_pull_output (SpaHandle *handle,
uint32_t n_info,
SpaOutputInfo *info)
{
SpaLibvaDec *this = (SpaLibvaDec *) handle;
SpaLibvaState *state;
uint32_t i;
bool have_error = false;
if (handle == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < n_info; i++) {
if (info[i].port_id != OUTPUT_PORT_ID) {
info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true;
continue;
}
state = &this->state[info[i].port_id];
if (state->current_format == NULL) {
info[i].status = SPA_RESULT_NO_FORMAT;
have_error = true;
continue;
}
info[i].status = SPA_RESULT_OK;
}
if (have_error)
return SPA_RESULT_ERROR;
return SPA_RESULT_OK;
}
static const SpaNode libva_dec_node = {
sizeof (SpaNode),
spa_libva_dec_node_get_props,
spa_libva_dec_node_set_props,
spa_libva_dec_node_send_command,
spa_libva_dec_node_set_event_callback,
spa_libva_dec_node_get_n_ports,
spa_libva_dec_node_get_port_ids,
spa_libva_dec_node_add_port,
spa_libva_dec_node_remove_port,
spa_libva_dec_node_port_enum_formats,
spa_libva_dec_node_port_set_format,
spa_libva_dec_node_port_get_format,
spa_libva_dec_node_port_get_info,
spa_libva_dec_node_port_get_props,
spa_libva_dec_node_port_set_props,
spa_libva_dec_node_port_use_buffers,
spa_libva_dec_node_port_alloc_buffers,
spa_libva_dec_node_port_get_status,
spa_libva_dec_node_port_push_input,
spa_libva_dec_node_port_pull_output,
};
static int
spa_libva_dec_get_interface (SpaHandle *handle,
uint32_t interface_id,
const void **interface)
{
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (interface_id) {
case SPA_INTERFACE_ID_NODE:
*interface = &libva_dec_node;
break;
default:
return SPA_RESULT_UNKNOWN_INTERFACE;
}
return SPA_RESULT_OK;
}
SpaHandle *
spa_libva_dec_new (void)
{
SpaHandle *handle;
SpaLibvaDec *this;
handle = calloc (1, sizeof (SpaLibvaDec));
handle->get_interface = spa_libva_dec_get_interface;
this = (SpaLibvaDec *) handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_libva_dec_props (&this->props[1]);
this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[INPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
this->state[OUTPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[OUTPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
return handle;
}

View file

@ -1,530 +0,0 @@
/* Spa Libva Encoder
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <spa/node.h>
#include <spa/video/format.h>
typedef struct _SpaLibvaEnc SpaLibvaEnc;
typedef struct {
SpaProps props;
} SpaLibvaEncProps;
static void
reset_libva_enc_props (SpaLibvaEncProps *props)
{
}
#define INPUT_PORT_ID 0
#define OUTPUT_PORT_ID 1
#define IS_VALID_PORT(id) ((id) < 2)
#define MAX_BUFFERS 32
typedef struct _LibvaBuffer LibvaBuffer;
struct _LibvaBuffer {
SpaBuffer buffer;
SpaMeta metas[1];
SpaMetaHeader header;
SpaData datas[1];
SpaLibvaEnc *enc;
SpaBuffer *imported;
bool outstanding;
LibvaBuffer *next;
};
typedef struct {
SpaVideoRawFormat raw_format[2];
SpaFormat *current_format;
bool have_buffers;
LibvaBuffer buffers[MAX_BUFFERS];
SpaPortInfo info;
SpaAllocParam *params[1];
SpaAllocParamBuffers param_buffers;
SpaPortStatus status;
} SpaLibvaState;
struct _SpaLibvaEnc {
SpaHandle handle;
SpaLibvaEncProps props[2];
SpaEventCallback event_cb;
void *user_data;
SpaLibvaState state[2];
};
enum {
PROP_ID_LAST,
};
static const SpaPropInfo prop_info[] =
{
{ 0, },
};
static int
spa_libva_enc_node_get_props (SpaHandle *handle,
SpaProps **props)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_set_props (SpaHandle *handle,
const SpaProps *props)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaEncProps *p = &this->props[1];
int res;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (props == NULL) {
reset_libva_enc_props (p);
return SPA_RESULT_OK;
}
res = spa_props_copy_values (props, &p->props);
return res;
}
static int
spa_libva_enc_node_send_command (SpaHandle *handle,
SpaCommand *command)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (command->type) {
case SPA_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
case SPA_COMMAND_START:
if (this->event_cb) {
SpaEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_EVENT_TYPE_STARTED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_STOP:
if (this->event_cb) {
SpaEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_EVENT_TYPE_STOPPED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_FLUSH:
case SPA_COMMAND_DRAIN:
case SPA_COMMAND_MARKER:
return SPA_RESULT_NOT_IMPLEMENTED;
}
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_set_event_callback (SpaHandle *handle,
SpaEventCallback event,
void *user_data)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this->event_cb = event;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_get_n_ports (SpaHandle *handle,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 1;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 1;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_get_port_ids (SpaHandle *handle,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids != NULL)
input_ids[0] = 0;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 1;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_add_port (SpaHandle *handle,
SpaDirection direction,
uint32_t *port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_remove_port (SpaHandle *handle,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_enum_formats (SpaHandle *handle,
uint32_t port_id,
uint32_t index,
SpaFormat **format)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
switch (index) {
case 0:
spa_video_raw_format_init (&state->raw_format[0]);
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = &state->raw_format[0].format;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_set_format (SpaHandle *handle,
uint32_t port_id,
bool test_only,
const SpaFormat *format)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
int res;
SpaFormat *f, *tf;
size_t fs;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (format == NULL) {
state->current_format = NULL;
return SPA_RESULT_OK;
}
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
if ((res = spa_video_raw_format_parse (format, &state->raw_format[0]) < 0))
return res;
f = &state->raw_format[0].format;
tf = &state->raw_format[1].format;
fs = sizeof (SpaVideoRawFormat);
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
} else
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!test_only) {
memcpy (tf, f, fs);
state->current_format = tf;
}
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_get_format (SpaHandle *handle,
uint32_t port_id,
const SpaFormat **format)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
if (handle == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id];
if (state->current_format == NULL)
return SPA_RESULT_NO_FORMAT;
*format = state->current_format;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_get_info (SpaHandle *handle,
uint32_t port_id,
const SpaPortInfo **info)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*info = &this->state[port_id].info;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_get_props (SpaHandle *handle,
uint32_t port_id,
SpaProps **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_set_props (SpaHandle *handle,
uint32_t port_id,
const SpaProps *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_get_status (SpaHandle *handle,
uint32_t port_id,
const SpaPortStatus **status)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
if (handle == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
*status = &this->state[port_id].status;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_use_buffers (SpaHandle *handle,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
{
if (handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (!IS_VALID_PORT (port_id))
return SPA_RESULT_INVALID_PORT;
return SPA_RESULT_OK;
}
static int
spa_libva_enc_node_port_alloc_buffers (SpaHandle *handle,
uint32_t port_id,
SpaAllocParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_libva_enc_node_port_push_input (SpaHandle *handle,
uint32_t n_info,
SpaInputInfo *info)
{
return SPA_RESULT_INVALID_PORT;
}
static int
spa_libva_enc_node_port_pull_output (SpaHandle *handle,
uint32_t n_info,
SpaOutputInfo *info)
{
SpaLibvaEnc *this = (SpaLibvaEnc *) handle;
SpaLibvaState *state;
uint32_t i;
bool have_error = false;
if (handle == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < n_info; i++) {
if (info[i].port_id != OUTPUT_PORT_ID) {
info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true;
continue;
}
state = &this->state[info[i].port_id];
if (state->current_format == NULL) {
info[i].status = SPA_RESULT_NO_FORMAT;
have_error = true;
continue;
}
info[i].status = SPA_RESULT_OK;
}
if (have_error)
return SPA_RESULT_ERROR;
return SPA_RESULT_OK;
}
static const SpaNode libva_enc_node = {
sizeof (SpaNode),
spa_libva_enc_node_get_props,
spa_libva_enc_node_set_props,
spa_libva_enc_node_send_command,
spa_libva_enc_node_set_event_callback,
spa_libva_enc_node_get_n_ports,
spa_libva_enc_node_get_port_ids,
spa_libva_enc_node_add_port,
spa_libva_enc_node_remove_port,
spa_libva_enc_node_port_enum_formats,
spa_libva_enc_node_port_set_format,
spa_libva_enc_node_port_get_format,
spa_libva_enc_node_port_get_info,
spa_libva_enc_node_port_get_props,
spa_libva_enc_node_port_set_props,
spa_libva_enc_node_port_use_buffers,
spa_libva_enc_node_port_alloc_buffers,
spa_libva_enc_node_port_get_status,
spa_libva_enc_node_port_push_input,
spa_libva_enc_node_port_pull_output,
};
static int
spa_libva_enc_get_interface (SpaHandle *handle,
uint32_t interface_id,
const void **interface)
{
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (interface_id) {
case SPA_INTERFACE_ID_NODE:
*interface = &libva_enc_node;
break;
default:
return SPA_RESULT_UNKNOWN_INTERFACE;
}
return SPA_RESULT_OK;
}
SpaHandle *
spa_libva_enc_new (void)
{
SpaHandle *handle;
SpaLibvaEnc *this;
handle = calloc (1, sizeof (SpaLibvaEnc));
handle->get_interface = spa_libva_enc_get_interface;
this = (SpaLibvaEnc *) handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_libva_enc_props (&this->props[1]);
this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[INPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
this->state[OUTPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;
this->state[OUTPUT_PORT_ID].status.flags = SPA_PORT_STATUS_FLAG_NONE;
return handle;
}

View file

@ -1,96 +0,0 @@
/* Spa V4l2 support
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <spa/plugin.h>
#include <spa/node.h>
SpaHandle * spa_libva_dec_new (void);
SpaHandle * spa_libva_enc_new (void);
static int
libva_dec_instantiate (const struct spa_handle_factory *factory,
SpaHandle **handle)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
*handle = spa_libva_dec_new ();
return SPA_RESULT_OK;
}
static int
libva_enc_instantiate (const struct spa_handle_factory *factory,
SpaHandle **handle)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
*handle = spa_libva_enc_new ();
return SPA_RESULT_OK;
}
static const struct spa_interface_info libva_interfaces[] =
{
{ SPA_INTERFACE_ID_NODE,
SPA_INTERFACE_ID_NODE_NAME,
SPA_INTERFACE_ID_NODE_DESCRIPTION,
},
};
static int
libva_enum_interface_info (const struct spa_handle_factory *factory,
uint32_t index,
const struct spa_interface_info **info)
{
if (index >= 1)
return SPA_RESULT_ENUM_END;
*info = &libva_interfaces[index];
return SPA_RESULT_OK;
}
static const struct spa_handle_factory factories[] =
{
{ "libva-dec",
NULL,
libva_dec_instantiate,
libva_enum_interface_info,
},
{ "libva-enc",
NULL,
libva_enc_instantiate,
libva_enum_interface_info,
}
};
int
spa_handle_factory_enum (uint32_t index,
const struct spa_handle_factory **factory)
{
if (index >= 2)
return SPA_RESULT_ENUM_END;
*factory = &factories[index];
return SPA_RESULT_OK;
}

View file

@ -1,11 +0,0 @@
libva_sources = ['libva.c',
'libva-dec.c',
'libva-enc.c']
libvalib = shared_library('spa-libva',
libva_sources,
include_directories : inc,
dependencies : libva_dep,
link_with : spalib,
install : true,
install_dir : '@0@/spa'.format(get_option('libdir')))

File diff suppressed because it is too large Load diff

View file

@ -1,38 +0,0 @@
/*
* Copyright © 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _VAAPI_RECORDER_H_
#define _VAAPI_RECORDER_H_
struct vaapi_recorder;
struct vaapi_recorder *
vaapi_recorder_create(int drm_fd, int width, int height, const char *filename);
void
vaapi_recorder_destroy(struct vaapi_recorder *r);
int
vaapi_recorder_frame(struct vaapi_recorder *r, int fd, int stride);
#endif /* _VAAPI_RECORDER_H_ */

View file

@ -3,8 +3,6 @@ subdir('audiomixer')
subdir('audiotestsrc') subdir('audiotestsrc')
subdir('ffmpeg') subdir('ffmpeg')
subdir('test') subdir('test')
#subdir('libva')
subdir('videotestsrc') subdir('videotestsrc')
subdir('volume') subdir('volume')
subdir('v4l2') subdir('v4l2')
subdir('xv')

View file

@ -49,20 +49,19 @@ struct type {
struct spa_type_param_alloc_meta_enable param_alloc_meta_enable; struct spa_type_param_alloc_meta_enable param_alloc_meta_enable;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->node = spa_type_map_get_id (map, SPA_TYPE__Node); type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
type->clock = spa_type_map_get_id (map, SPA_TYPE__Clock); type->clock = spa_type_map_get_id(map, SPA_TYPE__Clock);
type->format = spa_type_map_get_id (map, SPA_TYPE__Format); type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id (map, SPA_TYPE__Props); type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_live = spa_type_map_get_id (map, SPA_TYPE_PROPS__live); type->prop_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live);
spa_type_meta_map (map, &type->meta); spa_type_meta_map(map, &type->meta);
spa_type_data_map (map, &type->data); spa_type_data_map(map, &type->data);
spa_type_event_node_map (map, &type->event_node); spa_type_event_node_map(map, &type->event_node);
spa_type_command_node_map (map, &type->command_node); spa_type_command_node_map(map, &type->command_node);
spa_type_param_alloc_buffers_map (map, &type->param_alloc_buffers); spa_type_param_alloc_buffers_map(map, &type->param_alloc_buffers);
spa_type_param_alloc_meta_enable_map (map, &type->param_alloc_meta_enable); spa_type_param_alloc_meta_enable_map(map, &type->param_alloc_meta_enable);
} }
struct props { struct props {
@ -121,8 +120,7 @@ struct impl {
#define DEFAULT_LIVE false #define DEFAULT_LIVE false
static void static void reset_props(struct impl *this, struct props *props)
reset_props (struct impl *this, struct props *props)
{ {
props->live = DEFAULT_LIVE; props->live = DEFAULT_LIVE;
} }
@ -140,43 +138,39 @@ reset_props (struct impl *this, struct props *props)
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \ SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__) SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
static int static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
impl_node_get_props (struct spa_node *node,
struct spa_props **props)
{ {
struct impl *this; struct impl *this;
struct spa_pod_builder b = { NULL, }; struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (props != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(props != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer)); spa_pod_builder_init(&b, this->props_buffer, sizeof(this->props_buffer));
spa_pod_builder_props (&b, &f[0], this->type.props, spa_pod_builder_props(&b, &f[0], this->type.props,
PROP (&f[1], this->type.prop_live, SPA_POD_TYPE_BOOL, this->props.live)); PROP(&f[1], this->type.prop_live, SPA_POD_TYPE_BOOL,
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_props); this->props.live));
*props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_set_props(struct spa_node *node, const struct spa_props *props)
impl_node_set_props (struct spa_node *node,
const struct spa_props *props)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (props == NULL) { if (props == NULL) {
reset_props (this, &this->props); reset_props(this, &this->props);
} else { } else {
spa_props_query (props, spa_props_query(props,
this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live, this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live, 0);
0);
} }
if (this->props.live) if (this->props.live)
@ -187,8 +181,7 @@ impl_node_set_props (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static void static void set_timer(struct impl *this, bool enabled)
set_timer (struct impl *this, bool enabled)
{ {
if (this->callbacks.need_input || this->props.live) { if (this->callbacks.need_input || this->props.live) {
if (enabled) { if (enabled) {
@ -204,53 +197,50 @@ set_timer (struct impl *this, bool enabled)
this->timerspec.it_value.tv_sec = 0; this->timerspec.it_value.tv_sec = 0;
this->timerspec.it_value.tv_nsec = 0; this->timerspec.it_value.tv_nsec = 0;
} }
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL); timerfd_settime(this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
} }
} }
static inline void static inline void read_timer(struct impl *this)
read_timer (struct impl *this)
{ {
uint64_t expirations; uint64_t expirations;
if (this->callbacks.need_input || this->props.live) { if (this->callbacks.need_input || this->props.live) {
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t)) if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) < sizeof(uint64_t))
perror ("read timerfd"); perror("read timerfd");
} }
} }
static void static void render_buffer(struct impl *this, struct buffer *b)
render_buffer (struct impl *this, struct buffer *b)
{ {
} }
static int static int consume_buffer(struct impl *this)
consume_buffer (struct impl *this)
{ {
struct buffer *b; struct buffer *b;
struct spa_port_io *io = this->io; struct spa_port_io *io = this->io;
int n_bytes; int n_bytes;
read_timer (this); read_timer(this);
if (spa_list_is_empty (&this->ready)) { if (spa_list_is_empty(&this->ready)) {
io->status = SPA_RESULT_NEED_BUFFER; io->status = SPA_RESULT_NEED_BUFFER;
if (this->callbacks.need_input) if (this->callbacks.need_input)
this->callbacks.need_input (&this->node, this->user_data); this->callbacks.need_input(&this->node, this->user_data);
} }
if (spa_list_is_empty (&this->ready)) { if (spa_list_is_empty(&this->ready)) {
spa_log_error (this->log, NAME " %p: no buffers", this); spa_log_error(this->log, NAME " %p: no buffers", this);
return SPA_RESULT_NEED_BUFFER; return SPA_RESULT_NEED_BUFFER;
} }
b = spa_list_first (&this->ready, struct buffer, link); b = spa_list_first(&this->ready, struct buffer, link);
spa_list_remove (&b->link); spa_list_remove(&b->link);
n_bytes = b->outbuf->datas[0].maxsize; n_bytes = b->outbuf->datas[0].maxsize;
spa_log_trace (this->log, NAME " %p: dequeue buffer %d", this, b->outbuf->id); spa_log_trace(this->log, NAME " %p: dequeue buffer %d", this, b->outbuf->id);
render_buffer (this, b); render_buffer(this, b);
b->outbuf->datas[0].chunk->offset = 0; b->outbuf->datas[0].chunk->offset = 0;
b->outbuf->datas[0].chunk->size = n_bytes; b->outbuf->datas[0].chunk->size = n_bytes;
@ -264,7 +254,7 @@ consume_buffer (struct impl *this)
this->buffer_count++; this->buffer_count++;
this->elapsed_time = this->buffer_count; this->elapsed_time = this->buffer_count;
set_timer (this, true); set_timer(this, true);
io->buffer_id = b->outbuf->id; io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_NEED_BUFFER; io->status = SPA_RESULT_NEED_BUFFER;
@ -273,26 +263,23 @@ consume_buffer (struct impl *this)
return SPA_RESULT_NEED_BUFFER; return SPA_RESULT_NEED_BUFFER;
} }
static void static void on_input(struct spa_source *source)
on_input (struct spa_source *source)
{ {
struct impl *this = source->data; struct impl *this = source->data;
consume_buffer (this); consume_buffer(this);
} }
static int static int impl_node_send_command(struct spa_node *node, struct spa_command *command)
impl_node_send_command (struct spa_node *node,
struct spa_command *command)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) { if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
struct timespec now; struct timespec now;
if (!this->have_format) if (!this->have_format)
@ -304,18 +291,17 @@ impl_node_send_command (struct spa_node *node,
if (this->started) if (this->started)
return SPA_RESULT_OK; return SPA_RESULT_OK;
clock_gettime (CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
if (this->props.live) if (this->props.live)
this->start_time = SPA_TIMESPEC_TO_TIME (&now); this->start_time = SPA_TIMESPEC_TO_TIME(&now);
else else
this->start_time = 0; this->start_time = 0;
this->buffer_count = 0; this->buffer_count = 0;
this->elapsed_time = 0; this->elapsed_time = 0;
this->started = true; this->started = true;
set_timer (this, true); set_timer(this, true);
} } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -326,28 +312,27 @@ impl_node_send_command (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
this->started = false; this->started = false;
set_timer (this, false); set_timer(this, false);
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_set_callbacks (struct spa_node *node, impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, const struct spa_node_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size,
void *user_data) void *user_data)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (this->data_loop == NULL && callbacks->need_input != NULL) { if (this->data_loop == NULL && callbacks->need_input != NULL) {
spa_log_error (this->log, "a data_loop is needed for async operation"); spa_log_error(this->log, "a data_loop is needed for async operation");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
this->callbacks = *callbacks; this->callbacks = *callbacks;
@ -357,13 +342,13 @@ impl_node_set_callbacks (struct spa_node *node,
} }
static int static int
impl_node_get_n_ports (struct spa_node *node, impl_node_get_n_ports(struct spa_node *node,
uint32_t *n_input_ports, uint32_t *n_input_ports,
uint32_t *max_input_ports, uint32_t *max_input_ports,
uint32_t *n_output_ports, uint32_t *n_output_ports,
uint32_t *max_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, SPA_RESULT_INVALID_ARGUMENTS);
if (n_input_ports) if (n_input_ports)
*n_input_ports = 0; *n_input_ports = 0;
@ -378,13 +363,13 @@ impl_node_get_n_ports (struct spa_node *node,
} }
static int static int
impl_node_get_port_ids (struct spa_node *node, impl_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports, uint32_t n_input_ports,
uint32_t *input_ids, uint32_t *input_ids,
uint32_t n_output_ports, uint32_t n_output_ports,
uint32_t *output_ids) uint32_t *output_ids)
{ {
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (n_output_ports > 0 && output_ids != NULL) if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0; output_ids[0] = 0;
@ -392,57 +377,50 @@ impl_node_get_port_ids (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
impl_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_remove_port (struct spa_node *node, impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_port_enum_formats (struct spa_node *node, impl_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_format **format, struct spa_format **format,
const struct spa_format *filter, const struct spa_format *filter, uint32_t index)
uint32_t index)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
static int static int clear_buffers(struct impl *this)
clear_buffers (struct impl *this)
{ {
if (this->n_buffers > 0) { if (this->n_buffers > 0) {
spa_log_info (this->log, NAME " %p: clear buffers", this); spa_log_info(this->log, NAME " %p: clear buffers", this);
this->n_buffers = 0; this->n_buffers = 0;
spa_list_init (&this->ready); spa_list_init(&this->ready);
this->started = false; this->started = false;
set_timer (this, false); set_timer(this, false);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_format (struct spa_node *node, impl_node_port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t flags, uint32_t flags,
@ -450,38 +428,38 @@ impl_node_port_set_format (struct spa_node *node,
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (format == NULL) { if (format == NULL) {
this->have_format = false; this->have_format = false;
clear_buffers (this); clear_buffers(this);
} else { } else {
if (SPA_POD_SIZE (format) > sizeof (this->format_buffer)) if (SPA_POD_SIZE(format) > sizeof(this->format_buffer))
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
memcpy (this->format_buffer, format, SPA_POD_SIZE (format)); memcpy(this->format_buffer, format, SPA_POD_SIZE(format));
this->have_format = true; this->have_format = true;
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_get_format (struct spa_node *node, impl_node_port_get_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_format **format) const struct spa_format **format)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -492,19 +470,19 @@ impl_node_port_get_format (struct spa_node *node,
} }
static int static int
impl_node_port_get_info (struct spa_node *node, impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_port_info **info) const struct spa_port_info **info)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
*info = &this->info; *info = &this->info;
@ -512,7 +490,7 @@ impl_node_port_get_info (struct spa_node *node,
} }
static int static int
impl_node_port_enum_params (struct spa_node *node, impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t index, uint32_t index,
@ -522,40 +500,47 @@ impl_node_port_enum_params (struct spa_node *node,
struct spa_pod_builder b = { NULL }; struct spa_pod_builder b = { NULL };
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer)); spa_pod_builder_init(&b, this->params_buffer, sizeof(this->params_buffer));
switch (index) { switch (index) {
case 0: case 0:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_buffers.Buffers, spa_pod_builder_object(&b, &f[0], 0, this->type.param_alloc_buffers.Buffers,
PROP (&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT, 128), PROP(&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT,
PROP (&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT, 1), 128),
PROP_U_MM (&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32), PROP(&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT,
PROP (&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT, 16)); 1),
PROP_U_MM(&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT,
32,
2, 32),
PROP(&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT,
16));
break; break;
case 1: case 1:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable, spa_pod_builder_object(&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable,
PROP (&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header), PROP(&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID,
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (struct spa_meta_header))); this->type.meta.Header),
PROP(&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT,
sizeof(struct spa_meta_header)));
break; break;
default: default:
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_param); *param = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_param);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_param (struct spa_node *node, impl_node_port_set_param(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_param *param) const struct spa_param *param)
@ -564,7 +549,7 @@ impl_node_port_set_param (struct spa_node *node,
} }
static int static int
impl_node_port_use_buffers (struct spa_node *node, impl_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_buffer **buffers, struct spa_buffer **buffers,
@ -573,16 +558,16 @@ impl_node_port_use_buffers (struct spa_node *node,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
clear_buffers (this); clear_buffers(this);
for (i = 0; i < n_buffers; i++) { for (i = 0; i < n_buffers; i++) {
struct buffer *b; struct buffer *b;
@ -591,13 +576,13 @@ impl_node_port_use_buffers (struct spa_node *node,
b = &this->buffers[i]; b = &this->buffers[i];
b->outbuf = buffers[i]; b->outbuf = buffers[i];
b->outstanding = true; b->outstanding = true;
b->h = spa_buffer_find_meta (buffers[i], this->type.meta.Header); b->h = spa_buffer_find_meta(buffers[i], this->type.meta.Header);
if ((d[0].type == this->type.data.MemPtr || if ((d[0].type == this->type.data.MemPtr ||
d[0].type == this->type.data.MemFd || d[0].type == this->type.data.MemFd ||
d[0].type == this->type.data.DmaBuf) && d[0].type == this->type.data.DmaBuf) && d[0].data == NULL) {
d[0].data == NULL) { spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
spa_log_error (this->log, NAME " %p: invalid memory on buffer %p", this, buffers[i]); buffers[i]);
} }
} }
this->n_buffers = n_buffers; this->n_buffers = n_buffers;
@ -606,7 +591,7 @@ impl_node_port_use_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_alloc_buffers (struct spa_node *node, impl_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_param **params, struct spa_param **params,
@ -616,11 +601,11 @@ impl_node_port_alloc_buffers (struct spa_node *node,
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -629,34 +614,31 @@ impl_node_port_alloc_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_set_io (struct spa_node *node, impl_node_port_set_io(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_port_io *io) struct spa_port_io *io)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT_NUM (this, direction, port_id), SPA_RESULT_INVALID_PORT); spa_return_val_if_fail(CHECK_PORT_NUM(this, direction, port_id), SPA_RESULT_INVALID_PORT);
this->io = io; this->io = io;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_port_send_command (struct spa_node *node, impl_node_port_send_command(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_command *command) struct spa_command *command)
@ -664,50 +646,48 @@ impl_node_port_send_command (struct spa_node *node,
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int impl_node_process_input(struct spa_node *node)
impl_node_process_input (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct spa_port_io *input; struct spa_port_io *input;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
input = this->io; input = this->io;
spa_return_val_if_fail (input != NULL, SPA_RESULT_WRONG_STATE); spa_return_val_if_fail(input != NULL, SPA_RESULT_WRONG_STATE);
if (input->status == SPA_RESULT_HAVE_BUFFER && if (input->status == SPA_RESULT_HAVE_BUFFER && input->buffer_id != SPA_ID_INVALID) {
input->buffer_id != SPA_ID_INVALID) {
struct buffer *b = &this->buffers[input->buffer_id]; struct buffer *b = &this->buffers[input->buffer_id];
if (!b->outstanding) { if (!b->outstanding) {
spa_log_warn (this->log, NAME " %p: buffer %u in use", this, input->buffer_id); spa_log_warn(this->log, NAME " %p: buffer %u in use", this,
input->buffer_id);
input->status = SPA_RESULT_INVALID_BUFFER_ID; input->status = SPA_RESULT_INVALID_BUFFER_ID;
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
spa_log_trace (this->log, NAME " %p: queue buffer %u", this, input->buffer_id); spa_log_trace(this->log, NAME " %p: queue buffer %u", this, input->buffer_id);
spa_list_insert (this->ready.prev, &b->link); spa_list_insert(this->ready.prev, &b->link);
b->outstanding = false; b->outstanding = false;
input->buffer_id = SPA_ID_INVALID; input->buffer_id = SPA_ID_INVALID;
input->status = SPA_RESULT_OK; input->status = SPA_RESULT_OK;
} }
if (this->callbacks.need_input == NULL) if (this->callbacks.need_input == NULL)
return consume_buffer (this); return consume_buffer(this);
else else
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_process_output(struct spa_node *node)
impl_node_process_output (struct spa_node *node)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static const struct spa_node impl_node = { static const struct spa_node impl_node = {
sizeof (struct spa_node), sizeof(struct spa_node),
NULL, NULL,
impl_node_get_props, impl_node_get_props,
impl_node_set_props, impl_node_set_props,
@ -732,22 +712,18 @@ static const struct spa_node impl_node = {
impl_node_process_output, impl_node_process_output,
}; };
static int static int impl_clock_get_props(struct spa_clock *clock, struct spa_props **props)
impl_clock_get_props (struct spa_clock *clock, {
struct spa_props **props) return SPA_RESULT_NOT_IMPLEMENTED;
}
static int impl_clock_set_props(struct spa_clock *clock, const struct spa_props *props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_clock_set_props (struct spa_clock *clock, impl_clock_get_time(struct spa_clock *clock,
const struct spa_props *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
impl_clock_get_time (struct spa_clock *clock,
int32_t *rate, int32_t *rate,
int64_t *ticks, int64_t *ticks,
int64_t *monotonic_time) int64_t *monotonic_time)
@ -755,13 +731,13 @@ impl_clock_get_time (struct spa_clock *clock,
struct timespec now; struct timespec now;
uint64_t tnow; uint64_t tnow;
spa_return_val_if_fail (clock != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(clock != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (rate) if (rate)
*rate = SPA_NSEC_PER_SEC; *rate = SPA_NSEC_PER_SEC;
clock_gettime (CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
tnow = SPA_TIMESPEC_TO_TIME (&now); tnow = SPA_TIMESPEC_TO_TIME(&now);
if (ticks) if (ticks)
*ticks = tnow; *ticks = tnow;
@ -772,7 +748,7 @@ impl_clock_get_time (struct spa_clock *clock,
} }
static const struct spa_clock impl_clock = { static const struct spa_clock impl_clock = {
sizeof (struct spa_clock), sizeof(struct spa_clock),
NULL, NULL,
SPA_CLOCK_STATE_STOPPED, SPA_CLOCK_STATE_STOPPED,
impl_clock_get_props, impl_clock_get_props,
@ -780,15 +756,12 @@ static const struct spa_clock impl_clock = {
impl_clock_get_time, impl_clock_get_time,
}; };
static int static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
@ -802,24 +775,23 @@ impl_get_interface (struct spa_handle *handle,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_clear(struct spa_handle *handle)
impl_clear (struct spa_handle *handle)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
if (this->data_loop) if (this->data_loop)
spa_loop_remove_source (this->data_loop, &this->timer_source); spa_loop_remove_source(this->data_loop, &this->timer_source);
close (this->timer_source.fd); close(this->timer_source.fd);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_init (const struct spa_handle_factory *factory, impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -828,8 +800,8 @@ impl_init (const struct spa_handle_factory *factory,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface; handle->get_interface = impl_get_interface;
handle->clear = impl_clear; handle->clear = impl_clear;
@ -837,28 +809,28 @@ impl_init (const struct spa_handle_factory *factory,
this = (struct impl *) handle; this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
this->data_loop = support[i].data; this->data_loop = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed"); spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
init_type (&this->type, this->map); init_type(&this->type, this->map);
this->node = impl_node; this->node = impl_node;
this->clock = impl_clock; this->clock = impl_clock;
reset_props (this, &this->props); reset_props(this, &this->props);
spa_list_init (&this->ready); spa_list_init(&this->ready);
this->timer_source.func = on_input; this->timer_source.func = on_input;
this->timer_source.data = this; this->timer_source.data = this;
this->timer_source.fd = timerfd_create (CLOCK_MONOTONIC, TFD_CLOEXEC); this->timer_source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
this->timer_source.mask = SPA_IO_IN; this->timer_source.mask = SPA_IO_IN;
this->timer_source.rmask = 0; this->timer_source.rmask = 0;
this->timerspec.it_value.tv_sec = 0; this->timerspec.it_value.tv_sec = 0;
@ -867,31 +839,29 @@ impl_init (const struct spa_handle_factory *factory,
this->timerspec.it_interval.tv_nsec = 0; this->timerspec.it_interval.tv_nsec = 0;
if (this->data_loop) if (this->data_loop)
spa_loop_add_source (this->data_loop, &this->timer_source); spa_loop_add_source(this->data_loop, &this->timer_source);
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | SPA_PORT_INFO_FLAG_NO_REF;
SPA_PORT_INFO_FLAG_NO_REF;
if (this->props.live) if (this->props.live)
this->info.flags |= SPA_PORT_INFO_FLAG_LIVE; this->info.flags |= SPA_PORT_INFO_FLAG_LIVE;
spa_log_info (this->log, NAME " %p: initialized", this); spa_log_info(this->log, NAME " %p: initialized", this);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static const struct spa_interface_info impl_interfaces[] = static const struct spa_interface_info impl_interfaces[] = {
{ {SPA_TYPE__Node,},
{ SPA_TYPE__Node, }, {SPA_TYPE__Clock,},
{ SPA_TYPE__Clock, },
}; };
static int static int
impl_enum_interface_info (const struct spa_handle_factory *factory, impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info, 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(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:
@ -903,10 +873,10 @@ impl_enum_interface_info (const struct spa_handle_factory *factory,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
const struct spa_handle_factory spa_fakesink_factory = const struct spa_handle_factory spa_fakesink_factory = {
{ NAME, NAME,
NULL, NULL,
sizeof (struct impl), sizeof(struct impl),
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };

View file

@ -50,21 +50,20 @@ struct type {
struct spa_type_param_alloc_meta_enable param_alloc_meta_enable; struct spa_type_param_alloc_meta_enable param_alloc_meta_enable;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->node = spa_type_map_get_id (map, SPA_TYPE__Node); type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
type->clock = spa_type_map_get_id (map, SPA_TYPE__Clock); type->clock = spa_type_map_get_id(map, SPA_TYPE__Clock);
type->format = spa_type_map_get_id (map, SPA_TYPE__Format); type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id (map, SPA_TYPE__Props); type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_live = spa_type_map_get_id (map, SPA_TYPE_PROPS__live); type->prop_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live);
type->prop_pattern = spa_type_map_get_id (map, SPA_TYPE_PROPS__patternType); type->prop_pattern = spa_type_map_get_id(map, SPA_TYPE_PROPS__patternType);
spa_type_meta_map (map, &type->meta); spa_type_meta_map(map, &type->meta);
spa_type_data_map (map, &type->data); spa_type_data_map(map, &type->data);
spa_type_event_node_map (map, &type->event_node); spa_type_event_node_map(map, &type->event_node);
spa_type_command_node_map (map, &type->command_node); spa_type_command_node_map(map, &type->command_node);
spa_type_param_alloc_buffers_map (map, &type->param_alloc_buffers); spa_type_param_alloc_buffers_map(map, &type->param_alloc_buffers);
spa_type_param_alloc_meta_enable_map (map, &type->param_alloc_meta_enable); spa_type_param_alloc_meta_enable_map(map, &type->param_alloc_meta_enable);
} }
struct props { struct props {
@ -126,8 +125,7 @@ struct impl {
#define DEFAULT_LIVE false #define DEFAULT_LIVE false
#define DEFAULT_PATTERN 0 #define DEFAULT_PATTERN 0
static void static void reset_props(struct impl *this, struct props *props)
reset_props (struct impl *this, struct props *props)
{ {
props->live = DEFAULT_LIVE; props->live = DEFAULT_LIVE;
props->pattern = DEFAULT_PATTERN; props->pattern = DEFAULT_PATTERN;
@ -146,48 +144,44 @@ reset_props (struct impl *this, struct props *props)
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \ SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__) SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
static int static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
impl_node_get_props (struct spa_node *node,
struct spa_props **props)
{ {
struct impl *this; struct impl *this;
struct spa_pod_builder b = { NULL, }; struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (props != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(props != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer)); spa_pod_builder_init(&b, this->props_buffer, sizeof(this->props_buffer));
spa_pod_builder_props (&b, &f[0], this->type.props, spa_pod_builder_props(&b, &f[0], this->type.props,
PROP (&f[1], this->type.prop_live, SPA_POD_TYPE_BOOL, this->props.live), PROP(&f[1], this->type.prop_live, SPA_POD_TYPE_BOOL,
PROP_EN (&f[1], this->type.prop_pattern, SPA_POD_TYPE_ID, 1, this->props.live),
PROP_EN(&f[1], this->type.prop_pattern, SPA_POD_TYPE_ID, 1,
this->props.pattern, this->props.pattern,
this->props.pattern)); this->props.pattern));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_props); *props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_set_props(struct spa_node *node, const struct spa_props *props)
impl_node_set_props (struct spa_node *node,
const struct spa_props *props)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (props == NULL) { if (props == NULL) {
reset_props (this, &this->props); reset_props(this, &this->props);
} else { } else {
spa_props_query (props, spa_props_query(props,
this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live, this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live,
this->type.prop_pattern, SPA_POD_TYPE_ID, &this->props.pattern, this->type.prop_pattern, SPA_POD_TYPE_ID, &this->props.pattern, 0);
0);
} }
if (this->props.live) if (this->props.live)
@ -198,14 +192,12 @@ impl_node_set_props (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int fill_buffer(struct impl *this, struct buffer *b)
fill_buffer (struct impl *this, struct buffer *b)
{ {
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static void static void set_timer(struct impl *this, bool enabled)
set_timer (struct impl *this, bool enabled)
{ {
if (this->callbacks.have_output || this->props.live) { if (this->callbacks.have_output || this->props.live) {
if (enabled) { if (enabled) {
@ -221,45 +213,43 @@ set_timer (struct impl *this, bool enabled)
this->timerspec.it_value.tv_sec = 0; this->timerspec.it_value.tv_sec = 0;
this->timerspec.it_value.tv_nsec = 0; this->timerspec.it_value.tv_nsec = 0;
} }
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL); timerfd_settime(this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
} }
} }
static inline void static inline void read_timer(struct impl *this)
read_timer (struct impl *this)
{ {
uint64_t expirations; uint64_t expirations;
if (this->callbacks.have_output || this->props.live) { if (this->callbacks.have_output || this->props.live) {
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t)) if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) < sizeof(uint64_t))
perror ("read timerfd"); perror("read timerfd");
} }
} }
static int static int make_buffer(struct impl *this)
make_buffer (struct impl *this)
{ {
struct buffer *b; struct buffer *b;
struct spa_port_io *io = this->io; struct spa_port_io *io = this->io;
int n_bytes; int n_bytes;
read_timer (this); read_timer(this);
if (spa_list_is_empty (&this->empty)) { if (spa_list_is_empty(&this->empty)) {
set_timer (this, false); set_timer(this, false);
this->underrun = true; this->underrun = true;
spa_log_error (this->log, NAME " %p: out of buffers", this); spa_log_error(this->log, NAME " %p: out of buffers", this);
return SPA_RESULT_OUT_OF_BUFFERS; return SPA_RESULT_OUT_OF_BUFFERS;
} }
b = spa_list_first (&this->empty, struct buffer, link); b = spa_list_first(&this->empty, struct buffer, link);
spa_list_remove (&b->link); spa_list_remove(&b->link);
b->outstanding = true; b->outstanding = true;
n_bytes = b->outbuf->datas[0].maxsize; n_bytes = b->outbuf->datas[0].maxsize;
spa_log_trace (this->log, NAME " %p: dequeue buffer %d", this, b->outbuf->id); spa_log_trace(this->log, NAME " %p: dequeue buffer %d", this, b->outbuf->id);
fill_buffer (this, b); fill_buffer(this, b);
b->outbuf->datas[0].chunk->offset = 0; b->outbuf->datas[0].chunk->offset = 0;
b->outbuf->datas[0].chunk->size = n_bytes; b->outbuf->datas[0].chunk->size = n_bytes;
@ -273,7 +263,7 @@ make_buffer (struct impl *this)
this->buffer_count++; this->buffer_count++;
this->elapsed_time = this->buffer_count; this->elapsed_time = this->buffer_count;
set_timer (this, true); set_timer(this, true);
io->buffer_id = b->outbuf->id; io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_HAVE_BUFFER; io->status = SPA_RESULT_HAVE_BUFFER;
@ -281,30 +271,27 @@ make_buffer (struct impl *this)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
} }
static void static void on_output(struct spa_source *source)
on_output (struct spa_source *source)
{ {
struct impl *this = source->data; struct impl *this = source->data;
int res; int res;
res = make_buffer (this); res = make_buffer(this);
if (res == SPA_RESULT_HAVE_BUFFER && this->callbacks.have_output) if (res == SPA_RESULT_HAVE_BUFFER && this->callbacks.have_output)
this->callbacks.have_output (&this->node, this->user_data); this->callbacks.have_output(&this->node, this->user_data);
} }
static int static int impl_node_send_command(struct spa_node *node, struct spa_command *command)
impl_node_send_command (struct spa_node *node,
struct spa_command *command)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) { if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
struct timespec now; struct timespec now;
if (!this->have_format) if (!this->have_format)
@ -316,18 +303,17 @@ impl_node_send_command (struct spa_node *node,
if (this->started) if (this->started)
return SPA_RESULT_OK; return SPA_RESULT_OK;
clock_gettime (CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
if (this->props.live) if (this->props.live)
this->start_time = SPA_TIMESPEC_TO_TIME (&now); this->start_time = SPA_TIMESPEC_TO_TIME(&now);
else else
this->start_time = 0; this->start_time = 0;
this->buffer_count = 0; this->buffer_count = 0;
this->elapsed_time = 0; this->elapsed_time = 0;
this->started = true; this->started = true;
set_timer (this, true); set_timer(this, true);
} } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -338,28 +324,27 @@ impl_node_send_command (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
this->started = false; this->started = false;
set_timer (this, false); set_timer(this, false);
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_set_callbacks (struct spa_node *node, impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, const struct spa_node_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size,
void *user_data) void *user_data)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (this->data_loop == NULL && callbacks->have_output != NULL) { if (this->data_loop == NULL && callbacks->have_output != NULL) {
spa_log_error (this->log, "a data_loop is needed for async operation"); spa_log_error(this->log, "a data_loop is needed for async operation");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
this->callbacks = *callbacks; this->callbacks = *callbacks;
@ -369,13 +354,13 @@ impl_node_set_callbacks (struct spa_node *node,
} }
static int static int
impl_node_get_n_ports (struct spa_node *node, impl_node_get_n_ports(struct spa_node *node,
uint32_t *n_input_ports, uint32_t *n_input_ports,
uint32_t *max_input_ports, uint32_t *max_input_ports,
uint32_t *n_output_ports, uint32_t *n_output_ports,
uint32_t *max_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, SPA_RESULT_INVALID_ARGUMENTS);
if (n_input_ports) if (n_input_ports)
*n_input_ports = 0; *n_input_ports = 0;
@ -390,13 +375,13 @@ impl_node_get_n_ports (struct spa_node *node,
} }
static int static int
impl_node_get_port_ids (struct spa_node *node, impl_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports, uint32_t n_input_ports,
uint32_t *input_ids, uint32_t *input_ids,
uint32_t n_output_ports, uint32_t n_output_ports,
uint32_t *output_ids) uint32_t *output_ids)
{ {
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (n_output_ports > 0 && output_ids != NULL) if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0; output_ids[0] = 0;
@ -404,24 +389,19 @@ impl_node_get_port_ids (struct spa_node *node,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
impl_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_remove_port (struct spa_node *node, impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_port_enum_formats (struct spa_node *node, impl_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_format **format, struct spa_format **format,
@ -430,31 +410,30 @@ impl_node_port_enum_formats (struct spa_node *node,
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
static int static int clear_buffers(struct impl *this)
clear_buffers (struct impl *this)
{ {
if (this->n_buffers > 0) { if (this->n_buffers > 0) {
spa_log_info (this->log, NAME " %p: clear buffers", this); spa_log_info(this->log, NAME " %p: clear buffers", this);
this->n_buffers = 0; this->n_buffers = 0;
spa_list_init (&this->empty); spa_list_init(&this->empty);
this->started = false; this->started = false;
set_timer (this, false); set_timer(this, false);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_format (struct spa_node *node, impl_node_port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t flags, uint32_t flags,
@ -462,19 +441,19 @@ impl_node_port_set_format (struct spa_node *node,
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (format == NULL) { if (format == NULL) {
this->have_format = false; this->have_format = false;
clear_buffers (this); clear_buffers(this);
} else { } else {
if (SPA_POD_SIZE (format) > sizeof (this->format_buffer)) if (SPA_POD_SIZE(format) > sizeof(this->format_buffer))
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
memcpy (this->format_buffer, format, SPA_POD_SIZE (format)); memcpy(this->format_buffer, format, SPA_POD_SIZE(format));
this->have_format = true; this->have_format = true;
} }
@ -485,19 +464,19 @@ impl_node_port_set_format (struct spa_node *node,
} }
static int static int
impl_node_port_get_format (struct spa_node *node, impl_node_port_get_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_format **format) const struct spa_format **format)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -508,19 +487,19 @@ impl_node_port_get_format (struct spa_node *node,
} }
static int static int
impl_node_port_get_info (struct spa_node *node, impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_port_info **info) const struct spa_port_info **info)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
*info = &this->info; *info = &this->info;
@ -528,7 +507,7 @@ impl_node_port_get_info (struct spa_node *node,
} }
static int static int
impl_node_port_enum_params (struct spa_node *node, impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t index, uint32_t index,
@ -538,40 +517,47 @@ impl_node_port_enum_params (struct spa_node *node,
struct spa_pod_builder b = { NULL }; struct spa_pod_builder b = { NULL };
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer)); spa_pod_builder_init(&b, this->params_buffer, sizeof(this->params_buffer));
switch (index) { switch (index) {
case 0: case 0:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_buffers.Buffers, spa_pod_builder_object(&b, &f[0], 0, this->type.param_alloc_buffers.Buffers,
PROP (&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT, 128), PROP(&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT,
PROP (&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT, 1), 128),
PROP_U_MM (&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32), PROP(&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT,
PROP (&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT, 16)); 1),
PROP_U_MM(&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT,
32,
2, 32),
PROP(&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT,
16));
break; break;
case 1: case 1:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable, spa_pod_builder_object(&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable,
PROP (&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header), PROP(&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID,
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (struct spa_meta_header))); this->type.meta.Header),
PROP(&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT,
sizeof(struct spa_meta_header)));
break; break;
default: default:
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_param); *param = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_param);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_param (struct spa_node *node, impl_node_port_set_param(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_param *param) const struct spa_param *param)
@ -580,7 +566,7 @@ impl_node_port_set_param (struct spa_node *node,
} }
static int static int
impl_node_port_use_buffers (struct spa_node *node, impl_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_buffer **buffers, struct spa_buffer **buffers,
@ -589,16 +575,16 @@ impl_node_port_use_buffers (struct spa_node *node,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
clear_buffers (this); clear_buffers(this);
for (i = 0; i < n_buffers; i++) { for (i = 0; i < n_buffers; i++) {
struct buffer *b; struct buffer *b;
@ -607,15 +593,15 @@ impl_node_port_use_buffers (struct spa_node *node,
b = &this->buffers[i]; b = &this->buffers[i];
b->outbuf = buffers[i]; b->outbuf = buffers[i];
b->outstanding = false; b->outstanding = false;
b->h = spa_buffer_find_meta (buffers[i], this->type.meta.Header); b->h = spa_buffer_find_meta(buffers[i], this->type.meta.Header);
if ((d[0].type == this->type.data.MemPtr || if ((d[0].type == this->type.data.MemPtr ||
d[0].type == this->type.data.MemFd || d[0].type == this->type.data.MemFd ||
d[0].type == this->type.data.DmaBuf) && d[0].type == this->type.data.DmaBuf) && d[0].data == NULL) {
d[0].data == NULL) { spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
spa_log_error (this->log, NAME " %p: invalid memory on buffer %p", this, buffers[i]); buffers[i]);
} }
spa_list_insert (this->empty.prev, &b->link); spa_list_insert(this->empty.prev, &b->link);
} }
this->n_buffers = n_buffers; this->n_buffers = n_buffers;
this->underrun = false; this->underrun = false;
@ -624,21 +610,21 @@ impl_node_port_use_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_alloc_buffers (struct spa_node *node, impl_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_param **params, struct spa_param **params,
uint32_t n_params, uint32_t n_params,
struct spa_buffer **buffers, struct spa_buffer **buffers,
uint32_t *n_buffers) uint32_t * n_buffers)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
if (!this->have_format) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -647,63 +633,59 @@ impl_node_port_alloc_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_set_io (struct spa_node *node, impl_node_port_set_io(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_port_io *io) struct spa_port_io *io)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT_NUM (this, direction, port_id), SPA_RESULT_INVALID_PORT); spa_return_val_if_fail(CHECK_PORT_NUM(this, direction, port_id), SPA_RESULT_INVALID_PORT);
this->io = io; this->io = io;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static inline void static inline void reuse_buffer(struct impl *this, uint32_t id)
reuse_buffer (struct impl *this, uint32_t id)
{ {
struct buffer *b = &this->buffers[id]; struct buffer *b = &this->buffers[id];
spa_return_if_fail (b->outstanding); spa_return_if_fail(b->outstanding);
spa_log_trace (this->log, NAME " %p: reuse buffer %d", this, id); spa_log_trace(this->log, NAME " %p: reuse buffer %d", this, id);
b->outstanding = false; b->outstanding = false;
spa_list_insert (this->empty.prev, &b->link); spa_list_insert(this->empty.prev, &b->link);
if (this->underrun) { if (this->underrun) {
set_timer (this, true); set_timer(this, true);
this->underrun = false; this->underrun = false;
} }
} }
static int static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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(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(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(buffer_id < this->n_buffers, SPA_RESULT_INVALID_BUFFER_ID);
reuse_buffer (this, buffer_id); reuse_buffer(this, buffer_id);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_send_command (struct spa_node *node, impl_node_port_send_command(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_command *command) struct spa_command *command)
@ -711,40 +693,38 @@ impl_node_port_send_command (struct spa_node *node,
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int impl_node_process_input(struct spa_node *node)
impl_node_process_input (struct spa_node *node)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int impl_node_process_output(struct spa_node *node)
impl_node_process_output (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct spa_port_io *io; struct spa_port_io *io;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
io = this->io; io = this->io;
spa_return_val_if_fail (io != NULL, SPA_RESULT_WRONG_STATE); spa_return_val_if_fail(io != NULL, SPA_RESULT_WRONG_STATE);
if (io->status == SPA_RESULT_HAVE_BUFFER) if (io->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
if (io->buffer_id != SPA_ID_INVALID) { if (io->buffer_id != SPA_ID_INVALID) {
reuse_buffer (this, this->io->buffer_id); reuse_buffer(this, this->io->buffer_id);
this->io->buffer_id = SPA_ID_INVALID; this->io->buffer_id = SPA_ID_INVALID;
} }
if (this->callbacks.have_output == NULL && (io->status == SPA_RESULT_NEED_BUFFER)) if (this->callbacks.have_output == NULL && (io->status == SPA_RESULT_NEED_BUFFER))
return make_buffer (this); return make_buffer(this);
else else
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static const struct spa_node impl_node = { static const struct spa_node impl_node = {
sizeof (struct spa_node), sizeof(struct spa_node),
NULL, NULL,
impl_node_get_props, impl_node_get_props,
impl_node_set_props, impl_node_set_props,
@ -769,22 +749,18 @@ static const struct spa_node impl_node = {
impl_node_process_output, impl_node_process_output,
}; };
static int static int impl_clock_get_props(struct spa_clock *clock, struct spa_props **props)
impl_clock_get_props (struct spa_clock *clock, {
struct spa_props **props) return SPA_RESULT_NOT_IMPLEMENTED;
}
static int impl_clock_set_props(struct spa_clock *clock, const struct spa_props *props)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_clock_set_props (struct spa_clock *clock, impl_clock_get_time(struct spa_clock *clock,
const struct spa_props *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
impl_clock_get_time (struct spa_clock *clock,
int32_t *rate, int32_t *rate,
int64_t *ticks, int64_t *ticks,
int64_t *monotonic_time) int64_t *monotonic_time)
@ -792,13 +768,13 @@ impl_clock_get_time (struct spa_clock *clock,
struct timespec now; struct timespec now;
uint64_t tnow; uint64_t tnow;
spa_return_val_if_fail (clock != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(clock != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (rate) if (rate)
*rate = SPA_NSEC_PER_SEC; *rate = SPA_NSEC_PER_SEC;
clock_gettime (CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
tnow = SPA_TIMESPEC_TO_TIME (&now); tnow = SPA_TIMESPEC_TO_TIME(&now);
if (ticks) if (ticks)
*ticks = tnow; *ticks = tnow;
@ -809,7 +785,7 @@ impl_clock_get_time (struct spa_clock *clock,
} }
static const struct spa_clock impl_clock = { static const struct spa_clock impl_clock = {
sizeof (struct spa_clock), sizeof(struct spa_clock),
NULL, NULL,
SPA_CLOCK_STATE_STOPPED, SPA_CLOCK_STATE_STOPPED,
impl_clock_get_props, impl_clock_get_props,
@ -817,15 +793,12 @@ static const struct spa_clock impl_clock = {
impl_clock_get_time, impl_clock_get_time,
}; };
static int static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
@ -839,24 +812,23 @@ impl_get_interface (struct spa_handle *handle,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_clear(struct spa_handle *handle)
impl_clear (struct spa_handle *handle)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
if (this->data_loop) if (this->data_loop)
spa_loop_remove_source (this->data_loop, &this->timer_source); spa_loop_remove_source(this->data_loop, &this->timer_source);
close (this->timer_source.fd); close(this->timer_source.fd);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_init (const struct spa_handle_factory *factory, impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -865,8 +837,8 @@ impl_init (const struct spa_handle_factory *factory,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface; handle->get_interface = impl_get_interface;
handle->clear = impl_clear; handle->clear = impl_clear;
@ -874,28 +846,28 @@ impl_init (const struct spa_handle_factory *factory,
this = (struct impl *) handle; this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
this->data_loop = support[i].data; this->data_loop = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed"); spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
init_type (&this->type, this->map); init_type(&this->type, this->map);
this->node = impl_node; this->node = impl_node;
this->clock = impl_clock; this->clock = impl_clock;
reset_props (this, &this->props); reset_props(this, &this->props);
spa_list_init (&this->empty); spa_list_init(&this->empty);
this->timer_source.func = on_output; this->timer_source.func = on_output;
this->timer_source.data = this; this->timer_source.data = this;
this->timer_source.fd = timerfd_create (CLOCK_MONOTONIC, TFD_CLOEXEC); this->timer_source.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
this->timer_source.mask = SPA_IO_IN; this->timer_source.mask = SPA_IO_IN;
this->timer_source.rmask = 0; this->timer_source.rmask = 0;
this->timerspec.it_value.tv_sec = 0; this->timerspec.it_value.tv_sec = 0;
@ -904,31 +876,29 @@ impl_init (const struct spa_handle_factory *factory,
this->timerspec.it_interval.tv_nsec = 0; this->timerspec.it_interval.tv_nsec = 0;
if (this->data_loop) if (this->data_loop)
spa_loop_add_source (this->data_loop, &this->timer_source); spa_loop_add_source(this->data_loop, &this->timer_source);
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | SPA_PORT_INFO_FLAG_NO_REF;
SPA_PORT_INFO_FLAG_NO_REF;
if (this->props.live) if (this->props.live)
this->info.flags |= SPA_PORT_INFO_FLAG_LIVE; this->info.flags |= SPA_PORT_INFO_FLAG_LIVE;
spa_log_info (this->log, NAME " %p: initialized", this); spa_log_info(this->log, NAME " %p: initialized", this);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static const struct spa_interface_info impl_interfaces[] = static const struct spa_interface_info impl_interfaces[] = {
{ {SPA_TYPE__Node,},
{ SPA_TYPE__Node, }, {SPA_TYPE__Clock,},
{ SPA_TYPE__Clock, },
}; };
static int static int
impl_enum_interface_info (const struct spa_handle_factory *factory, impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info, 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(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:
@ -940,10 +910,10 @@ impl_enum_interface_info (const struct spa_handle_factory *factory,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
const struct spa_handle_factory spa_fakesrc_factory = const struct spa_handle_factory spa_fakesrc_factory = {
{ NAME, NAME,
NULL, NULL,
sizeof (struct impl), sizeof(struct impl),
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };

View file

@ -24,11 +24,9 @@ extern const struct spa_handle_factory spa_fakesrc_factory;
extern const struct spa_handle_factory spa_fakesink_factory; extern const struct spa_handle_factory spa_fakesink_factory;
int int
spa_handle_factory_enum(const struct spa_handle_factory **factory, spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
uint32_t index)
{ {
spa_return_val_if_fail(factory != NULL, spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:

View file

@ -45,11 +45,10 @@ struct type {
struct spa_type_monitor monitor; struct spa_type_monitor monitor;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->handle_factory = spa_type_map_get_id (map, SPA_TYPE__HandleFactory); type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory);
spa_type_monitor_map (map, &type->monitor); spa_type_monitor_map(map, &type->monitor);
} }
struct impl { struct impl {
@ -64,7 +63,7 @@ struct impl {
struct spa_monitor_callbacks callbacks; struct spa_monitor_callbacks callbacks;
void *user_data; void *user_data;
struct udev* udev; struct udev *udev;
struct udev_monitor *umonitor; struct udev_monitor *umonitor;
struct udev_enumerate *enumerate; struct udev_enumerate *enumerate;
uint32_t index; uint32_t index;
@ -76,122 +75,131 @@ struct impl {
struct spa_source source; struct spa_source source;
}; };
static int static int impl_udev_open(struct impl *this)
impl_udev_open (struct impl *this)
{ {
if (this->udev != NULL) if (this->udev != NULL)
return SPA_RESULT_OK; return SPA_RESULT_OK;
this->udev = udev_new (); this->udev = udev_new();
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static void static void fill_item(struct impl *this, struct item *item, struct udev_device *udevice)
fill_item (struct impl *this, struct item *item, struct udev_device *udevice)
{ {
const char *str, *name; const char *str, *name;
struct spa_pod_builder b = { NULL, }; struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[3]; struct spa_pod_frame f[3];
if (item->udevice) if (item->udevice)
udev_device_unref (item->udevice); udev_device_unref(item->udevice);
item->udevice = udevice; item->udevice = udevice;
if (udevice == NULL) if (udevice == NULL)
return; return;
name = udev_device_get_property_value (item->udevice, "ID_V4L_PRODUCT"); name = udev_device_get_property_value(item->udevice, "ID_V4L_PRODUCT");
if (!(name && *name)) { if (!(name && *name)) {
name = udev_device_get_property_value (item->udevice, "ID_MODEL_FROM_DATABASE"); name = udev_device_get_property_value(item->udevice, "ID_MODEL_FROM_DATABASE");
if (!(name && *name)) { if (!(name && *name)) {
name = udev_device_get_property_value (item->udevice, "ID_MODEL_ENC"); name = udev_device_get_property_value(item->udevice, "ID_MODEL_ENC");
if (!(name && *name)) { if (!(name && *name)) {
name = udev_device_get_property_value (item->udevice, "ID_MODEL"); name = udev_device_get_property_value(item->udevice, "ID_MODEL");
} }
} }
} }
if (!(name && *name)) if (!(name && *name))
name = "Unknown"; name = "Unknown";
spa_pod_builder_init (&b, this->item_buffer, sizeof (this->item_buffer)); spa_pod_builder_init(&b, this->item_buffer, sizeof(this->item_buffer));
spa_pod_builder_push_object (&b, &f[0], 0, this->type.monitor.MonitorItem); spa_pod_builder_push_object(&b, &f[0], 0, this->type.monitor.MonitorItem);
spa_pod_builder_add (&b, spa_pod_builder_add(&b,
SPA_POD_PROP (&f[1], this->type.monitor.id, 0, SPA_POD_TYPE_STRING, 1, udev_device_get_syspath (item->udevice)), SPA_POD_PROP(&f[1], this->type.monitor.id, 0, SPA_POD_TYPE_STRING, 1,
SPA_POD_PROP (&f[1], this->type.monitor.flags, 0, SPA_POD_TYPE_INT, 1, 0), udev_device_get_syspath(item->udevice)),
SPA_POD_PROP (&f[1], this->type.monitor.state, 0, SPA_POD_TYPE_INT, 1, SPA_MONITOR_ITEM_STATE_AVAILABLE), SPA_POD_PROP(&f[1], this->type.monitor.flags, 0, SPA_POD_TYPE_INT, 1,
SPA_POD_PROP (&f[1], this->type.monitor.name, 0, SPA_POD_TYPE_STRING, 1, name), 0),
SPA_POD_PROP (&f[1], this->type.monitor.klass, 0, SPA_POD_TYPE_STRING, 1, "Video/Source"), SPA_POD_PROP(&f[1], this->type.monitor.state, 0, SPA_POD_TYPE_INT, 1,
SPA_POD_PROP (&f[1], this->type.monitor.factory, 0, SPA_POD_TYPE_POINTER, 1, this->type.handle_factory, SPA_MONITOR_ITEM_STATE_AVAILABLE),
&spa_v4l2_source_factory), SPA_POD_PROP(&f[1], this->type.monitor.name, 0, SPA_POD_TYPE_STRING, 1,
name),
SPA_POD_PROP(&f[1], this->type.monitor.klass, 0, SPA_POD_TYPE_STRING, 1,
"Video/Source"),
SPA_POD_PROP(&f[1], this->type.monitor.factory, 0, SPA_POD_TYPE_POINTER, 1,
this->type.handle_factory, &spa_v4l2_source_factory),
0); 0);
spa_pod_builder_add(&b,
spa_pod_builder_add (&b,
SPA_POD_TYPE_PROP, &f[1], this->type.monitor.info, 0, SPA_POD_TYPE_PROP, &f[1], this->type.monitor.info, 0,
SPA_POD_TYPE_STRUCT, 1, &f[2], 0); SPA_POD_TYPE_STRUCT, 1, &f[2], 0);
spa_pod_builder_add (&b, spa_pod_builder_add(&b,
SPA_POD_TYPE_STRING, "udev-probed", SPA_POD_TYPE_STRING, "1", SPA_POD_TYPE_STRING, "udev-probed", SPA_POD_TYPE_STRING, "1",
SPA_POD_TYPE_STRING, "device.api", SPA_POD_TYPE_STRING, "v4l2", SPA_POD_TYPE_STRING, "device.api", SPA_POD_TYPE_STRING, "v4l2",
SPA_POD_TYPE_STRING, "device.path", SPA_POD_TYPE_STRING, udev_device_get_devnode (item->udevice), SPA_POD_TYPE_STRING, "device.path", SPA_POD_TYPE_STRING,
0); udev_device_get_devnode(item->udevice), 0);
str = udev_device_get_property_value (item->udevice, "ID_PATH"); str = udev_device_get_property_value(item->udevice, "ID_PATH");
if (!(str && *str)) if (!(str && *str))
str = udev_device_get_syspath (item->udevice); str = udev_device_get_syspath(item->udevice);
if (str && *str) { if (str && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.bus_path", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.bus_path", SPA_POD_TYPE_STRING,
str, 0);
} }
if ((str = udev_device_get_syspath (item->udevice)) && *str) { if ((str = udev_device_get_syspath(item->udevice)) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "sysfs.path", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "sysfs.path", SPA_POD_TYPE_STRING,
str, 0);
} }
if ((str = udev_device_get_property_value (item->udevice, "ID_ID")) && *str) { if ((str = udev_device_get_property_value(item->udevice, "ID_ID")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "udev.id", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "udev.id", SPA_POD_TYPE_STRING,
str, 0);
} }
if ((str = udev_device_get_property_value (item->udevice, "ID_BUS")) && *str) { if ((str = udev_device_get_property_value(item->udevice, "ID_BUS")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.bus", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.bus", SPA_POD_TYPE_STRING,
str, 0);
} }
if ((str = udev_device_get_property_value (item->udevice, "SUBSYSTEM")) && *str) { if ((str = udev_device_get_property_value(item->udevice, "SUBSYSTEM")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.subsystem", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.subsystem",
SPA_POD_TYPE_STRING, str, 0);
} }
if ((str = udev_device_get_property_value (item->udevice, "ID_VENDOR_ID")) && *str) { if ((str = udev_device_get_property_value(item->udevice, "ID_VENDOR_ID")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.vendor.id", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.vendor.id",
SPA_POD_TYPE_STRING, str, 0);
} }
str = udev_device_get_property_value (item->udevice, "ID_VENDOR_FROM_DATABASE"); str = udev_device_get_property_value(item->udevice, "ID_VENDOR_FROM_DATABASE");
if (!(str && *str)) { if (!(str && *str)) {
str = udev_device_get_property_value (item->udevice, "ID_VENDOR_ENC"); str = udev_device_get_property_value(item->udevice, "ID_VENDOR_ENC");
if (!(str && *str)) { if (!(str && *str)) {
str = udev_device_get_property_value (item->udevice, "ID_VENDOR"); str = udev_device_get_property_value(item->udevice, "ID_VENDOR");
} }
} }
if (str && *str) { if (str && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.vendor.name", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.vendor.name",
SPA_POD_TYPE_STRING, str, 0);
} }
if ((str = udev_device_get_property_value (item->udevice, "ID_MODEL_ID")) && *str) { if ((str = udev_device_get_property_value(item->udevice, "ID_MODEL_ID")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.product.id", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.product.id",
SPA_POD_TYPE_STRING, str, 0);
} }
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.product.name", SPA_POD_TYPE_STRING, name, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.product.name", SPA_POD_TYPE_STRING,
if ((str = udev_device_get_property_value (item->udevice, "ID_SERIAL")) && *str) { name, 0);
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.serial", SPA_POD_TYPE_STRING, str, 0); if ((str = udev_device_get_property_value(item->udevice, "ID_SERIAL")) && *str) {
spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.serial", SPA_POD_TYPE_STRING,
str, 0);
} }
if ((str = udev_device_get_property_value (item->udevice, "ID_V4L_CAPABILITIES")) && *str) { if ((str = udev_device_get_property_value(item->udevice, "ID_V4L_CAPABILITIES")) && *str) {
spa_pod_builder_add (&b, SPA_POD_TYPE_STRING, "device.capabilities", SPA_POD_TYPE_STRING, str, 0); spa_pod_builder_add(&b, SPA_POD_TYPE_STRING, "device.capabilities",
SPA_POD_TYPE_STRING, str, 0);
} }
spa_pod_builder_add (&b, spa_pod_builder_add(&b, -SPA_POD_TYPE_STRUCT, &f[2], -SPA_POD_TYPE_PROP, &f[1], 0);
-SPA_POD_TYPE_STRUCT, &f[2],
-SPA_POD_TYPE_PROP, &f[1],
0);
spa_pod_builder_pop (&b, &f[0]); spa_pod_builder_pop(&b, &f[0]);
item->item = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_monitor_item); item->item = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_monitor_item);
} }
static void static void impl_on_fd_events(struct spa_source *source)
impl_on_fd_events (struct spa_source *source)
{ {
struct impl *this = source->data; struct impl *this = source->data;
struct udev_device *dev; struct udev_device *dev;
@ -202,121 +210,115 @@ impl_on_fd_events (struct spa_source *source)
struct spa_pod_frame f[1]; struct spa_pod_frame f[1];
uint8_t buffer[4096]; uint8_t buffer[4096];
dev = udev_monitor_receive_device (this->umonitor); dev = udev_monitor_receive_device(this->umonitor);
fill_item (this, &this->uitem, dev); fill_item(this, &this->uitem, dev);
if (dev == NULL) if (dev == NULL)
return; return;
if ((action = udev_device_get_action (dev)) == NULL) if ((action = udev_device_get_action(dev)) == NULL)
action = "change"; action = "change";
if (strcmp (action, "add") == 0) { if (strcmp(action, "add") == 0) {
type = this->type.monitor.Added; type = this->type.monitor.Added;
} else if (strcmp (action, "change") == 0) { } else if (strcmp(action, "change") == 0) {
type = this->type.monitor.Changed; type = this->type.monitor.Changed;
} else if (strcmp (action, "remove") == 0) { } else if (strcmp(action, "remove") == 0) {
type = this->type.monitor.Removed; type = this->type.monitor.Removed;
} else } else
return; return;
spa_pod_builder_init (&b, buffer, sizeof (buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
spa_pod_builder_object (&b, &f[0], 0, type, spa_pod_builder_object(&b, &f[0], 0, type, SPA_POD_TYPE_POD, this->uitem.item);
SPA_POD_TYPE_POD, this->uitem.item);
event = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_event); event = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_event);
this->callbacks.event (&this->monitor, event, this->user_data); this->callbacks.event(&this->monitor, event, this->user_data);
} }
static int static int
impl_monitor_set_callbacks (struct spa_monitor *monitor, impl_monitor_set_callbacks(struct spa_monitor *monitor,
const struct spa_monitor_callbacks *callbacks, const struct spa_monitor_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size, void *user_data)
void *user_data)
{ {
int res; int res;
struct impl *this; struct impl *this;
spa_return_val_if_fail (monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (monitor, struct impl, monitor); this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
if (callbacks) { if (callbacks) {
this->callbacks = *callbacks; this->callbacks = *callbacks;
this->user_data = user_data; this->user_data = user_data;
if ((res = impl_udev_open (this)) < 0) if ((res = impl_udev_open(this)) < 0)
return res; return res;
this->umonitor = udev_monitor_new_from_netlink (this->udev, "udev"); this->umonitor = udev_monitor_new_from_netlink(this->udev, "udev");
if (!this->umonitor) if (!this->umonitor)
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
udev_monitor_filter_add_match_subsystem_devtype (this->umonitor, udev_monitor_filter_add_match_subsystem_devtype(this->umonitor,
"video4linux", "video4linux", NULL);
NULL);
udev_monitor_enable_receiving (this->umonitor); udev_monitor_enable_receiving(this->umonitor);
this->source.func = impl_on_fd_events; this->source.func = impl_on_fd_events;
this->source.data = this; this->source.data = this;
this->source.fd = udev_monitor_get_fd (this->umonitor);; this->source.fd = udev_monitor_get_fd(this->umonitor);;
this->source.mask = SPA_IO_IN | SPA_IO_ERR; this->source.mask = SPA_IO_IN | SPA_IO_ERR;
spa_loop_add_source (this->main_loop, &this->source); spa_loop_add_source(this->main_loop, &this->source);
} else { } else {
spa_zero (this->callbacks); spa_zero(this->callbacks);
spa_loop_remove_source (this->main_loop, &this->source); spa_loop_remove_source(this->main_loop, &this->source);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_monitor_enum_items (struct spa_monitor *monitor, impl_monitor_enum_items(struct spa_monitor *monitor, struct spa_monitor_item **item, uint32_t index)
struct spa_monitor_item **item,
uint32_t index)
{ {
int res; int res;
struct impl *this; struct impl *this;
struct udev_device *dev; struct udev_device *dev;
spa_return_val_if_fail (monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(monitor != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (item != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(item != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (monitor, struct impl, monitor); this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
if ((res = impl_udev_open (this)) < 0) if ((res = impl_udev_open(this)) < 0)
return res; return res;
if (index == 0) { if (index == 0) {
if (this->enumerate) if (this->enumerate)
udev_enumerate_unref (this->enumerate); udev_enumerate_unref(this->enumerate);
this->enumerate = udev_enumerate_new (this->udev); this->enumerate = udev_enumerate_new(this->udev);
udev_enumerate_add_match_subsystem (this->enumerate, "video4linux"); udev_enumerate_add_match_subsystem(this->enumerate, "video4linux");
udev_enumerate_scan_devices (this->enumerate); udev_enumerate_scan_devices(this->enumerate);
this->devices = udev_enumerate_get_list_entry (this->enumerate); this->devices = udev_enumerate_get_list_entry(this->enumerate);
this->index = 0; this->index = 0;
} }
while (index > this->index && this->devices) { while (index > this->index && this->devices) {
this->devices = udev_list_entry_get_next (this->devices); this->devices = udev_list_entry_get_next(this->devices);
this->index++; this->index++;
} }
if (this->devices == NULL) { if (this->devices == NULL) {
fill_item (this, &this->uitem, NULL); fill_item(this, &this->uitem, NULL);
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
dev = udev_device_new_from_syspath (this->udev, dev = udev_device_new_from_syspath(this->udev, udev_list_entry_get_name(this->devices));
udev_list_entry_get_name (this->devices));
fill_item (this, &this->uitem, dev); fill_item(this, &this->uitem, dev);
if (dev == NULL) if (dev == NULL)
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*item = this->uitem.item; *item = this->uitem.item;
this->devices = udev_list_entry_get_next (this->devices); this->devices = udev_list_entry_get_next(this->devices);
this->index++; this->index++;
return SPA_RESULT_OK; return SPA_RESULT_OK;
@ -324,20 +326,17 @@ impl_monitor_enum_items (struct spa_monitor *monitor,
static const struct spa_monitor impl_monitor = { static const struct spa_monitor impl_monitor = {
NULL, NULL,
sizeof (struct spa_monitor), sizeof(struct spa_monitor),
impl_monitor_set_callbacks, impl_monitor_set_callbacks,
impl_monitor_enum_items, impl_monitor_enum_items,
}; };
static int static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
@ -349,14 +348,13 @@ impl_get_interface (struct spa_handle *handle,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_clear(struct spa_handle *handle)
impl_clear (struct spa_handle *handle)
{ {
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_init (const struct spa_handle_factory *factory, impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -365,61 +363,59 @@ impl_init (const struct spa_handle_factory *factory,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface; handle->get_interface = impl_get_interface;
handle->clear = impl_clear, handle->clear = impl_clear, this = (struct impl *) handle;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
this->main_loop = support[i].data; this->main_loop = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed"); spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
if (this->main_loop == NULL) { if (this->main_loop == NULL) {
spa_log_error (this->log, "a main-loop is needed"); spa_log_error(this->log, "a main-loop is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
init_type (&this->type, this->map); init_type(&this->type, this->map);
this->monitor = impl_monitor; this->monitor = impl_monitor;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static const struct spa_interface_info impl_interfaces[] = static const struct spa_interface_info impl_interfaces[] = {
{ {SPA_TYPE__Monitor,},
{ SPA_TYPE__Monitor, },
}; };
static int static int
impl_enum_interface_info (const struct spa_handle_factory *factory, impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info, 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(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (index < 0 || index >= SPA_N_ELEMENTS (impl_interfaces)) if (index < 0 || index >= SPA_N_ELEMENTS(impl_interfaces))
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*info = &impl_interfaces[index]; *info = &impl_interfaces[index];
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
const struct spa_handle_factory spa_v4l2_monitor_factory = const struct spa_handle_factory spa_v4l2_monitor_factory = {
{ NAME, NAME,
NULL, NULL,
sizeof (struct impl), sizeof(struct impl),
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -23,11 +23,9 @@
extern const struct spa_handle_factory spa_videotestsrc_factory; extern const struct spa_handle_factory spa_videotestsrc_factory;
int int
spa_handle_factory_enum(const struct spa_handle_factory **factory, spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index)
uint32_t index)
{ {
spa_return_val_if_fail(factory != NULL, spa_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:

File diff suppressed because it is too large Load diff

View file

@ -22,12 +22,9 @@
extern const struct spa_handle_factory spa_volume_factory; extern const struct spa_handle_factory spa_volume_factory;
int 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_return_val_if_fail(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:

View file

@ -78,24 +78,23 @@ struct type {
struct spa_type_param_alloc_meta_enable param_alloc_meta_enable; struct spa_type_param_alloc_meta_enable param_alloc_meta_enable;
}; };
static inline void static inline void init_type(struct type *type, struct spa_type_map *map)
init_type (struct type *type, struct spa_type_map *map)
{ {
type->node = spa_type_map_get_id (map, SPA_TYPE__Node); type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
type->format = spa_type_map_get_id (map, SPA_TYPE__Format); type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id (map, SPA_TYPE__Props); type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_volume = spa_type_map_get_id (map, SPA_TYPE_PROPS__volume); type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->prop_mute = spa_type_map_get_id (map, SPA_TYPE_PROPS__mute); type->prop_mute = spa_type_map_get_id(map, SPA_TYPE_PROPS__mute);
spa_type_meta_map (map, &type->meta); spa_type_meta_map(map, &type->meta);
spa_type_data_map (map, &type->data); spa_type_data_map(map, &type->data);
spa_type_media_type_map (map, &type->media_type); spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype); spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map (map, &type->format_audio); spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map (map, &type->audio_format); spa_type_audio_format_map(map, &type->audio_format);
spa_type_event_node_map (map, &type->event_node); spa_type_event_node_map(map, &type->event_node);
spa_type_command_node_map (map, &type->command_node); spa_type_command_node_map(map, &type->command_node);
spa_type_param_alloc_buffers_map (map, &type->param_alloc_buffers); spa_type_param_alloc_buffers_map(map, &type->param_alloc_buffers);
spa_type_param_alloc_meta_enable_map (map, &type->param_alloc_meta_enable); spa_type_param_alloc_meta_enable_map(map, &type->param_alloc_meta_enable);
} }
struct impl { struct impl {
@ -128,8 +127,7 @@ struct impl {
#define DEFAULT_VOLUME 1.0 #define DEFAULT_VOLUME 1.0
#define DEFAULT_MUTE false #define DEFAULT_MUTE false
static void static void reset_props(struct props *props)
reset_props (struct props *props)
{ {
props->volume = DEFAULT_VOLUME; props->volume = DEFAULT_VOLUME;
props->mute = DEFAULT_MUTE; props->mute = DEFAULT_MUTE;
@ -147,84 +145,77 @@ reset_props (struct props *props)
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__) SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
static int static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
impl_node_get_props (struct spa_node *node,
struct spa_props **props)
{ {
struct impl *this; struct impl *this;
struct spa_pod_builder b = { NULL, }; struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (props != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(props != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer)); spa_pod_builder_init(&b, this->props_buffer, sizeof(this->props_buffer));
spa_pod_builder_props (&b, &f[0], this->type.props, spa_pod_builder_props(&b, &f[0], this->type.props,
PROP_MM (&f[1], this->type.prop_volume, SPA_POD_TYPE_DOUBLE, this->props.volume, 0.0, 10.0), PROP_MM(&f[1], this->type.prop_volume, SPA_POD_TYPE_DOUBLE,
PROP (&f[1], this->type.prop_mute, SPA_POD_TYPE_BOOL, this->props.mute)); this->props.volume,
0.0, 10.0),
PROP(&f[1], this->type.prop_mute, SPA_POD_TYPE_BOOL,
this->props.mute));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_props); *props = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_props);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_set_props(struct spa_node *node, const struct spa_props *props)
impl_node_set_props (struct spa_node *node,
const struct spa_props *props)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (props == NULL) { if (props == NULL) {
reset_props (&this->props); reset_props(&this->props);
} else { } else {
spa_props_query (props, spa_props_query(props,
this->type.prop_volume, SPA_POD_TYPE_DOUBLE, &this->props.volume, this->type.prop_volume, SPA_POD_TYPE_DOUBLE, &this->props.volume,
this->type.prop_mute, SPA_POD_TYPE_BOOL, &this->props.mute, this->type.prop_mute, SPA_POD_TYPE_BOOL, &this->props.mute, 0);
0);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_node_send_command(struct spa_node *node, struct spa_command *command)
impl_node_send_command (struct spa_node *node,
struct spa_command *command)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) { if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
this->started = true; this->started = true;
} } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
this->started = false; this->started = false;
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_set_callbacks (struct spa_node *node, impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, const struct spa_node_callbacks *callbacks,
size_t callbacks_size, size_t callbacks_size, void *user_data)
void *user_data)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks; this->callbacks = *callbacks;
this->user_data = user_data; this->user_data = user_data;
@ -233,13 +224,13 @@ impl_node_set_callbacks (struct spa_node *node,
} }
static int static int
impl_node_get_n_ports (struct spa_node *node, impl_node_get_n_ports(struct spa_node *node,
uint32_t *n_input_ports, uint32_t *n_input_ports,
uint32_t *max_input_ports, uint32_t *max_input_ports,
uint32_t *n_output_ports, uint32_t *n_output_ports,
uint32_t *max_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, SPA_RESULT_INVALID_ARGUMENTS);
if (n_input_ports) if (n_input_ports)
*n_input_ports = 1; *n_input_ports = 1;
@ -254,13 +245,13 @@ impl_node_get_n_ports (struct spa_node *node,
} }
static int static int
impl_node_get_port_ids (struct spa_node *node, impl_node_get_port_ids(struct spa_node *node,
uint32_t n_input_ports, uint32_t n_input_ports,
uint32_t *input_ids, uint32_t *input_ids,
uint32_t n_output_ports, uint32_t n_output_ports,
uint32_t *output_ids) uint32_t *output_ids)
{ {
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
if (n_input_ports > 0 && input_ids) if (n_input_ports > 0 && input_ids)
input_ids[0] = 0; input_ids[0] = 0;
@ -271,24 +262,19 @@ impl_node_get_port_ids (struct spa_node *node,
} }
static int static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
impl_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_remove_port (struct spa_node *node, impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction,
uint32_t port_id)
{ {
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static int static int
impl_node_port_enum_formats (struct spa_node *node, impl_node_port_enum_formats(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_format **format, struct spa_format **format,
@ -303,57 +289,61 @@ impl_node_port_enum_formats (struct spa_node *node,
struct spa_pod_frame f[2]; struct spa_pod_frame f[2];
uint32_t count, match; uint32_t count, match;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
count = match = filter ? 0 : index; count = match = filter ? 0 : index;
next: next:
spa_pod_builder_init (&b, buffer, sizeof (buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (count++) { switch (count++) {
case 0: case 0:
spa_pod_builder_format (&b, &f[0], this->type.format, spa_pod_builder_format(&b, &f[0], this->type.format,
this->type.media_type.audio, this->type.media_subtype.raw, this->type.media_type.audio,
PROP_U_EN (&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID, 3, this->type.media_subtype.raw,
PROP_U_EN(&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID, 3,
this->type.audio_format.S16, this->type.audio_format.S16,
this->type.audio_format.S16, this->type.audio_format.S16,
this->type.audio_format.S32), this->type.audio_format.S32),
PROP_U_MM (&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX), PROP_U_MM(&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT,
PROP_U_MM (&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX)); 44100,
1, INT32_MAX),
PROP_U_MM(&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT,
2,
1, INT32_MAX));
break; break;
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
fmt = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_format); fmt = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer)); spa_pod_builder_init(&b, this->format_buffer, sizeof(this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index) if ((res = spa_format_filter(fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next; goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, struct spa_format); *format = SPA_POD_BUILDER_DEREF(&b, 0, struct spa_format);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int clear_buffers(struct impl *this, struct port *port)
clear_buffers (struct impl *this, struct port *port)
{ {
if (port->n_buffers > 0) { if (port->n_buffers > 0) {
spa_log_info (this->log, NAME " %p: clear buffers", this); spa_log_info(this->log, NAME " %p: clear buffers", this);
port->n_buffers = 0; port->n_buffers = 0;
spa_list_init (&port->empty); spa_list_init(&port->empty);
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_format (struct spa_node *node, impl_node_port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t flags, uint32_t flags,
@ -362,26 +352,28 @@ impl_node_port_set_format (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (format == NULL) { if (format == NULL) {
port->have_format = false; port->have_format = false;
clear_buffers (this, port); clear_buffers(this, port);
} else { } else {
struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE (format), struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE (format), }; SPA_FORMAT_MEDIA_SUBTYPE(format),
};
if (info.media_type != this->type.media_type.audio || if (info.media_type != this->type.media_type.audio ||
info.media_subtype != this->type.media_subtype.raw) info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio)) if (!spa_format_audio_raw_parse(format, &info.info.raw, &this->type.format_audio))
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
this->current_format = info; this->current_format = info;
@ -392,7 +384,7 @@ impl_node_port_set_format (struct spa_node *node,
} }
static int static int
impl_node_port_get_format (struct spa_node *node, impl_node_port_get_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_format **format) const struct spa_format **format)
@ -400,14 +392,15 @@ impl_node_port_get_format (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format) if (!port->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -418,7 +411,7 @@ impl_node_port_get_format (struct spa_node *node,
} }
static int static int
impl_node_port_get_info (struct spa_node *node, impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_port_info **info) const struct spa_port_info **info)
@ -426,21 +419,22 @@ impl_node_port_get_info (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
*info = &port->info; *info = &port->info;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_enum_params (struct spa_node *node, impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
uint32_t index, uint32_t index,
@ -451,43 +445,51 @@ impl_node_port_enum_params (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
spa_pod_builder_init (&b, port->params_buffer, sizeof (port->params_buffer)); spa_pod_builder_init(&b, port->params_buffer, sizeof(port->params_buffer));
switch (index) { switch (index) {
case 0: case 0:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_buffers.Buffers, spa_pod_builder_object(&b, &f[0], 0, this->type.param_alloc_buffers.Buffers,
PROP (&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT, 16), PROP(&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT,
PROP (&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT, 16), 16),
PROP_U_MM (&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT, MAX_BUFFERS, 2, MAX_BUFFERS), PROP(&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT,
PROP (&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT, 16)); 16),
PROP_U_MM(&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT,
MAX_BUFFERS,
2, MAX_BUFFERS),
PROP(&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT,
16));
break; break;
case 1: case 1:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable, spa_pod_builder_object(&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable,
PROP (&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header), PROP(&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID,
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (struct spa_meta_header))); this->type.meta.Header),
PROP(&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT,
sizeof(struct spa_meta_header)));
break; break;
default: default:
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_param); *param = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_param);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_set_param (struct spa_node *node, impl_node_port_set_param(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
const struct spa_param *param) const struct spa_param *param)
@ -496,7 +498,7 @@ impl_node_port_set_param (struct spa_node *node,
} }
static int static int
impl_node_port_use_buffers (struct spa_node *node, impl_node_port_use_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_buffer **buffers, struct spa_buffer **buffers,
@ -506,18 +508,19 @@ impl_node_port_use_buffers (struct spa_node *node,
struct port *port; struct port *port;
uint32_t i; uint32_t i;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (!port->have_format) if (!port->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
clear_buffers (this, port); clear_buffers(this, port);
for (i = 0; i < n_buffers; i++) { for (i = 0; i < n_buffers; i++) {
struct buffer *b; struct buffer *b;
@ -526,20 +529,19 @@ impl_node_port_use_buffers (struct spa_node *node,
b = &port->buffers[i]; b = &port->buffers[i];
b->outbuf = buffers[i]; b->outbuf = buffers[i];
b->outstanding = true; b->outstanding = true;
b->h = spa_buffer_find_meta (buffers[i], this->type.meta.Header); b->h = spa_buffer_find_meta(buffers[i], this->type.meta.Header);
if ((d[0].type == this->type.data.MemPtr || if ((d[0].type == this->type.data.MemPtr ||
d[0].type == this->type.data.MemFd || d[0].type == this->type.data.MemFd ||
d[0].type == this->type.data.DmaBuf) && d[0].type == this->type.data.DmaBuf) && d[0].data != NULL) {
d[0].data != NULL) {
b->ptr = d[0].data; b->ptr = d[0].data;
b->size = d[0].maxsize; b->size = d[0].maxsize;
} } else {
else { spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
spa_log_error (this->log, NAME " %p: invalid memory on buffer %p", this, buffers[i]); buffers[i]);
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
spa_list_insert (port->empty.prev, &b->link); spa_list_insert(port->empty.prev, &b->link);
} }
port->n_buffers = n_buffers; port->n_buffers = n_buffers;
@ -547,7 +549,7 @@ impl_node_port_use_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_alloc_buffers (struct spa_node *node, impl_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_param **params, struct spa_param **params,
@ -559,7 +561,7 @@ impl_node_port_alloc_buffers (struct spa_node *node,
} }
static int static int
impl_node_port_set_io (struct spa_node *node, impl_node_port_set_io(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_port_io *io) struct spa_port_io *io)
@ -567,47 +569,45 @@ impl_node_port_set_io (struct spa_node *node,
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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), SPA_RESULT_INVALID_PORT);
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port->io = io; port->io = io;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static void static void recycle_buffer(struct impl *this, uint32_t id)
recycle_buffer (struct impl *this, uint32_t id)
{ {
struct port *port = &this->out_ports[0]; struct port *port = &this->out_ports[0];
struct buffer *b = &port->buffers[id]; struct buffer *b = &port->buffers[id];
if (!b->outstanding) { if (!b->outstanding) {
spa_log_warn (this->log, NAME " %p: buffer %d not outstanding", this, id); spa_log_warn(this->log, NAME " %p: buffer %d not outstanding", this, id);
return; return;
} }
spa_list_insert (port->empty.prev, &b->link); spa_list_insert(port->empty.prev, &b->link);
b->outstanding = false; b->outstanding = false;
spa_log_trace (this->log, NAME " %p: recycle buffer %d", this, id); spa_log_trace(this->log, NAME " %p: recycle buffer %d", this, id);
} }
static int static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{ {
struct impl *this; struct impl *this;
struct port *port; struct port *port;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); 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); spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id),
SPA_RESULT_INVALID_PORT);
port = &this->out_ports[port_id]; port = &this->out_ports[port_id];
@ -617,13 +617,13 @@ impl_node_port_reuse_buffer (struct spa_node *node,
if (buffer_id >= port->n_buffers) if (buffer_id >= port->n_buffers)
return SPA_RESULT_INVALID_BUFFER_ID; return SPA_RESULT_INVALID_BUFFER_ID;
recycle_buffer (this, buffer_id); recycle_buffer(this, buffer_id);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_node_port_send_command (struct spa_node *node, impl_node_port_send_command(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
struct spa_command *command) struct spa_command *command)
@ -631,32 +631,29 @@ impl_node_port_send_command (struct spa_node *node,
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static struct spa_buffer * static struct spa_buffer *find_free_buffer(struct impl *this, struct port *port)
find_free_buffer (struct impl *this, struct port *port)
{ {
struct buffer *b; struct buffer *b;
if (spa_list_is_empty (&port->empty)) if (spa_list_is_empty(&port->empty))
return NULL; return NULL;
b = spa_list_first (&port->empty, struct buffer, link); b = spa_list_first(&port->empty, struct buffer, link);
spa_list_remove (&b->link); spa_list_remove(&b->link);
b->outstanding = true; b->outstanding = true;
return b->outbuf; return b->outbuf;
} }
static inline void static inline void release_buffer(struct impl *this, struct spa_buffer *buffer)
release_buffer (struct impl *this, struct spa_buffer *buffer)
{ {
if (this->callbacks.reuse_buffer) if (this->callbacks.reuse_buffer)
this->callbacks.reuse_buffer (&this->node, 0, buffer->id, this->user_data); this->callbacks.reuse_buffer(&this->node, 0, buffer->id, this->user_data);
} }
static void static void do_volume(struct impl *this, struct spa_buffer *dbuf, struct spa_buffer *sbuf)
do_volume (struct impl *this, struct spa_buffer *dbuf, struct spa_buffer *sbuf)
{ {
uint32_t si, di, i, n_samples, n_bytes, soff, doff ; uint32_t si, di, i, n_samples, n_bytes, soff, doff;
struct spa_data *sd, *dd; struct spa_data *sd, *dd;
uint16_t *src, *dst; uint16_t *src, *dst;
double volume; double volume;
@ -673,11 +670,11 @@ do_volume (struct impl *this, struct spa_buffer *dbuf, struct spa_buffer *sbuf)
sd = &sbuf->datas[si]; sd = &sbuf->datas[si];
dd = &dbuf->datas[di]; dd = &dbuf->datas[di];
src = (uint16_t*) ((uint8_t*)sd->data + sd->chunk->offset + soff); src = (uint16_t *) ((uint8_t *) sd->data + sd->chunk->offset + soff);
dst = (uint16_t*) ((uint8_t*)dd->data + dd->chunk->offset + doff); dst = (uint16_t *) ((uint8_t *) dd->data + dd->chunk->offset + doff);
n_bytes = SPA_MIN (sd->chunk->size - soff, dd->chunk->size - doff); n_bytes = SPA_MIN(sd->chunk->size - soff, dd->chunk->size - doff);
n_samples = n_bytes / sizeof (uint16_t); n_samples = n_bytes / sizeof(uint16_t);
for (i = 0; i < n_samples; i++) for (i = 0; i < n_samples; i++)
*src++ = *dst++ * volume; *src++ = *dst++ * volume;
@ -696,8 +693,7 @@ do_volume (struct impl *this, struct spa_buffer *dbuf, struct spa_buffer *sbuf)
} }
} }
static int static int impl_node_process_input(struct spa_node *node)
impl_node_process_input (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct spa_port_io *input; struct spa_port_io *input;
@ -705,29 +701,29 @@ impl_node_process_input (struct spa_node *node)
struct port *in_port, *out_port; struct port *in_port, *out_port;
struct spa_buffer *dbuf, *sbuf; struct spa_buffer *dbuf, *sbuf;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
out_port = &this->out_ports[0]; out_port = &this->out_ports[0];
output = out_port->io; output = out_port->io;
spa_return_val_if_fail (output != NULL, SPA_RESULT_ERROR); spa_return_val_if_fail(output != NULL, SPA_RESULT_ERROR);
if (output->status == SPA_RESULT_HAVE_BUFFER) if (output->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
in_port = &this->in_ports[0]; in_port = &this->in_ports[0];
input = in_port->io; input = in_port->io;
spa_return_val_if_fail (input != NULL, SPA_RESULT_ERROR); spa_return_val_if_fail(input != NULL, SPA_RESULT_ERROR);
if ((dbuf = find_free_buffer (this, out_port)) == NULL) if ((dbuf = find_free_buffer(this, out_port)) == NULL)
return SPA_RESULT_OUT_OF_BUFFERS; return SPA_RESULT_OUT_OF_BUFFERS;
sbuf = in_port->buffers[input->buffer_id].outbuf; sbuf = in_port->buffers[input->buffer_id].outbuf;
input->status = SPA_RESULT_NEED_BUFFER; input->status = SPA_RESULT_NEED_BUFFER;
do_volume (this, sbuf, dbuf); do_volume(this, sbuf, dbuf);
output->buffer_id = dbuf->id; output->buffer_id = dbuf->id;
output->status = SPA_RESULT_HAVE_BUFFER; output->status = SPA_RESULT_HAVE_BUFFER;
@ -735,33 +731,32 @@ impl_node_process_input (struct spa_node *node)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
} }
static int static int impl_node_process_output(struct spa_node *node)
impl_node_process_output (struct spa_node *node)
{ {
struct impl *this; struct impl *this;
struct port *in_port, *out_port; struct port *in_port, *out_port;
struct spa_port_io *input, *output; struct spa_port_io *input, *output;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, struct impl, node); this = SPA_CONTAINER_OF(node, struct impl, node);
out_port = &this->out_ports[0]; out_port = &this->out_ports[0];
output = out_port->io; output = out_port->io;
spa_return_val_if_fail (output != NULL, SPA_RESULT_ERROR); spa_return_val_if_fail(output != NULL, SPA_RESULT_ERROR);
if (output->status == SPA_RESULT_HAVE_BUFFER) if (output->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER; return SPA_RESULT_HAVE_BUFFER;
/* recycle */ /* recycle */
if (output->buffer_id != SPA_ID_INVALID) { if (output->buffer_id != SPA_ID_INVALID) {
recycle_buffer (this, output->buffer_id); recycle_buffer(this, output->buffer_id);
output->buffer_id = SPA_ID_INVALID; output->buffer_id = SPA_ID_INVALID;
} }
in_port = &this->in_ports[0]; in_port = &this->in_ports[0];
input = in_port->io; input = in_port->io;
spa_return_val_if_fail (input != NULL, SPA_RESULT_ERROR); spa_return_val_if_fail(input != NULL, SPA_RESULT_ERROR);
input->range = output->range; input->range = output->range;
input->status = SPA_RESULT_NEED_BUFFER; input->status = SPA_RESULT_NEED_BUFFER;
@ -770,7 +765,7 @@ impl_node_process_output (struct spa_node *node)
} }
static const struct spa_node impl_node = { static const struct spa_node impl_node = {
sizeof (struct spa_node), sizeof(struct spa_node),
NULL, NULL,
impl_node_get_props, impl_node_get_props,
impl_node_set_props, impl_node_set_props,
@ -795,15 +790,12 @@ static const struct spa_node impl_node = {
impl_node_process_output, impl_node_process_output,
}; };
static int static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{ {
struct impl *this; struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (struct impl *) handle; this = (struct impl *) handle;
@ -815,14 +807,13 @@ impl_get_interface (struct spa_handle *handle,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int impl_clear(struct spa_handle *handle)
impl_clear (struct spa_handle *handle)
{ {
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static int static int
impl_init (const struct spa_handle_factory *factory, impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
const struct spa_dict *info, const struct spa_dict *info,
const struct spa_support *support, const struct spa_support *support,
@ -831,8 +822,8 @@ impl_init (const struct spa_handle_factory *factory,
struct impl *this; struct impl *this;
uint32_t i; uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS); 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(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface; handle->get_interface = impl_get_interface;
handle->clear = impl_clear; handle->clear = impl_clear;
@ -840,43 +831,42 @@ impl_init (const struct spa_handle_factory *factory,
this = (struct impl *) handle; this = (struct impl *) handle;
for (i = 0; i < n_support; i++) { for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0) if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data; this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0) else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data; this->log = support[i].data;
} }
if (this->map == NULL) { if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed"); spa_log_error(this->log, "a type-map is needed");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
init_type (&this->type, this->map); init_type(&this->type, this->map);
this->node = impl_node; this->node = impl_node;
reset_props (&this->props); reset_props(&this->props);
this->in_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | this->in_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
SPA_PORT_INFO_FLAG_IN_PLACE; SPA_PORT_INFO_FLAG_IN_PLACE;
spa_list_init (&this->in_ports[0].empty); spa_list_init(&this->in_ports[0].empty);
this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
SPA_PORT_INFO_FLAG_NO_REF; SPA_PORT_INFO_FLAG_NO_REF;
spa_list_init (&this->out_ports[0].empty); spa_list_init(&this->out_ports[0].empty);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static const struct spa_interface_info impl_interfaces[] = static const struct spa_interface_info impl_interfaces[] = {
{ {SPA_TYPE__Node,},
{ SPA_TYPE__Node, },
}; };
static int static int
impl_enum_interface_info (const struct spa_handle_factory *factory, impl_enum_interface_info(const struct spa_handle_factory *factory,
const struct spa_interface_info **info, 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(factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS); spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) { switch (index) {
case 0: case 0:
@ -888,10 +878,10 @@ impl_enum_interface_info (const struct spa_handle_factory *factory,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
const struct spa_handle_factory spa_volume_factory = const struct spa_handle_factory spa_volume_factory = {
{ NAME, NAME,
NULL, NULL,
sizeof (struct impl), sizeof(struct impl),
impl_init, impl_init,
impl_enum_interface_info, impl_enum_interface_info,
}; };

View file

@ -1,10 +0,0 @@
xv_sources = ['xv.c',
'xv-sink.c']
xvlib = shared_library('spa-xv',
xv_sources,
include_directories : [spa_inc, spa_libinc],
dependencies : xv_dep,
link_with : spalib,
install : true,
install_dir : '@0@/spa'.format(get_option('libdir')))

View file

@ -1,605 +0,0 @@
/* Spa Xv Sink
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <spa/type-map.h>
#include <spa/log.h>
#include <spa/list.h>
#include <spa/node.h>
#include <spa/video/format-utils.h>
#include <lib/props.h>
static const char default_device[] = "/dev/video0";
struct props {
char device[64];
char device_name[128];
int device_fd;
};
static void
reset_props (struct props *props)
{
strncpy (props->device, default_device, 64);
}
#define MAX_BUFFERS 32
struct buffer {
struct spa_buffer buffer;
struct spa_meta meta[1];
struct spa_meta_header header;
struct spa_data data[1];
struct spa_list link;
bool outstanding;
};
struct port {
bool opened;
int fd;
struct spa_port_io *io;
bool have_format;
uint8_t format_buffer[1024];
struct spa_video_info current_format;
struct spa_port_info info;
struct buffer buffers[MAX_BUFFERS];
struct spa_list ready;
};
struct type {
uint32_t node;
uint32_t props;
uint32_t prop_device;
uint32_t prop_device_name;
uint32_t prop_device_fd;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_command_node command_node;
};
static inline void
init_type (struct type *type, struct spa_type_map *map)
{
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
type->props = spa_type_map_get_id (map, SPA_TYPE__Props);
type->prop_device = spa_type_map_get_id (map, SPA_TYPE_PROPS__device);
type->prop_device_name = spa_type_map_get_id (map, SPA_TYPE_PROPS__deviceName);
type->prop_device_fd = spa_type_map_get_id (map, SPA_TYPE_PROPS__deviceFd);
spa_type_media_type_map (map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype);
spa_type_format_video_map (map, &type->format_video);
spa_type_command_node_map (map, &type->command_node);
}
struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
uint8_t props_buffer[512];
struct props props;
struct spa_node_callbacks callbacks;
void *user_data;
struct port in_ports[1];
};
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0)
#include "xv-utils.c"
#define PROP(f,key,type,...) \
SPA_POD_PROP (f,key,0,type,1,__VA_ARGS__)
#define PROP_R(f,key,type,...) \
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_READONLY,type,1,__VA_ARGS__)
static int
spa_xv_sink_node_get_props (struct spa_node *node,
struct spa_props **props)
{
struct impl *this;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2];
if (node == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0], this->type.props,
PROP (&f[1], this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP_R (&f[1], this->type.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP_R (&f[1], this->type.prop_device_fd, SPA_POD_TYPE_INT, this->props.device_fd));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_props);
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_set_props (struct spa_node *node,
const struct spa_props *props)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (props == NULL) {
reset_props (&this->props);
} else {
spa_props_query (props,
this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
0);
}
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_send_command (struct spa_node *node,
struct spa_command *command)
{
struct impl *this;
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
spa_xv_start (this);
}
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
spa_xv_stop (this);
}
else
return SPA_RESULT_NOT_IMPLEMENTED;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_set_callbacks (struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
{
struct impl *this;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_get_n_ports (struct spa_node *node,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
uint32_t *max_output_ports)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
*n_input_ports = 0;
if (n_output_ports)
*n_output_ports = 1;
if (max_input_ports)
*max_input_ports = 0;
if (max_output_ports)
*max_output_ports = 1;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_get_port_ids (struct spa_node *node,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
uint32_t *output_ids)
{
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_output_ports > 0 && output_ids != NULL)
output_ids[0] = 0;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_remove_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_enum_formats (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_format **format,
const struct spa_format *filter,
uint32_t index)
{
//struct impl *this;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
//this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
switch (index) {
case 0:
break;
default:
return SPA_RESULT_ENUM_END;
}
*format = NULL;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_set_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
{
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
if (format == NULL) {
port->have_format = false;
return SPA_RESULT_OK;
} else {
struct spa_video_info info = { SPA_FORMAT_MEDIA_TYPE (format),
SPA_FORMAT_MEDIA_SUBTYPE (format), };
if (info.media_type != this->type.media_type.video &&
info.media_subtype != this->type.media_subtype.raw)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (spa_xv_set_format (this, &info, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0)
return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
port->current_format = info;
port->have_format = true;
}
}
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_get_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_format **format)
{
struct impl *this;
struct port *port;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
*format = NULL;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_get_info (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_port_info **info)
{
struct impl *this;
struct port *port;
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
*info = &port->info;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_enum_params (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
struct spa_param **param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_set_param (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_param *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_use_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_alloc_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_set_io (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_port_io *io)
{
struct impl *this;
struct port *port;
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, struct impl, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port = &this->in_ports[0];
port->io = io;
return SPA_RESULT_OK;
}
static int
spa_xv_sink_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_port_send_command (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_process_input (struct spa_node *node)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int
spa_xv_sink_node_process_output (struct spa_node *node)
{
return SPA_RESULT_INVALID_PORT;
}
static const struct spa_node xvsink_node = {
sizeof (struct spa_node),
NULL,
spa_xv_sink_node_get_props,
spa_xv_sink_node_set_props,
spa_xv_sink_node_send_command,
spa_xv_sink_node_set_callbacks,
spa_xv_sink_node_get_n_ports,
spa_xv_sink_node_get_port_ids,
spa_xv_sink_node_add_port,
spa_xv_sink_node_remove_port,
spa_xv_sink_node_port_enum_formats,
spa_xv_sink_node_port_set_format,
spa_xv_sink_node_port_get_format,
spa_xv_sink_node_port_get_info,
spa_xv_sink_node_port_enum_params,
spa_xv_sink_node_port_set_param,
spa_xv_sink_node_port_use_buffers,
spa_xv_sink_node_port_alloc_buffers,
spa_xv_sink_node_port_set_io,
spa_xv_sink_node_port_reuse_buffer,
spa_xv_sink_node_port_send_command,
spa_xv_sink_node_process_input,
spa_xv_sink_node_process_output,
};
static int
spa_xv_sink_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{
struct impl *this;
if (handle == NULL || interface == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (struct impl *) handle;
if (interface_id == this->type.node)
*interface = &this->node;
else
return SPA_RESULT_UNKNOWN_INTERFACE;
return SPA_RESULT_OK;
}
static int
xv_sink_clear (struct spa_handle *handle)
{
return SPA_RESULT_OK;
}
static int
xv_sink_init (const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
struct impl *this;
uint32_t i;
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_xv_sink_get_interface;
handle->clear = xv_sink_clear;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error (this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
init_type (&this->type, this->map);
this->node = xvsink_node;
reset_props (&this->props);
this->in_ports[0].info.flags = 0;
return SPA_RESULT_OK;
}
static const struct spa_interface_info xv_sink_interfaces[] =
{
{ SPA_TYPE__Node, },
};
static int
xv_sink_enum_interface_info (const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
{
if (factory == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
switch (index) {
case 0:
*info = &xv_sink_interfaces[index];
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
}
const struct spa_handle_factory spa_xv_sink_factory =
{
"xv-sink",
NULL,
sizeof (struct impl),
xv_sink_init,
xv_sink_enum_interface_info,
};

View file

@ -1,62 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <poll.h>
#define CLEAR(x) memset(&(x), 0, sizeof(x))
static int
spa_xv_open (struct impl *this)
{
struct port *port = &this->in_ports[0];
if (port->opened)
return 0;
port->opened = true;
return 0;
}
static int
spa_xv_set_format (struct impl *this, struct spa_video_info *info, bool try_only)
{
if (spa_xv_open (this) < 0)
return -1;
return 0;
}
static int
spa_xv_close (struct impl *this)
{
struct port *port = &this->in_ports[0];
if (!port->opened)
return 0;
port->opened = false;
return 0;
}
static int
spa_xv_start (struct impl *this)
{
if (spa_xv_open (this) < 0)
return -1;
return 0;
}
static int
spa_xv_stop (struct impl *this)
{
spa_xv_close (this);
return 0;
}

View file

@ -1,40 +0,0 @@
/* Spa Xv support
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <spa/plugin.h>
#include <spa/node.h>
extern const struct spa_handle_factory spa_xv_sink_factory;
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
{
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:
*factory = &spa_xv_sink_factory;
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
}