mirror of
https://github.com/alsa-project/alsa-utils
synced 2025-01-03 09:49:43 +01:00
alsaloop: Delay the restart a bit (to handle snd-aloop playback xruns better)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
b67d215d20
commit
d53eb0309d
2 changed files with 28 additions and 7 deletions
|
@ -143,6 +143,8 @@ struct loopback {
|
||||||
unsigned int linked:1; /* linked streams */
|
unsigned int linked:1; /* linked streams */
|
||||||
unsigned int reinit:1;
|
unsigned int reinit:1;
|
||||||
unsigned int running:1;
|
unsigned int running:1;
|
||||||
|
unsigned int stop_pending:1;
|
||||||
|
snd_pcm_uframes_t stop_count;
|
||||||
sync_type_t sync; /* type of sync */
|
sync_type_t sync; /* type of sync */
|
||||||
slave_type_t slave;
|
slave_type_t slave;
|
||||||
int thread; /* thread number */
|
int thread; /* thread number */
|
||||||
|
|
|
@ -738,6 +738,15 @@ static int writeit(struct loopback_handle *lhandle)
|
||||||
lhandle->buf_pos += r;
|
lhandle->buf_pos += r;
|
||||||
lhandle->buf_pos %= lhandle->buf_size;
|
lhandle->buf_pos %= lhandle->buf_size;
|
||||||
xrun_profile(lhandle->loopback);
|
xrun_profile(lhandle->loopback);
|
||||||
|
if (lhandle->loopback->stop_pending) {
|
||||||
|
lhandle->loopback->stop_count += r;
|
||||||
|
if (lhandle->loopback->stop_count * lhandle->pitch >
|
||||||
|
lhandle->loopback->latency * 3) {
|
||||||
|
lhandle->loopback->stop_pending = 0;
|
||||||
|
lhandle->loopback->reinit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1521,6 +1530,7 @@ int pcmjob_start(struct loopback *loop)
|
||||||
goto __error;
|
goto __error;
|
||||||
}
|
}
|
||||||
loop->running = 1;
|
loop->running = 1;
|
||||||
|
loop->stop_pending = 0;
|
||||||
if (loop->xrun) {
|
if (loop->xrun) {
|
||||||
getcurtimestamp(&loop->xrun_last_update);
|
getcurtimestamp(&loop->xrun_last_update);
|
||||||
loop->xrun_last_pdelay = XRUN_PROFILE_UNKNOWN;
|
loop->xrun_last_pdelay = XRUN_PROFILE_UNKNOWN;
|
||||||
|
@ -1638,6 +1648,7 @@ static int ctl_event_check(snd_ctl_elem_value_t *val, snd_ctl_event_t *ev)
|
||||||
static int handle_ctl_events(struct loopback_handle *lhandle,
|
static int handle_ctl_events(struct loopback_handle *lhandle,
|
||||||
unsigned short events)
|
unsigned short events)
|
||||||
{
|
{
|
||||||
|
struct loopback *loop = lhandle->loopback;
|
||||||
snd_ctl_event_t *ev;
|
snd_ctl_event_t *ev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -1647,16 +1658,24 @@ static int handle_ctl_events(struct loopback_handle *lhandle,
|
||||||
break;
|
break;
|
||||||
if (snd_ctl_event_get_type(ev) != SND_CTL_EVENT_ELEM)
|
if (snd_ctl_event_get_type(ev) != SND_CTL_EVENT_ELEM)
|
||||||
continue;
|
continue;
|
||||||
if (lhandle == lhandle->loopback->play)
|
if (lhandle == loop->play)
|
||||||
goto __ctl_check;
|
goto __ctl_check;
|
||||||
if (verbose > 6)
|
if (verbose > 6)
|
||||||
snd_output_printf(lhandle->loopback->output, "%s: ctl event!!!! %s\n", lhandle->id, snd_ctl_event_elem_get_name(ev));
|
snd_output_printf(loop->output, "%s: ctl event!!!! %s\n", lhandle->id, snd_ctl_event_elem_get_name(ev));
|
||||||
if (ctl_event_check(lhandle->ctl_active, ev)) {
|
if (ctl_event_check(lhandle->ctl_active, ev)) {
|
||||||
err = get_active(lhandle);
|
err = get_active(lhandle);
|
||||||
if (verbose > 7)
|
if (verbose > 7)
|
||||||
snd_output_printf(lhandle->loopback->output, "%s: ctl event active %i\n", lhandle->id, err);
|
snd_output_printf(loop->output, "%s: ctl event active %i\n", lhandle->id, err);
|
||||||
if (err != lhandle->loopback->running)
|
if (!err) {
|
||||||
goto __restart;
|
if (lhandle->loopback->running) {
|
||||||
|
loop->stop_pending = 1;
|
||||||
|
loop->stop_count = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loop->stop_pending = 0;
|
||||||
|
if (loop->running == 0)
|
||||||
|
goto __restart;
|
||||||
|
}
|
||||||
} else if (ctl_event_check(lhandle->ctl_format, ev)) {
|
} else if (ctl_event_check(lhandle->ctl_format, ev)) {
|
||||||
err = get_format(lhandle);
|
err = get_format(lhandle);
|
||||||
if (lhandle->format != err)
|
if (lhandle->format != err)
|
||||||
|
@ -1676,8 +1695,8 @@ static int handle_ctl_events(struct loopback_handle *lhandle,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
__restart:
|
__restart:
|
||||||
pcmjob_stop(lhandle->loopback);
|
pcmjob_stop(loop);
|
||||||
err = pcmjob_start(lhandle->loopback);
|
err = pcmjob_start(loop);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue