mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	bluetooth: add modarg to allow disabling mSBC codec
Add module-bluetooth-discover argument enable_msbc, default is true (enabled) Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
This commit is contained in:
		
							parent
							
								
									310e2877a0
								
							
						
					
					
						commit
						6a92940796
					
				
					 5 changed files with 25 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,7 @@ PA_MODULE_LOAD_ONCE(true);
 | 
			
		|||
PA_MODULE_USAGE(
 | 
			
		||||
    "headset=ofono|native|auto"
 | 
			
		||||
    "autodetect_mtu=<boolean>"
 | 
			
		||||
    "enable_msbc=<boolean, enable mSBC support in native and oFono backends, default is true>"
 | 
			
		||||
    "output_rate_refresh_interval_ms=<interval between attempts to improve output rate in milliseconds>"
 | 
			
		||||
    "enable_native_hfp_hf=<boolean, enable HFP support in native backend>"
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			@ -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 =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue