bluez5: Workaround incorrect SCO MTU

It seems that some BT adapters don't return correct SCO MTU, see
https://marc.info/?t=148586768600002&r=1&w=2
Do not try to autodetect the MTU and use a fix MTU size of 48 bytes.
This commit is contained in:
Frédéric Danis 2020-07-17 18:05:31 +02:00
parent 06a6e11806
commit 2d91e62a19
3 changed files with 11 additions and 32 deletions

View file

@ -235,7 +235,7 @@ static int sco_acquire_cb(void *data, bool optional)
t->read_mtu = 48;
t->write_mtu = 48;
if (true) {
if (false) {
struct sco_options sco_opt;
len = sizeof(sco_opt);

View file

@ -128,9 +128,6 @@ struct impl {
/* Times */
uint64_t start_time;
uint64_t total_samples;
/* MTU */
uint32_t write_mtu;
};
#define NAME "sco-sink"
@ -318,9 +315,9 @@ static void flush_data(struct impl *this)
/* if buffer has data, copy it into the write buffer */
if (datas[0].chunk->size - port->ready_offset > 0) {
uint32_t avail = SPA_MIN(this->write_mtu, datas[0].chunk->size - port->ready_offset);
uint32_t size = (avail + port->write_buffer_size) > this->write_mtu ?
this->write_mtu - port->write_buffer_size : avail;
uint32_t avail = SPA_MIN(this->transport->write_mtu, datas[0].chunk->size - port->ready_offset);
uint32_t size = (avail + port->write_buffer_size) > this->transport->write_mtu ?
this->transport->write_mtu - port->write_buffer_size : avail;
memcpy(port->write_buffer + port->write_buffer_size,
(uint8_t *)datas[0].data + port->ready_offset,
size);
@ -339,7 +336,7 @@ static void flush_data(struct impl *this)
}
/* send the data if the write buffer is full */
if (port->write_buffer_size >= this->write_mtu) {
if (port->write_buffer_size >= this->transport->write_mtu) {
uint64_t now_time;
int written;
@ -348,7 +345,7 @@ static void flush_data(struct impl *this)
if (this->start_time == 0)
this->start_time = now_time;
written = write(this->sock_fd, port->write_buffer, this->write_mtu);
written = write(this->sock_fd, port->write_buffer, this->transport->write_mtu);
if (written <= 0) {
spa_log_debug(this->log, "failed to write data");
goto stop;
@ -388,7 +385,7 @@ static void sco_on_timeout(struct spa_source *source)
/* delay if no buffers available */
if (spa_list_is_empty(&port->ready)) {
set_timeout(this, this->write_mtu / port->frame_size * SPA_NSEC_PER_SEC / port->current_format.info.raw.rate);
set_timeout(this, this->transport->write_mtu / port->frame_size * SPA_NSEC_PER_SEC / port->current_format.info.raw.rate);
port->io->status = SPA_STATUS_NEED_DATA;
spa_node_call_ready(&this->callbacks, SPA_STATUS_NEED_DATA);
return;
@ -417,6 +414,8 @@ static int do_start(struct impl *this)
if (this->sock_fd < 0)
return -1;
spa_return_val_if_fail(this->transport->write_mtu <= sizeof(this->port.write_buffer), -EINVAL);
/* Add the timeout callback */
this->source.data = this;
this->source.fd = this->timerfd;
@ -1049,16 +1048,6 @@ impl_init(const struct spa_handle_factory *factory,
&this->transport_listener, &transport_events, this);
this->sock_fd = -1;
/* TODO: For now, we always use an MTU size of 48 bytes like bluezalsa
* because the MTU size returned by the kernel is incorrect (or our
* interpretation of it) */
#if 0
this->write_mtu = this->transport->write_mtu;
#else
this->write_mtu = 48;
#endif
spa_return_val_if_fail(this->write_mtu <= sizeof(port->write_buffer), -EINVAL);
this->timerfd = spa_system_timerfd_create(this->data_system,
CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);

View file

@ -117,7 +117,6 @@ struct impl {
struct timespec now;
uint32_t sample_count;
uint32_t read_mtu;
};
#define NAME "sco-source"
@ -337,7 +336,7 @@ static void sco_on_ready_read(struct spa_source *source)
datas = port->current_buffer->buf->datas;
/* read */
size_read = read_data(this, (uint8_t *)datas[0].data + port->ready_offset, this->read_mtu);
size_read = read_data(this, (uint8_t *)datas[0].data + port->ready_offset, this->transport->read_mtu);
if (size_read < 0) {
spa_log_error(this->log, "failed to read data");
goto stop;
@ -346,7 +345,7 @@ static void sco_on_ready_read(struct spa_source *source)
/* send buffer if full */
port->ready_offset += size_read;
if ((this->read_mtu + port->ready_offset) > (this->props.max_latency * port->frame_size)) {
if ((this->transport->read_mtu + port->ready_offset) > (this->props.max_latency * port->frame_size)) {
datas[0].chunk->offset = 0;
datas[0].chunk->size = port->ready_offset;
datas[0].chunk->stride = port->frame_size;
@ -1065,15 +1064,6 @@ impl_init(const struct spa_handle_factory *factory,
&this->transport_listener, &transport_events, this);
this->sock_fd = -1;
/* TODO: For now, we always use an MTU size of 48 bytes like bluezalsa
* because the MTU size returned by the kernel is incorrect (or our
* interpretation of it) */
#if 0
this->read_mtu = this->transport->read_mtu;
#else
this->read_mtu = 48;
#endif
return 0;
}