bluetooth: mSBC: ignore empty encoded frame
authorIgor V. Kovalenko <igor.v.kovalenko@gmail.com>
Wed, 3 Mar 2021 20:13:52 +0000 (23:13 +0300)
committerPulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org>
Mon, 5 Apr 2021 15:43:32 +0000 (15:43 +0000)
If input block size is shorter than SBC frame codesize, encoder will return 0.
Log this and skip whole input block.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>

src/modules/bluetooth/bt-codec-msbc.c

index 107e067..c49a0f9 100644 (file)
@@ -170,8 +170,16 @@ static size_t encode_buffer(void *codec_info, uint32_t timestamp, const uint8_t
     frame->padding = 0x00;
 
     if (PA_UNLIKELY(encoded <= 0)) {
-        pa_log_error("SBC encoding error (%li)", (long) encoded);
-        return -1;
+        pa_log_error("SBC encoding error (%li) for input size %lu, SBC codesize %lu",
+                    (long) encoded, input_size, sbc_get_codesize(&sbc_info->sbc));
+
+        if (encoded < 0) {
+            *processed = 0;
+            return -1;
+        } else {
+            *processed = input_size;
+            return 0;
+        }
     }
 
     pa_assert_fp((size_t) encoded == sbc_info->codesize);