All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlo Wood <carlo@alinoe.com>
To: Jaroslav Kysela <perex@suse.cz>
Cc: "xvoice@yahoogroups.com" <xvoice@yahoogroups.com>,
	"kai.vehmanen@wakkanet.fi" <kai.vehmanen@wakkanet.fi>,
	"alsa-devel@lists.sourceforge.net"
	<alsa-devel@lists.sourceforge.net>
Subject: Re: Re: [xvoice] Hacking ViaVoice, part 4
Date: Sun, 13 Jul 2003 01:05:39 +0200	[thread overview]
Message-ID: <20030712230539.GA9060@alinoe.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0307122025230.1101-100000@pnote.perex-int.cz>

On Sat, Jul 12, 2003 at 08:56:16PM +0200, Jaroslav Kysela wrote:
> On Sat, 12 Jul 2003, Carlo Wood wrote:
> 
> > On Sat, Jul 12, 2003 at 02:08:34PM +0200, Carlo Wood wrote:
> > > Hence, the problem is now reduced to the question:
> > > Why is snd_pcm_update_hw_ptr_interrupt not called anymore
> > > after we did run into an xrun?
> > 
> > I added a few more printk's and already I can guess
> > what is the reason that the 'blackbox' (the rest)
> > stops calling snd_pcm_update_hw_ptr_interrupt:
> > 
> > I thought it was said that an xrun should simply be ignored?
> 
> Yes, but at another level - in the OSS emulation code.

Well, I traced back to this point from an application
that only uses the OSS interface.

> > What is the correct way to recover from this, to continue
> > recording in this case, after the xrun?
> 
> Call read() or poll(POLLIN) again. I think that your problem might be that 
> poll(POLLIN) does not trigger the input in the current ALSA code. Please, 
> try this patch with ViaVoice (the patch is also in the ALSA CVS tree):

This application (ViaVoice) calls neither poll() nor select().
It only calls read() when the SNDCTL_DSP_GETISPACE ioctl returns
that there are bytes that can be read without blocking.

I applied the patch, but it won't do anything: poll is never called.


Allow me to give a summary of the problem:

An old application that uses the OSS interface opens /dev/dsp
and goes in a loop where it only calls read() when the
SNDCTL_DSP_GETISPACE ioctl reports that there is data to be read.

However, before it actually starts that loop is wastes some cpu
so that the (small) recording buffer runs full (with a Creative
soundblaster Live! that happens after 128 ms).

OSS interface or not, the sound recording causes
`snd_pcm_update_hw_ptr_interrupt' to be called.   And as soon
as the buffer overruns this function calls:

    snd_pcm_stop(substream,
		 runtime->status->state == SNDRV_PCM_STATE_DRAINING ?
		 SNDRV_PCM_STATE_SETUP : SNDRV_PCM_STATE_XRUN);

Stopping the stream.

The application calls ioctl(fd, SNDCTL_DSP_GETISPACE, &info)
which runs that there is 2048 bytes available.  The application
calls read() and reads 1024 bytes; THIS read() DOES NOT CAUSE
THE STREAM TO BE STARTED AGAIN.  Next the application calls
again ioctl(fd, SNDCTL_DSP_GETISPACE, &info), which now returns
1024 bytes, and reads the last 1024 bytes.  Again, this read
does not start the stream again.

If subsequential reads would start the stream again, then
this isn't helpful because the application never calls read()
again as ioctl(fd, SNDCTL_DSP_GETISPACE, &info) returns
zero bytes to be read from then on.

Isn't this a bug in the OSS emulation of ALSA?  The correct
behaviour seems to be that the stream is started again as soon
as there is space in the buffer again, thus after the first 'read()',
or after the second read when at least one fragment of space is
available, or in the very least after the read() that causes
the buffer to be empty.

If not, then it is a bug in ViaVoice - how *should* ViaVoice have
worked to this deadlock?

-- 
Carlo Wood <carlo@alinoe.com>


-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1

  reply	other threads:[~2003-07-12 23:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20030712120834.GA5378@alinoe.com>
2003-07-12 13:50 ` [xvoice] Hacking ViaVoice, part 4 Carlo Wood
2003-07-12 18:56   ` Jaroslav Kysela
2003-07-12 23:05     ` Carlo Wood [this message]
2003-07-12 23:10       ` Carlo Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030712230539.GA9060@alinoe.com \
    --to=carlo@alinoe.com \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=kai.vehmanen@wakkanet.fi \
    --cc=perex@suse.cz \
    --cc=xvoice@yahoogroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.