* snd_pcm_wait() More details required.
@ 2004-03-21 14:49 James Courtier-Dutton
2004-03-22 9:56 ` Jaroslav Kysela
2004-03-22 10:10 ` Clemens Ladisch
0 siblings, 2 replies; 10+ messages in thread
From: James Courtier-Dutton @ 2004-03-21 14:49 UTC (permalink / raw)
To: ALSA development
I need more details on exactly what snd_pcm_wait() is supposed to do.
The documentation on the www.alsa-project.org gives: -
Wait for a PCM to become ready.
Parameters:
pcm PCM handle
timeout maximum time in milliseconds to wait
Returns:
a positive value on success otherwise a negative error code (-EPIPE
for the xrun and -ESTRPIPE for the suspended status, others for general
errors)
Return values:
0 timeout occurred
1 PCM stream is ready for I/O
So, when is a PCM ready?
If a PCM is already in SND_PCM_STATE_RUNNING, when is snd_pcm_wait()
supposed to return ?
I have discovered a problem with xine when using it. I have done a work
around in xine so that dmix now works in xine. I think that my
assumptions regarding snd_pcm_wait() might have been wrong, so I want to
get accurate details from yourselves.
It also might be a good idea to update the documentation for
snd_pcm_wait() with more details.
Cheers
James
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: snd_pcm_wait() More details required. 2004-03-21 14:49 snd_pcm_wait() More details required James Courtier-Dutton @ 2004-03-22 9:56 ` Jaroslav Kysela 2004-03-22 17:31 ` James Courtier-Dutton 2004-03-22 10:10 ` Clemens Ladisch 1 sibling, 1 reply; 10+ messages in thread From: Jaroslav Kysela @ 2004-03-22 9:56 UTC (permalink / raw) To: James Courtier-Dutton; +Cc: ALSA development yOn Sun, 21 Mar 2004, James Courtier-Dutton wrote: > I need more details on exactly what snd_pcm_wait() is supposed to do. > The documentation on the www.alsa-project.org gives: - > Wait for a PCM to become ready. > > Parameters: > pcm PCM handle > timeout maximum time in milliseconds to wait > > Returns: > a positive value on success otherwise a negative error code (-EPIPE > for the xrun and -ESTRPIPE for the suspended status, others for general > errors) > > Return values: > 0 timeout occurred > 1 PCM stream is ready for I/O > > > > So, when is a PCM ready? > If a PCM is already in SND_PCM_STATE_RUNNING, when is snd_pcm_wait() > supposed to return ? When avail >= avail_min. > I have discovered a problem with xine when using it. I have done a work > around in xine so that dmix now works in xine. I think that my > assumptions regarding snd_pcm_wait() might have been wrong, so I want to > get accurate details from yourselves. > It also might be a good idea to update the documentation for > snd_pcm_wait() with more details. We had a bug in the resample plugin which causes that snd_pcm_wait() function was broken. Try alsa-lib from CVS. Jaroslav ----- Jaroslav Kysela <perex@suse.cz> Linux Kernel Sound Maintainer ALSA Project, SuSE Labs ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-22 9:56 ` Jaroslav Kysela @ 2004-03-22 17:31 ` James Courtier-Dutton 2004-03-22 17:51 ` Jaroslav Kysela 0 siblings, 1 reply; 10+ messages in thread From: James Courtier-Dutton @ 2004-03-22 17:31 UTC (permalink / raw) To: Jaroslav Kysela; +Cc: ALSA development Jaroslav Kysela wrote: >> >>So, when is a PCM ready? >>If a PCM is already in SND_PCM_STATE_RUNNING, when is snd_pcm_wait() >>supposed to return ? > > > When avail >= avail_min. 1) Does this depend on period size in any way? For example, if period size is 6000 frames, and I set avail_min to 2000 frames, will snd_pcm_wait() return when avail=2000 or avail=6000 ? Another example, if persiod size is 1500, and I set avail_min to 2000, will snd_pcm_wait() return when avail=200 or avail=3000 (2*1500)? 2) Is snd_pcm_wait() a call that uses little or no CPU time, much like a poll? 3) It appears from the docs that I can set avail_min at any time, even in SND_PCM_STATE_RUNNING. commands to set it would be: - snd_pcm_sw_params_current(this->audio_fd, swparams); snd_pcm_sw_params_set_avail_min(this->audio_fd, swparams, new_avail_min_size); snd_pcm_sw_params(this->audio_fd, swparams); or is there a better way to do it while in SND_PCM_STATE_RUNNING ? 4) If snd_pcm_wait() is waiting, and with another thread we change the avail_min value, will the snd_pcm_wait() use the new value, or is the new value only used on the next call to snd_pcm_wait() > > >>I have discovered a problem with xine when using it. I have done a work >>around in xine so that dmix now works in xine. I think that my >>assumptions regarding snd_pcm_wait() might have been wrong, so I want to >> get accurate details from yourselves. >>It also might be a good idea to update the documentation for >>snd_pcm_wait() with more details. > > > We had a bug in the resample plugin which causes that snd_pcm_wait() > function was broken. Try alsa-lib from CVS. My current tests were not using the resampler. i.e. app using 48k, sound card using 48k. I will try some tests that would use the resampler. > > Jaroslav > ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-22 17:31 ` James Courtier-Dutton @ 2004-03-22 17:51 ` Jaroslav Kysela 2004-03-23 12:33 ` Clemens Ladisch 0 siblings, 1 reply; 10+ messages in thread From: Jaroslav Kysela @ 2004-03-22 17:51 UTC (permalink / raw) To: James Courtier-Dutton; +Cc: ALSA development On Mon, 22 Mar 2004, James Courtier-Dutton wrote: > Jaroslav Kysela wrote: > >> > >>So, when is a PCM ready? > >>If a PCM is already in SND_PCM_STATE_RUNNING, when is snd_pcm_wait() > >>supposed to return ? > > > > > > When avail >= avail_min. > > 1) Does this depend on period size in any way? > For example, if period size is 6000 frames, and I set avail_min to 2000 > frames, will snd_pcm_wait() return when avail=2000 or avail=6000 ? > Another example, if persiod size is 1500, and I set avail_min to 2000, > will snd_pcm_wait() return when avail=200 or avail=3000 (2*1500)? Pointers are updated in the interrupt or when you call snd_pcm_hwsync() or snd_pcm_delay(). > 2) Is snd_pcm_wait() a call that uses little or no CPU time, much like a > poll? snd_pcm_wait() uses poll(). > 3) It appears from the docs that I can set avail_min at any time, even > in SND_PCM_STATE_RUNNING. > commands to set it would be: - > snd_pcm_sw_params_current(this->audio_fd, swparams); > snd_pcm_sw_params_set_avail_min(this->audio_fd, swparams, > new_avail_min_size); > snd_pcm_sw_params(this->audio_fd, swparams); > > or is there a better way to do it while in SND_PCM_STATE_RUNNING ? No, you may cache the sw_params structure. > 4) If snd_pcm_wait() is waiting, and with another thread we change the > avail_min value, will the snd_pcm_wait() use the new value, or is the > new value only used on the next call to snd_pcm_wait() The threshold will be used immediately. > My current tests were not using the resampler. i.e. app using 48k, sound > card using 48k. I will try some tests that would use the resampler. Then I need more info how I can reproduce the bug. Jaroslav ----- Jaroslav Kysela <perex@suse.cz> Linux Kernel Sound Maintainer ALSA Project, SuSE Labs ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-22 17:51 ` Jaroslav Kysela @ 2004-03-23 12:33 ` Clemens Ladisch 2004-03-23 13:40 ` Jaroslav Kysela 0 siblings, 1 reply; 10+ messages in thread From: Clemens Ladisch @ 2004-03-23 12:33 UTC (permalink / raw) To: Jaroslav Kysela; +Cc: James Courtier-Dutton, ALSA development Jaroslav Kysela wrote: > On Mon, 22 Mar 2004, James Courtier-Dutton wrote: > > > My current tests were not using the resampler. i.e. app using 48k, sound > > card using 48k. I will try some tests that would use the resampler. > > Then I need more info how I can reproduce the bug. The following test program shows strange behaviour: // ---------- bite off here ---------------------------------------- #include <alsa/asoundlib.h> #define CHECK(command) do { \ err = (command); \ if (err < 0) { \ printf("%s failed: %s\n", #command, snd_strerror(err)); \ return 1; \ } \ } while (0) int main(int argc, char *argv[]) { snd_pcm_t *pcm; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; int err; static char silence[12000 * 2 * 2]; if (argc < 2) return 1; CHECK(snd_pcm_open(&pcm, argv[1], SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)); snd_pcm_hw_params_alloca(&hw_params); CHECK(snd_pcm_hw_params_any(pcm, hw_params)); CHECK(snd_pcm_hw_params_set_access(pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)); CHECK(snd_pcm_hw_params_set_format(pcm, hw_params, SND_PCM_FORMAT_S16)); CHECK(snd_pcm_hw_params_set_channels(pcm, hw_params, 2)); CHECK(snd_pcm_hw_params_set_rate(pcm, hw_params, 48000, 0)); CHECK(snd_pcm_hw_params_set_buffer_size(pcm, hw_params, 12000)); CHECK(snd_pcm_hw_params_set_period_size(pcm, hw_params, 6000, 0)); CHECK(snd_pcm_hw_params(pcm, hw_params)); snd_pcm_sw_params_alloca(&sw_params); CHECK(snd_pcm_sw_params_current(pcm, sw_params)); CHECK(snd_pcm_sw_params_set_start_threshold(pcm, sw_params, 12000)); CHECK(snd_pcm_sw_params_set_avail_min(pcm, sw_params, 6000)); CHECK(snd_pcm_sw_params(pcm, sw_params)); for (;;) { CHECK(snd_pcm_wait(pcm, 2000)); if (err == 0) printf("timeout!\n"); err = snd_pcm_writei(pcm, silence, 12000); if (err >= 0) printf("%d frames written\n", err); else if (err == -EAGAIN) printf("pcm not ready!\n"); else CHECK(err); } } // ---------- bite off here ---------------------------------------- With an AC'97 device: $ ./waittest hw:0 12000 frames written 6000 frames written 6000 frames written 6000 frames written 6000 frames written ... $ ./waittest dmix:hw:0 timeout! 12000 frames written pcm is not ready! 6000 frames written 6000 frames written 6000 frames written 6000 frames written ... When running with dmix, the first call to snd_pcm_wait() times out although the pcm is ready (it seems the hardware pcm is still stopped and doesn't generate interrupts), and the second call to snd_pcm_wait() returns 1 although the pcm is not yet ready. Regards, Clemens ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-23 12:33 ` Clemens Ladisch @ 2004-03-23 13:40 ` Jaroslav Kysela 2004-03-24 7:58 ` Clemens Ladisch 0 siblings, 1 reply; 10+ messages in thread From: Jaroslav Kysela @ 2004-03-23 13:40 UTC (permalink / raw) To: Clemens Ladisch; +Cc: James Courtier-Dutton, ALSA development On Tue, 23 Mar 2004, Clemens Ladisch wrote: > Jaroslav Kysela wrote: > > > On Mon, 22 Mar 2004, James Courtier-Dutton wrote: > > > > > My current tests were not using the resampler. i.e. app using 48k, sound > > > card using 48k. I will try some tests that would use the resampler. > > > > Then I need more info how I can reproduce the bug. > > The following test program shows strange behaviour: Thanks. It's fixed in CVS now. Jaroslav ----- Jaroslav Kysela <perex@suse.cz> Linux Kernel Sound Maintainer ALSA Project, SuSE Labs ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-23 13:40 ` Jaroslav Kysela @ 2004-03-24 7:58 ` Clemens Ladisch 2004-03-24 8:59 ` Jaroslav Kysela 0 siblings, 1 reply; 10+ messages in thread From: Clemens Ladisch @ 2004-03-24 7:58 UTC (permalink / raw) To: Jaroslav Kysela; +Cc: James Courtier-Dutton, ALSA development Jaroslav Kysela wrote: > On Tue, 23 Mar 2004, Clemens Ladisch wrote: > > The following test program shows strange behaviour: > > Thanks. It's fixed in CVS now. The second problem persists, i.e., snd_pcm_wait() returns although the pcm isn't actually ready: $ ./waittest dmix:hw:0 12000 frames written pcm is not ready! 6000 frames written 6000 frames written 6000 frames written ... Regards, Clemens ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-24 7:58 ` Clemens Ladisch @ 2004-03-24 8:59 ` Jaroslav Kysela 0 siblings, 0 replies; 10+ messages in thread From: Jaroslav Kysela @ 2004-03-24 8:59 UTC (permalink / raw) To: Clemens Ladisch; +Cc: James Courtier-Dutton, ALSA development On Wed, 24 Mar 2004, Clemens Ladisch wrote: > Jaroslav Kysela wrote: > > On Tue, 23 Mar 2004, Clemens Ladisch wrote: > > > The following test program shows strange behaviour: > > > > Thanks. It's fixed in CVS now. > > The second problem persists, i.e., snd_pcm_wait() returns although the > pcm isn't actually ready: > > $ ./waittest dmix:hw:0 > 12000 frames written > pcm is not ready! > 6000 frames written Fixed again. I was not able reproduce this problem with some hardware. Jaroslav ----- Jaroslav Kysela <perex@suse.cz> Linux Kernel Sound Maintainer ALSA Project, SuSE Labs ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-21 14:49 snd_pcm_wait() More details required James Courtier-Dutton 2004-03-22 9:56 ` Jaroslav Kysela @ 2004-03-22 10:10 ` Clemens Ladisch 2004-03-22 10:09 ` Jaroslav Kysela 1 sibling, 1 reply; 10+ messages in thread From: Clemens Ladisch @ 2004-03-22 10:10 UTC (permalink / raw) To: James Courtier-Dutton; +Cc: ALSA development, Jaroslav Kysela James Courtier-Dutton wrote: > I need more details on exactly what snd_pcm_wait() is supposed to do. > The documentation on the www.alsa-project.org gives: - > Wait for a PCM to become ready. > ... > So, when is a PCM ready? When you can read/write some data without blocking, i.e., avail >= avail_min. > I have discovered a problem with xine when using it. I have done a work > around in xine so that dmix now works in xine. I think that my > assumptions regarding snd_pcm_wait() might have been wrong, so I want to > get accurate details from yourselves. I think the implementation of dmix is broken in this regard. If I read the code correctly, snd_pcm_direct_poll_revents() returns POLLIN/OUT even if the pcm is empty. Jaroslav, shouldn't this function reset the events variable when empty is set? Regards, Clemens ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: snd_pcm_wait() More details required. 2004-03-22 10:10 ` Clemens Ladisch @ 2004-03-22 10:09 ` Jaroslav Kysela 0 siblings, 0 replies; 10+ messages in thread From: Jaroslav Kysela @ 2004-03-22 10:09 UTC (permalink / raw) To: Clemens Ladisch; +Cc: James Courtier-Dutton, ALSA development On Mon, 22 Mar 2004, Clemens Ladisch wrote: > > I have discovered a problem with xine when using it. I have done a work > > around in xine so that dmix now works in xine. I think that my > > assumptions regarding snd_pcm_wait() might have been wrong, so I want to > > get accurate details from yourselves. > > I think the implementation of dmix is broken in this regard. If I > read the code correctly, snd_pcm_direct_poll_revents() returns > POLLIN/OUT even if the pcm is empty. > > Jaroslav, shouldn't this function reset the events variable when empty > is set? No, in case when no timer events are available, the revents should be zero from the kernel space, so we don't need to explicitly clear this variable. Jaroslav ----- Jaroslav Kysela <perex@suse.cz> Linux Kernel Sound Maintainer ALSA Project, SuSE Labs ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-03-24 9:01 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-03-21 14:49 snd_pcm_wait() More details required James Courtier-Dutton 2004-03-22 9:56 ` Jaroslav Kysela 2004-03-22 17:31 ` James Courtier-Dutton 2004-03-22 17:51 ` Jaroslav Kysela 2004-03-23 12:33 ` Clemens Ladisch 2004-03-23 13:40 ` Jaroslav Kysela 2004-03-24 7:58 ` Clemens Ladisch 2004-03-24 8:59 ` Jaroslav Kysela 2004-03-22 10:10 ` Clemens Ladisch 2004-03-22 10:09 ` Jaroslav Kysela
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.