alsa: adjust latency based on buffer size

This commit is contained in:
Wim Taymans 2018-04-30 09:27:20 +02:00
parent d5e658e8f9
commit b8a37381da
3 changed files with 27 additions and 10 deletions

View file

@ -33,7 +33,7 @@
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0)
static const char default_device[] = "hw:0";
static const uint32_t default_min_latency = 1024;
static const uint32_t default_min_latency = 64;
static const uint32_t default_max_latency = 1024;
static void reset_props(struct props *props)
@ -488,6 +488,7 @@ impl_node_port_use_buffers(struct spa_node *node,
for (i = 0; i < n_buffers; i++) {
struct buffer *b = &this->buffers[i];
struct spa_data *d = buffers[i]->datas;
uint32_t type;
b->outbuf = buffers[i];
@ -495,13 +496,14 @@ impl_node_port_use_buffers(struct spa_node *node,
b->h = spa_buffer_find_meta(b->outbuf, this->type.meta.Header);
type = buffers[i]->datas[0].type;
type = d[0].type;
if ((type == this->type.data.MemFd ||
type == this->type.data.DmaBuf ||
type == this->type.data.MemPtr) && buffers[i]->datas[0].data == NULL) {
type == this->type.data.MemPtr) && d[0].data == NULL) {
spa_log_error(this->log, NAME " %p: need mapped memory", this);
return -EINVAL;
}
this->threshold = d[0].maxsize / this->frame_size;
}
this->n_buffers = n_buffers;

View file

@ -34,12 +34,14 @@
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
static const char default_device[] = "hw:0";
static const uint32_t default_min_latency = 1024;
static const uint32_t default_min_latency = 64;
static const uint32_t default_max_latency = 1024;
static void reset_props(struct props *props)
{
strncpy(props->device, default_device, 64);
props->min_latency = default_min_latency;
props->max_latency = default_max_latency;
}
static int impl_node_enum_params(struct spa_node *node,
@ -108,6 +110,14 @@ static int impl_node_enum_params(struct spa_node *node,
":", t->param.propType, "ir", p->min_latency,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
break;
case 4:
param = spa_pod_builder_object(&b,
id, t->param.PropInfo,
":", t->param.propId, "I", t->prop_max_latency,
":", t->param.propName, "s", "The maximum latency",
":", t->param.propType, "ir", p->max_latency,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
break;
default:
return 0;
}
@ -120,7 +130,8 @@ static int impl_node_enum_params(struct spa_node *node,
":", t->prop_device, "S", p->device, sizeof(p->device),
":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name),
":", t->prop_card_name, "S-r", p->card_name, sizeof(p->card_name),
":", t->prop_min_latency, "i", p->min_latency);
":", t->prop_min_latency, "i", p->min_latency,
":", t->prop_max_latency, "i", p->max_latency);
break;
default:
return 0;
@ -157,7 +168,8 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
}
spa_pod_object_parse(param,
":", t->prop_device, "?S", p->device, sizeof(p->device),
":", t->prop_min_latency, "?i", &p->min_latency, NULL);
":", t->prop_min_latency, "?i", &p->min_latency,
":", t->prop_max_latency, "?i", &p->max_latency, NULL);
}
else
return -ENOENT;
@ -365,8 +377,11 @@ impl_node_port_enum_params(struct spa_node *node,
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "i", this->props.min_latency * this->frame_size,
":", t->param_buffers.stride, "i", 0,
":", t->param_buffers.size, "iru", this->props.max_latency *
this->frame_size,
SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size,
INT32_MAX),
":", t->param_buffers.stride, "i", this->frame_size,
":", t->param_buffers.buffers, "ir", 2,
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
":", t->param_buffers.align, "i", 16);
@ -509,6 +524,8 @@ impl_node_port_use_buffers(struct spa_node *node,
return -EINVAL;
}
spa_list_append(&this->free, &b->link);
this->threshold = d[0].maxsize / this->frame_size;
}
this->n_buffers = n_buffers;

View file

@ -705,8 +705,6 @@ int spa_alsa_start(struct state *state, bool xrun_recover)
state->source.rmask = 0;
spa_loop_add_source(state->data_loop, &state->source);
state->threshold = state->props.min_latency;
if (state->stream == SND_PCM_STREAM_PLAYBACK) {
state->alsa_started = false;
} else {