Skip to content

Commit

Permalink
plugout_alsa: add pause support
Browse files Browse the repository at this point in the history
This fixes issue #127 for hardware devices with pause support.

Devices without pause support will still get the EPIPE error
message on resume and lose some samples.
  • Loading branch information
mmitch committed Apr 29, 2024
1 parent 82d3497 commit e743484
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugout_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
/* Handle for the PCM device */
snd_pcm_t *pcm_handle;

bool can_pause;

#if GBS_BYTE_ORDER == GBS_ORDER_LITTLE_ENDIAN
#define SND_PCM_FORMAT_S16_NE SND_PCM_FORMAT_S16_LE
#else
Expand Down Expand Up @@ -98,9 +100,18 @@ static long alsa_open(enum plugout_endian *endian, long rate, long *buffer_bytes

*buffer_bytes = buffer_frames * 4;

can_pause = snd_pcm_hw_params_can_pause(hwparams);

return 0;
}

static void alsa_pause(int pause)
{
int err;
if (can_pause && (err = snd_pcm_pause(pcm_handle, pause)))
fprintf(stderr, _("snd_pcm_pause failed: %s\n"), snd_strerror(err));
}

static long is_suspended(snd_pcm_sframes_t retval)
{
#ifdef HAVE_ESTRPIPE
Expand Down Expand Up @@ -140,6 +151,7 @@ const struct output_plugin plugout_alsa = {
.name = "alsa",
.description = "ALSA sound driver",
.open = alsa_open,
.pause = alsa_pause,
.write = alsa_write,
.close = alsa_close,
};

0 comments on commit e743484

Please sign in to comment.