node: add xrun callback

Let alsa emit xrun callbacks.
Write the xrun stats to the activation area of the node so all
clients can read it.
This commit is contained in:
Wim Taymans 2019-08-22 13:23:48 +02:00
parent 570575f052
commit 6ad4adc194
8 changed files with 80 additions and 15 deletions

View file

@ -542,17 +542,20 @@ static int alsa_recover(struct state *state, int err)
case SND_PCM_STATE_XRUN:
{
struct timeval now, trigger, diff;
uint64_t xrun, missing;
uint64_t delay, missing;
snd_pcm_status_get_tstamp (status, &now);
snd_pcm_status_get_trigger_tstamp (status, &trigger);
timersub(&now, &trigger, &diff);
xrun = SPA_TIMEVAL_TO_USEC(&diff);
missing = xrun * state->rate / SPA_USEC_PER_SEC;
delay = SPA_TIMEVAL_TO_USEC(&diff);
missing = delay * state->rate / SPA_USEC_PER_SEC;
spa_log_error(state->log, "%p: xrun of %"PRIu64" usec %"PRIu64" %f",
state, xrun, missing, state->safety);
state, delay, missing, state->safety);
spa_node_call_xrun(&state->callbacks,
SPA_TIMEVAL_TO_USEC(&trigger), delay, NULL);
state->sample_count += missing ? missing : state->threshold;
break;

View file

@ -430,10 +430,17 @@ static int slave_reuse_buffer(void *data, uint32_t port_id, uint32_t buffer_id)
return res;
}
static int slave_xrun(void *data, uint64_t trigger, uint64_t delay, struct spa_pod *info)
{
struct impl *this = data;
return spa_node_call_xrun(&this->callbacks, trigger, delay, info);
}
static const struct spa_node_callbacks slave_node_callbacks = {
SPA_VERSION_NODE_CALLBACKS,
.ready = slave_ready,
.reuse_buffer = slave_reuse_buffer,
.xrun = slave_xrun,
};
static int impl_node_add_listener(void *object,