Skip to content

ALSA Pulse plugin returns -EIO from snd_pcm_avail_delay() in case of -PA_ERR_NODATA #65

Description

@argothiel

Environment

  • Ubuntu 26.04 under WSL2 / WSLg
  • libasound2-plugins 1.2.12-2build1
  • PulseAudio server available through WSLg

Problem

Immediately after configuring a playback PCM opened through the ALSA pulse plugin, snd_pcm_avail_delay() returns -EIO. This seems to be an issue with pulse_delay() which calls pa_stream_get_latency(). PulseAudio documents that this function returns -PA_ERR_NODATA when timing information is not available yet. The ALSA Pulse plugin compares the result against positive PA_ERR_NODATA; it therefore treats that temporary condition as an unrelated failure and returns -EIO:

Reproducer

#include <alsa/asoundlib.h>
#include <assert.h>
#include <stdio.h>

int main(void)
{
    snd_pcm_t *pcm;
    snd_pcm_sframes_t avail, delay;
    int err;

    err = snd_pcm_open(&pcm, "pulse", SND_PCM_STREAM_PLAYBACK, 0);
    assert(err == 0);

    err = snd_pcm_set_params(
        pcm,
        SND_PCM_FORMAT_FLOAT_LE,
        SND_PCM_ACCESS_RW_INTERLEAVED,
        2,
        48000,
        1,
        20000);
    assert(err == 0);

    err = snd_pcm_avail_delay(pcm, &avail, &delay);
    printf("snd_pcm_avail_delay: %s (%d)\n", snd_strerror(err), err);

    snd_pcm_close(pcm);
    return err < 0;
}

Build and run:

cc main.c -lasound && ./a.out

Actual result

snd_pcm_avail_delay: Input/output error (-5)

Expected result

snd_pcm_avail_delay() should wait until PulseAudio timing information is available, then return the available-frame and delay values.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions