Skip to content

Commit

Permalink
Improve SCO socket read error handling
Browse files Browse the repository at this point in the history
A combination of buggy adapter firmware and bugs in the BlueZ drivers,
especially with older kernels, means that SCO sockets can return
unexpected errors. This commit makes our SCO decoders more robust in
such cases.
  • Loading branch information
borine authored and arkq committed Mar 30, 2023
1 parent 9cb3d75 commit 6837b54
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,29 @@ static void *sco_cvsd_dec_thread(struct ba_transport_thread *th) {

if ((size_t)len == buffer.nmemb * buffer.size) {
debug("Resizing CVSD read buffer: %zd -> %zd",
buffer.nmemb * buffer.size, buffer.nmemb * buffer.size * 2);
buffer.nmemb * buffer.size, buffer.nmemb * 2 * buffer.size);
if (ffb_init_int16_t(&buffer, buffer.nmemb * 2) == -1)
error("Couldn't resize CVSD read buffer: %s", strerror(errno));
}

if (!ba_transport_pcm_is_active(t_pcm))
continue;

ssize_t samples = len / sizeof(int16_t);
if (len > 0)
ffb_seek(&buffer, len / buffer.size);

ssize_t samples;
if ((samples = ffb_len_out(&buffer)) <= 0)
continue;

io_pcm_scale(t_pcm, buffer.data, samples);
if ((samples = io_pcm_write(t_pcm, buffer.data, samples)) == -1)
error("FIFO write error: %s", strerror(errno));
else if (samples == 0)
ba_transport_stop_if_no_clients(t);

ffb_shift(&buffer, samples);

}

exit:
Expand Down Expand Up @@ -457,7 +465,8 @@ static void *sco_msbc_dec_thread(struct ba_transport_thread *th) {
if (!ba_transport_pcm_is_active(t_pcm))
continue;

ffb_seek(&msbc.data, len);
if (len > 0)
ffb_seek(&msbc.data, len);

int err;
if ((err = msbc_decode(&msbc)) < 0) {
Expand Down

0 comments on commit 6837b54

Please sign in to comment.