Remove dynamic types

Do not use dynamic types anymore. The reason is that it's difficult:

- to maintain a shared type database over a network.
- the extra overhead when translating between processes and for
  maintaining the translation tables.
- race conditions in translating in RT-threads, this is a problem
  because we want to make event streams.

We now have simple enums with types and extension points for all
types. This is also nicer to use in general.
We don't need the mapper anymore or pass strings around as types.
There is a parallel type info system to get more info about ids and
enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
Wim Taymans 2018-08-23 17:47:57 +02:00
parent e6977fa178
commit fca3e1d85d
162 changed files with 5200 additions and 7461 deletions

View file

@ -22,7 +22,6 @@
#include <stdio.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/buffer/alloc.h>
@ -33,58 +32,13 @@
#include <spa/param/io.h>
#include <spa/pod/filter.h>
#include <spa/debug/pod.h>
#include <spa/debug/types.h>
#define NAME "audioconvert"
#define PROP_DEFAULT_TRUNCATE false
#define PROP_DEFAULT_DITHER 0
struct type {
uint32_t node;
uint32_t format;
uint32_t prop_truncate;
uint32_t prop_dither;
uint32_t prop_volume;
uint32_t io_prop_volume;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
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->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->prop_truncate = spa_type_map_get_id(map, SPA_TYPE_PROPS__truncate);
type->prop_dither = spa_type_map_get_id(map, SPA_TYPE_PROPS__ditherType);
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
struct props {
bool truncate;
uint32_t dither;
@ -125,8 +79,6 @@ struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct props props;
@ -157,7 +109,6 @@ static int make_link(struct impl *this,
struct spa_audio_info *info)
{
struct link *l = &this->links[this->n_links++];
struct type *t = &this->type;
l->out_node = out_node;
l->out_port = out_port;
@ -173,28 +124,26 @@ static int make_link(struct impl *this,
&l->out_info);
spa_node_port_set_io(out_node,
SPA_DIRECTION_OUTPUT, out_port,
t->io.Buffers,
SPA_ID_IO_Buffers,
&l->io, sizeof(l->io));
spa_node_port_get_info(in_node,
SPA_DIRECTION_INPUT, in_port,
&l->in_info);
spa_node_port_set_io(in_node,
SPA_DIRECTION_INPUT, in_port,
t->io.Buffers,
SPA_ID_IO_Buffers,
&l->io, sizeof(l->io));
return 0;
}
static void clean_link(struct impl *this, struct link *link)
{
struct type *t = &this->type;
spa_node_port_set_param(link->in_node,
SPA_DIRECTION_INPUT, link->in_port,
t->param.idFormat, 0, NULL);
SPA_ID_PARAM_Format, 0, NULL);
spa_node_port_set_param(link->out_node,
SPA_DIRECTION_OUTPUT, link->out_port,
t->param.idFormat, 0, NULL);
SPA_ID_PARAM_Format, 0, NULL);
if (link->buffers)
free(link->buffers);
link->buffers = NULL;
@ -221,19 +170,18 @@ static int debug_params(struct impl *this, struct spa_node *node,
if (res <= 0)
break;
spa_debug_pod(2, this->map, param);
spa_debug_pod(2, spa_debug_types, param);
}
spa_log_error(this->log, "failed filter:");
if (filter)
spa_debug_pod(2, this->map, filter);
spa_debug_pod(2, spa_debug_types, filter);
return 0;
}
static int negotiate_link_format(struct impl *this, struct link *link)
{
struct type *t = &this->type;
struct spa_pod_builder b = { 0 };
uint8_t buffer[4096];
uint32_t state;
@ -249,20 +197,20 @@ static int negotiate_link_format(struct impl *this, struct link *link)
filter = NULL;
if ((res = spa_node_port_enum_params(link->out_node,
SPA_DIRECTION_OUTPUT, link->out_port,
t->param.idEnumFormat, &state,
SPA_ID_PARAM_EnumFormat, &state,
filter, &format, &b)) <= 0) {
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
t->param.idEnumFormat, filter);
SPA_ID_PARAM_EnumFormat, filter);
return -ENOTSUP;
}
filter = format;
state = 0;
if ((res = spa_node_port_enum_params(link->in_node,
SPA_DIRECTION_INPUT, link->in_port,
t->param.idEnumFormat, &state,
SPA_ID_PARAM_EnumFormat, &state,
filter, &format, &b)) <= 0) {
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
t->param.idEnumFormat, filter);
SPA_ID_PARAM_EnumFormat, filter);
return -ENOTSUP;
}
filter = format;
@ -271,13 +219,13 @@ static int negotiate_link_format(struct impl *this, struct link *link)
if ((res = spa_node_port_set_param(link->out_node,
SPA_DIRECTION_OUTPUT, link->out_port,
t->param.idFormat, 0,
SPA_ID_PARAM_Format, 0,
filter)) < 0)
return res;
if ((res = spa_node_port_set_param(link->in_node,
SPA_DIRECTION_INPUT, link->in_port,
t->param.idFormat, 0,
SPA_ID_PARAM_Format, 0,
filter)) < 0)
return res;
@ -317,7 +265,6 @@ static int setup_convert(struct impl *this)
static int negotiate_link_buffers(struct impl *this, struct link *link)
{
struct type *t = &this->type;
uint8_t buffer[4096];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
uint32_t state;
@ -334,19 +281,19 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
state = 0;
if ((res = spa_node_port_enum_params(link->in_node,
SPA_DIRECTION_INPUT, link->in_port,
t->param.idBuffers, &state,
SPA_ID_PARAM_Buffers, &state,
param, &param, &b)) <= 0) {
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
t->param.idBuffers, param);
SPA_ID_PARAM_Buffers, param);
return -ENOTSUP;
}
state = 0;
if ((res = spa_node_port_enum_params(link->out_node,
SPA_DIRECTION_OUTPUT, link->out_port,
t->param.idBuffers, &state,
SPA_ID_PARAM_Buffers, &state,
param, &param, &b)) <= 0) {
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
t->param.idBuffers, param);
SPA_ID_PARAM_Buffers, param);
return -ENOTSUP;
}
@ -372,10 +319,10 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
}
if (spa_pod_object_parse(param,
":", t->param_buffers.buffers, "i", &buffers,
":", t->param_buffers.blocks, "i", &blocks,
":", t->param_buffers.size, "i", &size,
":", t->param_buffers.align, "i", &align,
":", SPA_PARAM_BUFFERS_buffers, "i", &buffers,
":", SPA_PARAM_BUFFERS_blocks, "i", &blocks,
":", SPA_PARAM_BUFFERS_size, "i", &size,
":", SPA_PARAM_BUFFERS_align, "i", &align,
NULL) < 0)
return -EINVAL;
@ -386,7 +333,7 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
memset(datas, 0, sizeof(struct spa_data) * blocks);
aligns = alloca(sizeof(uint32_t) * blocks);
for (i = 0; i < blocks; i++) {
datas[i].type = t->data.MemPtr;
datas[i].type = SPA_DATA_MemPtr;
datas[i].maxsize = size;
aligns[i] = align;
}
@ -484,16 +431,19 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
if ((res = setup_convert(this)) < 0)
goto error;
setup_buffers(this, SPA_DIRECTION_INPUT);
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
error:
@ -607,25 +557,22 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
if (id == t->param_io.idPropsIn) {
switch (id) {
next:
case SPA_ID_PARAM_PropInfo:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
switch (*index) {
case 0:
param = spa_pod_builder_object(builder,
id, t->param_io.Prop,
":", t->param_io.id, "I", this->type.io_prop_volume,
":", t->param_io.size, "i", sizeof(struct spa_pod_float),
":", t->param.propId, "I", this->type.prop_volume,
":", t->param.propType, "fru", 1.0,
id, SPA_ID_PARAM_PropInfo,
":", SPA_PROP_INFO_id, "I", SPA_PROP_volume,
":", SPA_PROP_INFO_type, "fru", 1.0,
SPA_POD_PROP_MIN_MAX(0.0, 10.0));
break;
default:
@ -638,10 +585,10 @@ impl_node_port_enum_params(struct spa_node *node,
goto next;
return 1;
}
else
default:
return spa_node_port_enum_params(this->fmt[direction], direction, port_id,
id, index, filter, result, builder);
}
}
static int
@ -700,20 +647,18 @@ impl_node_port_set_io(struct spa_node *node,
uint32_t id, void *data, size_t size)
{
struct impl *this;
struct type *t;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_log_debug(this->log, "set io %d %d %d", id, direction, port_id);
if (id == t->io.ControlRange)
if (id == SPA_ID_IO_ControlRange)
res = spa_node_port_set_io(this->resample, direction, 0, id, data, size);
else if (id == t->io_prop_volume)
res = spa_node_port_set_io(this->channelmix, direction, 0, id, data, size);
// else if (id == t->io_prop_volume)
// res = spa_node_port_set_io(this->channelmix, direction, 0, id, data, size);
else
res = spa_node_port_set_io(this->fmt[direction], direction, port_id, id, data, size);
@ -818,7 +763,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -877,17 +822,9 @@ impl_init(const struct spa_handle_factory *factory,
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)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
this->node = impl_node;
this->hnd_fmt[SPA_DIRECTION_INPUT] = SPA_MEMBER(this, sizeof(struct impl), struct spa_handle);
@ -914,13 +851,13 @@ impl_init(const struct spa_handle_factory *factory,
info, support, n_support);
size = spa_handle_factory_get_size(&spa_resample_factory, info);
spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_INPUT], this->type.node, &iface);
spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_INPUT], SPA_ID_INTERFACE_Node, &iface);
this->fmt[SPA_DIRECTION_INPUT] = iface;
spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_OUTPUT], this->type.node, &iface);
spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_OUTPUT], SPA_ID_INTERFACE_Node, &iface);
this->fmt[SPA_DIRECTION_OUTPUT] = iface;
spa_handle_get_interface(this->hnd_channelmix, this->type.node, &iface);
spa_handle_get_interface(this->hnd_channelmix, SPA_ID_INTERFACE_Node, &iface);
this->channelmix = iface;
spa_handle_get_interface(this->hnd_resample, this->type.node, &iface);
spa_handle_get_interface(this->hnd_resample, SPA_ID_INTERFACE_Node, &iface);
this->resample = iface;
props_reset(&this->props);
@ -929,7 +866,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{ SPA_ID_INTERFACE_Node, },
};
static int

View file

@ -22,7 +22,6 @@
#include <stdio.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@ -84,58 +83,12 @@ struct port {
struct spa_list queue;
};
struct type {
uint32_t node;
uint32_t format;
uint32_t prop_volume;
uint32_t io_prop_volume;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
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->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
#include "channelmix-ops.c"
struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct props props;
@ -245,13 +198,16 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -350,7 +306,6 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *other;
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0);
@ -359,24 +314,24 @@ static int port_enum_formats(struct spa_node *node,
case 0:
if (other->have_format) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, "i", other->format.info.raw.rate,
":", t->format_audio.channels, "iru", 2,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, "i", other->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "iru", 2,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
} else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, "iru", DEFAULT_RATE,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "iru", DEFAULT_CHANNELS,
":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
}
break;
@ -393,7 +348,6 @@ static int port_get_format(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
@ -402,13 +356,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", port->format.info.raw.format,
":", t->format_audio.layout, "i", port->format.info.raw.layout,
":", t->format_audio.rate, "i", port->format.info.raw.rate,
":", t->format_audio.channels, "i", port->format.info.raw.channels);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels);
return 1;
}
@ -422,7 +376,6 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this;
struct type *t;
struct port *port, *other;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
@ -434,7 +387,6 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -444,28 +396,34 @@ impl_node_port_enum_params(struct spa_node *node,
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, id, t->param.List,
":", t->param.listId, "I", list[*index]);
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
break;
case SPA_ID_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
break;
case SPA_ID_PARAM_Buffers:
{
uint32_t buffers, size;
if (!port->have_format)
@ -482,44 +440,47 @@ impl_node_port_enum_params(struct spa_node *node,
}
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.buffers, "iru", buffers,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", buffers,
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
":", t->param_buffers.blocks, "i", port->blocks,
":", t->param_buffers.size, "iru", size * port->stride,
":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks,
":", SPA_PARAM_BUFFERS_size, "iru", size * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
":", t->param_buffers.stride, "i", port->stride,
":", t->param_buffers.align, "i", 16);
":", SPA_PARAM_BUFFERS_stride, "i", port->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
}
else if (id == t->param.idMeta) {
case SPA_ID_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else
break;
default:
return -ENOENT;
}
(*index)++;
@ -547,7 +508,6 @@ static int port_set_format(struct spa_node *node,
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port, *other;
struct type *t = &this->type;
int res = 0;
port = GET_PORT(this, direction, port_id);
@ -566,14 +526,14 @@ static int port_set_format(struct spa_node *node,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != t->media_type.audio ||
info.media_subtype != t->media_subtype.raw)
if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
return -EINVAL;
if (info.info.raw.format != t->audio_format.F32)
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED)
return -EINVAL;
@ -599,17 +559,11 @@ impl_node_port_set_param(struct spa_node *node,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -626,12 +580,10 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
struct port *port;
uint32_t i, size = SPA_ID_INVALID;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -650,7 +602,7 @@ impl_node_port_use_buffers(struct spa_node *node,
b = &port->buffers[i];
b->flags = 0;
b->outbuf = buffers[i];
b->h = spa_buffer_find_meta_data(buffers[i], t->meta.Header, sizeof(*b->h));
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
if (size == SPA_ID_INVALID)
size = d[0].maxsize;
@ -658,9 +610,9 @@ impl_node_port_use_buffers(struct spa_node *node,
if (size != d[0].maxsize)
return -EINVAL;
if (!((d[0].type == t->data.MemPtr ||
d[0].type == t->data.MemFd ||
d[0].type == t->data.DmaBuf) && d[0].data != NULL)) {
if (!((d[0].type == SPA_DATA_MemPtr ||
d[0].type == SPA_DATA_MemFd ||
d[0].type == SPA_DATA_DmaBuf) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
buffers[i]);
return -EINVAL;
@ -695,21 +647,19 @@ impl_node_port_set_io(struct spa_node *node,
{
struct impl *this;
struct port *port;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
if (id == t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
port->io = data;
else if (id == t->io_prop_volume)
port->control.volume = data;
// else if (id == t->io_prop_volume)
// port->control.volume = data;
else
return -ENOENT;
@ -879,7 +829,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -919,16 +869,9 @@ impl_init(const struct spa_handle_factory *factory,
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)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
this->node = impl_node;
@ -948,7 +891,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_ID_INTERFACE_Node,},
};
static int

View file

@ -670,8 +670,8 @@ typedef void (*convert_func_t) (void *data, int n_dst, void *dst[n_dst],
int n_src, const void *src[n_src], int n_bytes);
static const struct conv_info {
off_t src_fmt;
off_t dst_fmt;
uint32_t src_fmt;
uint32_t dst_fmt;
#define FEATURE_SSE (1<<0)
uint32_t features;
@ -681,86 +681,67 @@ static const struct conv_info {
} conv_table[] =
{
/* to f32 */
{ offsetof(struct spa_type_audio_format, U8),
offsetof(struct spa_type_audio_format, F32), 0,
{ SPA_AUDIO_FORMAT_U8, SPA_AUDIO_FORMAT_F32, 0,
conv_u8_to_f32, conv_u8_to_f32d, conv_u8d_to_f32 },
#if defined (__SSE2__)
{ offsetof(struct spa_type_audio_format, S16),
offsetof(struct spa_type_audio_format, F32), FEATURE_SSE,
{ SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_F32, FEATURE_SSE,
conv_s16_to_f32, conv_s16_to_f32d_sse, conv_s16d_to_f32 },
#endif
{ offsetof(struct spa_type_audio_format, S16),
offsetof(struct spa_type_audio_format, F32), 0,
{ SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_F32, 0,
conv_s16_to_f32, conv_s16_to_f32d, conv_s16d_to_f32 },
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, F32), 0,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_F32, 0,
conv_copy, deinterleave_32, interleave_32 },
{ offsetof(struct spa_type_audio_format, S32),
offsetof(struct spa_type_audio_format, F32), 0,
{ SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_F32, 0,
conv_s32_to_f32, conv_s32_to_f32d, conv_s32d_to_f32 },
{ offsetof(struct spa_type_audio_format, S24),
offsetof(struct spa_type_audio_format, F32), 0,
{ SPA_AUDIO_FORMAT_S24, SPA_AUDIO_FORMAT_F32, 0,
conv_s24_to_f32, conv_s24_to_f32d, conv_s24d_to_f32 },
{ offsetof(struct spa_type_audio_format, S24_32),
offsetof(struct spa_type_audio_format, F32), 0,
{ SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_F32, 0,
conv_s24_32_to_f32, conv_s24_32_to_f32d, conv_s24_32d_to_f32 },
/* from f32 */
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, U8), 0,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_U8, 0,
conv_f32_to_u8, conv_f32_to_u8d, conv_f32d_to_u8 },
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, S16), 0,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S16, 0,
conv_f32_to_s16, conv_f32_to_s16d, conv_f32d_to_s16 },
#if defined (__SSE2__)
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, S32), FEATURE_SSE,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S32, FEATURE_SSE,
conv_f32_to_s32, conv_f32_to_s32d, conv_f32d_to_s32_sse },
#endif
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, S32), 0,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S32, 0,
conv_f32_to_s32, conv_f32_to_s32d, conv_f32d_to_s32 },
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, S24), 0,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24, 0,
conv_f32_to_s24, conv_f32_to_s24d, conv_f32d_to_s24 },
{ offsetof(struct spa_type_audio_format, F32),
offsetof(struct spa_type_audio_format, S24_32), 0,
{ SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24_32, 0,
conv_f32_to_s24_32, conv_f32_to_s24_32d, conv_f32d_to_s24_32 },
/* u8 */
{ offsetof(struct spa_type_audio_format, U8),
offsetof(struct spa_type_audio_format, U8), 0,
{ SPA_AUDIO_FORMAT_U8, SPA_AUDIO_FORMAT_U8, 0,
conv_copy, deinterleave_8, interleave_8 },
/* s16 */
{ offsetof(struct spa_type_audio_format, S16),
offsetof(struct spa_type_audio_format, S16), 0,
{ SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_S16, 0,
conv_copy, deinterleave_16, interleave_16 },
/* s32 */
{ offsetof(struct spa_type_audio_format, S32),
offsetof(struct spa_type_audio_format, S32), 0,
{ SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_S32, 0,
conv_copy, deinterleave_32, interleave_32 },
/* s24 */
{ offsetof(struct spa_type_audio_format, S24),
offsetof(struct spa_type_audio_format, S24), 0,
{ SPA_AUDIO_FORMAT_S24, SPA_AUDIO_FORMAT_S24, 0,
conv_copy, deinterleave_24, interleave_24 },
/* s24_32 */
{ offsetof(struct spa_type_audio_format, S24_32),
offsetof(struct spa_type_audio_format, S24_32), 0,
{ SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_S24_32, 0,
conv_copy, deinterleave_32, interleave_32 },
};
static const struct conv_info *find_conv_info(struct spa_type_audio_format *audio_format,
uint32_t src_fmt, uint32_t dst_fmt, uint32_t features)
static const struct conv_info *find_conv_info(uint32_t src_fmt, uint32_t dst_fmt, uint32_t features)
{
int i;
for (i = 0; i < SPA_N_ELEMENTS(conv_table); i++) {
if (*SPA_MEMBER(audio_format, conv_table[i].src_fmt, uint32_t) == src_fmt &&
*SPA_MEMBER(audio_format, conv_table[i].dst_fmt, uint32_t) == dst_fmt &&
if (conv_table[i].src_fmt == src_fmt &&
conv_table[i].dst_fmt == dst_fmt &&
(conv_table[i].features == 0 || (conv_table[i].features & features) != 0))
return &conv_table[i];
}

View file

@ -22,7 +22,6 @@
#include <stdio.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@ -31,6 +30,7 @@
#include <spa/param/meta.h>
#include <spa/param/io.h>
#include <spa/pod/filter.h>
#include <spa/debug/types.h>
#define NAME "fmtconvert"
@ -96,54 +96,12 @@ struct port {
struct spa_list queue;
};
struct type {
uint32_t node;
uint32_t format;
uint32_t prop_truncate;
uint32_t prop_dither;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
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->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->prop_truncate = spa_type_map_get_id(map, SPA_TYPE_PROPS__truncate);
type->prop_dither = spa_type_map_get_id(map, SPA_TYPE_PROPS__ditherType);
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
#include "fmt-ops.c"
struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct props props;
@ -193,7 +151,6 @@ static int collect_format(struct impl *this, enum spa_direction direction, struc
static int setup_convert(struct impl *this)
{
uint32_t src_fmt, dst_fmt;
struct type *t = &this->type;
struct format informat, outformat;
const struct conv_info *conv;
@ -206,11 +163,11 @@ static int setup_convert(struct impl *this)
dst_fmt = outformat.format.info.raw.format;
spa_log_info(this->log, NAME " %p: %s/%d@%d.%d->%s/%d@%d.%d", this,
spa_type_map_get_type(this->map, src_fmt),
spa_debug_type_find_name(spa_debug_types, src_fmt),
informat.format.info.raw.channels,
informat.format.info.raw.rate,
informat.format.info.raw.layout,
spa_type_map_get_type(this->map, dst_fmt),
spa_debug_type_find_name(spa_debug_types, dst_fmt),
outformat.format.info.raw.channels,
outformat.format.info.raw.rate,
outformat.format.info.raw.layout);
@ -222,7 +179,7 @@ static int setup_convert(struct impl *this)
return -EINVAL;
/* find fast path */
conv = find_conv_info(&t->audio_format, src_fmt, dst_fmt, FEATURE_SSE);
conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE);
if (conv != NULL) {
spa_log_info(this->log, NAME " %p: got converter features %08x", this,
conv->features);
@ -267,13 +224,16 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -455,7 +415,6 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct spa_audio_info *other;
other = &this->formats[SPA_DIRECTION_REVERSE(direction)].format;
@ -464,41 +423,41 @@ static int port_enum_formats(struct spa_node *node,
case 0:
if (other->info.raw.channels > 0) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "Ieu", other->info.raw.format,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "Ieu", other->info.raw.format,
SPA_POD_PROP_ENUM(3, other->info.raw.format,
t->audio_format.F32,
t->audio_format.F32_OE),
":", t->format_audio.layout, "ieu", other->info.raw.layout,
SPA_AUDIO_FORMAT_F32,
SPA_AUDIO_FORMAT_F32_OE),
":", SPA_FORMAT_AUDIO_layout, "ieu", other->info.raw.layout,
SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_LAYOUT_NON_INTERLEAVED),
":", t->format_audio.rate, "i", other->info.raw.rate,
":", t->format_audio.channels, "i", other->info.raw.channels);
":", SPA_FORMAT_AUDIO_rate, "i", other->info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", other->info.raw.channels);
} else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "Ieu", t->audio_format.S16,
SPA_POD_PROP_ENUM(11, t->audio_format.U8,
t->audio_format.S16,
t->audio_format.S16_OE,
t->audio_format.F32,
t->audio_format.F32_OE,
t->audio_format.S32,
t->audio_format.S32_OE,
t->audio_format.S24,
t->audio_format.S24_OE,
t->audio_format.S24_32,
t->audio_format.S24_32_OE),
":", t->format_audio.layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16,
SPA_POD_PROP_ENUM(11, SPA_AUDIO_FORMAT_U8,
SPA_AUDIO_FORMAT_S16,
SPA_AUDIO_FORMAT_S16_OE,
SPA_AUDIO_FORMAT_F32,
SPA_AUDIO_FORMAT_F32_OE,
SPA_AUDIO_FORMAT_S32,
SPA_AUDIO_FORMAT_S32_OE,
SPA_AUDIO_FORMAT_S24,
SPA_AUDIO_FORMAT_S24_OE,
SPA_AUDIO_FORMAT_S24_32,
SPA_AUDIO_FORMAT_S24_32_OE),
":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_LAYOUT_NON_INTERLEAVED),
":", t->format_audio.rate, "iru", DEFAULT_RATE,
":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "iru", DEFAULT_CHANNELS,
":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
}
break;
@ -515,7 +474,6 @@ static int port_get_format(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
@ -524,13 +482,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", port->format.info.raw.format,
":", t->format_audio.layout, "i", port->format.info.raw.layout,
":", t->format_audio.rate, "i", port->format.info.raw.rate,
":", t->format_audio.channels, "i", port->format.info.raw.channels);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels);
return 1;
}
@ -544,7 +502,6 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this;
struct type *t;
struct port *port, *other;
struct spa_pod *param;
@ -557,7 +514,6 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -567,28 +523,34 @@ impl_node_port_enum_params(struct spa_node *node,
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, id, t->param.List,
":", t->param.listId, "I", list[*index]);
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
break;
case SPA_ID_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
break;
case SPA_ID_PARAM_Buffers:
{
uint32_t buffers, size;
const char *size_fmt;
@ -608,44 +570,48 @@ impl_node_port_enum_params(struct spa_node *node,
}
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.buffers, "iru", buffers,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", buffers,
SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS),
":", t->param_buffers.blocks, "i", port->blocks,
":", t->param_buffers.size, size_fmt, size * port->stride,
":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks,
":", SPA_PARAM_BUFFERS_size, size_fmt, size * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
":", t->param_buffers.stride, "i", port->stride,
":", t->param_buffers.align, "i", 16);
":", SPA_PARAM_BUFFERS_stride, "i", port->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
}
else if (id == t->param.idMeta) {
case SPA_ID_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else
break;
default:
return -ENOENT;
}
(*index)++;
@ -655,18 +621,20 @@ impl_node_port_enum_params(struct spa_node *node,
return 1;
}
static int calc_width(struct spa_audio_info *info, struct type *t)
static int calc_width(struct spa_audio_info *info)
{
if (info->info.raw.format == t->audio_format.U8)
switch (info->info.raw.format) {
case SPA_AUDIO_FORMAT_U8:
return 1;
else if (info->info.raw.format == t->audio_format.S16 ||
info->info.raw.format == t->audio_format.S16_OE)
case SPA_AUDIO_FORMAT_S16:
case SPA_AUDIO_FORMAT_S16_OE:
return 2;
else if (info->info.raw.format == t->audio_format.S24 ||
info->info.raw.format == t->audio_format.S24_OE)
case SPA_AUDIO_FORMAT_S24:
case SPA_AUDIO_FORMAT_S24_OE:
return 3;
else
default:
return 4;
}
}
static int clear_buffers(struct impl *this, struct port *port)
@ -695,7 +663,6 @@ static int port_set_format(struct spa_node *node,
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port;
struct type *t = &this->type;
int res = 0;
port = GET_PORT(this, direction, port_id);
@ -715,11 +682,11 @@ static int port_set_format(struct spa_node *node,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != t->media_type.audio ||
info.media_subtype != t->media_subtype.raw)
if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
return -EINVAL;
if (this->n_formats[direction] > 0) {
@ -735,7 +702,7 @@ static int port_set_format(struct spa_node *node,
port->have_format = true;
port->format = info;
port->stride = calc_width(&info, t);
port->stride = calc_width(&info);
if (info.info.raw.layout == SPA_AUDIO_LAYOUT_INTERLEAVED) {
port->stride *= info.info.raw.channels;
@ -762,20 +729,19 @@ impl_node_port_set_param(struct spa_node *node,
const struct spa_pod *param)
{
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
switch (id) {
case SPA_ID_PARAM_Format:
return port_set_format(node, direction, port_id, flags, param);
}
else
default:
return -ENOENT;
}
}
static int
@ -788,12 +754,10 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
struct port *port;
uint32_t i, size = SPA_ID_INVALID;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -812,7 +776,7 @@ impl_node_port_use_buffers(struct spa_node *node,
b = &port->buffers[i];
b->flags = 0;
b->outbuf = buffers[i];
b->h = spa_buffer_find_meta_data(buffers[i], t->meta.Header, sizeof(*b->h));
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
if (size == SPA_ID_INVALID)
size = d[0].maxsize;
@ -820,9 +784,9 @@ impl_node_port_use_buffers(struct spa_node *node,
if (size != d[0].maxsize)
return -EINVAL;
if (!((d[0].type == t->data.MemPtr ||
d[0].type == t->data.MemFd ||
d[0].type == t->data.DmaBuf) && d[0].data != NULL)) {
if (!((d[0].type == SPA_DATA_MemPtr ||
d[0].type == SPA_DATA_MemFd ||
d[0].type == SPA_DATA_DmaBuf) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
buffers[i]);
return -EINVAL;
@ -859,12 +823,10 @@ impl_node_port_set_io(struct spa_node *node,
{
struct impl *this;
struct port *port;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -873,13 +835,16 @@ impl_node_port_set_io(struct spa_node *node,
spa_log_debug(this->log, NAME " %p: port %d:%d update io %d %p",
this, direction, port_id, id, data);
if (id == t->io.Buffers)
switch (id) {
case SPA_ID_IO_Buffers:
port->io = data;
else if (id == t->io.ControlRange)
break;
case SPA_ID_IO_ControlRange:
port->ctrl = data;
else
break;
default:
return -ENOENT;
}
return 0;
}
@ -1172,7 +1137,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -1211,17 +1176,9 @@ impl_init(const struct spa_handle_factory *factory,
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)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
this->node = impl_node;
init_port(this, SPA_DIRECTION_OUTPUT, 0, SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS);
@ -1233,7 +1190,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_ID_INTERFACE_Node,},
};
static int

View file

@ -23,7 +23,6 @@
#include <limits.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@ -32,6 +31,7 @@
#include <spa/param/meta.h>
#include <spa/param/io.h>
#include <spa/pod/filter.h>
#include <spa/debug/types.h>
#define NAME "merger"
@ -41,41 +41,6 @@
#define MAX_BUFFERS 64
#define MAX_PORTS 128
struct type {
uint32_t node;
uint32_t format;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
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->format = spa_type_map_get_id(map, SPA_TYPE__Format);
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
struct buffer {
#define BUFFER_FLAG_QUEUED (1<<0)
uint32_t flags;
@ -109,8 +74,6 @@ struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
const struct spa_node_callbacks *callbacks;
@ -164,13 +127,16 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -339,7 +305,6 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
uint32_t rate;
const char *rspec;
@ -356,39 +321,39 @@ static int port_enum_formats(struct spa_node *node,
if (direction == SPA_DIRECTION_OUTPUT) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "Ieu", t->audio_format.F32,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_F32,
SPA_POD_PROP_ENUM(11,
t->audio_format.F32,
t->audio_format.F32_OE,
t->audio_format.S32,
t->audio_format.S32_OE,
t->audio_format.S24_32,
t->audio_format.S24_32_OE,
t->audio_format.S24,
t->audio_format.S24_OE,
t->audio_format.S16,
t->audio_format.S16_OE,
t->audio_format.U8),
":", t->format_audio.layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_FORMAT_F32,
SPA_AUDIO_FORMAT_F32_OE,
SPA_AUDIO_FORMAT_S32,
SPA_AUDIO_FORMAT_S32_OE,
SPA_AUDIO_FORMAT_S24_32,
SPA_AUDIO_FORMAT_S24_32_OE,
SPA_AUDIO_FORMAT_S24,
SPA_AUDIO_FORMAT_S24_OE,
SPA_AUDIO_FORMAT_S16,
SPA_AUDIO_FORMAT_S16_OE,
SPA_AUDIO_FORMAT_U8),
":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_LAYOUT_NON_INTERLEAVED),
":", t->format_audio.rate, rspec, rate,
":", SPA_FORMAT_AUDIO_rate, rspec, rate,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "i", this->port_count);
":", SPA_FORMAT_AUDIO_channels, "i", this->port_count);
}
else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, rspec, rate,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, rspec, rate,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "i", 1);
":", SPA_FORMAT_AUDIO_channels, "i", 1);
}
break;
default:
@ -404,7 +369,6 @@ static int port_get_format(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
@ -413,13 +377,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", port->format.info.raw.format,
":", t->format_audio.layout, "i", port->format.info.raw.layout,
":", t->format_audio.rate, "i", port->format.info.raw.rate,
":", t->format_audio.channels, "i", port->format.info.raw.channels);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels);
return 1;
}
@ -433,7 +397,6 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this;
struct type *t;
struct port *port;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
@ -445,7 +408,6 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -456,72 +418,75 @@ impl_node_port_enum_params(struct spa_node *node,
spa_log_debug(this->log, NAME " %p: enum param %d %d", this, id, this->have_format);
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO, };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, id, t->param.List,
":", t->param.listId, "I", list[*index]);
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
break;
case SPA_ID_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
break;
case SPA_ID_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
return 0;
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "iru", 1024 * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride),
":", t->param_buffers.blocks, "i", port->blocks,
":", t->param_buffers.stride, "i", port->stride,
":", t->param_buffers.buffers, "iru", 1,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 1,
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
":", t->param_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks,
":", SPA_PARAM_BUFFERS_size, "iru", 1024 * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride),
":", SPA_PARAM_BUFFERS_stride, "i", port->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_ID_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "i", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else
break;
default:
return -ENOENT;
}
(*index)++;
@ -557,7 +522,6 @@ static struct port *find_in_port(struct impl *this)
static int setup_convert(struct impl *this)
{
const struct conv_info *conv;
struct type *t = &this->type;
struct port *inport, *outport;
uint32_t src_fmt, dst_fmt;
@ -570,17 +534,17 @@ static int setup_convert(struct impl *this)
dst_fmt = outport->format.info.raw.format;
spa_log_info(this->log, NAME " %p: %s/%d@%d.%dx%d->%s/%d@%d.%d", this,
spa_type_map_get_type(this->map, src_fmt),
spa_debug_type_find_name(spa_debug_types, src_fmt),
inport->format.info.raw.channels,
inport->format.info.raw.rate,
inport->format.info.raw.layout,
this->port_count,
spa_type_map_get_type(this->map, dst_fmt),
spa_debug_type_find_name(spa_debug_types, dst_fmt),
outport->format.info.raw.channels,
outport->format.info.raw.rate,
outport->format.info.raw.layout);
conv = find_conv_info(&t->audio_format, src_fmt, dst_fmt, FEATURE_SSE);
conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE);
if (conv != NULL) {
spa_log_info(this->log, NAME " %p: got converter features %08x", this,
conv->features);
@ -601,18 +565,20 @@ static int setup_convert(struct impl *this)
return -ENOTSUP;
}
static int calc_width(struct spa_audio_info *info, struct type *t)
static int calc_width(struct spa_audio_info *info)
{
if (info->info.raw.format == t->audio_format.U8)
switch (info->info.raw.format) {
case SPA_AUDIO_FORMAT_U8:
return 1;
else if (info->info.raw.format == t->audio_format.S16 ||
info->info.raw.format == t->audio_format.S16_OE)
case SPA_AUDIO_FORMAT_S16:
case SPA_AUDIO_FORMAT_S16_OE:
return 2;
else if (info->info.raw.format == t->audio_format.S24 ||
info->info.raw.format == t->audio_format.S24_OE)
case SPA_AUDIO_FORMAT_S24:
case SPA_AUDIO_FORMAT_S24_OE:
return 3;
else
default:
return 4;
}
}
static int port_set_format(struct spa_node *node,
@ -623,7 +589,6 @@ static int port_set_format(struct spa_node *node,
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port;
struct type *t = &this->type;
port = GET_PORT(this, direction, port_id);
@ -643,11 +608,11 @@ static int port_set_format(struct spa_node *node,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != t->media_type.audio ||
info.media_subtype != t->media_subtype.raw)
if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
return -EINVAL;
if ((this->have_format || this->force_rate) &&
@ -658,7 +623,7 @@ static int port_set_format(struct spa_node *node,
if (info.info.raw.channels != this->port_count)
return -EINVAL;
} else {
if (info.info.raw.format != t->audio_format.F32)
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED)
return -EINVAL;
@ -667,7 +632,7 @@ static int port_set_format(struct spa_node *node,
}
port->format = info;
port->stride = calc_width(&info, t);
port->stride = calc_width(&info);
if (info.info.raw.layout == SPA_AUDIO_LAYOUT_INTERLEAVED) {
port->stride *= info.info.raw.channels;
port->blocks = 1;
@ -700,20 +665,19 @@ impl_node_port_set_param(struct spa_node *node,
const struct spa_pod *param)
{
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
switch (id) {
case SPA_ID_PARAM_Format:
return port_set_format(node, direction, port_id, flags, param);
}
else
default:
return -ENOENT;
}
}
static void queue_buffer(struct impl *this, struct port *port, uint32_t id)
@ -755,12 +719,10 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
struct port *port;
uint32_t i;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -780,9 +742,9 @@ impl_node_port_use_buffers(struct spa_node *node,
b->buf = buffers[i];
b->flags = 0;
if (!((d[0].type == t->data.MemPtr ||
d[0].type == t->data.MemFd ||
d[0].type == t->data.DmaBuf) && d[0].data != NULL)) {
if (!((d[0].type == SPA_DATA_MemPtr ||
d[0].type == SPA_DATA_MemFd ||
d[0].type == SPA_DATA_DmaBuf) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p %d %p", this,
buffers[i], d[0].type, d[0].data);
return -EINVAL;
@ -814,24 +776,25 @@ impl_node_port_set_io(struct spa_node *node,
{
struct impl *this;
struct port *port;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
if (id == t->io.Buffers)
switch (id) {
case SPA_ID_IO_Buffers:
port->io = data;
else if (id == t->io.ControlRange)
break;
case SPA_ID_IO_ControlRange:
port->ctrl = data;
else
break;
default:
return -ENOENT;
}
return 0;
}
@ -983,7 +946,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -1026,16 +989,9 @@ impl_init(const struct spa_handle_factory *factory,
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)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
if ((str = spa_dict_lookup(info, "node.format.rate")))
if ((rate = atoi(str)) != 0) {
@ -1056,7 +1012,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_ID_INTERFACE_Node,},
};
static int

View file

@ -24,7 +24,6 @@
#include <speex/speex_resampler.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@ -79,52 +78,10 @@ struct port {
uint32_t offset;
};
struct type {
uint32_t node;
uint32_t format;
uint32_t prop_truncate;
uint32_t prop_dither;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
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->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->prop_truncate = spa_type_map_get_id(map, SPA_TYPE_PROPS__truncate);
type->prop_dither = spa_type_map_get_id(map, SPA_TYPE_PROPS__ditherType);
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct props props;
@ -211,13 +168,16 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -316,7 +276,6 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *other;
other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0);
@ -325,24 +284,24 @@ static int port_enum_formats(struct spa_node *node,
case 0:
if (other->have_format) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, "iru", other->format.info.raw.rate,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, "iru", other->format.info.raw.rate,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "i", other->format.info.raw.channels);
":", SPA_FORMAT_AUDIO_channels, "i", other->format.info.raw.channels);
} else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, "iru", DEFAULT_RATE,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "iru", DEFAULT_CHANNELS,
":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
}
break;
@ -359,7 +318,6 @@ static int port_get_format(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
@ -368,13 +326,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", port->format.info.raw.format,
":", t->format_audio.layout, "i", port->format.info.raw.layout,
":", t->format_audio.rate, "i", port->format.info.raw.rate,
":", t->format_audio.channels, "i", port->format.info.raw.channels);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels);
return 1;
}
@ -388,7 +346,6 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this;
struct type *t;
struct port *port, *other;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
@ -400,7 +357,6 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -410,28 +366,32 @@ impl_node_port_enum_params(struct spa_node *node,
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, id, t->param.List,
":", t->param.listId, "I", list[*index]);
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
break;
case SPA_ID_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
break;
case SPA_ID_PARAM_Buffers:
{
uint32_t buffers, size;
if (!port->have_format)
@ -449,44 +409,46 @@ impl_node_port_enum_params(struct spa_node *node,
}
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.buffers, "iru", buffers,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", buffers,
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
":", t->param_buffers.blocks, "i", port->blocks,
":", t->param_buffers.size, "iru", size * port->stride,
":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks,
":", SPA_PARAM_BUFFERS_size, "iru", size * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
":", t->param_buffers.stride, "i", port->stride,
":", t->param_buffers.align, "i", 16);
":", SPA_PARAM_BUFFERS_stride, "i", port->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
}
else if (id == t->param.idMeta) {
case SPA_ID_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else
break;
default:
return -ENOENT;
}
(*index)++;
@ -514,7 +476,6 @@ static int port_set_format(struct spa_node *node,
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port, *other;
struct type *t = &this->type;
int res = 0;
port = GET_PORT(this, direction, port_id);
@ -532,14 +493,14 @@ static int port_set_format(struct spa_node *node,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != t->media_type.audio ||
info.media_subtype != t->media_subtype.raw)
if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
return -EINVAL;
if (info.info.raw.format != t->audio_format.F32)
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED)
return -EINVAL;
@ -565,17 +526,11 @@ impl_node_port_set_param(struct spa_node *node,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -592,12 +547,10 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
struct port *port;
uint32_t i, size = SPA_ID_INVALID;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -616,7 +569,7 @@ impl_node_port_use_buffers(struct spa_node *node,
b = &port->buffers[i];
b->flags = 0;
b->outbuf = buffers[i];
b->h = spa_buffer_find_meta_data(buffers[i], t->meta.Header, sizeof(*b->h));
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
if (size == SPA_ID_INVALID)
size = d[0].maxsize;
@ -624,9 +577,9 @@ impl_node_port_use_buffers(struct spa_node *node,
if (size != d[0].maxsize)
return -EINVAL;
if (!((d[0].type == t->data.MemPtr ||
d[0].type == t->data.MemFd ||
d[0].type == t->data.DmaBuf) && d[0].data != NULL)) {
if (!((d[0].type == SPA_DATA_MemPtr ||
d[0].type == SPA_DATA_MemFd ||
d[0].type == SPA_DATA_DmaBuf) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
buffers[i]);
return -EINVAL;
@ -663,20 +616,18 @@ impl_node_port_set_io(struct spa_node *node,
{
struct impl *this;
struct port *port;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
if (id == t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
port->io = data;
else if (id == t->io.ControlRange)
else if (id == SPA_ID_IO_ControlRange)
port->ctrl = data;
else
return -ENOENT;
@ -859,7 +810,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -907,16 +858,9 @@ impl_init(const struct spa_handle_factory *factory,
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)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
this->node = impl_node;
@ -936,7 +880,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_ID_INTERFACE_Node,},
};
static int

View file

@ -23,7 +23,6 @@
#include <limits.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@ -32,6 +31,7 @@
#include <spa/param/meta.h>
#include <spa/param/io.h>
#include <spa/pod/filter.h>
#include <spa/debug/types.h>
#define NAME "splitter"
@ -41,41 +41,6 @@
#define MAX_BUFFERS 64
#define MAX_PORTS 128
struct type {
uint32_t node;
uint32_t format;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
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->format = spa_type_map_get_id(map, SPA_TYPE__Format);
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
struct buffer {
#define BUFFER_FLAG_QUEUED (1<<0)
uint32_t flags;
@ -109,8 +74,6 @@ struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
const struct spa_node_callbacks *callbacks;
@ -164,13 +127,16 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -339,7 +305,6 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
uint32_t rate;
const char *rspec;
@ -356,39 +321,39 @@ static int port_enum_formats(struct spa_node *node,
if (direction == SPA_DIRECTION_INPUT) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "Ieu", t->audio_format.F32,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_F32,
SPA_POD_PROP_ENUM(11,
t->audio_format.F32,
t->audio_format.F32_OE,
t->audio_format.S32,
t->audio_format.S32_OE,
t->audio_format.S24_32,
t->audio_format.S24_32_OE,
t->audio_format.S24,
t->audio_format.S24_OE,
t->audio_format.S16,
t->audio_format.S16_OE,
t->audio_format.U8),
":", t->format_audio.layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_FORMAT_F32,
SPA_AUDIO_FORMAT_F32_OE,
SPA_AUDIO_FORMAT_S32,
SPA_AUDIO_FORMAT_S32_OE,
SPA_AUDIO_FORMAT_S24_32,
SPA_AUDIO_FORMAT_S24_32_OE,
SPA_AUDIO_FORMAT_S24,
SPA_AUDIO_FORMAT_S24_OE,
SPA_AUDIO_FORMAT_S16,
SPA_AUDIO_FORMAT_S16_OE,
SPA_AUDIO_FORMAT_U8),
":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_LAYOUT_NON_INTERLEAVED),
":", t->format_audio.rate, rspec, rate,
":", SPA_FORMAT_AUDIO_rate, rspec, rate,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "i", this->port_count);
":", SPA_FORMAT_AUDIO_channels, "i", this->port_count);
}
else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, rspec, rate,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, rspec, rate,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "i", 1);
":", SPA_FORMAT_AUDIO_channels, "i", 1);
}
break;
default:
@ -404,7 +369,6 @@ static int port_get_format(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
@ -413,13 +377,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", port->format.info.raw.format,
":", t->format_audio.layout, "i", port->format.info.raw.layout,
":", t->format_audio.rate, "i", port->format.info.raw.rate,
":", t->format_audio.channels, "i", port->format.info.raw.channels);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels);
return 1;
}
@ -433,7 +397,6 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this;
struct type *t;
struct port *port;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
@ -445,7 +408,6 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -456,72 +418,77 @@ impl_node_port_enum_params(struct spa_node *node,
spa_log_debug(this->log, NAME " %p: enum param %d %d", this, id, this->have_format);
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, id, t->param.List,
":", t->param.listId, "I", list[*index]);
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
break;
case SPA_ID_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
break;
case SPA_ID_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
return 0;
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "iru", 1024 * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride),
":", t->param_buffers.blocks, "i", port->blocks,
":", t->param_buffers.stride, "i", port->stride,
":", t->param_buffers.buffers, "iru", 1,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 1,
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
":", t->param_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks,
":", SPA_PARAM_BUFFERS_size, "iru", 1024 * port->stride,
SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride),
":", SPA_PARAM_BUFFERS_stride, "i", port->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_ID_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else
break;
default:
return -ENOENT;
}
(*index)++;
@ -557,7 +524,6 @@ static struct port *find_out_port(struct impl *this)
static int setup_convert(struct impl *this)
{
const struct conv_info *conv;
struct type *t = &this->type;
struct port *inport, *outport;
uint32_t src_fmt, dst_fmt;
@ -570,17 +536,17 @@ static int setup_convert(struct impl *this)
dst_fmt = outport->format.info.raw.format;
spa_log_info(this->log, NAME " %p: %s/%d@%d.%dx%d->%s/%d@%d.%d", this,
spa_type_map_get_type(this->map, src_fmt),
spa_debug_type_find_name(spa_debug_types, src_fmt),
inport->format.info.raw.channels,
inport->format.info.raw.rate,
inport->format.info.raw.layout,
this->port_count,
spa_type_map_get_type(this->map, dst_fmt),
spa_debug_type_find_name(spa_debug_types, dst_fmt),
outport->format.info.raw.channels,
outport->format.info.raw.rate,
outport->format.info.raw.layout);
conv = find_conv_info(&t->audio_format, src_fmt, dst_fmt, FEATURE_SSE);
conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE);
if (conv != NULL) {
spa_log_info(this->log, NAME " %p: got converter features %08x", this,
conv->features);
@ -601,18 +567,20 @@ static int setup_convert(struct impl *this)
return -ENOTSUP;
}
static int calc_width(struct spa_audio_info *info, struct type *t)
static int calc_width(struct spa_audio_info *info)
{
if (info->info.raw.format == t->audio_format.U8)
switch (info->info.raw.format) {
case SPA_AUDIO_FORMAT_U8:
return 1;
else if (info->info.raw.format == t->audio_format.S16 ||
info->info.raw.format == t->audio_format.S16_OE)
case SPA_AUDIO_FORMAT_S16:
case SPA_AUDIO_FORMAT_S16_OE:
return 2;
else if (info->info.raw.format == t->audio_format.S24 ||
info->info.raw.format == t->audio_format.S24_OE)
case SPA_AUDIO_FORMAT_S24:
case SPA_AUDIO_FORMAT_S24_OE:
return 3;
else
default:
return 4;
}
}
static int port_set_format(struct spa_node *node,
@ -623,7 +591,6 @@ static int port_set_format(struct spa_node *node,
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port;
struct type *t = &this->type;
port = GET_PORT(this, direction, port_id);
@ -643,11 +610,11 @@ static int port_set_format(struct spa_node *node,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != t->media_type.audio ||
info.media_subtype != t->media_subtype.raw)
if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
return -EINVAL;
if ((this->have_format || this->force_rate) &&
@ -658,7 +625,7 @@ static int port_set_format(struct spa_node *node,
if (info.info.raw.channels != this->port_count)
return -EINVAL;
} else {
if (info.info.raw.format != t->audio_format.F32)
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED)
return -EINVAL;
@ -667,7 +634,7 @@ static int port_set_format(struct spa_node *node,
}
port->format = info;
port->stride = calc_width(&info, t);
port->stride = calc_width(&info);
if (info.info.raw.layout == SPA_AUDIO_LAYOUT_INTERLEAVED) {
port->stride *= info.info.raw.channels;
port->blocks = 1;
@ -700,20 +667,19 @@ impl_node_port_set_param(struct spa_node *node,
const struct spa_pod *param)
{
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
switch (id) {
case SPA_ID_PARAM_Format:
return port_set_format(node, direction, port_id, flags, param);
}
else
default:
return -ENOENT;
}
}
static void queue_buffer(struct impl *this, struct port *port, uint32_t id)
@ -755,12 +721,10 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
struct port *port;
uint32_t i;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -780,9 +744,9 @@ impl_node_port_use_buffers(struct spa_node *node,
b->buf = buffers[i];
b->flags = 0;
if (!((d[0].type == t->data.MemPtr ||
d[0].type == t->data.MemFd ||
d[0].type == t->data.DmaBuf) && d[0].data != NULL)) {
if (!((d[0].type == SPA_DATA_MemPtr ||
d[0].type == SPA_DATA_MemFd ||
d[0].type == SPA_DATA_DmaBuf) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p %d %p", this,
buffers[i], d[0].type, d[0].data);
return -EINVAL;
@ -814,20 +778,18 @@ impl_node_port_set_io(struct spa_node *node,
{
struct impl *this;
struct port *port;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
if (id == t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
port->io = data;
else if (id == t->io.ControlRange)
else if (id == SPA_ID_IO_ControlRange)
port->ctrl = data;
else
return -ENOENT;
@ -993,7 +955,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -1036,16 +998,9 @@ impl_init(const struct spa_handle_factory *factory,
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)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
if ((str = spa_dict_lookup(info, "node.format.rate")))
if ((rate = atoi(str)) != 0) {
@ -1065,7 +1020,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_ID_INTERFACE_Node,},
};
static int