All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: andi@rhlx01.fht-esslingen.de
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: OSS SNDCTL_DSP_GETISPACE, non-blocking read: messy :-\
Date: Mon, 27 Oct 2003 13:01:37 +0100	[thread overview]
Message-ID: <s5hbrs27uu6.wl@alsa2.suse.de> (raw)
In-Reply-To: <20031025200221.GA6415@rhlx01.fht-esslingen.de>

At Sat, 25 Oct 2003 22:02:21 +0200,
Andreas Mohr wrote:
> 
> Hi all,
> 
> RAT (Robust Audio Tool, http://www-mice.cs.ucl.ac.uk/multimedia/software/rat/)
> shows quite miserable behaviour on ALSA/OSS (current CVS):
> 
> andi@note:/home/andi$ rat 193.8.230.138/2074
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> audio_read: Resource temporarily unavailable
> .
> .
> .
> andi@note:/home/andi$
> 
> I've been analyzing the reason for about 1.5 hours now,
> and I guess I know what the problem is, but I'm uncertain as to how it should
> be fixed (I could probably fix it, but I REALLY want to leave it to much more
> experienced people since I'm afraid that code is VERY easy to break...).
> 
> Our SNDCTL_DSP_GETISPACE implementation in alsa-driver/acore/oss/pcm_oss.c
> calls snd_pcm_oss_get_space(), which returns the number of bytes available
> to read (e.g. 224).
> 
> RAT then does a read() with exactly this amount of bytes.
> 
> The read() causes alsa-kernel/core/oss/pcm_oss.c/snd_pcm_oss_read()
> to be called, with this amount of bytes passed.
> 
> This now calls snd_pcm_oss_read1(), with the bytes set to the same amount
> again.
> 
> For some stupid reason, _read1() now ALWAYS calls into snd_pcm_oss_read2()
> with an amount of runtime->oss.period_bytes bytes to be read, which happens
> to be 256.
> 
> With a blocking read, this would probably be no problem, since we just wait
> until we have enough data in the buffer, however with a non-blocking read,
> snd_pcm_lib_read(), which gets called by snd_pcm_oss_read3() that's being
> called by snd_pcm_oss_read2(), simply returns -EAGAIN since it cannot handle
> the much too large request.
> 
> 
> Or, as a short summary:
> The application is perfectly well aware of how many bytes there are left
> to read (from calling SNDCTL_DSP_GETISPACE) and then does a read() with
> this amount of bytes, however since the ALSA OSS layer attempts to read
> this byte amount in blocks of runtime->oss.period_bytes bytes from the sound
> device, we ARTIFICIALLY cause a -EAGAIN to be returned due to insufficient
> available data, thus potentially confusing many OSS applications.
> 
> Now what to do here?

this problem is a bit touch, because the ALSA OSS layer does the
sample-rate conversion, etc.
when the sample rate is converted between 44.1kHz and 48kHz, some
round error may happen and it will be accumulated.   hence, the size
will be different between two cases: reading a whole period once and
reading a period by multiple calls.

i'll take a more deeper look...


Takashi


-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/

  reply	other threads:[~2003-10-27 12:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-25 20:02 OSS SNDCTL_DSP_GETISPACE, non-blocking read: messy :-\ Andreas Mohr
2003-10-27 12:01 ` Takashi Iwai [this message]
2003-10-27 12:11   ` Andreas Mohr
2003-10-28 11:21     ` Takashi Iwai
2003-10-28 12:36       ` Jaroslav Kysela
2003-10-28 13:24         ` Takashi Iwai
2003-10-28 13:30         ` Jaroslav Kysela
2003-10-28 14:27           ` Takashi Iwai

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=s5hbrs27uu6.wl@alsa2.suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=andi@rhlx01.fht-esslingen.de \
    /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.