Unify props, params and formats

Make enum_params and set_param to configure properties, format
and other parameters. This allows us to remove some duplicate
code and make the properties and parameters much more extensible.
Use the object id to mark the id of the parameter.
Remove the spa_format and spa_props.
We can now make the client-node easier by merging the various
format methods into the params.
Make the stream API more powerful now that we can pass params
around.
This commit is contained in:
Wim Taymans 2017-11-07 17:39:31 +01:00
parent b6ee67905d
commit f3bca48398
87 changed files with 3773 additions and 3580 deletions

View file

@ -42,20 +42,22 @@ static void reset_props(struct props *props)
props->max_latency = default_max_latency;
}
static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this;
struct spa_pod_builder b = { NULL, };
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(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_pod_builder_init(&b, this->props_buffer, sizeof(this->props_buffer));
*props = spa_pod_builder_props(&b,
this->type.props,
if (id == this->type.param.idProps) {
spa_pod_builder_object(builder,
id, this->type.props,
":", this->type.prop_device, "S", this->props.device, sizeof(this->props.device),
":", this->type.prop_device_name, "S", this->props.device_name, sizeof(this->props.device_name),
":", this->type.prop_card_name, "S", this->props.card_name, sizeof(this->props.card_name),
@ -63,11 +65,15 @@ static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
2, 1, INT32_MAX,
":", this->type.prop_max_latency, "ir", this->props.max_latency,
2, 1, INT32_MAX);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return SPA_RESULT_OK;
}
static int impl_node_set_props(struct spa_node *node, const struct spa_props *props)
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
struct state *this;
@ -75,14 +81,18 @@ static int impl_node_set_props(struct spa_node *node, const struct spa_props *pr
this = SPA_CONTAINER_OF(node, struct state, node);
if (props == NULL) {
reset_props(&this->props);
return SPA_RESULT_OK;
} else {
spa_props_parse(props,
if (id == this->type.param.idProps) {
if (param == NULL) {
reset_props(&this->props);
return SPA_RESULT_OK;
}
spa_pod_object_parse(param,
":", this->type.prop_device, "?S", this->props.device, sizeof(this->props.device),
":", this->type.prop_min_latency, "?i", &this->props.min_latency, NULL);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
return SPA_RESULT_OK;
}
@ -213,23 +223,130 @@ static int impl_node_remove_port(struct spa_node *node, enum spa_direction direc
}
static int
impl_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)
impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_port_info **info)
{
struct state *this;
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(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
return spa_alsa_enum_format(this, format, filter, index);
*info = &this->info;
return SPA_RESULT_OK;
}
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
return spa_alsa_enum_format(this, index, filter, builder);
}
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
struct type *t = &this->type;
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
if(*index > 0)
return SPA_RESULT_ENUM_END;
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", this->current_format.info.raw.format,
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
return SPA_RESULT_OK;
}
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this;
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (id == t->param.idEnumFormat) {
return port_enum_formats(node, direction, port_id, index, filter, builder);
}
else if (id == t->param.idFormat) {
return port_get_format(node, direction, port_id, index, filter, builder);
}
else if (id == t->param.idBuffers) {
if (*index > 0)
return SPA_RESULT_ENUM_END;
spa_pod_builder_object(builder,
id, t->param_alloc_buffers.Buffers,
":", t->param_alloc_buffers.size, "iru", this->props.min_latency * this->frame_size,
2, this->props.min_latency * this->frame_size,
INT32_MAX,
":", t->param_alloc_buffers.stride, "i", 0,
":", t->param_alloc_buffers.buffers, "ir", 2,
2, 2, MAX_BUFFERS,
":", t->param_alloc_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
switch (*index) {
case 0:
spa_pod_builder_object(builder,
id, t->param_alloc_meta_enable.MetaEnable,
":", t->param_alloc_meta_enable.type, "I", t->meta.Header,
":", t->param_alloc_meta_enable.size, "i", sizeof(struct spa_meta_header));
break;
case 1:
spa_pod_builder_object(builder,
id, t->param_alloc_meta_enable.MetaEnable,
":", t->param_alloc_meta_enable.type, "I", t->meta.Ringbuffer,
":", t->param_alloc_meta_enable.size, "i", sizeof(struct spa_meta_ringbuffer),
":", t->param_alloc_meta_enable.ringbufferSize, "iru",
this->props.max_latency * this->frame_size,
2, this->props.min_latency * this->frame_size,
this->period_frames * this->frame_size,
":", t->param_alloc_meta_enable.ringbufferStride, "i", 0,
":", t->param_alloc_meta_enable.ringbufferBlocks, "i", 1,
":", t->param_alloc_meta_enable.ringbufferAlign, "i", 16);
break;
default:
return SPA_RESULT_ENUM_END;
}
}
else
return SPA_RESULT_UNKNOWN_PARAM;
(*index)++;
return SPA_RESULT_OK;
}
static int clear_buffers(struct state *this)
@ -241,22 +358,14 @@ static int clear_buffers(struct state *this)
return SPA_RESULT_OK;
}
static int
impl_node_port_set_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
static int port_set_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t flags,
const struct spa_pod_object *format)
{
struct state *this;
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
int err;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (format == NULL) {
spa_log_info(this->log, "clear format");
spa_alsa_pause(this, false);
@ -264,9 +373,11 @@ impl_node_port_set_format(struct spa_node *node,
spa_alsa_close(this);
this->have_format = false;
} else {
struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE(format),
};
struct spa_audio_info info = { 0 };
spa_pod_object_parse(format,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != this->type.media_type.audio ||
info.media_subtype != this->type.media_subtype.raw)
@ -290,124 +401,27 @@ impl_node_port_set_format(struct spa_node *node,
return SPA_RESULT_OK;
}
static int
impl_node_port_get_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const struct spa_format **format)
{
struct state *this;
struct spa_pod_builder b = { NULL, };
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
spa_pod_builder_init(&b, this->format_buffer, sizeof(this->format_buffer));
*format = spa_pod_builder_format(&b,
t->format,
t->media_type.audio, t->media_subtype.raw,
":", t->format_audio.format, "I", this->current_format.info.raw.format,
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
return SPA_RESULT_OK;
}
static int
impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_port_info **info)
{
struct state *this;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
*info = &this->info;
return SPA_RESULT_OK;
}
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
struct spa_param **param)
{
struct state *this;
struct spa_pod_builder b = { NULL };
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
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));
switch (index) {
case 0:
*param = spa_pod_builder_param(&b,
t->param_alloc_buffers.Buffers,
":", t->param_alloc_buffers.size, "iru", this->props.min_latency * this->frame_size,
2, this->props.min_latency * this->frame_size,
INT32_MAX,
":", t->param_alloc_buffers.stride, "i", 0,
":", t->param_alloc_buffers.buffers, "ir", 2,
2, 2, MAX_BUFFERS,
":", t->param_alloc_buffers.align, "i", 16);
break;
case 1:
*param = spa_pod_builder_param(&b,
t->param_alloc_meta_enable.MetaEnable,
":", t->param_alloc_meta_enable.type, "I", t->meta.Header,
":", t->param_alloc_meta_enable.size, "i", sizeof(struct spa_meta_header));
break;
case 2:
*param = spa_pod_builder_param(&b,
t->param_alloc_meta_enable.MetaEnable,
":", t->param_alloc_meta_enable.type, "I", t->meta.Ringbuffer,
":", t->param_alloc_meta_enable.size, "i", sizeof(struct spa_meta_ringbuffer),
":", t->param_alloc_meta_enable.ringbufferSize, "iru",
this->props.max_latency * this->frame_size,
2, this->props.min_latency * this->frame_size,
this->period_frames * this->frame_size,
":", t->param_alloc_meta_enable.ringbufferStride, "i", 0,
":", t->param_alloc_meta_enable.ringbufferBlocks, "i", 1,
":", t->param_alloc_meta_enable.ringbufferAlign, "i", 16);
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
}
static int
impl_node_port_set_param(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_param *param)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
struct state *this;
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (id == t->param.idFormat) {
return port_set_format(node, direction, port_id, flags, param);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
}
static int
@ -462,7 +476,7 @@ static int
impl_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
struct spa_pod_object **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
@ -573,17 +587,14 @@ static const struct spa_dict node_info = {
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
&node_info,
impl_node_get_props,
impl_node_set_props,
impl_node_enum_params,
impl_node_set_param,
impl_node_send_command,
impl_node_set_callbacks,
impl_node_get_n_ports,
impl_node_get_port_ids,
impl_node_add_port,
impl_node_remove_port,
impl_node_port_enum_formats,
impl_node_port_set_format,
impl_node_port_get_format,
impl_node_port_get_info,
impl_node_port_enum_params,
impl_node_port_set_param,

View file

@ -41,20 +41,21 @@ static void reset_props(struct props *props)
props->min_latency = default_min_latency;
}
static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
static int impl_node_enum_params(struct spa_node *node,
uint32_t id, uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this;
struct spa_pod_builder b = { NULL, };
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(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_pod_builder_init(&b, this->props_buffer, sizeof(this->props_buffer));
*props = spa_pod_builder_props(&b,
this->type.props,
spa_pod_builder_object(builder,
id, this->type.props,
":", this->type.prop_device, "S", this->props.device, sizeof(this->props.device),
":", this->type.prop_device_name, "S", this->props.device_name, sizeof(this->props.device_name),
":", this->type.prop_card_name, "S", this->props.card_name, sizeof(this->props.card_name),
@ -64,7 +65,8 @@ static int impl_node_get_props(struct spa_node *node, struct spa_props **props)
return SPA_RESULT_OK;
}
static int impl_node_set_props(struct spa_node *node, const struct spa_props *props)
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
struct state *this;
@ -72,14 +74,9 @@ static int impl_node_set_props(struct spa_node *node, const struct spa_props *pr
this = SPA_CONTAINER_OF(node, struct state, node);
if (props == NULL) {
reset_props(&this->props);
return SPA_RESULT_OK;
} else {
spa_props_parse(props,
":", this->type.prop_device, "?S", this->props.device, sizeof(this->props.device),
":", this->type.prop_min_latency, "?i", &this->props.min_latency, NULL);
}
spa_pod_object_parse(param,
":", this->type.prop_device, "?S", this->props.device, sizeof(this->props.device),
":", this->type.prop_min_latency, "?i", &this->props.min_latency, NULL);
return SPA_RESULT_OK;
}
@ -227,21 +224,21 @@ static int impl_node_remove_port(struct spa_node *node, enum spa_direction direc
}
static int
impl_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)
impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_port_info **info)
{
struct state *this;
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(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
return spa_alsa_enum_format(this, format, filter, index);
*info = &this->info;
return SPA_RESULT_OK;
}
static void recycle_buffer(struct state *this, uint32_t buffer_id)
@ -257,6 +254,97 @@ static void recycle_buffer(struct state *this, uint32_t buffer_id)
spa_list_append(&this->free, &b->link);
}
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
return spa_alsa_enum_format(this, index, filter, builder);
}
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
struct type *t = &this->type;
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
if (*index > 0)
return SPA_RESULT_ENUM_END;
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", this->current_format.info.raw.format,
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
return SPA_RESULT_OK;
}
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct state *this;
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(builder != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (id == t->param.idEnumFormat) {
return port_enum_formats(node, direction, port_id, index, filter, builder);
}
else if (id == t->param.idFormat) {
return port_get_format(node, direction, port_id, index, filter, builder);
}
else if (id == t->param.idBuffers) {
spa_pod_builder_object(builder,
id, t->param_alloc_buffers.Buffers,
":", t->param_alloc_buffers.size, "i", this->props.min_latency * this->frame_size,
":", t->param_alloc_buffers.stride, "i", 0,
":", t->param_alloc_buffers.buffers, "ir", 2,
2, 1, 32,
":", t->param_alloc_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
switch (*index) {
case 0:
spa_pod_builder_object(builder,
id, t->param_alloc_meta_enable.MetaEnable,
":", t->param_alloc_meta_enable.type, "I", t->meta.Header,
":", t->param_alloc_meta_enable.size, "i", sizeof(struct spa_meta_header));
break;
default:
return SPA_RESULT_ENUM_END;
}
}
else
return SPA_RESULT_UNKNOWN_PARAM;
(*index)++;
return SPA_RESULT_OK;
}
static int clear_buffers(struct state *this)
{
if (this->n_buffers > 0) {
@ -267,29 +355,24 @@ static int clear_buffers(struct state *this)
return SPA_RESULT_OK;
}
static int
impl_node_port_set_format(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id, uint32_t flags, const struct spa_format *format)
static int port_set_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t flags, const struct spa_pod_object *format)
{
struct state *this;
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
int err;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (format == NULL) {
spa_alsa_pause(this, false);
clear_buffers(this);
spa_alsa_close(this);
this->have_format = false;
} else {
struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE(format),
SPA_FORMAT_MEDIA_SUBTYPE(format),
};
struct spa_audio_info info = { 0 };
spa_pod_object_parse(format,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != this->type.media_type.audio ||
info.media_subtype != this->type.media_subtype.raw)
@ -313,102 +396,27 @@ impl_node_port_set_format(struct spa_node *node,
return SPA_RESULT_OK;
}
static int
impl_node_port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_format **format)
{
struct state *this;
struct spa_pod_builder b = { NULL, };
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
spa_pod_builder_init(&b, this->format_buffer, sizeof(this->format_buffer));
*format = spa_pod_builder_format(&b,
t->format,
t->media_type.audio, t->media_subtype.raw,
":", t->format_audio.format, "I", this->current_format.info.raw.format,
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
return SPA_RESULT_OK;
}
static int
impl_node_port_get_info(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_port_info **info)
{
struct state *this;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
*info = &this->info;
return SPA_RESULT_OK;
}
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, uint32_t index, struct spa_param **param)
{
struct state *this;
struct spa_pod_builder b = { NULL, };
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
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));
switch (index) {
case 0:
*param = spa_pod_builder_param(&b,
t->param_alloc_buffers.Buffers,
":", t->param_alloc_buffers.size, "i", this->props.min_latency * this->frame_size,
":", t->param_alloc_buffers.stride, "i", 0,
":", t->param_alloc_buffers.buffers, "ir", 2,
2, 1, 32,
":", t->param_alloc_buffers.align, "i", 16);
break;
case 1:
*param = spa_pod_builder_param(&b,
t->param_alloc_meta_enable.MetaEnable,
":", t->param_alloc_meta_enable.type, "I", t->meta.Header,
":", t->param_alloc_meta_enable.size, "i", sizeof(struct spa_meta_header));
break;
default:
return SPA_RESULT_NOT_IMPLEMENTED;
}
return SPA_RESULT_OK;
}
static int
impl_node_port_set_param(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, const struct spa_param *param)
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
struct state *this;
struct type *t;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
if (id == t->param.idFormat) {
return port_set_format(node, direction, port_id, flags, param);
}
else
return SPA_RESULT_UNKNOWN_PARAM;
}
static int
@ -461,7 +469,7 @@ static int
impl_node_port_alloc_buffers(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
struct spa_pod_object **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
@ -579,17 +587,14 @@ static const struct spa_dict node_info = {
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
&node_info,
impl_node_get_props,
impl_node_set_props,
impl_node_enum_params,
impl_node_set_param,
impl_node_send_command,
impl_node_set_callbacks,
impl_node_get_n_ports,
impl_node_get_port_ids,
impl_node_add_port,
impl_node_remove_port,
impl_node_port_enum_formats,
impl_node_port_set_format,
impl_node_port_get_format,
impl_node_port_get_info,
impl_node_port_enum_params,
impl_node_port_set_param,
@ -602,12 +607,15 @@ static const struct spa_node impl_node = {
impl_node_process_output,
};
static int impl_clock_get_props(struct spa_clock *clock, struct spa_props **props)
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod_builder *builder)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static int impl_clock_set_props(struct spa_clock *clock, const struct spa_props *props)
static int impl_clock_set_param(struct spa_clock *clock,
uint32_t id, uint32_t flags,
const struct spa_pod_object *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -637,8 +645,8 @@ static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_get_props,
impl_clock_set_props,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};

View file

@ -117,7 +117,9 @@ static snd_pcm_format_t spa_alsa_format_to_alsa(struct type *map, uint32_t forma
}
int
spa_alsa_enum_format(struct state *state, struct spa_format **format, const struct spa_format *filter, uint32_t index)
spa_alsa_enum_format(struct state *state, uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
snd_pcm_t *hndl;
snd_pcm_hw_params_t *params;
@ -128,11 +130,11 @@ spa_alsa_enum_format(struct state *state, struct spa_format **format, const stru
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
struct spa_pod_frame f[2];
struct spa_pod_prop *prop;
struct spa_format *fmt;
struct spa_pod_object *fmt;
int res;
bool opened;
if (index == 1)
if (*index > 0)
return SPA_RESULT_ENUM_END;
opened = state->opened;
@ -143,8 +145,11 @@ spa_alsa_enum_format(struct state *state, struct spa_format **format, const stru
snd_pcm_hw_params_alloca(&params);
CHECK(snd_pcm_hw_params_any(hndl, params), "Broken configuration: no configurations available");
spa_pod_builder_push_format(&b, &f[0], state->type.format,
state->type.media_type.audio, state->type.media_subtype.raw);
spa_pod_builder_push_object(&b, &f[0],
state->type.param.idEnumFormat, state->type.format);
spa_pod_builder_add(&b,
"I", state->type.media_type.audio,
"I", state->type.media_subtype.raw, 0);
snd_pcm_format_mask_alloca(&fmask);
snd_pcm_hw_params_get_format_mask(params, fmask);
@ -195,13 +200,13 @@ spa_alsa_enum_format(struct state *state, struct spa_format **format, const stru
spa_pod_builder_pop(&b, &f[1]);
spa_pod_builder_pop(&b, &f[0]);
fmt = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_format);
fmt = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_pod_object);
spa_pod_builder_init(&b, state->format_buffer, sizeof(state->format_buffer));
if ((res = spa_format_filter(fmt, filter, &b)) < 0)
(*index)++;
if ((res = spa_pod_object_filter(fmt, filter, builder)) < 0)
return res;
*format = SPA_POD_BUILDER_DEREF(&b, 0, struct spa_format);
if (!opened)
spa_alsa_close(state);
@ -251,7 +256,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
CHECK(snd_pcm_hw_params_set_channels_near(hndl, params, &rchannels), "set_channels");
if (rchannels != info->channels) {
spa_log_info(state->log, "Channels doesn't match (requested %u, get %u", info->channels, rchannels);
if (flags & SPA_PORT_FORMAT_FLAG_NEAREST)
if (flags & SPA_NODE_PARAM_FLAG_NEAREST)
info->channels = rchannels;
else
return -EINVAL;
@ -262,7 +267,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
CHECK(snd_pcm_hw_params_set_rate_near(hndl, params, &rrate, 0), "set_rate_near");
if (rrate != info->rate) {
spa_log_info(state->log, "Rate doesn't match (requested %iHz, get %iHz)", info->rate, rrate);
if (flags & SPA_PORT_FORMAT_FLAG_NEAREST)
if (flags & SPA_NODE_PARAM_FLAG_NEAREST)
info->rate = rrate;
else
return -EINVAL;

View file

@ -37,7 +37,6 @@ extern "C" {
#include <spa/loop.h>
#include <spa/ringbuffer.h>
#include <spa/audio/format-utils.h>
#include <spa/format-builder.h>
struct props {
char device[64];
@ -67,6 +66,7 @@ struct type {
uint32_t prop_card_name;
uint32_t prop_min_latency;
uint32_t prop_max_latency;
struct spa_type_param param;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_media_type media_type;
@ -92,6 +92,7 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
type->prop_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency);
type->prop_max_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__maxLatency);
spa_type_param_map(map, &type->param);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_media_type_map(map, &type->media_type);
@ -124,7 +125,6 @@ struct state {
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
uint8_t props_buffer[1024];
struct props props;
bool opened;
@ -169,7 +169,9 @@ struct state {
int
spa_alsa_enum_format(struct state *state,
struct spa_format **format, const struct spa_format *filter, uint32_t index);
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder);
int spa_alsa_set_format(struct state *state, struct spa_audio_info *info, uint32_t flags);