I have just downloaded alsa-lib 0.9.0rc2
alsa-lib-0.9.0rc2/src/pcm/pcm_local.h

The code below will return negative value when avail < - pcm->boundary
It may happen if appl.ptr==0 and hw.ptr+pcm->buffer_size goes from 0x7fffffff
to 0x80000000 .

static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm)
{
        snd_pcm_sframes_t avail;
        avail = *pcm->hw.ptr + pcm->buffer_size - *pcm->appl.ptr;
        if (avail < 0)
                avail += pcm->boundary;
        else if ((snd_pcm_uframes_t) avail >= pcm->boundary)
                avail -= pcm->boundary;
        return avail;
}

May be the following code would be better?

static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm)
{
        snd_pcm_sframes_t avail;
        avail = *pcm->hw.ptr + pcm->buffer_size - *pcm->appl.ptr;
        if (avail < 0)
                avail += pcm->boundary;
        if (avail < 0)
                avail += pcm->boundary;
        else if ((snd_pcm_uframes_t) avail >= pcm->boundary)
                avail -= pcm->boundary;
        return avail;
}

The solution is not as simple as I thought. There has to be a discontinuity
somewhere.

I have the following questions about the design:

1. Is hw.ptr allowed to be set by the alsa-driver >= than
boundary?

2. Is snd_pcm_mmap_playback_avail allowed to return negative number?

What is confusing is that there seems to be a protection against returning
negative values, but it does not work 100 %.

There are more functions nearby which have the same problem.

What I need is just an ((unsigned)hw.ptr)%boundary

Best regards,
--
Tomasz Motylewski



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Alsa-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Reply via email to