]> git.sesse.net Git - nageru/commitdiff
Unplug ALSA cards as soon as we get the inotify message.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 11 Sep 2016 15:26:13 +0000 (17:26 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Oct 2016 22:55:44 +0000 (00:55 +0200)
If not, devices not in use would not be properly removed before
someone tried to remove them.

alsa_input.cpp
alsa_input.h

index 78faaf31ffc1ee584cc4f3fccad7f7e5fd25f15c..0ba07b145dc7a0fcc4f198fec772660d1f6088b8 100644 (file)
@@ -471,6 +471,19 @@ ALSAPool::ProbeResult ALSAPool::probe_device_once(unsigned card_index, unsigned
        return ALSAPool::ProbeResult::SUCCESS;
 }
 
+void ALSAPool::unplug_device(unsigned card_index, unsigned dev_index)
+{
+       char address[256];
+       snprintf(address, sizeof(address), "hw:%d,%d", card_index, dev_index);
+       for (unsigned i = 0; i < devices.size(); ++i) {
+               if (devices[i].state != Device::State::EMPTY &&
+                   devices[i].state != Device::State::DEAD &&
+                   devices[i].address == address) {
+                       free_card(i);
+               }
+       }
+}
+
 void ALSAPool::init()
 {
        thread(&ALSAPool::inotify_thread_func, this).detach();
@@ -519,7 +532,7 @@ void ALSAPool::inotify_thread_func()
                        if (sscanf(event->name, "pcmC%uD%u%c", &card, &device, &type) == 3 && type == 'c') {
                                if (event->mask & (IN_MOVED_FROM | IN_DELETE)) {
                                        printf("Deleted capture device: Card %u, device %u\n", card, device);
-                                       // TODO: Unplug.
+                                       unplug_device(card, device);
                                }
                                if (event->mask & (IN_MOVED_TO | IN_CREATE)) {
                                        printf("Adding capture device: Card %u, device %u\n", card, device);
index 4638e4bb802ff875dea5e48a59cb285fda852ff1..c0dbafc4e69e408c55538e3dc5446d51ef6a73c4 100644 (file)
@@ -182,6 +182,8 @@ private:
        };
        ProbeResult probe_device_once(unsigned card_index, unsigned dev_index);
 
+       void unplug_device(unsigned card_index, unsigned dev_index);
+
        // Must be called with <mu> held. Will allocate a new entry if needed.
        // The returned entry will be set to READY state.
        unsigned find_free_device_index(const std::string &name,