[pulseaudio-discuss] Behavior of pa_threaded_mainloop_wait ()

Tristin Celestin tristin_celestin at yahoo.com
Tue Feb 9 20:41:29 PST 2010


I have a stream state change callback that fires a signal when the stream is PA_STREAM_READY, PA_STREAM_FAILED, or PA_STREAM_TERMINATED
When trying to get a ready stream state in pulseaudio, I first wrote this. This hangs

    do {
	  stream_state = pa_stream_get_state (device.stream);
	  if (! PA_STREAM_IS_GOOD (stream_state))
	  {
	       error_number = pa_context_errno (device.context);
	       fprintf (stderr, "Could not acquire PulseAudio stream: %s\n", pa_strerror (error_number));
	       return;
	  }
	  else
	  {
	       fprintf (stderr, "PulseAudio stream state is %d.\n", stream_state);
	  }
	  pa_threaded_mainloop_wait (device.mainloop);
     } while (stream_state != PA_STREAM_READY);


Then I wrote this, based on the pa_simple code, and this doesn't hang

     stream_state = pa_stream_get_state (device.stream);
     while (stream_state != PA_STREAM_READY)
     {
	  stream_state = pa_stream_get_state (device.stream);
	  if (! PA_STREAM_IS_GOOD (stream_state))
	  {
	       error_number = pa_context_errno (device.context);
	       fprintf (stderr, "Could not acquire PulseAudio stream: %s\n", pa_strerror (error_number));
	       return;
	  }
	  else if (stream_state == PA_STREAM_READY)
	       break;
	  else
	       fprintf (stderr, "PulseAudio stream state is %d.\n", stream_state);
	  pa_threaded_mainloop_wait (device.mainloop);
     }

Why do I have to explicitly check inside the loop to see if the stream is ready, and then break? Do I have to have called wait() while the callback executes?


      



More information about the pulseaudio-discuss mailing list