]> git.sesse.net Git - nageru/blobdiff - nageru/audio_mixer.cpp
Don't reset an ALSA device when the only thing that changes is which channels to...
[nageru] / nageru / audio_mixer.cpp
index 07d10dad3650a9ca037263d661b4d5deca4adbf2..e441aac19ff9bd1bb73c3c2b5a7094270ed0a31f 100644 (file)
@@ -1256,21 +1256,16 @@ void AudioMixer::set_input_mapping_lock_held(const InputMapping &new_input_mappi
                const DeviceSpec device_spec{InputSourceType::ALSA_INPUT, card_index};
                AudioDevice *device = find_audio_device(device_spec);
                double extra_delay_ms = new_extra_delay_ms[device_spec];
-               if (interesting_channels[device_spec].empty()) {
-                       alsa_pool.release_device(card_index);
-               } else {
-                       alsa_pool.hold_device(card_index);
-               }
                if (device->interesting_channels != interesting_channels[device_spec]) {
                        device->interesting_channels = interesting_channels[device_spec];
                        device->extra_delay_ms = extra_delay_ms;
-                       alsa_pool.reset_device(device_spec.index);
                        reset_resampler_mutex_held(device_spec);
                } else if (device->extra_delay_ms != extra_delay_ms &&
                           device->resampling_queue != nullptr) {
                        device->extra_delay_ms = extra_delay_ms;
                        device->resampling_queue->change_expected_delay(get_delay_seconds(extra_delay_ms));
                }
+               start_or_stop_alsa_capture(device_spec);
        }
        for (unsigned card_index = 0; card_index < num_ffmpeg_inputs; ++card_index) {
                const DeviceSpec device_spec{InputSourceType::FFMPEG_VIDEO_INPUT, card_index};
@@ -1329,4 +1324,20 @@ bool AudioMixer::is_mono(unsigned bus_index)
        }
 }
 
+void AudioMixer::start_or_stop_alsa_capture(DeviceSpec device_spec)
+{
+       assert(device_spec.type == InputSourceType::ALSA_INPUT);
+       AudioDevice *device = find_audio_device(device_spec);
+       bool previously_held = alsa_pool.device_is_held(device_spec.index);
+       bool should_be_held = !device->interesting_channels.empty();
+       if (should_be_held) {
+               alsa_pool.hold_device(device_spec.index);
+       } else {
+               alsa_pool.release_device(device_spec.index);
+       }
+       if (previously_held != should_be_held) {
+               alsa_pool.reset_device(device_spec.index);
+       }
+}
+
 AudioMixer *global_audio_mixer = nullptr;