[pulseaudio-discuss] [RFC] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed (-77) proposed fix to check pcm state

Alexander E. Patrakov patrakov at gmail.com
Wed Nov 26 01:15:30 PST 2014


26.11.2014 13:54, Raymond Yau wrote:
> diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
> index 9e9b863..0031644 100644
> --- a/src/modules/alsa/alsa-sink.c
> +++ b/src/modules/alsa/alsa-sink.c

Some minor nitpicks.

> @@ -1727,8 +1727,18 @@ static void thread_func(void *userdata) {
>
>                   if (u->first) {
>                       pa_log_info("Starting playback.");
> -                    snd_pcm_start(u->pcm_handle);
> -
> +		    switch (snd_pcm_state(u->pcm_handle)) {
> +		    case SND_PCM_STATE_PREPARED:
> +			snd_pcm_start(u->pcm_handle);
> +			break;

You have lost the "Starting playback" log message.

> +		    case SND_PCM_STATE_RUNNING:
> +		        pa_log_warn("Sink already playing.");
> +			pa_alsa_dump(PA_LOG_DEBUG, u->pcm_handle);
> +		        break;
> +		    default:
> +		        pa_log_error("Invalid pcm state.");

I am not sure that just logging the error is enough. But at least it is 
not worse than the current situation.

> +			break;
> +		    }
>                       pa_smoother_resume(u->smoother, pa_rtclock_now(), true);
>
>                       u->first = false;

On the other hand, I have suspicion that it is an ALSA bug that you are 
possibly trying to work around. Is it that no other plugins end up in 
the already-running state, or that all other plugins ignore 
snd_pcm_start() when they are already started?

It would be very nice if you isolate the hardware and software 
parameters that PulseAudio tries to apply, write a simple ALSA test 
program that applies them, possibly writes some sound data and calls 
snd_pcm_start(), and test all available plugins using that program, so 
that we know whether this is limited to the multi plugin.

-- 
Alexander E. Patrakov


More information about the pulseaudio-discuss mailing list