mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
spa: alsa,v4l2: avoid double lookup on inotify events
Split up `process_{device,card}()` to have a separate function that does
the lookup based on the udev device, and only use that when there is
no available reference to the actual device/card object.
This commit is contained in:
parent
57a5417703
commit
69f9e75458
2 changed files with 61 additions and 59 deletions
|
|
@ -359,48 +359,51 @@ static bool check_access(struct impl *this, struct device *device)
|
|||
return device->accessible;
|
||||
}
|
||||
|
||||
static void process_device(struct impl *this, enum action action, struct udev_device *dev)
|
||||
static void process_device(struct impl *this, enum action action, struct device *device)
|
||||
{
|
||||
uint32_t id;
|
||||
struct device *device;
|
||||
bool emitted;
|
||||
|
||||
if ((id = get_device_id(this, dev)) == SPA_ID_INVALID)
|
||||
return;
|
||||
|
||||
device = find_device(this, id);
|
||||
|
||||
switch (action) {
|
||||
case ACTION_ADD:
|
||||
if (device == NULL)
|
||||
device = add_device(this, id, dev);
|
||||
if (device == NULL)
|
||||
return;
|
||||
if (!check_access(this, device))
|
||||
return;
|
||||
emit_object_info(this, device);
|
||||
break;
|
||||
case ACTION_REMOVE: {
|
||||
bool emitted = device->emitted;
|
||||
uint32_t id = device->id;
|
||||
|
||||
case ACTION_REMOVE:
|
||||
if (device == NULL)
|
||||
return;
|
||||
emitted = device->emitted;
|
||||
remove_device(this, device);
|
||||
|
||||
if (emitted)
|
||||
spa_device_emit_object_info(&this->hooks, id, NULL);
|
||||
break;
|
||||
|
||||
}
|
||||
case ACTION_DISABLE:
|
||||
if (device == NULL)
|
||||
return;
|
||||
if (device->emitted) {
|
||||
device->emitted = false;
|
||||
spa_device_emit_object_info(&this->hooks, id, NULL);
|
||||
spa_device_emit_object_info(&this->hooks, device->id, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void process_udev_device(struct impl *this, enum action action, struct udev_device *udev_device)
|
||||
{
|
||||
struct device *device;
|
||||
uint32_t id;
|
||||
|
||||
if ((id = get_device_id(this, udev_device)) == SPA_ID_INVALID)
|
||||
return;
|
||||
|
||||
device = find_device(this, id);
|
||||
if (action == ACTION_ADD && !device)
|
||||
device = add_device(this, id, udev_device);
|
||||
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
process_device(this, action, device);
|
||||
}
|
||||
|
||||
static int stop_inotify(struct impl *this)
|
||||
{
|
||||
if (this->notify.fd == -1)
|
||||
|
|
@ -453,9 +456,9 @@ static void impl_on_notify_events(struct spa_source *source)
|
|||
|
||||
bool access = check_access(this, device);
|
||||
if (access && !device->emitted)
|
||||
process_device(this, ACTION_ADD, device->dev);
|
||||
process_device(this, ACTION_ADD, device);
|
||||
else if (!access && device->emitted)
|
||||
process_device(this, ACTION_DISABLE, device->dev);
|
||||
process_device(this, ACTION_DISABLE, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -504,9 +507,9 @@ static void impl_on_fd_events(struct spa_source *source)
|
|||
|
||||
if (spa_streq(action, "add") ||
|
||||
spa_streq(action, "change")) {
|
||||
process_device(this, ACTION_ADD, dev);
|
||||
process_udev_device(this, ACTION_ADD, dev);
|
||||
} else if (spa_streq(action, "remove")) {
|
||||
process_device(this, ACTION_REMOVE, dev);
|
||||
process_udev_device(this, ACTION_REMOVE, dev);
|
||||
}
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
|
|
@ -576,7 +579,7 @@ static int enum_devices(struct impl *this)
|
|||
if (dev == NULL)
|
||||
continue;
|
||||
|
||||
process_device(this, ACTION_ADD, dev);
|
||||
process_udev_device(this, ACTION_ADD, dev);
|
||||
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue