From: Jamey Sharp <jamey@minilop.net>
To: alsa-devel@alsa-project.org
Subject: pcm_hw bug when calling snd_pcm_sw_params twice
Date: Mon, 7 Jan 2019 15:26:20 -0800 [thread overview]
Message-ID: <20190107232620.GA11810@eh> (raw)
[-- Attachment #1: Type: text/plain, Size: 783 bytes --]
I would have reported this to your bug tracker, but I can't find it; the
links on alsa-project.org are dead.
I've attached a small test program that demonstrates that calling
snd_pcm_sw_params twice changes the value of the period_event flag in
the sw_params struct, at least on pcm_hw devices.
In src/pcm/pcm_hw.c, in snd_pcm_hw_sw_params, there's an early
`sw_set_period_event(params, 0)` call. Its effect is not undone if the
function returns early. This is easiest to trigger by calling it with
unchanged parameters, although there are other early-exit paths with the
same problem.
I don't actually care about this bug, but since I noticed it while
reading the alsa-lib source code trying to figure out what a period
event is for, I thought I'd go ahead and report it.
Jamey
[-- Attachment #2: alsa_period_event.c --]
[-- Type: text/plain, Size: 1323 bytes --]
#define _GNU_SOURCE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#define check(v) if(v < 0) { perror(#v); exit(1); }
int main(void)
{
snd_pcm_t *handle;
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
int val = 0;
char *name = getenv("DEVICE");
snd_pcm_hw_params_alloca(&hw_params);
snd_pcm_sw_params_alloca(&sw_params);
if(!name)
name = "hw:0";
printf("opening %s\n", name);
check(snd_pcm_open(&handle, name, SND_PCM_STREAM_PLAYBACK, 0));
check(snd_pcm_hw_params_any(handle, hw_params));
check(snd_pcm_hw_params(handle, hw_params));
check(snd_pcm_sw_params_current(handle, sw_params));
// Enable the period event
check(snd_pcm_sw_params_set_period_event(handle, sw_params, 1));
check(snd_pcm_sw_params_get_period_event(sw_params, &val));
assert(val == 1);
// After applying sw params once, the params struct still says the
// period event is enabled.
check(snd_pcm_sw_params(handle, sw_params));
check(snd_pcm_sw_params_get_period_event(sw_params, &val));
assert(val == 1);
// Applying the same sw params a second time should still leave the
// period event enabled, but this assert fails.
check(snd_pcm_sw_params(handle, sw_params));
check(snd_pcm_sw_params_get_period_event(sw_params, &val));
assert(val == 1);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
next reply other threads:[~2019-01-07 23:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 23:26 Jamey Sharp [this message]
2019-01-09 11:08 ` pcm_hw bug when calling snd_pcm_sw_params twice 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=20190107232620.GA11810@eh \
--to=jamey@minilop.net \
--cc=alsa-devel@alsa-project.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox