bluez5: refcount transport acquire and release, let it manage fd

Backends don't necessarily allow for opening the same device multiple
times, and it shouldn't be necessary.

Since source and sink are not necessarily both running at the same time,
refcount the transport acquire/release so that it knows to close the fd
only when no source/sink is running.

Let the transport manage the fd lifecycle, also closing it once it is
not needed.

Don't return the fd from acquire(), since each transport is associated
with a single socket fd.
This commit is contained in:
Pauli Virtanen 2020-12-22 20:36:04 +02:00 committed by Wim Taymans
parent 8942f6b402
commit 036c10717d
7 changed files with 85 additions and 51 deletions

View file

@ -232,7 +232,7 @@ static int ofono_audio_acquire(void *data, bool optional)
transport->path, transport->fd, transport->codec);
ofono_transport_get_mtu(backend, transport);
ret = transport->fd;
ret = 0;
finish:
return ret;
@ -243,11 +243,6 @@ static int ofono_audio_release(void *data)
struct spa_bt_transport *transport = data;
struct spa_bt_backend *backend = transport->backend;
if (transport->fd < 0) {
spa_log_info(backend->log, NAME": transport %s already released", transport->path);
return 0;
}
spa_log_debug(backend->log, NAME": transport %p: Release %s",
transport, transport->path);