]> git.sesse.net Git - nageru/commitdiff
When we stop capturing from an ALSA card, close the PCM handle a bit sooner.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 10 Sep 2016 12:56:47 +0000 (14:56 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Oct 2016 22:55:44 +0000 (00:55 +0200)
alsa_input.cpp

index 0a39d3f1a5c55364387f4c4e1ad50c0bc6b99f5b..cf9c69f4dd877213ba3d0230aba98fefdf7bbd62 100644 (file)
@@ -149,7 +149,9 @@ bool ALSAInput::open_device()
 
 ALSAInput::~ALSAInput()
 {
-       WARN_ON_ERROR("snd_pcm_close()", snd_pcm_close(pcm_handle));
+       if (pcm_handle) {
+               WARN_ON_ERROR("snd_pcm_close()", snd_pcm_close(pcm_handle));
+       }
 }
 
 void ALSAInput::start_capture_thread()
@@ -180,6 +182,8 @@ void ALSAInput::capture_thread_func()
 
        if (should_quit) {
                // Don't call free_card(); that would be a deadlock.
+               WARN_ON_ERROR("snd_pcm_close()", snd_pcm_close(pcm_handle));
+               pcm_handle = nullptr;
                return;
        }
 
@@ -188,9 +192,13 @@ void ALSAInput::capture_thread_func()
                switch (do_capture()) {
                case CaptureEndReason::REQUESTED_QUIT:
                        // Don't call free_card(); that would be a deadlock.
+                       WARN_ON_ERROR("snd_pcm_close()", snd_pcm_close(pcm_handle));
+                       pcm_handle = nullptr;
                        return;
                case CaptureEndReason::DEVICE_GONE:
                        parent_pool->free_card(internal_dev_index);
+                       WARN_ON_ERROR("snd_pcm_close()", snd_pcm_close(pcm_handle));
+                       pcm_handle = nullptr;
                        return;
                case CaptureEndReason::OTHER_ERROR:
                        parent_pool->set_card_state(internal_dev_index, ALSAPool::Device::State::STARTING);