Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Jan 2013 20:12:47 +0200
From:      Alexander Motin <mav@FreeBSD.org>
To:        Andriy Gapon <avg@FreeBSD.org>
Cc:        freebsd-multimedia@FreeBSD.org
Subject:   Re: sound(4) vs alsa oss plugin
Message-ID:  <5108111F.3080205@FreeBSD.org>
In-Reply-To: <5103A438.9010806@FreeBSD.org>
References:  <5103A438.9010806@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 26.01.2013 11:39, Andriy Gapon wrote:
> 
> I think I discovered an interesting/unusual problem.
> 
> For some reason ALSA OSS plugin developers decided to use SNDCTL_DSP_GETOPTR and
> SNDCTL_DSP_GETIPTR to track state of playback/recording.
> http://manuals.opensound.com/developer/SNDCTL_DSP_GETOPTR.html
> http://manuals.opensound.com/developer/SNDCTL_DSP_GETIPTR.html
> Of all information returned by these ioctl they use just 'ptr' to track the
> progress by hardware.
> 
> Now I see that under a "right mix" of circumstances the following is possible:
> - a buffer is completely empty for recording or completely full for playback
> - an application / ALSA checks the buffer pointer and gets some value P
> - the application sleeps for some time, perhaps oversleeps due to system load or
> something else
> - the buffer is completely filled or drained depending on the direction
> - the application / ALSA checks the buffer pointer and gets the same value P
> - the application assumes that the buffer is in the old state and waits further
> - sound(4) code knows that the buffer is in the new state and does nothing
> 
> The above is only possible, obviously, if the buffer size is a multiple of a
> sample size.
> 
> So, couple of questions:
> - apparently this used to work (works?) in Linux - how?
> - is there any trick that we can do in our sound(4) code to prevent this 'ptr'
> full cycle from happening?
> 
> Ideally, it's the logic in the ALSA OSS plugin that should be fixed, but...
> The upstream is not very responsive.  I wonder if they still care about OSS at all.
> While patching audio/alsa-plugins is relatively easy, fixing a binary package
> for audio/linux-f10-alsa-plugins-oss is not.  And it's needed for things like
> skype, etc.
> 
> What do you think?
> 
> P.S.
> it's because of audio problems with skype that I found this issue.

I am not sure how it supposed to work in Linux, but IMHO it is obvious
that single ptr field is not sufficient in such conditions to identify
full buffer wrap. Additional checks for bytes or blocks fields could
help, but that is user-level side. I am not sure what kernel can do
about it.

>From the other side, case when buffer wrapped completely is IMHO already
fatal situation. It means that we are already late -- hardware already
started to either play or overwrite previous buffer. That is probably
not much better then if we would woke up some samples later.

-- 
Alexander Motin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5108111F.3080205>