void hold_device(unsigned index);
void release_device(unsigned index); // Note: index is allowed to go out of bounds.
+ bool device_is_held(unsigned index); // Same here.
// If device is held, start or restart capture. If device is not held,
// stop capture if it isn't already.
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};
}
}
+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;
void send_audio_level_callback();
std::vector<DeviceSpec> get_active_devices() const;
void set_input_mapping_lock_held(const InputMapping &input_mapping);
+ void start_or_stop_alsa_capture(DeviceSpec device_spec);
unsigned num_capture_cards, num_ffmpeg_inputs;