small cleanups

This commit is contained in:
Wim Taymans 2018-05-10 11:23:51 +02:00
parent 1ede97577b
commit 6d79ce2589
12 changed files with 46 additions and 72 deletions

View file

@ -118,9 +118,6 @@ enum spa_node_param_flags {
/** /**
* A spa_node is a component that can consume and produce buffers. * A spa_node is a component that can consume and produce buffers.
*
*
*
*/ */
struct spa_node { struct spa_node {
/* the version of this node. This can be used to expand this /* the version of this node. This can be used to expand this
@ -477,11 +474,11 @@ struct spa_node {
* Input areas with SPA_STATUS_HAVE_BUFFER are consumed if possible * Input areas with SPA_STATUS_HAVE_BUFFER are consumed if possible
* and the status is set to SPA_STATUS_NEED_BUFFER or SPA_STATUS_OK. * and the status is set to SPA_STATUS_NEED_BUFFER or SPA_STATUS_OK.
* *
* When the node has new output buffers, SPA_STATUS_HAVE_BUFFER * When the node has new output buffers, the SPA_STATUS_HAVE_BUFFER
* is returned. * bit will be set.
* *
* When no new output could be produced, SPA_STATUS_NEED_BUFFER is * When the node can accept new input in the next cycle, the
* returned. * SPA_STATUS_NEED_BUFFER bit will be set.
*/ */
int (*process) (struct spa_node *node); int (*process) (struct spa_node *node);
}; };

View file

@ -404,7 +404,7 @@ static int port_set_format(struct spa_node *node,
int err; int err;
if (format == NULL) { if (format == NULL) {
spa_log_info(this->log, "clear format"); spa_log_debug(this->log, "clear format");
spa_alsa_pause(this, false); spa_alsa_pause(this, false);
clear_buffers(this); clear_buffers(this);
spa_alsa_close(this); spa_alsa_close(this);
@ -475,7 +475,7 @@ impl_node_port_use_buffers(struct spa_node *node,
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
spa_log_info(this->log, "use buffers %d", n_buffers); spa_log_debug(this->log, "use buffers %d", n_buffers);
if (!this->have_format) if (!this->have_format)
return -EIO; return -EIO;

View file

@ -273,7 +273,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
rchannels = info->channels; rchannels = info->channels;
CHECK(snd_pcm_hw_params_set_channels_near(hndl, params, &rchannels), "set_channels"); CHECK(snd_pcm_hw_params_set_channels_near(hndl, params, &rchannels), "set_channels");
if (rchannels != info->channels) { if (rchannels != info->channels) {
spa_log_info(state->log, "Channels doesn't match (requested %u, get %u", info->channels, rchannels); spa_log_warn(state->log, "Channels doesn't match (requested %u, get %u", info->channels, rchannels);
if (flags & SPA_NODE_PARAM_FLAG_NEAREST) if (flags & SPA_NODE_PARAM_FLAG_NEAREST)
info->channels = rchannels; info->channels = rchannels;
else else
@ -284,7 +284,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
rrate = info->rate; rrate = info->rate;
CHECK(snd_pcm_hw_params_set_rate_near(hndl, params, &rrate, 0), "set_rate_near"); CHECK(snd_pcm_hw_params_set_rate_near(hndl, params, &rrate, 0), "set_rate_near");
if (rrate != info->rate) { if (rrate != info->rate) {
spa_log_info(state->log, "Rate doesn't match (requested %iHz, get %iHz)", info->rate, rrate); spa_log_warn(state->log, "Rate doesn't match (requested %iHz, get %iHz)", info->rate, rrate);
if (flags & SPA_NODE_PARAM_FLAG_NEAREST) if (flags & SPA_NODE_PARAM_FLAG_NEAREST)
info->rate = rrate; info->rate = rrate;
else else

View file

@ -457,7 +457,7 @@ static int setup_buffers(struct impl *this, enum spa_direction direction)
{ {
int i, res; int i, res;
spa_log_info(this->log, NAME " %p: %d", this, direction); spa_log_debug(this->log, NAME " %p: %d", this, direction);
if (direction == SPA_DIRECTION_INPUT) { if (direction == SPA_DIRECTION_INPUT) {
for (i = 1; i < this->n_links-1; i++) { for (i = 1; i < this->n_links-1; i++) {
@ -656,7 +656,7 @@ static int port_set_format(struct spa_node *node,
if (other->have_format) if (other->have_format)
res = setup_convert(this); res = setup_convert(this);
spa_log_info(this->log, NAME " %p: set format on port %d %d", this, port_id, res); spa_log_debug(this->log, NAME " %p: set format on port %d %d", this, port_id, res);
} }
return res; return res;
} }

View file

@ -163,7 +163,7 @@ static int setup_convert(struct impl *this)
src_fmt = inport->format.info.raw.format; src_fmt = inport->format.info.raw.format;
dst_fmt = outport->format.info.raw.format; dst_fmt = outport->format.info.raw.format;
spa_log_info(this->log, NAME " %p: %s/%d@%d.%d->%s/%d@%d.%d", this, spa_log_debug(this->log, NAME " %p: %s/%d@%d.%d->%s/%d@%d.%d", this,
spa_type_map_get_type(this->map, src_fmt), spa_type_map_get_type(this->map, src_fmt),
inport->format.info.raw.channels, inport->format.info.raw.channels,
inport->format.info.raw.rate, inport->format.info.raw.rate,
@ -545,7 +545,7 @@ static int calc_width(struct spa_audio_info *info, struct type *t)
static int clear_buffers(struct impl *this, struct port *port) static int clear_buffers(struct impl *this, struct port *port)
{ {
if (port->n_buffers > 0) { if (port->n_buffers > 0) {
spa_log_info(this->log, NAME " %p: clear buffers %p", this, port); spa_log_debug(this->log, NAME " %p: clear buffers %p", this, port);
port->n_buffers = 0; port->n_buffers = 0;
spa_list_init(&port->queue); spa_list_init(&port->queue);
} }
@ -602,7 +602,7 @@ static int port_set_format(struct spa_node *node,
if (other->have_format) if (other->have_format)
res = setup_convert(this); res = setup_convert(this);
spa_log_info(this->log, NAME " %p: set format on port %d %d %d %d", spa_log_debug(this->log, NAME " %p: set format on port %d %d %d %d",
this, port_id, res, port->stride, other->stride); this, port_id, res, port->stride, other->stride);
} }
return res; return res;
@ -654,7 +654,7 @@ impl_node_port_use_buffers(struct spa_node *node,
spa_return_val_if_fail(port->have_format, -EIO); spa_return_val_if_fail(port->have_format, -EIO);
spa_log_info(this->log, NAME " %p: use buffers %d on port %d", this, n_buffers, port_id); spa_log_debug(this->log, NAME " %p: use buffers %d on port %d", this, n_buffers, port_id);
clear_buffers(this, port); clear_buffers(this, port);

View file

@ -39,16 +39,9 @@
#define MAX_BUFFERS 64 #define MAX_BUFFERS 64
#define MAX_PORTS 128 #define MAX_PORTS 128
#define PORT_DEFAULT_VOLUME 1.0
#define PORT_DEFAULT_MUTE false
struct type { struct type {
uint32_t node; uint32_t node;
uint32_t format; uint32_t format;
uint32_t prop_volume;
uint32_t prop_mute;
uint32_t io_prop_volume;
uint32_t io_prop_mute;
struct spa_type_io io; struct spa_type_io io;
struct spa_type_param param; struct spa_type_param param;
struct spa_type_media_type media_type; struct spa_type_media_type media_type;
@ -67,10 +60,6 @@ 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->node = spa_type_map_get_id(map, SPA_TYPE__Node);
type->format = spa_type_map_get_id(map, SPA_TYPE__Format); type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->prop_mute = spa_type_map_get_id(map, SPA_TYPE_PROPS__mute);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
type->io_prop_mute = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "mute");
spa_type_io_map(map, &type->io); spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param); spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type); spa_type_media_type_map(map, &type->media_type);
@ -85,17 +74,6 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
spa_type_param_io_map(map, &type->param_io); spa_type_param_io_map(map, &type->param_io);
} }
struct port_props {
double volume;
int32_t mute;
};
static void port_props_reset(struct port_props *props)
{
props->volume = PORT_DEFAULT_VOLUME;
props->mute = PORT_DEFAULT_MUTE;
}
struct buffer { struct buffer {
#define BUFFER_FLAG_QUEUED (1<<0) #define BUFFER_FLAG_QUEUED (1<<0)
uint32_t flags; uint32_t flags;
@ -107,11 +85,8 @@ struct port {
bool valid; bool valid;
uint32_t id; uint32_t id;
struct port_props props;
struct spa_io_buffers *io; struct spa_io_buffers *io;
double *io_volume; struct spa_io_control_range *ctrl;
int32_t *io_mute;
struct spa_port_info info; struct spa_port_info info;
struct spa_dict info_props; struct spa_dict info_props;
@ -277,10 +252,6 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
port->valid = true; port->valid = true;
port->id = port_id; port->id = port_id;
port_props_reset(&port->props);
port->io_volume = &port->props.volume;
port->io_mute = &port->props.mute;
spa_list_init(&port->queue); spa_list_init(&port->queue);
port->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | port->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
SPA_PORT_INFO_FLAG_REMOVABLE; SPA_PORT_INFO_FLAG_REMOVABLE;
@ -293,7 +264,7 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
if (this->last_port <= port_id) if (this->last_port <= port_id)
this->last_port = port_id + 1; this->last_port = port_id + 1;
spa_log_info(this->log, NAME " %p: add port %d %d", this, port_id, this->have_format); spa_log_debug(this->log, NAME " %p: add port %d %d", this, port_id, this->have_format);
return 0; return 0;
} }
@ -328,7 +299,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
this->last_port = i + 1; this->last_port = i + 1;
} }
spa_log_info(this->log, NAME " %p: remove port %d", this, port_id); spa_log_debug(this->log, NAME " %p: remove port %d", this, port_id);
return 0; return 0;
} }
@ -457,7 +428,7 @@ impl_node_port_enum_params(struct spa_node *node,
next: next:
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
spa_log_info(this->log, NAME " %p: enum param %d %d", this, id, this->have_format); spa_log_debug(this->log, NAME " %p: enum param %d %d", this, id, this->have_format);
if (id == t->param.idList) { if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat, uint32_t list[] = { t->param.idEnumFormat,
@ -544,7 +515,7 @@ impl_node_port_enum_params(struct spa_node *node,
static int clear_buffers(struct impl *this, struct port *port) static int clear_buffers(struct impl *this, struct port *port)
{ {
if (port->n_buffers > 0) { if (port->n_buffers > 0) {
spa_log_info(this->log, NAME " %p: clear buffers %p", this, port); spa_log_debug(this->log, NAME " %p: clear buffers %p", this, port);
port->n_buffers = 0; port->n_buffers = 0;
spa_list_init(&port->queue); spa_list_init(&port->queue);
} }
@ -563,7 +534,7 @@ static int port_set_format(struct spa_node *node,
port = GET_PORT(this, direction, port_id); port = GET_PORT(this, direction, port_id);
spa_log_info(this->log, NAME " %p: set format %d", this, this->have_format); spa_log_debug(this->log, NAME " %p: set format %d", this, this->have_format);
if (format == NULL) { if (format == NULL) {
if (port->have_format) { if (port->have_format) {
@ -610,7 +581,7 @@ static int port_set_format(struct spa_node *node,
if (!port->have_format) { if (!port->have_format) {
this->n_formats++; this->n_formats++;
port->have_format = true; port->have_format = true;
spa_log_info(this->log, NAME " %p: set format on port %d", this, port_id); spa_log_debug(this->log, NAME " %p: set format on port %d", this, port_id);
} }
} }
@ -690,7 +661,7 @@ impl_node_port_use_buffers(struct spa_node *node,
spa_return_val_if_fail(port->have_format, -EIO); spa_return_val_if_fail(port->have_format, -EIO);
spa_log_info(this->log, NAME " %p: use buffers %d on port %d", this, n_buffers, port_id); spa_log_debug(this->log, NAME " %p: use buffers %d on port %d", this, n_buffers, port_id);
clear_buffers(this, port); clear_buffers(this, port);
@ -749,6 +720,8 @@ impl_node_port_set_io(struct spa_node *node,
if (id == t->io.Buffers) if (id == t->io.Buffers)
port->io = data; port->io = data;
else if (id == t->io.ControlRange)
port->ctrl = data;
else else
return -ENOENT; return -ENOENT;
@ -829,7 +802,12 @@ static int impl_node_process(struct spa_node *node)
spa_log_trace(this->log, NAME " %p: %d %d %d", this, spa_log_trace(this->log, NAME " %p: %d %d %d", this,
sd->chunk->size, dd->maxsize, inport->offset); sd->chunk->size, dd->maxsize, inport->offset);
size = SPA_MIN(sd->chunk->size - inport->offset, dd->maxsize); if (outport->ctrl)
size = SPA_MIN(outport->ctrl->max_size, dd->maxsize);
else
size = dd->maxsize;
size = SPA_MIN(size, sd->chunk->size - inport->offset);
memcpy(dd->data, SPA_MEMBER(sd->data, inport->offset, void), size); memcpy(dd->data, SPA_MEMBER(sd->data, inport->offset, void), size);
@ -839,7 +817,6 @@ static int impl_node_process(struct spa_node *node)
outio->buffer_id = dbuf->buf->id; outio->buffer_id = dbuf->buf->id;
outio->status = SPA_STATUS_HAVE_BUFFER; outio->status = SPA_STATUS_HAVE_BUFFER;
SPA_FLAG_SET(res, SPA_STATUS_HAVE_BUFFER); SPA_FLAG_SET(res, SPA_STATUS_HAVE_BUFFER);
} }
inport->offset += size; inport->offset += size;
if (inport->offset >= sbuf->buf->datas[0].chunk->size) { if (inport->offset >= sbuf->buf->datas[0].chunk->size) {

View file

@ -44,8 +44,8 @@
#define DEFAULT_CHANNELS 2 #define DEFAULT_CHANNELS 2
#define DEFAULT_SAMPLE_RATE 44100 #define DEFAULT_SAMPLE_RATE 44100
#define DEFAULT_BUFFER_SIZE 64 #define DEFAULT_BUFFER_SIZE (64 * sizeof(float))
#define MAX_BUFFER_SIZE 2048 #define MAX_BUFFER_SIZE (1024 * sizeof(float))
struct type { struct type {
struct spa_type_media_type media_type; struct spa_type_media_type media_type;

View file

@ -208,7 +208,7 @@ static int node_remove_port(struct spa_node *node, enum spa_direction direction,
static int clear_buffers(struct node *n, struct port *p) static int clear_buffers(struct node *n, struct port *p)
{ {
if (p->n_buffers > 0) { if (p->n_buffers > 0) {
pw_log_info(NAME " %p: clear buffers %p", n, p); pw_log_debug(NAME " %p: clear buffers %p", n, p);
p->n_buffers = 0; p->n_buffers = 0;
spa_list_init(&p->queue); spa_list_init(&p->queue);
} }
@ -586,7 +586,7 @@ static int port_set_format(struct spa_node *node, struct port *p,
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0) if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
return -EINVAL; return -EINVAL;
pw_log_info(NAME " %p: set format on port %p", n, p); pw_log_debug(NAME " %p: set format on port %p", n, p);
n->sample_rate = info.info.raw.rate; n->sample_rate = info.info.raw.rate;
if (!SPA_FLAG_CHECK(p->flags, PORT_FLAG_DSP)) { if (!SPA_FLAG_CHECK(p->flags, PORT_FLAG_DSP)) {

View file

@ -434,7 +434,7 @@ do_update_port(struct node *this,
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) { if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
port->have_format = false; port->have_format = false;
spa_log_info(this->log, "node %p: port %u update %d params", this, port_id, n_params); spa_log_debug(this->log, "node %p: port %u update %d params", this, port_id, n_params);
for (i = 0; i < port->n_params; i++) for (i = 0; i < port->n_params; i++)
free(port->params[i]); free(port->params[i]);
port->n_params = n_params; port->n_params = n_params;
@ -464,7 +464,7 @@ do_update_port(struct node *this,
} }
if (!port->valid) { if (!port->valid) {
spa_log_info(this->log, "node %p: adding port %d", this, port_id); spa_log_debug(this->log, "node %p: adding port %d", this, port_id);
port->have_format = false; port->have_format = false;
port->valid = true; port->valid = true;
for (i = 0; i < MAX_IO; i++) for (i = 0; i < MAX_IO; i++)
@ -494,7 +494,7 @@ static void do_uninit_port(struct node *this, enum spa_direction direction, uint
{ {
struct port *port; struct port *port;
spa_log_info(this->log, "node %p: removing port %d", this, port_id); spa_log_debug(this->log, "node %p: removing port %d", this, port_id);
if (direction == SPA_DIRECTION_INPUT) { if (direction == SPA_DIRECTION_INPUT) {
port = GET_IN_PORT(this, port_id); port = GET_IN_PORT(this, port_id);
@ -716,7 +716,7 @@ impl_node_port_use_buffers(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct node, node); this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl; impl = this->impl;
spa_log_info(this->log, "node %p: use buffers %p %u", this, buffers, n_buffers); spa_log_debug(this->log, "node %p: use buffers %p %u", this, buffers, n_buffers);
t = impl->t; t = impl->t;
@ -931,7 +931,7 @@ client_node_update(void *data,
this->max_outputs = max_output_ports; this->max_outputs = max_output_ports;
if (change_mask & PW_CLIENT_NODE_UPDATE_PARAMS) { if (change_mask & PW_CLIENT_NODE_UPDATE_PARAMS) {
int i; int i;
spa_log_info(this->log, "node %p: update %d params", this, n_params); spa_log_debug(this->log, "node %p: update %d params", this, n_params);
for (i = 0; i < this->n_params; i++) for (i = 0; i < this->n_params; i++)
free(this->params[i]); free(this->params[i]);
@ -941,7 +941,7 @@ client_node_update(void *data,
for (i = 0; i < this->n_params; i++) for (i = 0; i < this->n_params; i++)
this->params[i] = pw_spa_pod_copy(params[i]); this->params[i] = pw_spa_pod_copy(params[i]);
} }
spa_log_info(this->log, "node %p: got node update max_in %u, max_out %u", this, spa_log_debug(this->log, "node %p: got node update max_in %u, max_out %u", this,
this->max_inputs, this->max_outputs); this->max_inputs, this->max_outputs);
} }
@ -958,7 +958,7 @@ client_node_port_update(void *data,
struct node *this = &impl->node; struct node *this = &impl->node;
bool remove; bool remove;
spa_log_info(this->log, "node %p: got port update", this); spa_log_debug(this->log, "node %p: got port update", this);
if (!CHECK_PORT_ID(this, direction, port_id)) if (!CHECK_PORT_ID(this, direction, port_id))
return; return;

View file

@ -335,7 +335,7 @@ static int negotiate_format(struct impl *impl)
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
spa_log_info(this->log, "%p: negiotiate", impl); spa_log_debug(this->log, "%p: negiotiate", impl);
state = 0; state = 0;
if ((res = spa_node_port_enum_params(impl->adapter, if ((res = spa_node_port_enum_params(impl->adapter,
@ -385,7 +385,7 @@ static int negotiate_buffers(struct impl *impl)
struct spa_buffer_alloc_info info = { 0, }; struct spa_buffer_alloc_info info = { 0, };
void *skel; void *skel;
spa_log_info(this->log, "%p: %d", impl, impl->n_buffers); spa_log_debug(this->log, "%p: %d", impl, impl->n_buffers);
if (impl->n_buffers > 0) if (impl->n_buffers > 0)
return 0; return 0;
@ -593,7 +593,7 @@ impl_node_port_use_buffers(struct spa_node *node,
return res; return res;
spa_log_info(this->log, "%p: %d %d", impl, n_buffers, port_id); spa_log_debug(this->log, "%p: %d %d", impl, n_buffers, port_id);
if (n_buffers > 0 && impl->use_converter) { if (n_buffers > 0 && impl->use_converter) {
if (port_id == 0) if (port_id == 0)

View file

@ -750,7 +750,7 @@ static void client_node_transport(void *object, uint32_t node_id,
data->node_id = node_id; data->node_id = node_id;
pw_log_info("remote-node %p: create transport with fds %d %d for node %u", pw_log_debug("remote-node %p: create transport with fds %d %d for node %u",
proxy, readfd, writefd, node_id); proxy, readfd, writefd, node_id);
data->rtwritefd = writefd; data->rtwritefd = writefd;

View file

@ -633,7 +633,7 @@ static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direc
} else } else
size = buf_size; size = buf_size;
} }
pw_log_info("got buffer %d %d datas, mapped size %d", i, pw_log_debug("got buffer %d %d datas, mapped size %d", i,
buffers[i]->n_datas, size); buffers[i]->n_datas, size);
} }