[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 17/26] paaudio: get/put_buffer functions
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PULL 17/26] paaudio: get/put_buffer functions |
Date: |
Thu, 19 Sep 2019 10:36:20 +0200 |
From: Kővágó, Zoltán <address@hidden>
This lets us avoid some buffer copying when using mixeng.
Signed-off-by: Kővágó, Zoltán <address@hidden>
Message-id: address@hidden
Signed-off-by: Gerd Hoffmann <address@hidden>
---
audio/paaudio.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/audio/paaudio.c b/audio/paaudio.c
index ed31f863f7fe..6ccdf3141598 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -98,6 +98,59 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x)
} \
} while (0)
+static void *qpa_get_buffer_in(HWVoiceIn *hw, size_t *size)
+{
+ PAVoiceIn *p = (PAVoiceIn *) hw;
+ PAConnection *c = p->g->conn;
+ int r;
+
+ 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");
+ }
+
+ *size = MIN(p->read_length, *size);
+
+ pa_threaded_mainloop_unlock(c->mainloop);
+ return (void *) p->read_data;
+
+unlock_and_fail:
+ pa_threaded_mainloop_unlock(c->mainloop);
+ *size = 0;
+ return NULL;
+}
+
+static void qpa_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
+{
+ PAVoiceIn *p = (PAVoiceIn *) hw;
+ PAConnection *c = p->g->conn;
+ int r;
+
+ pa_threaded_mainloop_lock(c->mainloop);
+
+ CHECK_DEAD_GOTO(c, p->stream, unlock,
+ "pa_threaded_mainloop_lock failed\n");
+
+ assert(buf == p->read_data && size <= p->read_length);
+
+ p->read_data += size;
+ p->read_length -= size;
+
+ if (size && !p->read_length) {
+ r = pa_stream_drop(p->stream);
+ CHECK_SUCCESS_GOTO(c, r == 0, unlock, "pa_stream_drop failed\n");
+ }
+
+unlock:
+ pa_threaded_mainloop_unlock(c->mainloop);
+}
+
static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
{
PAVoiceIn *p = (PAVoiceIn *) hw;
@@ -136,6 +189,32 @@ unlock_and_fail:
return 0;
}
+static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size)
+{
+ PAVoiceOut *p = (PAVoiceOut *) hw;
+ PAConnection *c = p->g->conn;
+ void *ret;
+ int r;
+
+ pa_threaded_mainloop_lock(c->mainloop);
+
+ CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
+ "pa_threaded_mainloop_lock failed\n");
+
+ *size = -1;
+ r = pa_stream_begin_write(p->stream, &ret, size);
+ CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail,
+ "pa_stream_begin_write failed\n");
+
+ pa_threaded_mainloop_unlock(c->mainloop);
+ return ret;
+
+unlock_and_fail:
+ pa_threaded_mainloop_unlock(c->mainloop);
+ *size = 0;
+ return NULL;
+}
+
static size_t qpa_write(HWVoiceOut *hw, void *data, size_t length)
{
PAVoiceOut *p = (PAVoiceOut *) hw;
@@ -698,11 +777,15 @@ static struct audio_pcm_ops qpa_pcm_ops = {
.init_out = qpa_init_out,
.fini_out = qpa_fini_out,
.write = qpa_write,
+ .get_buffer_out = qpa_get_buffer_out,
+ .put_buffer_out = qpa_write, /* pa handles it */
.volume_out = qpa_volume_out,
.init_in = qpa_init_in,
.fini_in = qpa_fini_in,
.read = qpa_read,
+ .get_buffer_in = qpa_get_buffer_in,
+ .put_buffer_in = qpa_put_buffer_in,
.volume_in = qpa_volume_in
};
--
2.18.1
- [Qemu-devel] [PULL 00/26] Audio 20190919 patches, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 05/26] noaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 08/26] sdlaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 03/26] coreaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 20/26] audio: basic support for multichannel audio, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 01/26] audio: api for mixeng code free backends, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 15/26] audio: add mixeng option (documentation), Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 17/26] paaudio: get/put_buffer functions,
Gerd Hoffmann <=
- [Qemu-devel] [PULL 22/26] usb-audio: do not count on avail bytes actually available, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 11/26] audio: remove remains of the old backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 18/26] audio: support more than two channels in volume setting, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 12/26] audio: unify input and output mixeng buffer management, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 02/26] alsaaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 09/26] spiceaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 16/26] audio: make mixeng optional, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 10/26] wavaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 04/26] dsoundaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19
- [Qemu-devel] [PULL 07/26] paaudio: port to the new audio backend api, Gerd Hoffmann, 2019/09/19