All of lore.kernel.org
 help / color / mirror / Atom feed
* problems: flushing during snd_pcm_wait()
@ 2002-10-10 15:25 James Courtier-Dutton
  2002-10-11 11:52 ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: James Courtier-Dutton @ 2002-10-10 15:25 UTC (permalink / raw)
  To: alsa-devel

Hello
I have an application that has many different threads.
The sound card's PCM buffer is full during playback, and one thread is 
currently in snd_pcm_wait() waiting for enough space to appear in the 
buffer before doing the next snd_pcm_write().
A different thread wants to flush the buffer. There are two types of 
flush: -
1) Immeadiately empty the buffer.
2) Stop accepting snd_pcm_write() commands until the current buffer has 
drained.

Can someone please tell me which API calls I should make to get the 
buffer to flush properly.
I am currently doing things like: -
int flush() {
 <snip...>
      if ((result=snd_pcm_reset(this->audio_fd)) < 0) {
        printf("audio_alsa_out: Reset call failed err=%d\n",result);
      }
      if ((result=snd_pcm_drain(this->audio_fd)) < 0) {
        printf("audio_alsa_out: Drain call failed err=%d\n",result);
      }
      if ((result=snd_pcm_prepare(this->audio_fd)) < 0) {
        printf("audio_alsa_out: Prepare call failed err=%d\n",result);
      }
}

But this is causing all sorts of problems, one of which is that the 
application hangs, and has to be killed with -9, and the audio hardware 
ring buffer is left playing a repeated sound even with: -
/proc/asound/card0/pcm0p/sub0# cat status
closed

Cheers
James





-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: problems: flushing during snd_pcm_wait()
  2002-10-10 15:25 problems: flushing during snd_pcm_wait() James Courtier-Dutton
@ 2002-10-11 11:52 ` Takashi Iwai
  2002-10-11 12:50   ` James Courtier-Dutton
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2002-10-11 11:52 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel

At Fri, 11 Oct 2002 01:25:19 +1000,
James Courtier-Dutton wrote:
> 
> Hello
> I have an application that has many different threads.
> The sound card's PCM buffer is full during playback, and one thread is 
> currently in snd_pcm_wait() waiting for enough space to appear in the 
> buffer before doing the next snd_pcm_write().
> A different thread wants to flush the buffer. There are two types of 
> flush: -
> 1) Immeadiately empty the buffer.

snd_pcm_drop() ?

> 2) Stop accepting snd_pcm_write() commands until the current buffer has 
> drained.

snd_pcm_drain() ?


Takashi


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: problems: flushing during snd_pcm_wait()
  2002-10-11 11:52 ` Takashi Iwai
@ 2002-10-11 12:50   ` James Courtier-Dutton
  2002-10-11 13:00     ` Jaroslav Kysela
  0 siblings, 1 reply; 6+ messages in thread
From: James Courtier-Dutton @ 2002-10-11 12:50 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

Takashi Iwai wrote:

>At Fri, 11 Oct 2002 01:25:19 +1000,
>James Courtier-Dutton wrote:
>  
>
>>Hello
>>I have an application that has many different threads.
>>The sound card's PCM buffer is full during playback, and one thread is 
>>currently in snd_pcm_wait() waiting for enough space to appear in the 
>>buffer before doing the next snd_pcm_write().
>>A different thread wants to flush the buffer. There are two types of 
>>flush: -
>>1) Immeadiately empty the buffer.
>>    
>>
>
>snd_pcm_drop() ?
>
>  
>
>>2) Stop accepting snd_pcm_write() commands until the current buffer has 
>>drained.
>>    
>>
>
>snd_pcm_drain() ?
>
>
>Takashi
>
>  
>
Thankyou, I will use snd_pcm_drop(), but as a side note, what actually 
does "snd_pcm_reset()" do.
Just resetting delay to 0 does not make much sense to me.

Cheer




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: problems: flushing during snd_pcm_wait()
  2002-10-11 12:50   ` James Courtier-Dutton
@ 2002-10-11 13:00     ` Jaroslav Kysela
  2002-10-11 13:23       ` James Courtier-Dutton
  0 siblings, 1 reply; 6+ messages in thread
From: Jaroslav Kysela @ 2002-10-11 13:00 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: Takashi Iwai, alsa-devel@lists.sourceforge.net

On Fri, 11 Oct 2002, James Courtier-Dutton wrote:

> Takashi Iwai wrote:
> 
> >At Fri, 11 Oct 2002 01:25:19 +1000,
> >James Courtier-Dutton wrote:
> >  
> >
> >>Hello
> >>I have an application that has many different threads.
> >>The sound card's PCM buffer is full during playback, and one thread is 
> >>currently in snd_pcm_wait() waiting for enough space to appear in the 
> >>buffer before doing the next snd_pcm_write().
> >>A different thread wants to flush the buffer. There are two types of 
> >>flush: -
> >>1) Immeadiately empty the buffer.
> >>    
> >>
> >
> >snd_pcm_drop() ?
> >
> >  
> >
> >>2) Stop accepting snd_pcm_write() commands until the current buffer has 
> >>drained.
> >>    
> >>
> >
> >snd_pcm_drain() ?
> >
> >
> >Takashi
> >
> >  
> >
> Thankyou, I will use snd_pcm_drop(), but as a side note, what actually 
> does "snd_pcm_reset()" do.
> Just resetting delay to 0 does not make much sense to me.

It drops all samples in the ring buffer (thus reseting delay to 0). Note 
that everybody are welcome to improve the current documentation 
(preferably with patches).

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project  http://www.alsa-project.org
SuSE Linux    http://www.suse.com



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: problems: flushing during snd_pcm_wait()
  2002-10-11 13:00     ` Jaroslav Kysela
@ 2002-10-11 13:23       ` James Courtier-Dutton
  2002-10-11 14:22         ` Jaroslav Kysela
  0 siblings, 1 reply; 6+ messages in thread
From: James Courtier-Dutton @ 2002-10-11 13:23 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: alsa-devel@lists.sourceforge.net

>
>
>>>      
>>>
>>Thankyou, I will use snd_pcm_drop(), but as a side note, what actually 
>>does "snd_pcm_reset()" do.
>>Just resetting delay to 0 does not make much sense to me.
>>    
>>
>
>It drops all samples in the ring buffer (thus reseting delay to 0). Note 
>that everybody are welcome to improve the current documentation 
>(preferably with patches).
>
>						Jaroslav
>  
>
Ok, so snd_pcm_drop drops all samples in the buffer, so I would assume 
this sets the delay to 0.
so snd_pcm_reset drops all sample in the buffer, so as you say is sets 
delay to 0.
So my question is "What is the difference between the 2 functions?"

Cheers
James





-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: problems: flushing during snd_pcm_wait()
  2002-10-11 13:23       ` James Courtier-Dutton
@ 2002-10-11 14:22         ` Jaroslav Kysela
  0 siblings, 0 replies; 6+ messages in thread
From: Jaroslav Kysela @ 2002-10-11 14:22 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel@lists.sourceforge.net

On Fri, 11 Oct 2002, James Courtier-Dutton wrote:

> >>Thankyou, I will use snd_pcm_drop(), but as a side note, what actually 
> >>does "snd_pcm_reset()" do.
> >>Just resetting delay to 0 does not make much sense to me.
> >>    
> >>
> >
> >It drops all samples in the ring buffer (thus reseting delay to 0). Note 
> >that everybody are welcome to improve the current documentation 
> >(preferably with patches).
> >
> >						Jaroslav
> >  
> >
> Ok, so snd_pcm_drop drops all samples in the buffer, so I would assume 
> this sets the delay to 0.
> so snd_pcm_reset drops all sample in the buffer, so as you say is sets 
> delay to 0.
> So my question is "What is the difference between the 2 functions?"

reset() doesn't stop the stream. It's mainly useable, if you have streams 
linked together with hardware or if an application wants to act very 
realtime and has xrun detection disabled.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project  http://www.alsa-project.org
SuSE Linux    http://www.suse.com



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-10-11 14:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-10 15:25 problems: flushing during snd_pcm_wait() James Courtier-Dutton
2002-10-11 11:52 ` Takashi Iwai
2002-10-11 12:50   ` James Courtier-Dutton
2002-10-11 13:00     ` Jaroslav Kysela
2002-10-11 13:23       ` James Courtier-Dutton
2002-10-11 14:22         ` 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.