mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
bluetooth: use helper to set multiple transport object attributes
For mSBC to work correctly the following must be set correctly - codec object - transport write method - transport setsockopt method Use helper method to set all three simultaneously. Static configuration structure may be cleaner solution. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
This commit is contained in:
parent
62776cc815
commit
6c0c9cf845
4 changed files with 28 additions and 15 deletions
|
|
@ -599,19 +599,16 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
|
|||
c->state = 4;
|
||||
} else {
|
||||
c->state = 5;
|
||||
t->bt_codec = pa_bluetooth_get_hf_codec("CVSD");
|
||||
t->setsockopt = NULL;
|
||||
pa_bluetooth_transport_reconfigure(t, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL);
|
||||
transport_put(t);
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (sscanf(buf, "AT+BCS=%d", &val)) {
|
||||
if (val == 1) {
|
||||
t->bt_codec = pa_bluetooth_get_hf_codec("CVSD");
|
||||
t->setsockopt = NULL;
|
||||
pa_bluetooth_transport_reconfigure(t, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL);
|
||||
} else if (val == 2) {
|
||||
t->bt_codec = pa_bluetooth_get_hf_codec("mSBC");
|
||||
t->setsockopt = sco_setsockopt_enable_bt_voice;
|
||||
pa_bluetooth_transport_reconfigure(t, pa_bluetooth_get_hf_codec("mSBC"), sco_transport_write, sco_setsockopt_enable_bt_voice);
|
||||
} else
|
||||
pa_assert_not_reached();
|
||||
|
||||
|
|
@ -849,8 +846,6 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
|
|||
|
||||
t->acquire = sco_acquire_cb;
|
||||
t->release = sco_release_cb;
|
||||
t->write = sco_transport_write;
|
||||
t->bt_codec = pa_bluetooth_get_hf_codec("CVSD");
|
||||
t->destroy = transport_destroy;
|
||||
|
||||
/* If PA is the HF/HS we are in control of volume attenuation and
|
||||
|
|
@ -872,6 +867,8 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
|
|||
t->set_source_volume = set_source_volume;
|
||||
}
|
||||
|
||||
pa_bluetooth_transport_reconfigure(t, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL);
|
||||
|
||||
trd = pa_xnew0(struct transport_data, 1);
|
||||
trd->rfcomm_fd = fd;
|
||||
trd->mainloop = b->core->mainloop;
|
||||
|
|
|
|||
|
|
@ -227,8 +227,7 @@ static int card_acquire(struct hf_audio_card *card) {
|
|||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
card->transport->bt_codec = pa_bluetooth_get_hf_codec("CVSD");
|
||||
card->transport->setsockopt = NULL;
|
||||
pa_bluetooth_transport_reconfigure(card->transport, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL);
|
||||
card->fd = fd;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -410,8 +409,8 @@ static void hf_audio_agent_card_found(pa_bluetooth_backend *backend, const char
|
|||
card->transport = pa_bluetooth_transport_new(d, backend->ofono_bus_id, path, p, NULL, 0);
|
||||
card->transport->acquire = hf_audio_agent_transport_acquire;
|
||||
card->transport->release = hf_audio_agent_transport_release;
|
||||
card->transport->write = sco_transport_write;
|
||||
card->transport->userdata = card;
|
||||
pa_bluetooth_transport_reconfigure(card->transport, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL);
|
||||
|
||||
pa_bluetooth_transport_put(card->transport);
|
||||
pa_hashmap_put(backend->cards, card->path, card);
|
||||
|
|
@ -696,8 +695,7 @@ static DBusMessage *hf_audio_agent_new_connection(DBusConnection *c, DBusMessage
|
|||
|
||||
card->connecting = false;
|
||||
card->fd = fd;
|
||||
card->transport->bt_codec = pa_bluetooth_get_hf_codec("CVSD");
|
||||
card->transport->setsockopt = NULL;
|
||||
pa_bluetooth_transport_reconfigure(card->transport, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL);
|
||||
|
||||
pa_bluetooth_transport_set_state(card->transport, PA_BLUETOOTH_TRANSPORT_STATE_PLAYING);
|
||||
|
||||
|
|
|
|||
|
|
@ -184,6 +184,22 @@ pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const
|
|||
return t;
|
||||
}
|
||||
|
||||
void pa_bluetooth_transport_reconfigure(pa_bluetooth_transport *t, const pa_a2dp_codec *bt_codec,
|
||||
pa_bluetooth_transport_write_cb write_cb, pa_bluetooth_transport_setsockopt_cb setsockopt_cb) {
|
||||
pa_assert(t);
|
||||
|
||||
t->bt_codec = bt_codec;
|
||||
|
||||
t->write = write_cb;
|
||||
t->setsockopt = setsockopt_cb;
|
||||
|
||||
/* reset stream write type hint */
|
||||
t->stream_write_type = 0;
|
||||
|
||||
/* reset SCO MTU adjustment hint */
|
||||
t->last_read_size = 0;
|
||||
}
|
||||
|
||||
static const char *transport_state_to_string(pa_bluetooth_transport_state_t state) {
|
||||
switch(state) {
|
||||
case PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED:
|
||||
|
|
@ -1945,10 +1961,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
|
|||
dbus_message_unref(r);
|
||||
|
||||
t = pa_bluetooth_transport_new(d, sender, path, p, config, size);
|
||||
t->bt_codec = a2dp_codec;
|
||||
t->acquire = bluez5_transport_acquire_cb;
|
||||
t->release = bluez5_transport_release_cb;
|
||||
t->write = a2dp_transport_write;
|
||||
pa_bluetooth_transport_reconfigure(t, a2dp_codec, a2dp_transport_write, NULL);
|
||||
pa_bluetooth_transport_put(t);
|
||||
|
||||
pa_log_debug("Transport %s available for profile %s", t->path, pa_bluetooth_profile_to_string(t->profile));
|
||||
|
|
|
|||
|
|
@ -182,6 +182,9 @@ static inline void pa_bluetooth_native_backend_enable_shared_profiles(pa_bluetoo
|
|||
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);
|
||||
|
||||
void pa_bluetooth_transport_reconfigure(pa_bluetooth_transport *t, const pa_a2dp_codec *bt_codec,
|
||||
pa_bluetooth_transport_write_cb write_cb, pa_bluetooth_transport_setsockopt_cb setsockopt_cb);
|
||||
|
||||
void pa_bluetooth_transport_set_state(pa_bluetooth_transport *t, pa_bluetooth_transport_state_t state);
|
||||
void pa_bluetooth_transport_put(pa_bluetooth_transport *t);
|
||||
void pa_bluetooth_transport_unlink(pa_bluetooth_transport *t);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue