mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	bluetooth: Self unload module-bluetooth-device
If the device has been removed, unload the module without depending on module-bluetooth-discovery.
This commit is contained in:
		
							parent
							
								
									97bdeaaacd
								
							
						
					
					
						commit
						ea45f2c795
					
				
					 2 changed files with 22 additions and 4 deletions
				
			
		| 
						 | 
					@ -144,6 +144,7 @@ struct userdata {
 | 
				
			||||||
    pa_bluetooth_transport *transport;
 | 
					    pa_bluetooth_transport *transport;
 | 
				
			||||||
    char *accesstype;
 | 
					    char *accesstype;
 | 
				
			||||||
    pa_hook_slot *transport_removed_slot;
 | 
					    pa_hook_slot *transport_removed_slot;
 | 
				
			||||||
 | 
					    pa_hook_slot *device_removed_slot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_bluetooth_discovery *discovery;
 | 
					    pa_bluetooth_discovery *discovery;
 | 
				
			||||||
    pa_bool_t auto_connect;
 | 
					    pa_bool_t auto_connect;
 | 
				
			||||||
| 
						 | 
					@ -2524,6 +2525,17 @@ static int setup_dbus(struct userdata *u) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Run from main thread */
 | 
				
			||||||
 | 
					static pa_hook_result_t device_removed_cb(pa_bluetooth_device *d, void *call_data, struct userdata *u) {
 | 
				
			||||||
 | 
					    pa_assert(d);
 | 
				
			||||||
 | 
					    pa_assert(u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_log_debug("Device %s removed: unloading module", d->path);
 | 
				
			||||||
 | 
					    pa_module_unload(u->core, u->module, TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return PA_HOOK_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pa__init(pa_module* m) {
 | 
					int pa__init(pa_module* m) {
 | 
				
			||||||
    pa_modargs *ma;
 | 
					    pa_modargs *ma;
 | 
				
			||||||
    uint32_t channels;
 | 
					    uint32_t channels;
 | 
				
			||||||
| 
						 | 
					@ -2594,6 +2606,9 @@ int pa__init(pa_module* m) {
 | 
				
			||||||
    if (!(device = find_device(u, address, path)))
 | 
					    if (!(device = find_device(u, address, path)))
 | 
				
			||||||
        goto fail;
 | 
					        goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    u->device_removed_slot = pa_hook_connect(&device->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], PA_HOOK_NORMAL,
 | 
				
			||||||
 | 
					                                             (pa_hook_cb_t) device_removed_cb, u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Add the card structure. This will also initialize the default profile */
 | 
					    /* Add the card structure. This will also initialize the default profile */
 | 
				
			||||||
    if (add_card(u, device) < 0)
 | 
					    if (add_card(u, device) < 0)
 | 
				
			||||||
        goto fail;
 | 
					        goto fail;
 | 
				
			||||||
| 
						 | 
					@ -2681,6 +2696,11 @@ void pa__done(pa_module *m) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stop_thread(u);
 | 
					    stop_thread(u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (u->device_removed_slot) {
 | 
				
			||||||
 | 
					        pa_hook_slot_free(u->device_removed_slot);
 | 
				
			||||||
 | 
					        u->device_removed_slot = NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (USE_SCO_OVER_PCM(u))
 | 
					    if (USE_SCO_OVER_PCM(u))
 | 
				
			||||||
        restore_sco_volume_callbacks(u);
 | 
					        restore_sco_volume_callbacks(u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,11 +116,9 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (mi) {
 | 
					        if (mi) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Hmm, disconnection? Then let's unload our module */
 | 
					            /* Hmm, disconnection? Then the module unloads itself */
 | 
				
			||||||
 | 
					 | 
				
			||||||
            pa_log_debug("Unloading module for %s", d->path);
 | 
					 | 
				
			||||||
            pa_module_unload_request_by_index(u->core, mi->module, TRUE);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            pa_log_debug("Unregistering module for %s", d->path);
 | 
				
			||||||
            pa_hashmap_remove(u->hashmap, mi->path);
 | 
					            pa_hashmap_remove(u->hashmap, mi->path);
 | 
				
			||||||
            pa_xfree(mi->path);
 | 
					            pa_xfree(mi->path);
 | 
				
			||||||
            pa_xfree(mi);
 | 
					            pa_xfree(mi);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue