mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									ab26cafaf4
								
							
						
					
					
						commit
						439745505a
					
				
					 2 changed files with 33 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -114,6 +114,21 @@ static int profile_from_interface(const char *interface, enum profile *p) {
 | 
			
		|||
    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) {
 | 
			
		||||
    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) {
 | 
			
		||||
    pa_bluetooth_transport *transport;
 | 
			
		||||
    const char *key;
 | 
			
		||||
    DBusMessageIter variant_i;
 | 
			
		||||
    bool is_audio_interface;
 | 
			
		||||
| 
						 | 
				
			
			@ -473,6 +489,8 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
 | 
			
		|||
    if (key == NULL)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    transport = p == PROFILE_OFF ? NULL : d->transports[p];
 | 
			
		||||
 | 
			
		||||
    dbus_message_iter_recurse(i, &variant_i);
 | 
			
		||||
 | 
			
		||||
/*     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);
 | 
			
		||||
 | 
			
		||||
                d->profile_state[p] = state;
 | 
			
		||||
 | 
			
		||||
                if (!transport)
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                transport->state = pa_bt_audio_state_to_transport_state(state);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
| 
						 | 
				
			
			@ -1095,6 +1118,8 @@ static pa_bluetooth_transport *transport_new(pa_bluetooth_device *d, const char
 | 
			
		|||
        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++)
 | 
			
		||||
        pa_hook_init(&t->hooks[i], t);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,6 +84,12 @@ typedef enum pa_bluetooth_transport_hook {
 | 
			
		|||
    PA_BLUETOOTH_TRANSPORT_HOOK_MAX
 | 
			
		||||
} 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 {
 | 
			
		||||
    pa_bluetooth_device *device;
 | 
			
		||||
    char *owner;
 | 
			
		||||
| 
						 | 
				
			
			@ -92,6 +98,8 @@ struct pa_bluetooth_transport {
 | 
			
		|||
    uint8_t codec;
 | 
			
		||||
    uint8_t *config;
 | 
			
		||||
    int config_size;
 | 
			
		||||
 | 
			
		||||
    pa_bluetooth_transport_state_t state;
 | 
			
		||||
    pa_bool_t nrec;
 | 
			
		||||
 | 
			
		||||
    pa_hook hooks[PA_BLUETOOTH_TRANSPORT_HOOK_MAX];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue