Blob Blame History Raw
From 2ead0a39408cb335749dedca9b18b330a0af8d26 Mon Sep 17 00:00:00 2001
From: Wim Taymans <wtaymans@redhat.com>
Date: Mon, 24 Feb 2014 09:45:52 +0100
Subject: [PATCH] bluetooth: skip audio in smaller chunks

Render audio in smaller chunks, the amount of data to mix is not bounded
and we might end up hitting the maximum memory limit (96M).

Fixes rhbz#989552
---
 src/modules/bluetooth/module-bluetooth-device.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 6c0c746..d06f669 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1116,15 +1116,19 @@ static void thread_func(void *userdata) {
                             skip_bytes = pa_usec_to_bytes(skip_usec, &u->sample_spec);
 
                             if (skip_bytes > 0) {
-                                pa_memchunk tmp;
-
                                 pa_log_warn("Skipping %llu us (= %llu bytes) in audio stream",
                                             (unsigned long long) skip_usec,
                                             (unsigned long long) skip_bytes);
+                                do {
+                                  pa_memchunk tmp;
+                                  uint64_t to_skip = MIN (skip_bytes, 65535);
+
+                                  pa_sink_render_full(u->sink, to_skip, &tmp);
+                                  pa_memblock_unref(tmp.memblock);
 
-                                pa_sink_render_full(u->sink, skip_bytes, &tmp);
-                                pa_memblock_unref(tmp.memblock);
-                                u->write_index += skip_bytes;
+                                  u->write_index += to_skip;
+                                  skip_bytes -= to_skip;
+                                } while (skip_bytes > 0);
 
                                 if (u->profile == PROFILE_A2DP)
                                     a2dp_reduce_bitpool(u);
-- 
1.8.5.3