X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Faudio_mixer.cpp;fp=nageru%2Faudio_mixer.cpp;h=e441aac19ff9bd1bb73c3c2b5a7094270ed0a31f;hb=9768e380472e6ad68c8fc06efde3fa20f18bfc00;hp=07d10dad3650a9ca037263d661b4d5deca4adbf2;hpb=4c23038d9c18d22a9bfe577244a2d0fc293a7e6a;p=nageru diff --git a/nageru/audio_mixer.cpp b/nageru/audio_mixer.cpp index 07d10da..e441aac 100644 --- a/nageru/audio_mixer.cpp +++ b/nageru/audio_mixer.cpp @@ -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;