mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	alsa: remove device if inotify reports it's no longer accessible
When the session becomes inactive (eg. user on active seat switched), udev may make devices inaccessible. In this case, pipewire should give up the devices and close their open file descriptors.
This commit is contained in:
		
							parent
							
								
									277a9a2577
								
							
						
					
					
						commit
						bf3b5d4286
					
				
					 1 changed files with 15 additions and 1 deletions
				
			
		| 
						 | 
					@ -49,6 +49,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ACTION_ADD	0
 | 
					#define ACTION_ADD	0
 | 
				
			||||||
#define ACTION_REMOVE	1
 | 
					#define ACTION_REMOVE	1
 | 
				
			||||||
 | 
					#define ACTION_DISABLE	2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct device {
 | 
					struct device {
 | 
				
			||||||
	uint32_t id;
 | 
						uint32_t id;
 | 
				
			||||||
| 
						 | 
					@ -415,6 +416,15 @@ static void process_device(struct impl *this, uint32_t action, struct udev_devic
 | 
				
			||||||
		if (emitted)
 | 
							if (emitted)
 | 
				
			||||||
			spa_device_emit_object_info(&this->hooks, id, NULL);
 | 
								spa_device_emit_object_info(&this->hooks, id, NULL);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case ACTION_DISABLE:
 | 
				
			||||||
 | 
							if (device == NULL)
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							if (device->emitted) {
 | 
				
			||||||
 | 
								device->emitted = false;
 | 
				
			||||||
 | 
								spa_device_emit_object_info(&this->hooks, id, NULL);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -459,12 +469,16 @@ static void impl_on_notify_events(struct spa_source *source)
 | 
				
			||||||
			event = (const struct inotify_event *) p;
 | 
								event = (const struct inotify_event *) p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ((event->mask & IN_ATTRIB)) {
 | 
								if ((event->mask & IN_ATTRIB)) {
 | 
				
			||||||
 | 
									bool access;
 | 
				
			||||||
				if (sscanf(event->name, "controlC%u", &id) != 1)
 | 
									if (sscanf(event->name, "controlC%u", &id) != 1)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
				if ((device = find_device(this, id)) == NULL)
 | 
									if ((device = find_device(this, id)) == NULL)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
				if (!device->emitted)
 | 
									access = check_access(this, device);
 | 
				
			||||||
 | 
									if (access && !device->emitted)
 | 
				
			||||||
					process_device(this, ACTION_ADD, device->dev);
 | 
										process_device(this, ACTION_ADD, device->dev);
 | 
				
			||||||
 | 
									else if (!access && device->emitted)
 | 
				
			||||||
 | 
										process_device(this, ACTION_DISABLE, device->dev);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			/* /dev/snd/ might have been removed */
 | 
								/* /dev/snd/ might have been removed */
 | 
				
			||||||
			if ((event->mask & (IN_DELETE_SELF | IN_MOVE_SELF)))
 | 
								if ((event->mask & (IN_DELETE_SELF | IN_MOVE_SELF)))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue