Skip to content

Commit

Permalink
do not use avail_min for ALSA drain
Browse files Browse the repository at this point in the history
removes the possibility of a drain being affected by an application
changing avail_min.
  • Loading branch information
borine committed Oct 2, 2023
1 parent ad79ddb commit dcffc94
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/asound/bluealsa-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,6 @@ static int bluealsa_drain(snd_pcm_ioplug_t *io) {

bool aborted = false;

/* Temporarily set avail_min such that the IO thread does not wake us
* until the buffer is empty. */
snd_pcm_uframes_t saved_avail_min = pcm->io_avail_min;
pcm->io_avail_min = io->buffer_size;

struct pollfd pfd = { pcm->event_fd, POLLIN, 0 };
snd_pcm_sframes_t hw_ptr;
int ret = 0;
Expand Down Expand Up @@ -757,9 +752,6 @@ static int bluealsa_drain(snd_pcm_ioplug_t *io) {

}

/* Restore the avail_min parameter */
pcm->io_avail_min = saved_avail_min;

if (io->state == SND_PCM_STATE_DRAINING && !aborted)
if (!bluealsa_dbus_pcm_ctrl_send_drain(pcm->ba_pcm_ctrl_fd, NULL)) {
bluealsa_stop(io);
Expand Down Expand Up @@ -1039,6 +1031,15 @@ static int bluealsa_poll_revents(snd_pcm_ioplug_t *io, struct pollfd *pfd,
*revents = 0;
}
break;
case SND_PCM_STATE_DRAINING:
/* BlueALSA does not drain capture PCMs. So this state only
* occurs with playback PCMs. Do not wake the application until
* the buffer is empty. */
if ((snd_pcm_uframes_t)avail < io->buffer_size) {
ready = false;
*revents = 0;
}
break;
case SND_PCM_STATE_XRUN:
case SND_PCM_STATE_PAUSED:
case SND_PCM_STATE_SUSPENDED:
Expand Down

0 comments on commit dcffc94

Please sign in to comment.