aboutsummaryrefslogtreecommitdiff
path: root/audio/paaudio.c
diff options
context:
space:
mode:
authorKővágó, Zoltán <dirty.ice.hu@gmail.com>2019-10-13 21:58:00 +0200
committerGerd Hoffmann <kraxel@redhat.com>2019-10-18 08:14:05 +0200
commit337e8de6fbaa61b7dd14e6c29836673132891642 (patch)
treeeb21b7fba7c3b533bc5725a9f4698306142eecde /audio/paaudio.c
parent1930616b98c3669de2df0b271a98a308d6f85083 (diff)
paaudio: get/put_buffer functions
This lets us avoid some buffer copying when using mixeng. Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Message-id: d03d30138b9b5a9681cc90cbfbfec0a197cac88c.1570996490.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'audio/paaudio.c')
-rw-r--r--audio/paaudio.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 2cba492d82..77cd0bc0d0 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -99,6 +99,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;
@@ -137,6 +190,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;
@@ -701,11 +780,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
};