[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/13] paaudio: get/put_buffer functions
From: |
Gerd Hoffmann |
Subject: |
[PULL 06/13] paaudio: get/put_buffer functions |
Date: |
Fri, 18 Oct 2019 09:41:37 +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 2cba492d8265..77cd0bc0d026 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
};
--
2.18.1
- [PULL 03/13] audio: paaudio: ability to specify stream name, (continued)
- [PULL 03/13] audio: paaudio: ability to specify stream name, Gerd Hoffmann, 2019/10/18
- [PULL 13/13] paaudio: fix channel order for usb-audio 5.1 and 7.1 streams, Gerd Hoffmann, 2019/10/18
- [PULL 07/13] audio: support more than two channels in volume setting, Gerd Hoffmann, 2019/10/18
- [PULL 12/13] usbaudio: change playback counters to 64 bit, Gerd Hoffmann, 2019/10/18
- [PULL 09/13] audio: basic support for multichannel audio, Gerd Hoffmann, 2019/10/18
- [PULL 08/13] audio: replace shift in audio_pcm_info with bytes_per_frame, Gerd Hoffmann, 2019/10/18
- [PULL 10/13] usb-audio: do not count on avail bytes actually available, Gerd Hoffmann, 2019/10/18
- [PULL 04/13] audio: add mixing-engine option (documentation), Gerd Hoffmann, 2019/10/18
- [PULL 05/13] audio: make mixeng optional, Gerd Hoffmann, 2019/10/18
- [PULL 11/13] usb-audio: support more than two channels of audio, Gerd Hoffmann, 2019/10/18
- [PULL 06/13] paaudio: get/put_buffer functions,
Gerd Hoffmann <=
- [PULL 02/13] audio: paaudio: fix connection and stream name, Gerd Hoffmann, 2019/10/18
- Re: [PULL 00/13] Audio 20191018 patches, Peter Maydell, 2019/10/18