diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c index e42ce9148..2dd78fa45 100644 --- a/src/modules/bluetooth/backend-native.c +++ b/src/modules/bluetooth/backend-native.c @@ -613,7 +613,7 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf rfcomm_write_response(fd, "OK"); if (c->support_codec_negotiation) { - if (c->support_msbc) { + if (c->support_msbc && pa_bluetooth_discovery_get_enable_msbc(t->device->discovery)) { rfcomm_write_response(fd, "+BCS:2"); c->state = 4; } else { @@ -630,7 +630,7 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf } else if (sscanf(buf, "AT+BCS=%d", &val)) { if (val == 1) { pa_bluetooth_transport_reconfigure(t, pa_bluetooth_get_hf_codec("CVSD"), sco_transport_write, NULL); - } else if (val == 2) { + } else if (val == 2 && pa_bluetooth_discovery_get_enable_msbc(t->device->discovery)) { pa_bluetooth_transport_reconfigure(t, pa_bluetooth_get_hf_codec("mSBC"), sco_transport_write, sco_setsockopt_enable_bt_voice); } else { pa_assert_fp(val != 1 && val != 2); diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c index 0d55b797a..85dec44f1 100644 --- a/src/modules/bluetooth/backend-ofono.c +++ b/src/modules/bluetooth/backend-ofono.c @@ -548,7 +548,8 @@ static void hf_audio_agent_register(pa_bluetooth_backend *hf) { pa_assert_se(m = dbus_message_new_method_call(OFONO_SERVICE, "/", HF_AUDIO_MANAGER_INTERFACE, "Register")); codecs[ncodecs++] = HFP_AUDIO_CODEC_CVSD; - codecs[ncodecs++] = HFP_AUDIO_CODEC_MSBC; + if (pa_bluetooth_discovery_get_enable_msbc(hf->discovery)) + codecs[ncodecs++] = HFP_AUDIO_CODEC_MSBC; pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &pcodecs, ncodecs, DBUS_TYPE_INVALID)); diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c index 663c4beb4..bea1d999e 100644 --- a/src/modules/bluetooth/bluez5-util.c +++ b/src/modules/bluetooth/bluez5-util.c @@ -118,6 +118,7 @@ struct pa_bluetooth_discovery { pa_bluetooth_backend *ofono_backend, *native_backend; PA_LLIST_HEAD(pa_dbus_pending, pending); bool enable_native_hfp_hf; + bool enable_msbc; }; static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m, @@ -815,6 +816,14 @@ bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y) return y->enable_native_hfp_hf; } +bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y) +{ + pa_assert(y); + pa_assert(PA_REFCNT_VALUE(y) > 0); + + return y->enable_msbc; +} + pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local) { pa_bluetooth_device *d; void *state = NULL; @@ -2268,7 +2277,7 @@ static void object_manager_done(pa_bluetooth_discovery *y) { A2DP_OBJECT_MANAGER_PATH); } -pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backend, bool enable_native_hfp_hf) { +pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backend, bool enable_native_hfp_hf, bool enable_msbc) { pa_bluetooth_discovery *y; DBusError err; DBusConnection *conn; @@ -2282,6 +2291,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backe y->core = c; y->headset_backend = headset_backend; y->enable_native_hfp_hf = enable_native_hfp_hf; + y->enable_msbc = enable_msbc; y->adapters = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) adapter_free); y->devices = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h index a62bca0fa..f561d78f6 100644 --- a/src/modules/bluetooth/bluez5-util.h +++ b/src/modules/bluetooth/bluez5-util.h @@ -209,9 +209,10 @@ static inline bool pa_bluetooth_uuid_is_hsp_hs(const char *uuid) { #define HEADSET_BACKEND_NATIVE 1 #define HEADSET_BACKEND_AUTO 2 -pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend, bool default_profile_hfp); +pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core, int headset_backend, bool default_profile_hfp, bool enable_msbc); pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y); void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y); void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is_running); bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y); +bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y); #endif diff --git a/src/modules/bluetooth/module-bluez5-discover.c b/src/modules/bluetooth/module-bluez5-discover.c index 7700fdba7..09c68a331 100644 --- a/src/modules/bluetooth/module-bluez5-discover.c +++ b/src/modules/bluetooth/module-bluez5-discover.c @@ -37,6 +37,7 @@ PA_MODULE_LOAD_ONCE(true); PA_MODULE_USAGE( "headset=ofono|native|auto" "autodetect_mtu=" + "enable_msbc=" "output_rate_refresh_interval_ms=" "enable_native_hfp_hf=" ); @@ -44,6 +45,7 @@ PA_MODULE_USAGE( static const char* const valid_modargs[] = { "headset", "autodetect_mtu", + "enable_msbc", "output_rate_refresh_interval_ms", "enable_native_hfp_hf", NULL @@ -111,6 +113,7 @@ int pa__init(pa_module *m) { const char *headset_str; int headset_backend; bool autodetect_mtu; + bool enable_msbc; uint32_t output_rate_refresh_interval_ms; bool enable_native_hfp_hf = true; @@ -140,6 +143,10 @@ int pa__init(pa_module *m) { if (pa_modargs_get_value_boolean(ma, "autodetect_mtu", &autodetect_mtu) < 0) { pa_log("Invalid boolean value for autodetect_mtu parameter"); } + enable_msbc = true; + if (pa_modargs_get_value_boolean(ma, "enable_msbc", &enable_msbc) < 0) { + pa_log("Invalid boolean value for enable_msbc parameter"); + } if (pa_modargs_get_value_boolean(ma, "enable_native_hfp_hf", &enable_native_hfp_hf) < 0) { pa_log("enable_native_hfp_hf must be true or false"); goto fail; @@ -158,7 +165,7 @@ int pa__init(pa_module *m) { u->output_rate_refresh_interval_ms = output_rate_refresh_interval_ms; u->loaded_device_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend, enable_native_hfp_hf))) + if (!(u->discovery = pa_bluetooth_discovery_get(u->core, headset_backend, enable_native_hfp_hf, enable_msbc))) goto fail; u->device_connection_changed_slot =