bluetooth: mSBC: ignore all-zero packets

This is a workaround for hardware/driver which inserts all-zero packets in what
otherwise looks like a valid mSBC stream.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
This commit is contained in:
Igor V. Kovalenko 2021-03-02 15:00:04 +03:00 committed by PulseAudio Marge Bot
parent 6c0c9cf845
commit 7d191b64d9

View file

@ -182,6 +182,16 @@ static size_t encode_buffer(void *codec_info, uint32_t timestamp, const uint8_t
return MSBC_PACKET_SIZE; return MSBC_PACKET_SIZE;
} }
static inline bool is_all_zero(const uint8_t *ptr, size_t len) {
size_t i;
for (i = 0; i < len; ++i)
if (ptr[i] != 0)
return false;
return true;
}
/* /*
* We build a msbc frame up in the sbc_info buffer until we have a whole one * We build a msbc frame up in the sbc_info buffer until we have a whole one
*/ */
@ -191,6 +201,12 @@ static struct msbc_frame *msbc_find_frame(struct sbc_info *si, ssize_t *len,
int i; int i;
uint8_t *p = si->input_buffer; uint8_t *p = si->input_buffer;
/* skip input if it has all zero bytes
* this could happen with older kernels inserting all-zero blocks
* inside otherwise valid mSBC stream */
if (*len > 0 && is_all_zero(buf, *len))
*len = 0;
for (i = 0; i < *len; i++) { for (i = 0; i < *len; i++) {
union msbc_h2_id1 id1; union msbc_h2_id1 id1;