diff --git a/src/ba-rfcomm.c b/src/ba-rfcomm.c index 7bf57b518..52d534176 100644 --- a/src/ba-rfcomm.c +++ b/src/ba-rfcomm.c @@ -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. * @@ -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); @@ -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); diff --git a/src/ba-transport.c b/src/ba-transport.c index 60a1a3a16..1dc455973 100644 --- a/src/ba-transport.c +++ b/src/ba-transport.c @@ -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); @@ -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); @@ -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; @@ -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) diff --git a/src/ofono.c b/src/ofono.c index 2af366d56..5571f3b18 100644 --- a/src/ofono.c +++ b/src/ofono.c @@ -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. @@ -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); diff --git a/test/test-rfcomm.c b/test/test-rfcomm.c index 91dda0924..fcae6afc8 100644 --- a/test/test-rfcomm.c +++ b/test/test-rfcomm.c @@ -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. * @@ -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) {