paaudio: drop recording stream in qpa_fini_in

Every call to pa_stream_peek which returns a data length > 0
should have a corresponding pa_stream_drop. A call to qpa_read
does not necessarily call pa_stream_drop immediately after a
call to pa_stream_peek. Test in qpa_fini_in if a last
pa_stream_drop is needed.

This prevents following messages in the libvirt log file after
a recording stream gets closed and a new one opened.

pulseaudio: pa_stream_drop failed
pulseaudio: Reason: Bad state
pulseaudio: pa_stream_drop failed
pulseaudio: Reason: Bad state

To reproduce start qemu with
-audiodev pa,id=audio0,in.mixing-engine=off
and in the guest start and stop Audacity several times.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-id: 20200104091122.13971-3-vr_qemu@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Volker Rümelin 2020-01-04 10:11:20 +01:00 committed by Gerd Hoffmann
parent c435fea72b
commit 4db3e634c7

View File

@ -536,7 +536,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
{
int err;
pa_threaded_mainloop_lock(c->mainloop);
/*
* wait until actually connects. workaround pa bug #247
* https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247
@ -550,7 +549,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
dolog("Failed to disconnect! err=%d\n", err);
}
pa_stream_unref(stream);
pa_threaded_mainloop_unlock(c->mainloop);
}
static void qpa_fini_out (HWVoiceOut *hw)
@ -558,8 +556,12 @@ static void qpa_fini_out (HWVoiceOut *hw)
PAVoiceOut *pa = (PAVoiceOut *) hw;
if (pa->stream) {
qpa_simple_disconnect(pa->g->conn, pa->stream);
PAConnection *c = pa->g->conn;
pa_threaded_mainloop_lock(c->mainloop);
qpa_simple_disconnect(c, pa->stream);
pa->stream = NULL;
pa_threaded_mainloop_unlock(c->mainloop);
}
}
@ -568,8 +570,20 @@ static void qpa_fini_in (HWVoiceIn *hw)
PAVoiceIn *pa = (PAVoiceIn *) hw;
if (pa->stream) {
qpa_simple_disconnect(pa->g->conn, pa->stream);
PAConnection *c = pa->g->conn;
pa_threaded_mainloop_lock(c->mainloop);
if (pa->read_length) {
int r = pa_stream_drop(pa->stream);
if (r) {
qpa_logerr(pa_context_errno(c->context),
"pa_stream_drop failed\n");
}
pa->read_length = 0;
}
qpa_simple_disconnect(c, pa->stream);
pa->stream = NULL;
pa_threaded_mainloop_unlock(c->mainloop);
}
}