bluetooth: Add state to transport objects

Transport objects have an associated state even though it's not
explicitly exposed in BlueZ's D-Bus API (prior to 5.0). Instead, the
state is implicitly represented in the profile-specific D-Bus interface
(i.e. org.bluez.Headset, org.bluez.AudioSink, etc.) but it can be
convenient that bluetooth-util would abstract this separation.
This commit is contained in:
Mikel Astiz 2012-12-10 08:30:38 +01:00 committed by Tanu Kaskinen
parent ab26cafaf4
commit 439745505a
2 changed files with 33 additions and 0 deletions

View file

@ -114,6 +114,21 @@ static int profile_from_interface(const char *interface, enum profile *p) {
return -1; return -1;
} }
static pa_bluetooth_transport_state_t pa_bt_audio_state_to_transport_state(pa_bt_audio_state_t state) {
switch (state) {
case PA_BT_AUDIO_STATE_INVALID: /* Typically if state hasn't been received yet */
case PA_BT_AUDIO_STATE_DISCONNECTED:
case PA_BT_AUDIO_STATE_CONNECTING:
return PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
case PA_BT_AUDIO_STATE_CONNECTED:
return PA_BLUETOOTH_TRANSPORT_STATE_IDLE;
case PA_BT_AUDIO_STATE_PLAYING:
return PA_BLUETOOTH_TRANSPORT_STATE_PLAYING;
}
pa_assert_not_reached();
}
static pa_bluetooth_uuid *uuid_new(const char *uuid) { static pa_bluetooth_uuid *uuid_new(const char *uuid) {
pa_bluetooth_uuid *u; pa_bluetooth_uuid *u;
@ -456,6 +471,7 @@ static int parse_device_property(pa_bluetooth_device *d, DBusMessageIter *i) {
} }
static int parse_audio_property(pa_bluetooth_device *d, const char *interface, DBusMessageIter *i) { static int parse_audio_property(pa_bluetooth_device *d, const char *interface, DBusMessageIter *i) {
pa_bluetooth_transport *transport;
const char *key; const char *key;
DBusMessageIter variant_i; DBusMessageIter variant_i;
bool is_audio_interface; bool is_audio_interface;
@ -473,6 +489,8 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
if (key == NULL) if (key == NULL)
return -1; return -1;
transport = p == PROFILE_OFF ? NULL : d->transports[p];
dbus_message_iter_recurse(i, &variant_i); dbus_message_iter_recurse(i, &variant_i);
/* pa_log_debug("Parsing property org.bluez.{Audio|AudioSink|AudioSource|Headset}.%s", key); */ /* pa_log_debug("Parsing property org.bluez.{Audio|AudioSink|AudioSource|Headset}.%s", key); */
@ -500,6 +518,11 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
pa_assert(p != PROFILE_OFF); pa_assert(p != PROFILE_OFF);
d->profile_state[p] = state; d->profile_state[p] = state;
if (!transport)
break;
transport->state = pa_bt_audio_state_to_transport_state(state);
} }
break; break;
@ -1095,6 +1118,8 @@ static pa_bluetooth_transport *transport_new(pa_bluetooth_device *d, const char
memcpy(t->config, config, size); memcpy(t->config, config, size);
} }
t->state = pa_bt_audio_state_to_transport_state(d->profile_state[p]);
for (i = 0; i < PA_BLUETOOTH_TRANSPORT_HOOK_MAX; i++) for (i = 0; i < PA_BLUETOOTH_TRANSPORT_HOOK_MAX; i++)
pa_hook_init(&t->hooks[i], t); pa_hook_init(&t->hooks[i], t);

View file

@ -84,6 +84,12 @@ typedef enum pa_bluetooth_transport_hook {
PA_BLUETOOTH_TRANSPORT_HOOK_MAX PA_BLUETOOTH_TRANSPORT_HOOK_MAX
} pa_bluetooth_transport_hook_t; } pa_bluetooth_transport_hook_t;
typedef enum pa_bluetooth_transport_state {
PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED,
PA_BLUETOOTH_TRANSPORT_STATE_IDLE, /* Connected but not playing */
PA_BLUETOOTH_TRANSPORT_STATE_PLAYING
} pa_bluetooth_transport_state_t;
struct pa_bluetooth_transport { struct pa_bluetooth_transport {
pa_bluetooth_device *device; pa_bluetooth_device *device;
char *owner; char *owner;
@ -92,6 +98,8 @@ struct pa_bluetooth_transport {
uint8_t codec; uint8_t codec;
uint8_t *config; uint8_t *config;
int config_size; int config_size;
pa_bluetooth_transport_state_t state;
pa_bool_t nrec; pa_bool_t nrec;
pa_hook hooks[PA_BLUETOOTH_TRANSPORT_HOOK_MAX]; pa_hook hooks[PA_BLUETOOTH_TRANSPORT_HOOK_MAX];