All of lore.kernel.org
 help / color / mirror / Atom feed
* 1.1.3 bug report: dmix reports inconsistent status
@ 2017-05-24 19:18 Cheng Sun
  2017-05-26  9:16 ` Cheng Sun
  0 siblings, 1 reply; 2+ messages in thread
From: Cheng Sun @ 2017-05-24 19:18 UTC (permalink / raw)
  To: alsa-devel

Hi all,

The following commit (released in v1.1.3) introduced an issue where
dmix reports its state differently when snd_pcm_state is queried,
compared to snd_pcm_status.

    38a2d2eda880fda9ed5a4a219db498d9c0856d71

(I suspect faf53c197cabeb1eb0fd1f66cd001d1469ebac09 affects dshare
similarly, but this is not tested)

The sample program attached at the bottom of this email demonstrates
this behaviour by printing the following on underrun:

try 1: status_state=3, state=4
try 2: status_state=3, state=4
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred

Cheers,
Cheng


---

#include <assert.h>
#include <alsa/asoundlib.h>
#include <stdint.h>
#define FRAMES 100
int32_t buffer[FRAMES][2];
int main(int argc, char *argv[]) {
    const char *pcmname = argc == 2 ? argv[1] : "default";
    snd_pcm_t *pcm;
    assert( snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_PLAYBACK, 0) == 0 );
    assert( snd_pcm_set_params(pcm, SND_PCM_FORMAT_S32_LE,
SND_PCM_ACCESS_RW_INTERLEAVED, 2, 48000, 1, 250) == 0 );
    for (;;) {
        snd_pcm_sframes_t written = snd_pcm_writei(pcm, buffer, FRAMES);
        if (written <= 0) {
            snd_pcm_status_t *status;
            snd_pcm_status_alloca(&status);
            assert( snd_pcm_status(pcm, status) == 0 );

            int status_state, state;

            status_state = snd_pcm_status_get_state(status);
            state = snd_pcm_state(pcm);
            printf("try 1: status_state=%d, state=%d\n", status_state, state);

            status_state = snd_pcm_status_get_state(status);
            state = snd_pcm_state(pcm);
            printf("try 2: status_state=%d, state=%d\n", status_state, state);

            assert( snd_pcm_recover(pcm,written,0) == 0 );
        }
    }
}

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

* Re: 1.1.3 bug report: dmix reports inconsistent status
  2017-05-24 19:18 1.1.3 bug report: dmix reports inconsistent status Cheng Sun
@ 2017-05-26  9:16 ` Cheng Sun
  0 siblings, 0 replies; 2+ messages in thread
From: Cheng Sun @ 2017-05-26  9:16 UTC (permalink / raw)
  To: alsa-devel

On 24 May 2017 at 20:18, Cheng Sun <chengsun9@gmail.com> wrote:
> Hi all,
>
> The following commit (released in v1.1.3) introduced an issue where
> dmix reports its state differently when snd_pcm_state is queried,
> compared to snd_pcm_status.
>
>     38a2d2eda880fda9ed5a4a219db498d9c0856d71
>
> (I suspect faf53c197cabeb1eb0fd1f66cd001d1469ebac09 affects dshare
> similarly, but this is not tested)
>
> The sample program attached at the bottom of this email demonstrates
> this behaviour by printing the following on underrun:
>
> try 1: status_state=3, state=4
> try 2: status_state=3, state=4
> ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
>
> Cheers,
> Cheng

Just realised that my original sample program had a slight flaw
(snd_pcm_status only called once). Here's the corrected version, which
still exhibits the erroneous behaviour.

(Also to clarify, this problem is still present in v1.1.4 and master.)

Cheers,
Cheng

---

#include <assert.h>
#include <alsa/asoundlib.h>
#include <stdint.h>
#define FRAMES 100
int32_t buffer[FRAMES][2];
int main(int argc, char *argv[]) {
    const char *pcmname = argc == 2 ? argv[1] : "default";
    snd_pcm_t *pcm;
    assert( snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_PLAYBACK, 0) == 0 );
    assert( snd_pcm_set_params(pcm, SND_PCM_FORMAT_S32_LE,
SND_PCM_ACCESS_RW_INTERLEAVED, 2, 48000, 1, 250) == 0 );
    for (;;) {
        snd_pcm_sframes_t written = snd_pcm_writei(pcm, buffer, FRAMES);
        if (written <= 0) {
            snd_pcm_status_t *status;
            snd_pcm_status_alloca(&status);

            int status_state, state;

            assert( snd_pcm_status(pcm, status) == 0 );
            status_state = snd_pcm_status_get_state(status);
            state = snd_pcm_state(pcm);
            printf("try 1: status_state=%d, state=%d\n", status_state, state);

            assert( snd_pcm_status(pcm, status) == 0 );
            status_state = snd_pcm_status_get_state(status);
            state = snd_pcm_state(pcm);
            printf("try 2: status_state=%d, state=%d\n", status_state, state);

            assert( snd_pcm_recover(pcm,written,0) == 0 );
        }
    }
}

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

end of thread, other threads:[~2017-05-26  9:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 19:18 1.1.3 bug report: dmix reports inconsistent status Cheng Sun
2017-05-26  9:16 ` Cheng Sun

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.