pcm_hw bug when calling snd_pcm_sw_params twice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
#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;
}
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux