Rex Dieter a927022
From fa374b34894cf2c886466ca53c91edaf54f31279 Mon Sep 17 00:00:00 2001
Rex Dieter a927022
From: James Bunton <jamesbunton@delx.net.au>
Rex Dieter a927022
Date: Mon, 27 Jan 2014 01:14:38 +1100
Rex Dieter a927022
Subject: [PATCH 04/31] bluetooth: Don't abort on SBC decoding error
Rex Dieter a927022
Rex Dieter a927022
The Nokia E7 running Symbian Belle Refresh seems to generate invalid SBC
Rex Dieter a927022
packets every few minutes. This causes pulseaudio to disconnect the
Rex Dieter a927022
stream and log "SBC decoding error (-3)".
Rex Dieter a927022
Rex Dieter a927022
If a single packet is bad, pulseaudio should keep playing the stream.
Rex Dieter a927022
---
Rex Dieter a927022
 src/modules/bluetooth/module-bluez4-device.c | 12 +++++++-----
Rex Dieter a927022
 src/modules/bluetooth/module-bluez5-device.c | 12 +++++++-----
Rex Dieter a927022
 2 files changed, 14 insertions(+), 10 deletions(-)
Rex Dieter a927022
Rex Dieter a927022
diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c
Rex Dieter a927022
index 83e603f..90b1bcd 100644
Rex Dieter a927022
--- a/src/modules/bluetooth/module-bluez4-device.c
Rex Dieter a927022
+++ b/src/modules/bluetooth/module-bluez4-device.c
Rex Dieter a927022
@@ -937,7 +937,7 @@ static int a2dp_process_push(struct userdata *u) {
Rex Dieter a927022
                 pa_log_error("SBC decoding error (%li)", (long) decoded);
Rex Dieter a927022
                 pa_memblock_release(memchunk.memblock);
Rex Dieter a927022
                 pa_memblock_unref(memchunk.memblock);
Rex Dieter a927022
-                return -1;
Rex Dieter a927022
+                return 0;
Rex Dieter a927022
             }
Rex Dieter a927022
 
Rex Dieter a927022
 /*             pa_log_debug("SBC: decoded: %lu; written: %lu", (unsigned long) decoded, (unsigned long) written); */
Rex Dieter a927022
@@ -1039,10 +1039,12 @@ static void thread_func(void *userdata) {
Rex Dieter a927022
                 if (n_read < 0)
Rex Dieter a927022
                     goto io_fail;
Rex Dieter a927022
 
Rex Dieter a927022
-                /* We just read something, so we are supposed to write something, too */
Rex Dieter a927022
-                pending_read_bytes += n_read;
Rex Dieter a927022
-                do_write += pending_read_bytes / u->write_block_size;
Rex Dieter a927022
-                pending_read_bytes = pending_read_bytes % u->write_block_size;
Rex Dieter a927022
+                if (n_read > 0) {
Rex Dieter a927022
+                    /* We just read something, so we are supposed to write something, too */
Rex Dieter a927022
+                    pending_read_bytes += n_read;
Rex Dieter a927022
+                    do_write += pending_read_bytes / u->write_block_size;
Rex Dieter a927022
+                    pending_read_bytes = pending_read_bytes % u->write_block_size;
Rex Dieter a927022
+                }
Rex Dieter a927022
             }
Rex Dieter a927022
         }
Rex Dieter a927022
 
Rex Dieter a927022
diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c
Rex Dieter a927022
index 287e763..61723f8 100644
Rex Dieter a927022
--- a/src/modules/bluetooth/module-bluez5-device.c
Rex Dieter a927022
+++ b/src/modules/bluetooth/module-bluez5-device.c
Rex Dieter a927022
@@ -458,7 +458,7 @@ static int a2dp_process_push(struct userdata *u) {
Rex Dieter a927022
                 pa_log_error("SBC decoding error (%li)", (long) decoded);
Rex Dieter a927022
                 pa_memblock_release(memchunk.memblock);
Rex Dieter a927022
                 pa_memblock_unref(memchunk.memblock);
Rex Dieter a927022
-                return -1;
Rex Dieter a927022
+                return 0;
Rex Dieter a927022
             }
Rex Dieter a927022
 
Rex Dieter a927022
             /* Reset frame length, it can be changed due to bitpool change */
Rex Dieter a927022
@@ -1095,10 +1095,12 @@ static void thread_func(void *userdata) {
Rex Dieter a927022
                 if (n_read < 0)
Rex Dieter a927022
                     goto io_fail;
Rex Dieter a927022
 
Rex Dieter a927022
-                /* We just read something, so we are supposed to write something, too */
Rex Dieter a927022
-                pending_read_bytes += n_read;
Rex Dieter a927022
-                do_write += pending_read_bytes / u->write_block_size;
Rex Dieter a927022
-                pending_read_bytes = pending_read_bytes % u->write_block_size;
Rex Dieter a927022
+                if (n_read > 0) {
Rex Dieter a927022
+                    /* We just read something, so we are supposed to write something, too */
Rex Dieter a927022
+                    pending_read_bytes += n_read;
Rex Dieter a927022
+                    do_write += pending_read_bytes / u->write_block_size;
Rex Dieter a927022
+                    pending_read_bytes = pending_read_bytes % u->write_block_size;
Rex Dieter a927022
+                }
Rex Dieter a927022
             }
Rex Dieter a927022
         }
Rex Dieter a927022
 
Rex Dieter a927022
-- 
Rex Dieter a927022
1.9.3
Rex Dieter a927022