* [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency
@ 2015-09-11 19:03 Volker Rümelin
2015-09-11 23:22 ` Marc-André Lureau
2015-09-12 12:07 ` Marc-André Lureau
0 siblings, 2 replies; 6+ messages in thread
From: Volker Rümelin @ 2015-09-11 19:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann, Kővágó, Zoltán
Current code doesn't provide pulseaudio buffer attributes for
recording. Without buffer attributes pulseaudio uses a default
buffer of 4MB. 4MB is approximately 24s 16bit stereo audio
data at 44.1kHz.
This patch fixes bug #1492649
|Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>|
---
audio/paaudio.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/audio/paaudio.c b/audio/paaudio.c
index fea6071..c1169d4 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -608,6 +608,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
{
int error;
pa_sample_spec ss;
+ pa_buffer_attr ba;
struct audsettings obt_as = *as;
PAVoiceIn *pa = (PAVoiceIn *) hw;
paaudio *g = pa->g = drv_opaque;
@@ -616,6 +617,12 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
ss.channels = as->nchannels;
ss.rate = as->freq;
+ ba.fragsize = pa_frame_size (&ss) * g->conf.samples;
+ ba.maxlength = 5 * ba.fragsize;
+ ba.tlength = -1;
+ ba.prebuf = -1;
+ ba.minreq = -1;
+
obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
pa->stream = qpa_simple_new (
@@ -625,7 +632,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
g->conf.source,
&ss,
NULL, /* channel map */
- NULL, /* buffering attributes */
+ &ba, /* buffering attributes */
&error
);
if (!pa->stream) {
--
1.8.4.5
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency
2015-09-11 19:03 [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency Volker Rümelin
@ 2015-09-11 23:22 ` Marc-André Lureau
2015-09-12 11:23 ` Volker Rümelin
2015-09-12 12:07 ` Marc-André Lureau
1 sibling, 1 reply; 6+ messages in thread
From: Marc-André Lureau @ 2015-09-11 23:22 UTC (permalink / raw)
To: Volker Rümelin
Cc: Kővágó, Zoltán, QEMU, Gerd Hoffmann
Hi
On Fri, Sep 11, 2015 at 9:03 PM, Volker Rümelin <vr_qemu@t-online.de> wrote:
> Current code doesn't provide pulseaudio buffer attributes for
> recording. Without buffer attributes pulseaudio uses a default
> buffer of 4MB. 4MB is approximately 24s 16bit stereo audio
> data at 44.1kHz.
Why isn't the buffer processed as soon as some data is available?
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency
2015-09-11 23:22 ` Marc-André Lureau
@ 2015-09-12 11:23 ` Volker Rümelin
2015-09-12 14:35 ` Kővágó Zoltán
0 siblings, 1 reply; 6+ messages in thread
From: Volker Rümelin @ 2015-09-12 11:23 UTC (permalink / raw)
To: Marc-André Lureau
Cc: Kővágó, Zoltán, QEMU, Gerd Hoffmann
Hi,
Am 12.09.2015 um 01:22 schrieb Marc-André Lureau:
>> Current code doesn't provide pulseaudio buffer attributes for
>> recording. Without buffer attributes pulseaudio uses a default
>> buffer of 4MB. 4MB is approximately 24s 16bit stereo audio
>> data at 44.1kHz.
> Why isn't the buffer processed as soon as some data is available?
>
>
On start up qemu opens a connection to pulseaudio in function
qpa_init_in and pulseaudio immediately starts recording to the 4MB
ringbuffer. The qemu guest, Windows 8.1 in my case, doesn't consume that
data if there is no process listening on the audio interface. Now if the
guest starts recording, it will see audio data which was recorded 24s ago.
Regards,
Volker
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency
2015-09-12 11:23 ` Volker Rümelin
@ 2015-09-12 14:35 ` Kővágó Zoltán
2015-09-12 19:55 ` Volker Rümelin
0 siblings, 1 reply; 6+ messages in thread
From: Kővágó Zoltán @ 2015-09-12 14:35 UTC (permalink / raw)
To: Volker Rümelin, Marc-André Lureau; +Cc: QEMU, Gerd Hoffmann
2015-09-12 13:23 keltezéssel, Volker Rümelin írta:
> Hi,
>
> Am 12.09.2015 um 01:22 schrieb Marc-André Lureau:
>
>>> Current code doesn't provide pulseaudio buffer attributes for
>>> recording. Without buffer attributes pulseaudio uses a default
>>> buffer of 4MB. 4MB is approximately 24s 16bit stereo audio
>>> data at 44.1kHz.
>> Why isn't the buffer processed as soon as some data is available?
>>
>>
>
> On start up qemu opens a connection to pulseaudio in function
> qpa_init_in and pulseaudio immediately starts recording to the 4MB
> ringbuffer. The qemu guest, Windows 8.1 in my case, doesn't consume that
> data if there is no process listening on the audio interface. Now if the
> guest starts recording, it will see audio data which was recorded 24s ago.
Weird, pulseaudio shouldn't delay the input more than 2 seconds in the
default config. Maybe PA_STREAM_EARLY_REQUESTS help. See my patch at
[1]. Alternatively we should maybe call pa_stream_flush when enabling
the input to tell pulseaudio to drop previously recorded samples.
[1]: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg02455.html
Zoltan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency
2015-09-12 14:35 ` Kővágó Zoltán
@ 2015-09-12 19:55 ` Volker Rümelin
0 siblings, 0 replies; 6+ messages in thread
From: Volker Rümelin @ 2015-09-12 19:55 UTC (permalink / raw)
To: Kővágó Zoltán
Cc: Marc-André Lureau, QEMU, Gerd Hoffmann
Am 12.09.2015 um 16:35 schrieb Kővágó Zoltán:
> 2015-09-12 13:23 keltezéssel, Volker Rümelin írta:
>>
>> On start up qemu opens a connection to pulseaudio in function
>> qpa_init_in and pulseaudio immediately starts recording to the 4MB
>> ringbuffer. The qemu guest, Windows 8.1 in my case, doesn't consume that
>> data if there is no process listening on the audio interface. Now if the
>> guest starts recording, it will see audio data which was recorded 24s
>> ago.
>
> Weird, pulseaudio shouldn't delay the input more than 2 seconds in the
> default config. Maybe PA_STREAM_EARLY_REQUESTS help. See my patch at
> [1]. Alternatively we should maybe call pa_stream_flush when enabling
> the input to tell pulseaudio to drop previously recorded samples.
>
> [1]: https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg02455.html
>
Hi Zoltan,
I tested your suggestions.
There was the same 24s latency when I replaced PA_STREAM_ADJUST_LATENCY
with PA_STREAM_EARLY_REQUESTS in function pa_stream_connect_record. This
was to be expected, because the pulseaudio documentation only mentions
playback there.
A call to pa_stream_flush in qpa_ctl_in in case VOICE_ENABLE: also
didn't solve the problem.
But when I replaced pa_stream_flush with a repeated call to
pa_stream_peek and pa_stream_drop things started to improve. Now I
experience the 1-2s recording latency mentioned in the pulseaudio
documentation. But this is still much higher than the latency I see with
my old patch.
Regards,
Volker
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency
2015-09-11 19:03 [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency Volker Rümelin
2015-09-11 23:22 ` Marc-André Lureau
@ 2015-09-12 12:07 ` Marc-André Lureau
1 sibling, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2015-09-12 12:07 UTC (permalink / raw)
To: Volker Rümelin
Cc: Kővágó, Zoltán, QEMU, Gerd Hoffmann
Hi
On Fri, Sep 11, 2015 at 9:03 PM, Volker Rümelin <vr_qemu@t-online.de> wrote:
> Current code doesn't provide pulseaudio buffer attributes for
> recording. Without buffer attributes pulseaudio uses a default
> buffer of 4MB. 4MB is approximately 24s 16bit stereo audio
> data at 44.1kHz.
>
> This patch fixes bug #1492649
>
> |Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>|
> ---
> audio/paaudio.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/audio/paaudio.c b/audio/paaudio.c
> index fea6071..c1169d4 100644
> --- a/audio/paaudio.c
> +++ b/audio/paaudio.c
> @@ -608,6 +608,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
> {
> int error;
> pa_sample_spec ss;
> + pa_buffer_attr ba;
> struct audsettings obt_as = *as;
> PAVoiceIn *pa = (PAVoiceIn *) hw;
> paaudio *g = pa->g = drv_opaque;
> @@ -616,6 +617,12 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
> ss.channels = as->nchannels;
> ss.rate = as->freq;
>
> + ba.fragsize = pa_frame_size (&ss) * g->conf.samples;
> + ba.maxlength = 5 * ba.fragsize;
This 5 value is a bit arbitrary, I suppose it may increase max latency
up to 5 times the g->conf.samples. (what about using
PA_STREAM_ADJUST_LATENCY?)
Otherwise, the change looks good to me.
> + ba.tlength = -1;
> + ba.prebuf = -1;
> + ba.minreq = -1;
> +
> obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
>
> pa->stream = qpa_simple_new (
> @@ -625,7 +632,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
> g->conf.source,
> &ss,
> NULL, /* channel map */
> - NULL, /* buffering attributes */
> + &ba, /* buffering attributes */
> &error
> );
> if (!pa->stream) {
> --
> 1.8.4.5
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-09-12 19:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-11 19:03 [Qemu-devel] [PATCH] pulseaudio: reduce 24s recording latency Volker Rümelin
2015-09-11 23:22 ` Marc-André Lureau
2015-09-12 11:23 ` Volker Rümelin
2015-09-12 14:35 ` Kővágó Zoltán
2015-09-12 19:55 ` Volker Rümelin
2015-09-12 12:07 ` Marc-André Lureau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.