Skip to content

Commit

Permalink
Fix premature IO threads startup for oFono service
Browse files Browse the repository at this point in the history
After changes in 290ed7e the oFono IO threads shall be started
only after the SCO connection has been established. Trying to start
IO threads earlier results in an unnecessary error message.

This commit also adds D-Bus notification for HFP codec change when
oFono service is used.
  • Loading branch information
arkq committed Feb 19, 2022
1 parent 6e4ff9e commit 6509c47
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
10 changes: 1 addition & 9 deletions src/ba-rfcomm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - ba-rfcomm.c
* Copyright (c) 2016-2021 Arkadiusz Bokowy
* Copyright (c) 2016-2022 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand Down Expand Up @@ -470,10 +470,6 @@ static int rfcomm_handler_bcs_set_cb(struct ba_rfcomm *r, const struct bt_at *at
/* Codec negotiation process is complete. Update transport and
* notify connected clients, that transport has been changed. */
ba_transport_set_codec(t_sco, codec);
bluealsa_dbus_pcm_update(&t_sco->sco.spk_pcm,
BA_DBUS_PCM_UPDATE_SAMPLING | BA_DBUS_PCM_UPDATE_CODEC);
bluealsa_dbus_pcm_update(&t_sco->sco.mic_pcm,
BA_DBUS_PCM_UPDATE_SAMPLING | BA_DBUS_PCM_UPDATE_CODEC);

final:
pthread_cond_signal(&r->codec_selection_completed);
Expand All @@ -496,10 +492,6 @@ static int rfcomm_handler_resp_bcs_ok_cb(struct ba_rfcomm *r, const struct bt_at
* transport has been changed. Note, that this event might be emitted
* for an active transport - switching initiated by Audio Gateway. */
ba_transport_set_codec(t_sco, r->codec);
bluealsa_dbus_pcm_update(&t_sco->sco.spk_pcm,
BA_DBUS_PCM_UPDATE_SAMPLING | BA_DBUS_PCM_UPDATE_CODEC);
bluealsa_dbus_pcm_update(&t_sco->sco.mic_pcm,
BA_DBUS_PCM_UPDATE_SAMPLING | BA_DBUS_PCM_UPDATE_CODEC);

final:
pthread_cond_signal(&r->codec_selection_completed);
Expand Down
16 changes: 14 additions & 2 deletions src/ba-transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ static struct ba_transport *transport_new(

t->d = ba_device_ref(device);
t->type.profile = BA_TRANSPORT_PROFILE_NONE;
t->type.codec = -1;
t->ref_count = 1;

pthread_mutex_init(&t->type_mtx, NULL);
Expand Down Expand Up @@ -649,7 +650,7 @@ struct ba_transport *ba_transport_new_a2dp(
if ((t = transport_new(device, dbus_owner, dbus_path)) == NULL)
return NULL;

t->type = type;
t->type.profile = type.profile;

t->a2dp.codec = codec;
memcpy(&t->a2dp.configuration, configuration, codec->capabilities_size);
Expand Down Expand Up @@ -762,7 +763,7 @@ struct ba_transport *ba_transport_new_sco(
type.codec = HFP_CODEC_CVSD;
#endif

t->type = type;
t->type.profile = type.profile;

transport_pcm_init(&t->sco.spk_pcm, &t->thread_enc, BA_TRANSPORT_PCM_MODE_SINK);
t->sco.spk_pcm.max_bt_volume = 15;
Expand Down Expand Up @@ -1124,12 +1125,23 @@ static void ba_transport_set_codec_sco(struct ba_transport *t) {
g_assert_not_reached();
}

if (t->sco.spk_pcm.ba_dbus_exported)
bluealsa_dbus_pcm_update(&t->sco.spk_pcm,
BA_DBUS_PCM_UPDATE_SAMPLING | BA_DBUS_PCM_UPDATE_CODEC);

if (t->sco.mic_pcm.ba_dbus_exported)
bluealsa_dbus_pcm_update(&t->sco.mic_pcm,
BA_DBUS_PCM_UPDATE_SAMPLING | BA_DBUS_PCM_UPDATE_CODEC);

}

void ba_transport_set_codec(
struct ba_transport *t,
uint16_t codec_id) {

if (t->type.codec == codec_id)
return;

t->type.codec = codec_id;

if (t->type.profile & BA_TRANSPORT_PROFILE_MASK_A2DP)
Expand Down
4 changes: 1 addition & 3 deletions src/ofono.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - ofono.c
* Copyright (c) 2016-2021 Arkadiusz Bokowy
* Copyright (c) 2016-2022 Arkadiusz Bokowy
* 2018 Thierry Bultel
*
* This file is a part of bluez-alsa.
Expand Down Expand Up @@ -274,8 +274,6 @@ static void ofono_card_add(const char *dbus_sender, const char *card,
g_hash_table_insert(ofono_card_data_map, g_strdup(card), ocd);
ocd = NULL;

ba_transport_start(t);

fail:
if (a != NULL)
ba_adapter_unref(a);
Expand Down
6 changes: 4 additions & 2 deletions test/test-rfcomm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* test-rfcomm.c
* Copyright (c) 2016-2021 Arkadiusz Bokowy
* Copyright (c) 2016-2022 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand Down Expand Up @@ -62,7 +62,9 @@ void a2dp_sbc_transport_init(struct ba_transport *t) { (void)t; }
int a2dp_sbc_transport_start(struct ba_transport *t) { (void)t; return 0; }

int bluealsa_dbus_pcm_register(struct ba_transport_pcm *pcm) {
debug("%s: %p", __func__, (void *)pcm); return 0; }
debug("%s: %p", __func__, (void *)pcm);
pcm->ba_dbus_exported = true;
return 0; }
void bluealsa_dbus_pcm_update(struct ba_transport_pcm *pcm, unsigned int mask) {
debug("%s: %p %#x", __func__, (void *)pcm, mask);
if (mask & BA_DBUS_PCM_UPDATE_CODEC) {
Expand Down

0 comments on commit 6509c47

Please sign in to comment.