mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
backend-native: Add backend pointer to transport_data
This removes the inverse/recursive dependency of backend-native on the `pa_bluetooth_discovery` struct, which is supposed to be opaque outside of `bluez5-util` in favour of the many accessor functions defined in `bluez5-util.h`. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/740>
This commit is contained in:
parent
c6bd6656a2
commit
391dac58a9
3 changed files with 23 additions and 11 deletions
|
|
@ -67,6 +67,7 @@ struct transport_data {
|
||||||
int sco_fd;
|
int sco_fd;
|
||||||
pa_io_event *sco_io;
|
pa_io_event *sco_io;
|
||||||
pa_mainloop_api *mainloop;
|
pa_mainloop_api *mainloop;
|
||||||
|
pa_bluetooth_backend *backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hfp_config {
|
struct hfp_config {
|
||||||
|
|
@ -612,8 +613,9 @@ static pa_volume_t set_source_volume(pa_bluetooth_transport *t, pa_volume_t volu
|
||||||
|
|
||||||
static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf)
|
static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf)
|
||||||
{
|
{
|
||||||
struct pa_bluetooth_discovery *discovery = t->device->discovery;
|
|
||||||
struct hfp_config *c = t->config;
|
struct hfp_config *c = t->config;
|
||||||
|
struct transport_data *trd = t->userdata;
|
||||||
|
pa_bluetooth_backend *b = trd->backend;
|
||||||
int indicator, mode, val;
|
int indicator, mode, val;
|
||||||
char str[5];
|
char str[5];
|
||||||
const char *r;
|
const char *r;
|
||||||
|
|
@ -649,9 +651,9 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (len == 1 && r[0] == '1')
|
if (len == 1 && r[0] == '1')
|
||||||
discovery->native_backend->cind_enabled_indicators |= (1 << indicator);
|
b->cind_enabled_indicators |= (1 << indicator);
|
||||||
else if (len == 1 && r[0] == '0')
|
else if (len == 1 && r[0] == '0')
|
||||||
discovery->native_backend->cind_enabled_indicators &= ~(1 << indicator);
|
b->cind_enabled_indicators &= ~(1 << indicator);
|
||||||
else {
|
else {
|
||||||
pa_log_error("Unable to parse indicator of AT+BIA command: %s", buf);
|
pa_log_error("Unable to parse indicator of AT+BIA command: %s", buf);
|
||||||
rfcomm_write_response(fd, "ERROR");
|
rfcomm_write_response(fd, "ERROR");
|
||||||
|
|
@ -686,7 +688,7 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
|
||||||
return true;
|
return true;
|
||||||
} else if (c->state == 1 && pa_startswith(buf, "AT+CIND=?")) {
|
} else if (c->state == 1 && pa_startswith(buf, "AT+CIND=?")) {
|
||||||
/* UPower backend available, declare support for more indicators */
|
/* UPower backend available, declare support for more indicators */
|
||||||
if (discovery->native_backend->upower) {
|
if (b->upower) {
|
||||||
rfcomm_write_response(fd, "+CIND: "
|
rfcomm_write_response(fd, "+CIND: "
|
||||||
MANDATORY_CALL_INDICATORS ","
|
MANDATORY_CALL_INDICATORS ","
|
||||||
"(\"service\",(0-1)),"
|
"(\"service\",(0-1)),"
|
||||||
|
|
@ -702,8 +704,8 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (c->state == 2 && pa_startswith(buf, "AT+CIND?")) {
|
} else if (c->state == 2 && pa_startswith(buf, "AT+CIND?")) {
|
||||||
if (discovery->native_backend->upower)
|
if (b->upower)
|
||||||
rfcomm_write_response(fd, "+CIND: 0,0,0,0,%u", pa_upower_get_battery_level(discovery->native_backend->upower));
|
rfcomm_write_response(fd, "+CIND: 0,0,0,0,%u", pa_upower_get_battery_level(b->upower));
|
||||||
else
|
else
|
||||||
rfcomm_write_response(fd, "+CIND: 0,0,0,0");
|
rfcomm_write_response(fd, "+CIND: 0,0,0,0");
|
||||||
c->state = 3;
|
c->state = 3;
|
||||||
|
|
@ -716,7 +718,7 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
|
||||||
pa_log_warn("Unexpected mode for AT+CMER: %d", mode);
|
pa_log_warn("Unexpected mode for AT+CMER: %d", mode);
|
||||||
|
|
||||||
/* Configure CMER event reporting */
|
/* Configure CMER event reporting */
|
||||||
discovery->native_backend->cmer_indicator_reporting_enabled = !!val;
|
b->cmer_indicator_reporting_enabled = !!val;
|
||||||
|
|
||||||
pa_log_debug("Event indications enabled? %s", pa_yes_no(val));
|
pa_log_debug("Event indications enabled? %s", pa_yes_no(val));
|
||||||
|
|
||||||
|
|
@ -820,7 +822,7 @@ static int get_rfcomm_fd(pa_bluetooth_discovery *discovery) {
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
|
|
||||||
/* Find RFCOMM transport by checking if a HSP or HFP profile transport is available */
|
/* Find RFCOMM transport by checking if a HSP or HFP profile transport is available */
|
||||||
while ((t = pa_hashmap_iterate(discovery->transports, &state, NULL))) {
|
while ((t = pa_hashmap_iterate(pa_bluetooth_discovery_get_transports(discovery), &state, NULL))) {
|
||||||
/* Skip non-connected transports */
|
/* Skip non-connected transports */
|
||||||
if (!t || t->state == PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED) {
|
if (!t || t->state == PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED) {
|
||||||
pa_log_debug("Profile disconnected or unavailable");
|
pa_log_debug("Profile disconnected or unavailable");
|
||||||
|
|
@ -868,7 +870,8 @@ static pa_hook_result_t host_battery_level_changed_cb(pa_bluetooth_discovery *y,
|
||||||
|
|
||||||
static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
|
static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
|
||||||
pa_bluetooth_transport *t = userdata;
|
pa_bluetooth_transport *t = userdata;
|
||||||
pa_bluetooth_discovery *discovery = t->device->discovery;
|
struct transport_data *trd = t->userdata;
|
||||||
|
pa_bluetooth_backend *b = trd->backend;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pa_assert(io);
|
pa_assert(io);
|
||||||
|
|
@ -991,9 +994,9 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* Service Connection lost, reset indicators and event reporting to default values */
|
/* Service Connection lost, reset indicators and event reporting to default values */
|
||||||
discovery->native_backend->cmer_indicator_reporting_enabled = false;
|
b->cmer_indicator_reporting_enabled = false;
|
||||||
for (i = 1; i < CIND_INDICATOR_MAX; i++)
|
for (i = 1; i < CIND_INDICATOR_MAX; i++)
|
||||||
discovery->native_backend->cind_enabled_indicators |= (1 << i);
|
b->cind_enabled_indicators |= (1 << i);
|
||||||
|
|
||||||
pa_bluetooth_transport_unlink(t);
|
pa_bluetooth_transport_unlink(t);
|
||||||
pa_bluetooth_transport_free(t);
|
pa_bluetooth_transport_free(t);
|
||||||
|
|
@ -1157,6 +1160,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
|
||||||
trd = pa_xnew0(struct transport_data, 1);
|
trd = pa_xnew0(struct transport_data, 1);
|
||||||
trd->rfcomm_fd = fd;
|
trd->rfcomm_fd = fd;
|
||||||
trd->mainloop = b->core->mainloop;
|
trd->mainloop = b->core->mainloop;
|
||||||
|
trd->backend = b;
|
||||||
trd->rfcomm_io = trd->mainloop->io_new(b->core->mainloop, fd, PA_IO_EVENT_INPUT,
|
trd->rfcomm_io = trd->mainloop->io_new(b->core->mainloop, fd, PA_IO_EVENT_INPUT,
|
||||||
rfcomm_io_callback, t);
|
rfcomm_io_callback, t);
|
||||||
t->userdata = trd;
|
t->userdata = trd;
|
||||||
|
|
|
||||||
|
|
@ -1179,6 +1179,13 @@ bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y)
|
||||||
return y->enable_msbc;
|
return y->enable_msbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pa_hashmap* pa_bluetooth_discovery_get_transports(pa_bluetooth_discovery *y) {
|
||||||
|
pa_assert(y);
|
||||||
|
pa_assert(PA_REFCNT_VALUE(y) > 0);
|
||||||
|
|
||||||
|
return y->transports;
|
||||||
|
}
|
||||||
|
|
||||||
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local) {
|
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local) {
|
||||||
pa_bluetooth_device *d;
|
pa_bluetooth_device *d;
|
||||||
void *state = NULL;
|
void *state = NULL;
|
||||||
|
|
|
||||||
|
|
@ -271,4 +271,5 @@ void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is
|
||||||
bool pa_bluetooth_discovery_get_enable_native_hsp_hs(pa_bluetooth_discovery *y);
|
bool pa_bluetooth_discovery_get_enable_native_hsp_hs(pa_bluetooth_discovery *y);
|
||||||
bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y);
|
bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y);
|
||||||
bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y);
|
bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y);
|
||||||
|
pa_hashmap* pa_bluetooth_discovery_get_transports(pa_bluetooth_discovery *y);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue