2013-08-13 01:54:00 -03:00
|
|
|
#ifndef foobluez5utilhfoo
|
|
|
|
|
#define foobluez5utilhfoo
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2008-2013 João Paulo Rechi Vita
|
2019-04-06 11:15:58 +02:00
|
|
|
Copyrigth 2018-2019 Pali Rohár <pali.rohar@gmail.com>
|
2013-08-13 01:54:00 -03:00
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2014-11-26 14:14:51 +01:00
|
|
|
License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2013-08-13 01:54:00 -03:00
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#include <pulsecore/core.h>
|
|
|
|
|
|
2019-04-06 11:15:58 +02:00
|
|
|
#include "a2dp-codec-util.h"
|
|
|
|
|
|
2021-01-08 00:45:24 +01:00
|
|
|
#define BLUEZ_SERVICE "org.bluez"
|
|
|
|
|
#define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter1"
|
2021-01-18 11:04:43 +01:00
|
|
|
#define BLUEZ_BATTERY_PROVIDER_INTERFACE BLUEZ_SERVICE ".BatteryProvider1"
|
|
|
|
|
#define BLUEZ_BATTERY_PROVIDER_MANAGER_INTERFACE BLUEZ_SERVICE ".BatteryProviderManager1"
|
2021-01-08 00:45:24 +01:00
|
|
|
#define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device1"
|
|
|
|
|
#define BLUEZ_MEDIA_ENDPOINT_INTERFACE BLUEZ_SERVICE ".MediaEndpoint1"
|
|
|
|
|
#define BLUEZ_MEDIA_INTERFACE BLUEZ_SERVICE ".Media1"
|
|
|
|
|
#define BLUEZ_MEDIA_TRANSPORT_INTERFACE BLUEZ_SERVICE ".MediaTransport1"
|
|
|
|
|
#define BLUEZ_PROFILE_INTERFACE BLUEZ_SERVICE ".Profile1"
|
|
|
|
|
#define BLUEZ_PROFILE_MANAGER_INTERFACE BLUEZ_SERVICE ".ProfileManager1"
|
|
|
|
|
|
2021-01-19 20:27:35 +01:00
|
|
|
#define BLUEZ_ERROR_INVALID_ARGUMENTS BLUEZ_SERVICE ".Error.InvalidArguments"
|
|
|
|
|
#define BLUEZ_ERROR_NOT_AVAILABLE BLUEZ_SERVICE ".Error.NotAvailable"
|
2021-01-08 00:45:24 +01:00
|
|
|
#define BLUEZ_ERROR_NOT_SUPPORTED BLUEZ_SERVICE ".Error.NotSupported"
|
|
|
|
|
|
2013-09-24 19:45:24 -03:00
|
|
|
#define PA_BLUETOOTH_UUID_A2DP_SOURCE "0000110a-0000-1000-8000-00805f9b34fb"
|
|
|
|
|
#define PA_BLUETOOTH_UUID_A2DP_SINK "0000110b-0000-1000-8000-00805f9b34fb"
|
2017-09-02 15:44:58 +03:00
|
|
|
|
|
|
|
|
/* There are two HSP HS UUIDs. The first one (older?) is used both as the HSP
|
|
|
|
|
* profile identifier and as the HS role identifier, while the second one is
|
|
|
|
|
* only used to identify the role. As far as PulseAudio is concerned, the two
|
|
|
|
|
* UUIDs mean exactly the same thing. */
|
2014-08-22 11:07:11 +03:00
|
|
|
#define PA_BLUETOOTH_UUID_HSP_HS "00001108-0000-1000-8000-00805f9b34fb"
|
2017-09-02 15:44:58 +03:00
|
|
|
#define PA_BLUETOOTH_UUID_HSP_HS_ALT "00001131-0000-1000-8000-00805f9b34fb"
|
|
|
|
|
|
2014-08-22 11:07:11 +03:00
|
|
|
#define PA_BLUETOOTH_UUID_HSP_AG "00001112-0000-1000-8000-00805f9b34fb"
|
|
|
|
|
#define PA_BLUETOOTH_UUID_HFP_HF "0000111e-0000-1000-8000-00805f9b34fb"
|
|
|
|
|
#define PA_BLUETOOTH_UUID_HFP_AG "0000111f-0000-1000-8000-00805f9b34fb"
|
2013-09-24 19:45:24 -03:00
|
|
|
|
2021-03-27 10:53:07 +01:00
|
|
|
#define A2DP_MAX_GAIN 127
|
2021-03-27 11:42:37 +01:00
|
|
|
#define HSP_MAX_GAIN 15
|
|
|
|
|
|
2013-09-24 19:45:22 -03:00
|
|
|
typedef struct pa_bluetooth_transport pa_bluetooth_transport;
|
2013-09-18 16:16:58 -05:00
|
|
|
typedef struct pa_bluetooth_device pa_bluetooth_device;
|
2013-09-18 16:16:57 -05:00
|
|
|
typedef struct pa_bluetooth_adapter pa_bluetooth_adapter;
|
2013-08-13 01:54:00 -03:00
|
|
|
typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
|
2014-08-22 11:07:14 +03:00
|
|
|
typedef struct pa_bluetooth_backend pa_bluetooth_backend;
|
2013-08-13 01:54:00 -03:00
|
|
|
|
2013-09-18 16:16:56 -05:00
|
|
|
typedef enum pa_bluetooth_hook {
|
2020-06-07 17:07:20 +02:00
|
|
|
PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
|
|
|
|
|
PA_BLUETOOTH_HOOK_DEVICE_UNLINK, /* Call data: pa_bluetooth_device */
|
2021-01-18 14:26:47 +01:00
|
|
|
PA_BLUETOOTH_HOOK_DEVICE_BATTERY_LEVEL_CHANGED, /* Call data: pa_bluetooth_device */
|
2020-06-07 17:07:20 +02:00
|
|
|
PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
|
|
|
|
|
PA_BLUETOOTH_HOOK_TRANSPORT_SOURCE_VOLUME_CHANGED, /* Call data: pa_bluetooth_transport */
|
|
|
|
|
PA_BLUETOOTH_HOOK_TRANSPORT_SINK_VOLUME_CHANGED, /* Call data: pa_bluetooth_transport */
|
2013-09-18 16:16:56 -05:00
|
|
|
PA_BLUETOOTH_HOOK_MAX
|
|
|
|
|
} pa_bluetooth_hook_t;
|
|
|
|
|
|
2013-09-24 19:45:22 -03:00
|
|
|
typedef enum profile {
|
|
|
|
|
PA_BLUETOOTH_PROFILE_A2DP_SINK,
|
|
|
|
|
PA_BLUETOOTH_PROFILE_A2DP_SOURCE,
|
2016-08-20 10:39:30 -07:00
|
|
|
PA_BLUETOOTH_PROFILE_HSP_HS,
|
2021-01-29 21:32:09 +03:00
|
|
|
PA_BLUETOOTH_PROFILE_HSP_AG,
|
2016-08-18 08:48:48 -07:00
|
|
|
PA_BLUETOOTH_PROFILE_HFP_HF,
|
2016-08-20 10:39:30 -07:00
|
|
|
PA_BLUETOOTH_PROFILE_HFP_AG,
|
2013-09-24 19:45:22 -03:00
|
|
|
PA_BLUETOOTH_PROFILE_OFF
|
|
|
|
|
} pa_bluetooth_profile_t;
|
|
|
|
|
#define PA_BLUETOOTH_PROFILE_COUNT PA_BLUETOOTH_PROFILE_OFF
|
|
|
|
|
|
|
|
|
|
typedef enum pa_bluetooth_transport_state {
|
|
|
|
|
PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED,
|
|
|
|
|
PA_BLUETOOTH_TRANSPORT_STATE_IDLE,
|
|
|
|
|
PA_BLUETOOTH_TRANSPORT_STATE_PLAYING
|
|
|
|
|
} pa_bluetooth_transport_state_t;
|
|
|
|
|
|
|
|
|
|
typedef int (*pa_bluetooth_transport_acquire_cb)(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu);
|
|
|
|
|
typedef void (*pa_bluetooth_transport_release_cb)(pa_bluetooth_transport *t);
|
2014-10-24 09:56:50 +02:00
|
|
|
typedef void (*pa_bluetooth_transport_destroy_cb)(pa_bluetooth_transport *t);
|
2020-06-07 17:07:20 +02:00
|
|
|
typedef pa_volume_t (*pa_bluetooth_transport_set_volume_cb)(pa_bluetooth_transport *t, pa_volume_t volume);
|
2021-03-03 08:12:08 +03:00
|
|
|
typedef ssize_t (*pa_bluetooth_transport_write_cb)(pa_bluetooth_transport *t, int fd, const void* buffer, size_t size, size_t write_mtu);
|
2021-02-17 09:44:35 +03:00
|
|
|
typedef int (*pa_bluetooth_transport_setsockopt_cb)(pa_bluetooth_transport *t, int fd);
|
2013-09-24 19:45:22 -03:00
|
|
|
|
|
|
|
|
struct pa_bluetooth_transport {
|
|
|
|
|
pa_bluetooth_device *device;
|
|
|
|
|
|
|
|
|
|
char *owner;
|
|
|
|
|
char *path;
|
|
|
|
|
pa_bluetooth_profile_t profile;
|
|
|
|
|
|
2016-08-20 10:56:14 -07:00
|
|
|
void *config;
|
2013-09-24 19:45:22 -03:00
|
|
|
size_t config_size;
|
|
|
|
|
|
2021-03-02 21:33:24 +03:00
|
|
|
const pa_bt_codec *bt_codec;
|
2021-03-03 08:12:08 +03:00
|
|
|
int stream_write_type;
|
2021-02-17 16:31:13 +03:00
|
|
|
size_t last_read_size;
|
2019-04-06 11:15:58 +02:00
|
|
|
|
2020-06-07 17:07:20 +02:00
|
|
|
pa_volume_t source_volume;
|
|
|
|
|
pa_volume_t sink_volume;
|
2014-10-24 09:56:52 +02:00
|
|
|
|
2013-09-24 19:45:22 -03:00
|
|
|
pa_bluetooth_transport_state_t state;
|
|
|
|
|
|
|
|
|
|
pa_bluetooth_transport_acquire_cb acquire;
|
|
|
|
|
pa_bluetooth_transport_release_cb release;
|
2021-03-03 08:12:08 +03:00
|
|
|
pa_bluetooth_transport_write_cb write;
|
2021-02-17 09:44:35 +03:00
|
|
|
pa_bluetooth_transport_setsockopt_cb setsockopt;
|
2014-10-24 09:56:50 +02:00
|
|
|
pa_bluetooth_transport_destroy_cb destroy;
|
2020-06-07 17:07:20 +02:00
|
|
|
pa_bluetooth_transport_set_volume_cb set_sink_volume;
|
|
|
|
|
pa_bluetooth_transport_set_volume_cb set_source_volume;
|
2013-09-24 19:45:22 -03:00
|
|
|
void *userdata;
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-18 16:16:58 -05:00
|
|
|
struct pa_bluetooth_device {
|
|
|
|
|
pa_bluetooth_discovery *discovery;
|
|
|
|
|
pa_bluetooth_adapter *adapter;
|
|
|
|
|
|
2021-02-01 20:51:18 +03:00
|
|
|
bool enable_hfp_hf;
|
2014-05-24 12:56:35 +03:00
|
|
|
bool properties_received;
|
|
|
|
|
bool tried_to_link_with_adapter;
|
|
|
|
|
bool valid;
|
2017-02-04 20:32:15 +01:00
|
|
|
bool autodetect_mtu;
|
2020-12-18 17:05:44 +05:30
|
|
|
bool codec_switching_in_progress;
|
2021-04-22 21:59:37 +02:00
|
|
|
bool avrcp_absolute_volume;
|
2021-01-20 12:51:14 +03:00
|
|
|
uint32_t output_rate_refresh_interval_ms;
|
2013-09-18 16:16:58 -05:00
|
|
|
|
|
|
|
|
/* Device information */
|
|
|
|
|
char *path;
|
2013-09-24 19:45:36 -03:00
|
|
|
char *adapter_path;
|
2013-09-18 16:16:58 -05:00
|
|
|
char *alias;
|
|
|
|
|
char *address;
|
|
|
|
|
uint32_t class_of_device;
|
2016-08-07 18:45:52 +03:00
|
|
|
pa_hashmap *uuids; /* char* -> char* (hashmap-as-a-set) */
|
2020-12-18 17:05:44 +05:30
|
|
|
/* pa_a2dp_codec_id* -> pa_hashmap ( char* (remote endpoint) -> struct a2dp_codec_capabilities* ) */
|
|
|
|
|
pa_hashmap *a2dp_sink_endpoints;
|
|
|
|
|
pa_hashmap *a2dp_source_endpoints;
|
2013-09-24 19:45:22 -03:00
|
|
|
|
|
|
|
|
pa_bluetooth_transport *transports[PA_BLUETOOTH_PROFILE_COUNT];
|
2016-08-07 18:45:48 +03:00
|
|
|
|
|
|
|
|
pa_time_event *wait_for_profiles_timer;
|
2021-01-18 14:26:47 +01:00
|
|
|
|
|
|
|
|
bool has_battery_level;
|
|
|
|
|
uint8_t battery_level;
|
2021-01-18 11:04:43 +01:00
|
|
|
const char *battery_source;
|
2013-09-18 16:16:58 -05:00
|
|
|
};
|
|
|
|
|
|
2013-09-18 16:16:57 -05:00
|
|
|
struct pa_bluetooth_adapter {
|
|
|
|
|
pa_bluetooth_discovery *discovery;
|
|
|
|
|
char *path;
|
|
|
|
|
char *address;
|
2014-05-24 12:56:34 +03:00
|
|
|
|
|
|
|
|
bool valid;
|
2020-12-15 16:51:11 +05:30
|
|
|
bool application_registered;
|
2021-01-18 11:04:43 +01:00
|
|
|
bool battery_provider_registered;
|
2013-09-18 16:16:57 -05:00
|
|
|
};
|
|
|
|
|
|
2014-11-03 11:01:00 +01:00
|
|
|
#ifdef HAVE_BLUEZ_5_OFONO_HEADSET
|
|
|
|
|
pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y);
|
|
|
|
|
void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b);
|
|
|
|
|
#else
|
|
|
|
|
static inline pa_bluetooth_backend *pa_bluetooth_ofono_backend_new(pa_core *c, pa_bluetooth_discovery *y) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
static inline void pa_bluetooth_ofono_backend_free(pa_bluetooth_backend *b) {}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_BLUEZ_5_NATIVE_HEADSET
|
2021-02-16 08:46:19 +03:00
|
|
|
pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_shared_profiles);
|
2014-11-03 11:01:00 +01:00
|
|
|
void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b);
|
2021-02-16 08:46:19 +03:00
|
|
|
void pa_bluetooth_native_backend_enable_shared_profiles(pa_bluetooth_backend *b, bool enable);
|
2014-11-03 11:01:00 +01:00
|
|
|
#else
|
2021-02-16 08:46:19 +03:00
|
|
|
static inline pa_bluetooth_backend *pa_bluetooth_native_backend_new(pa_core *c, pa_bluetooth_discovery *y, bool enable_shared_profiles) {
|
2014-11-03 11:01:00 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
static inline void pa_bluetooth_native_backend_free(pa_bluetooth_backend *b) {}
|
2021-02-16 08:46:19 +03:00
|
|
|
static inline void pa_bluetooth_native_backend_enable_shared_profiles(pa_bluetooth_backend *b, bool enable) {}
|
2014-11-03 11:01:00 +01:00
|
|
|
#endif
|
2014-08-22 11:07:14 +03:00
|
|
|
|
2013-09-24 19:45:22 -03:00
|
|
|
pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const char *owner, const char *path,
|
|
|
|
|
pa_bluetooth_profile_t p, const uint8_t *config, size_t size);
|
|
|
|
|
|
2021-03-02 21:33:24 +03:00
|
|
|
void pa_bluetooth_transport_reconfigure(pa_bluetooth_transport *t, const pa_bt_codec *bt_codec,
|
2021-02-20 20:18:13 +03:00
|
|
|
pa_bluetooth_transport_write_cb write_cb, pa_bluetooth_transport_setsockopt_cb setsockopt_cb);
|
|
|
|
|
|
2014-09-08 12:14:42 +03:00
|
|
|
void pa_bluetooth_transport_set_state(pa_bluetooth_transport *t, pa_bluetooth_transport_state_t state);
|
2013-09-24 19:45:22 -03:00
|
|
|
void pa_bluetooth_transport_put(pa_bluetooth_transport *t);
|
2014-09-08 12:14:43 +03:00
|
|
|
void pa_bluetooth_transport_unlink(pa_bluetooth_transport *t);
|
2013-09-24 19:45:22 -03:00
|
|
|
void pa_bluetooth_transport_free(pa_bluetooth_transport *t);
|
2021-03-27 14:05:00 +01:00
|
|
|
void pa_bluetooth_transport_load_a2dp_sink_volume(pa_bluetooth_transport *t);
|
2013-09-24 19:45:22 -03:00
|
|
|
|
|
|
|
|
bool pa_bluetooth_device_any_transport_connected(const pa_bluetooth_device *d);
|
2021-03-02 21:33:24 +03:00
|
|
|
bool pa_bluetooth_device_switch_codec(pa_bluetooth_device *device, pa_bluetooth_profile_t profile, pa_hashmap *capabilities_hashmap, const pa_a2dp_endpoint_conf *endpoint_conf, void (*codec_switch_cb)(bool, pa_bluetooth_profile_t profile, void *), void *userdata);
|
2021-01-18 11:04:43 +01:00
|
|
|
void pa_bluetooth_device_report_battery_level(pa_bluetooth_device *d, uint8_t level, const char *reporting_source);
|
2013-09-24 19:45:22 -03:00
|
|
|
|
2013-09-18 16:16:58 -05:00
|
|
|
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_path(pa_bluetooth_discovery *y, const char *path);
|
|
|
|
|
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local);
|
|
|
|
|
|
2013-09-18 16:16:56 -05:00
|
|
|
pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
|
|
|
|
|
|
2013-09-24 19:45:24 -03:00
|
|
|
const char *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile);
|
2021-03-04 11:30:42 +01:00
|
|
|
bool pa_bluetooth_profile_should_attenuate_volume(pa_bluetooth_profile_t profile);
|
2021-04-22 21:59:37 +02:00
|
|
|
bool pa_bluetooth_profile_is_a2dp(pa_bluetooth_profile_t profile);
|
2013-09-24 19:45:24 -03:00
|
|
|
|
2017-09-02 15:44:58 +03:00
|
|
|
static inline bool pa_bluetooth_uuid_is_hsp_hs(const char *uuid) {
|
|
|
|
|
return pa_streq(uuid, PA_BLUETOOTH_UUID_HSP_HS) || pa_streq(uuid, PA_BLUETOOTH_UUID_HSP_HS_ALT);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 16:13:13 +01:00
|
|
|
#define HEADSET_BACKEND_OFONO 0
|
|
|
|
|
#define HEADSET_BACKEND_NATIVE 1
|
|
|
|
|
#define HEADSET_BACKEND_AUTO 2
|
|
|
|
|
|
2021-04-15 20:19:27 +03:00
|
|
|
pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend, bool enable_native_hsp_hs, bool enable_native_hfp_hf, bool enable_msbc);
|
2013-08-13 01:54:00 -03:00
|
|
|
pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y);
|
|
|
|
|
void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y);
|
2014-11-03 12:13:20 +01:00
|
|
|
void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running);
|
2021-04-15 20:19:27 +03:00
|
|
|
bool pa_bluetooth_discovery_get_enable_native_hsp_hs(pa_bluetooth_discovery *y);
|
2016-08-18 08:48:48 -07:00
|
|
|
bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y);
|
2021-03-03 19:32:43 +03:00
|
|
|
bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y);
|
2013-08-13 01:54:00 -03:00
|
|
|
#endif
|