alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* Infinite loop in snd_pcm_hw_htimestamp() for capture PCMs?
@ 2012-09-21 15:53 Andrew Eikum
  2012-09-21 16:02 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Eikum @ 2012-09-21 15:53 UTC (permalink / raw)
  To: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

Hi folks,

I've found some unexpected behavior in alsa-lib. The attached program
uses 100% CPU in an infinite loop, when I'd expect it to return either
an error or a valid htimestamp. I believe the loop occurs in
<src/pcm/pcm_hw.c:snd_pcm_hw_htimestamp()>. Am I not supposed to call
htimestamp() on this type of PCM? Is the PCM still in an invalid state
when htimestamp() is called?

Card: HDA ATI SB
Chip: Realtek ALC889

Happy for any insight.
Andrew

[-- Attachment #2: capture_inf_loop.c --]
[-- Type: text/x-csrc, Size: 2094 bytes --]

/* Causes an infinite loop in alsa-lib's snd_pcm_hw_htimestamp() in the
 * capture direction
 *
 * Build with:
 * $ gcc -o test -Wall capture_inf_loop.c -lasound
 */

#include <alsa/asoundlib.h>

int main(int argc, char **argv)
{
    snd_pcm_t *pcm;
    snd_pcm_uframes_t avail;
    snd_pcm_hw_params_t *hw_params;
    int err;
    struct timespec ts;
    unsigned int rate = 44100;

    err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_CAPTURE,
            SND_PCM_NONBLOCK);
    if(err < 0){
        fprintf(stderr, "snd_pcm_open: %s\n", snd_strerror(err));
        return 1;
    }

    snd_pcm_hw_params_malloc(&hw_params);

    err = snd_pcm_hw_params_any(pcm, hw_params);
    if(err < 0){
        fprintf(stderr, "snd_pcm_hw_params_any: %s\n", snd_strerror(err));
        return 1;
    }

    err = snd_pcm_hw_params_set_access(pcm, hw_params,
            SND_PCM_ACCESS_RW_INTERLEAVED);
    if(err < 0){
        fprintf(stderr, "snd_pcm_hw_params_set_access: %s\n",
                snd_strerror(err));
        return 1;
    }

    err = snd_pcm_hw_params_set_format(pcm, hw_params,
            SND_PCM_FORMAT_S16_LE);
    if(err < 0){
        fprintf(stderr, "snd_pcm_hw_params_set_access: %s\n",
                snd_strerror(err));
        return 1;
    }

    err = snd_pcm_hw_params_set_rate_near(pcm, hw_params, &rate, NULL);
    if(err < 0){
        fprintf(stderr, "snd_pcm_hw_params_set_rate_near: %s\n",
                snd_strerror(err));
        return 1;
    }

    err = snd_pcm_hw_params_set_channels(pcm, hw_params, 2);
    if(err < 0){
        fprintf(stderr, "snd_pcm_hw_params_set_rate_near: %s\n",
                snd_strerror(err));
        return 1;
    }

    err = snd_pcm_hw_params(pcm, hw_params);
    if(err < 0){
        fprintf(stderr, "snd_pcm_hw_params: %s\n", snd_strerror(err));
        return 1;
    }

    fprintf(stderr, "avail_update\n");
    snd_pcm_avail_update(pcm);

    fprintf(stderr, "entering htimestamp...\n");
    snd_pcm_htimestamp(pcm, &avail, &ts);
    fprintf(stderr, "done with htimestamp\n");

    snd_pcm_close(pcm);

    return 0;
}

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



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

end of thread, other threads:[~2012-09-21 16:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-21 15:53 Infinite loop in snd_pcm_hw_htimestamp() for capture PCMs? Andrew Eikum
2012-09-21 16:02 ` Takashi Iwai
2012-09-21 16:15   ` Andrew Eikum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).