[alsa-devel] [BUG] snd_pcm_drop() does not stop the PCM immediately

Martin Schreiber mse00000 at gmail.com
Wed Mar 14 16:50:48 CET 2018


On 03/14/2018 04:13 PM, Takashi Iwai wrote:
> 
> It's a best-effort base stopping mechanism with dmix, so it's a sort
> of expected behavior, unfortunately.  Due to its nature of
> implementation, scratching off the existing data from the mixed buffer
> isn't so trivial for now.
> 
eSpeakNG has the workaround in pcaudiolib (see outcommented part):
"
int
alsa_object_flush(struct audio_object *object)
{
	struct alsa_object *self = to_alsa_object(object);
	if (self && self->handle){
		snd_pcm_drop(self->handle);
	}
/*
	if (!self) return 0;

	// Using snd_pcm_drop does not discard the audio, so reopen the device
	// to reset the sound buffer.
	if (self->is_open) {
		audio_object_close(object);
			//this crashes write operation in other thread!
		return audio_object_open(object, self->format, self->rate,
self->channels);
	}
*/
	return 0;
}

"
"
void
alsa_object_close(struct audio_object *object)
{
	struct alsa_object *self = to_alsa_object(object);

	if (self->handle) {
		snd_pcm_close(self->handle);
		self->handle = NULL;
		self->is_open = 1;
	}
}
"
Does snd_pcm_close() "scratching off the existing data from the mixed
buffer"? If yes, how could the workaround be made without letting crash
pending write operations in separate thread?

Thanks, Martin


More information about the Alsa-devel mailing list