From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Volker Rümelin" <vr_qemu@t-online.de>,
"Gerd Hoffmann" <kraxel@redhat.com>
Subject: [PULL 4/6] paaudio: try to drain the recording stream
Date: Mon, 6 Jan 2020 13:52:34 +0100 [thread overview]
Message-ID: <20200106125236.24132-5-kraxel@redhat.com> (raw)
In-Reply-To: <20200106125236.24132-1-kraxel@redhat.com>
From: Volker Rümelin <vr_qemu@t-online.de>
There is no guarantee a single call to pa_stream_peek every
timer_period microseconds can read a recording stream faster
than the data gets produced at the source. Let qpa_read try to
drain the recording stream.
To reproduce the problem:
Start qemu with -audiodev pa,id=audio0,in.mixing-engine=off
On the host connect the qemu recording stream to the monitor of
a hardware output device. While the problem can also be seen
with a hardware input device, it's obvious with the monitor of
a hardware output device.
In the guest start audio recording with audacity and notice the
slow recording data rate.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-id: 20200104091122.13971-4-vr_qemu@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
audio/paaudio.c | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 7db1dc15f09e..b23274550e1c 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -156,34 +156,43 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
{
PAVoiceIn *p = (PAVoiceIn *) hw;
PAConnection *c = p->g->conn;
- size_t l;
- int r;
+ size_t total = 0;
pa_threaded_mainloop_lock(c->mainloop);
CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
"pa_threaded_mainloop_lock failed\n");
- if (!p->read_length) {
- r = pa_stream_peek(p->stream, &p->read_data, &p->read_length);
- CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
- "pa_stream_peek failed\n");
- }
+ while (total < length) {
+ size_t l;
+ int r;
- l = MIN(p->read_length, length);
- memcpy(data, p->read_data, l);
+ if (!p->read_length) {
+ r = pa_stream_peek(p->stream, &p->read_data, &p->read_length);
+ CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
+ "pa_stream_peek failed\n");
+ if (!p->read_length) {
+ /* buffer is empty */
+ break;
+ }
+ }
- p->read_data += l;
- p->read_length -= l;
+ l = MIN(p->read_length, length - total);
+ memcpy((char *)data + total, p->read_data, l);
- if (!p->read_length) {
- r = pa_stream_drop(p->stream);
- CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
- "pa_stream_drop failed\n");
+ p->read_data += l;
+ p->read_length -= l;
+ total += l;
+
+ if (!p->read_length) {
+ r = pa_stream_drop(p->stream);
+ CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
+ "pa_stream_drop failed\n");
+ }
}
pa_threaded_mainloop_unlock(c->mainloop);
- return l;
+ return total;
unlock_and_fail:
pa_threaded_mainloop_unlock(c->mainloop);
--
2.18.1
next prev parent reply other threads:[~2020-01-06 12:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-06 12:52 [PULL 0/6] Audio 20200106 patches Gerd Hoffmann
2020-01-06 12:52 ` [PULL 1/6] hda-codec: fix playback rate control Gerd Hoffmann
2020-01-06 12:52 ` [PULL 2/6] hda-codec: fix recording " Gerd Hoffmann
2020-01-06 12:52 ` [PULL 3/6] paaudio: drop recording stream in qpa_fini_in Gerd Hoffmann
2020-01-06 12:52 ` Gerd Hoffmann [this message]
2020-01-06 12:52 ` [PULL 5/6] paaudio: wait until the recording stream is ready Gerd Hoffmann
2020-01-06 12:52 ` [PULL 6/6] audio: fix integer overflow Gerd Hoffmann
2020-01-06 17:44 ` [PULL 0/6] Audio 20200106 patches Peter Maydell
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=20200106125236.24132-5-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vr_qemu@t-online.de \
/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;
as well as URLs for NNTP newsgroup(s).