[vlc-commits] pulse: use pa_stream_begin_write()

Thomas Guillem git at videolan.org
Tue Feb 12 15:15:27 CET 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Feb 11 16:28:01 2019 +0100| [0bdc7268dc450de0e4b2944726f366cb340eca21] | committer: Thomas Guillem

pulse: use pa_stream_begin_write()

Instead of using a free callback with a hackish way to get the block pointer.
Even if pa_stream_begin_write() is used to optimize the number of memcpy, this
commit won't change the total number of memcpy. The memcpy is just moved to the
Play() function.

pa_stream_begin_write() is available since 0.9.16. I guess that's why it was
not used since the beginning.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0bdc7268dc450de0e4b2944726f366cb340eca21
---

 modules/audio_output/pulse.c | 47 ++++++++++++++------------------------------
 1 file changed, 15 insertions(+), 32 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 5075dd92ce..a76fd6c657 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -458,30 +458,6 @@ static int TimeGet(audio_output_t *aout, vlc_tick_t *restrict delay)
     return ret;
 }
 
-/* Memory free callback. The block_t address is in front of the data. */
-static void data_free(void *data)
-{
-    block_t **pp = data, *block;
-
-    memcpy(&block, pp - 1, sizeof (block));
-    block_Release(block);
-}
-
-static void *data_convert(block_t **pp)
-{
-    block_t *block = *pp;
-    /* In most cases, there is enough head room, and this is really cheap: */
-    block = block_Realloc(block, sizeof (block), block->i_buffer);
-    *pp = block;
-    if (unlikely(block == NULL))
-        return NULL;
-
-    memcpy(block->p_buffer, &block, sizeof (block));
-    block->p_buffer += sizeof (block);
-    block->i_buffer -= sizeof (block);
-    return block->p_buffer;
-}
-
 /**
  * Queue one audio frame to the playback stream
  */
@@ -490,11 +466,6 @@ static void Play(audio_output_t *aout, block_t *block, vlc_tick_t date)
     aout_sys_t *sys = aout->sys;
     pa_stream *s = sys->stream;
 
-    const void *ptr = data_convert(&block);
-    if (unlikely(ptr == NULL))
-        return;
-
-    size_t len = block->i_buffer;
 
     /* Note: The core already holds the output FIFO lock at this point.
      * Therefore we must not under any circumstances (try to) acquire the
@@ -515,12 +486,24 @@ static void Play(audio_output_t *aout, block_t *block, vlc_tick_t date)
         pa_operation_unref(pa_stream_flush(s, NULL, NULL));
     }
 #endif
+    while (block->i_buffer > 0)
+    {
+        void *ptr;
+        size_t len = block->i_buffer;
+
+        if (pa_stream_begin_write(s, &ptr, &len))
+            vlc_pa_error(aout, "cannot begin write", sys->context);
 
-    if (pa_stream_write(s, ptr, len, data_free, 0, PA_SEEK_RELATIVE) < 0) {
-        vlc_pa_error(aout, "cannot write", sys->context);
-        block_Release(block);
+        memcpy(ptr, block->p_buffer, len);
+        block->p_buffer += len;
+        block->i_buffer -= len;
+
+        if (pa_stream_write(s, ptr, len, NULL, 0, PA_SEEK_RELATIVE) < 0)
+            vlc_pa_error(aout, "cannot write", sys->context);
     }
 
+    block_Release(block);
+
     pa_threaded_mainloop_unlock(sys->mainloop);
 }
 



More information about the vlc-commits mailing list