From e70020b45630d99132a99892ecc6e1dcd1ce6f8a Mon Sep 17 00:00:00 2001 From: David Henningsson Date: Thu, 18 Aug 2011 13:37:39 +0200 Subject: [PATCH] pulsesink: Allow writes in bigger chunks There's no use in splitting the incoming data down to the segsize limit - by writing as much as possible in one chunk, we increase performance and avoid PulseAudio unnecessary rewinds. Signed-off-by: David Henningsson --- ext/pulse/pulsesink.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index c9f0b58..b90ebe3 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -1430,9 +1430,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample, towrite = out_samples * bps; - /* Only ever write segsize bytes at once. This will - * also limit the PA shm buffer to segsize - */ + /* Wait for at least segsize bytes to become available */ if (towrite > buf->spec.segsize) towrite = buf->spec.segsize; @@ -1481,7 +1479,7 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample, goto uncork_failed; } - /* we can't write a single byte, wait a bit */ + /* we can't write segsize bytes, wait a bit */ GST_LOG_OBJECT (psink, "waiting for free space"); pa_threaded_mainloop_wait (mainloop); @@ -1489,14 +1487,10 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample, goto was_paused; } - /* make sure we only buffer up latency-time samples */ - if (pbuf->m_writable > buf->spec.segsize) { - /* limit buffering to latency-time value */ - pbuf->m_writable = buf->spec.segsize; - - GST_LOG_OBJECT (psink, "Limiting buffering to %" G_GSIZE_FORMAT, - pbuf->m_writable); - } + /* Recalculate what we can write in the next chunk */ + towrite = out_samples * bps; + if (pbuf->m_writable > towrite) + pbuf->m_writable = towrite; GST_LOG_OBJECT (psink, "requesting %" G_GSIZE_FORMAT " bytes of " "shared memory", pbuf->m_writable); @@ -1510,14 +1504,9 @@ gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample, GST_LOG_OBJECT (psink, "got %" G_GSIZE_FORMAT " bytes of shared memory", pbuf->m_writable); - /* Just to make sure that we didn't get more than requested */ - if (pbuf->m_writable > buf->spec.segsize) { - /* limit buffering to latency-time value */ - pbuf->m_writable = buf->spec.segsize; - } } - if (pbuf->m_writable < towrite) + if (towrite > pbuf->m_writable) towrite = pbuf->m_writable; avail = towrite / bps; -- 2.7.4