Behavior of pa_threaded_mainloop_wait ()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?


      



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux