X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=audio_mixer.cpp;h=e7d545f69c6320c25cddcde039f3b100d8332529;hb=4a300e3cab7b1b1ef5a32e1f4a7ec319c48e95e5;hp=887b1056ac1799c8ce8f2075041ff6ecf32bf4f1;hpb=1ddeee498397ab599d0ee131f7896f543486d0ad;p=nageru diff --git a/audio_mixer.cpp b/audio_mixer.cpp index 887b105..e7d545f 100644 --- a/audio_mixer.cpp +++ b/audio_mixer.cpp @@ -167,8 +167,10 @@ void deinterleave_samples(const vector &in, vector *out_l, vector< } // namespace -AudioMixer::AudioMixer(unsigned num_cards) - : num_cards(num_cards), +AudioMixer::AudioMixer(unsigned num_capture_cards, unsigned num_ffmpeg_inputs) + : num_capture_cards(num_capture_cards), + num_ffmpeg_inputs(num_ffmpeg_inputs), + ffmpeg_inputs(new AudioDevice[num_ffmpeg_inputs]), limiter(OUTPUT_FREQUENCY), correlation(OUTPUT_FREQUENCY) { @@ -387,6 +389,8 @@ AudioMixer::AudioDevice *AudioMixer::find_audio_device(DeviceSpec device) return &video_cards[device.index]; case InputSourceType::ALSA_INPUT: return &alsa_inputs[device.index]; + case InputSourceType::FFMPEG_VIDEO_INPUT: + return &ffmpeg_inputs[device.index]; case InputSourceType::SILENCE: default: assert(false); @@ -425,7 +429,8 @@ void AudioMixer::fill_audio_bus(const map> &samples_ca memset(output, 0, num_samples * 2 * sizeof(*output)); } else { assert(bus.device.type == InputSourceType::CAPTURE_CARD || - bus.device.type == InputSourceType::ALSA_INPUT); + bus.device.type == InputSourceType::ALSA_INPUT || + bus.device.type == InputSourceType::FFMPEG_VIDEO_INPUT); const float *lsrc, *rsrc; unsigned lstride, rstride; float *dptr = output; @@ -455,6 +460,12 @@ vector AudioMixer::get_active_devices() const ret.push_back(device_spec); } } + for (unsigned card_index = 0; card_index < num_ffmpeg_inputs; ++card_index) { + const DeviceSpec device_spec{InputSourceType::FFMPEG_VIDEO_INPUT, card_index}; + if (!find_audio_device(device_spec)->interesting_channels.empty()) { + ret.push_back(device_spec); + } + } return ret; } @@ -878,7 +889,7 @@ map AudioMixer::get_devices() lock_guard lock(audio_mutex); map devices; - for (unsigned card_index = 0; card_index < num_cards; ++card_index) { + for (unsigned card_index = 0; card_index < num_capture_cards; ++card_index) { const DeviceSpec spec{ InputSourceType::CAPTURE_CARD, card_index }; const AudioDevice *device = &video_cards[card_index]; DeviceInfo info; @@ -898,6 +909,14 @@ map AudioMixer::get_devices() info.alsa_address = device.address; devices.insert(make_pair(spec, info)); } + for (unsigned card_index = 0; card_index < num_ffmpeg_inputs; ++card_index) { + const DeviceSpec spec{ InputSourceType::FFMPEG_VIDEO_INPUT, card_index }; + const AudioDevice *device = &ffmpeg_inputs[card_index]; + DeviceInfo info; + info.display_name = device->display_name; + info.num_channels = 2; + devices.insert(make_pair(spec, info)); + } return devices; } @@ -924,16 +943,25 @@ void AudioMixer::serialize_device(DeviceSpec device_spec, DeviceSpecProto *devic case InputSourceType::ALSA_INPUT: alsa_pool.serialize_device(device_spec.index, device_spec_proto); break; + case InputSourceType::FFMPEG_VIDEO_INPUT: + device_spec_proto->set_type(DeviceSpecProto::FFMPEG_VIDEO_INPUT); + device_spec_proto->set_index(device_spec.index); + device_spec_proto->set_display_name(ffmpeg_inputs[device_spec.index].display_name); + break; } } void AudioMixer::set_simple_input(unsigned card_index) { + assert(card_index < num_capture_cards + num_ffmpeg_inputs); InputMapping new_input_mapping; InputMapping::Bus input; input.name = "Main"; - input.device.type = InputSourceType::CAPTURE_CARD; - input.device.index = card_index; + if (card_index >= num_capture_cards) { + input.device = DeviceSpec{InputSourceType::FFMPEG_VIDEO_INPUT, card_index - num_capture_cards}; + } else { + input.device = DeviceSpec{InputSourceType::CAPTURE_CARD, card_index}; + } input.source_channel[0] = 0; input.source_channel[1] = 1; @@ -953,6 +981,11 @@ unsigned AudioMixer::get_simple_input() const input_mapping.buses[0].source_channel[0] == 0 && input_mapping.buses[0].source_channel[1] == 1) { return input_mapping.buses[0].device.index; + } else if (input_mapping.buses.size() == 1 && + input_mapping.buses[0].device.type == InputSourceType::FFMPEG_VIDEO_INPUT && + input_mapping.buses[0].source_channel[0] == 0 && + input_mapping.buses[0].source_channel[1] == 1) { + return input_mapping.buses[0].device.index + num_capture_cards; } else { return numeric_limits::max(); } @@ -976,12 +1009,15 @@ void AudioMixer::set_input_mapping_lock_held(const InputMapping &new_input_mappi map> interesting_channels; for (const InputMapping::Bus &bus : new_input_mapping.buses) { if (bus.device.type == InputSourceType::CAPTURE_CARD || - bus.device.type == InputSourceType::ALSA_INPUT) { + bus.device.type == InputSourceType::ALSA_INPUT || + bus.device.type == InputSourceType::FFMPEG_VIDEO_INPUT) { for (unsigned channel = 0; channel < 2; ++channel) { if (bus.source_channel[channel] != -1) { interesting_channels[bus.device].insert(bus.source_channel[channel]); } } + } else { + assert(bus.device.type == InputSourceType::SILENCE); } } @@ -1021,6 +1057,8 @@ void AudioMixer::set_input_mapping_lock_held(const InputMapping &new_input_mappi metrics.labels.emplace_back("source_type", "capture_card"); } else if (bus.device.type == InputSourceType::ALSA_INPUT) { metrics.labels.emplace_back("source_type", "alsa_input"); + } else if (bus.device.type == InputSourceType::FFMPEG_VIDEO_INPUT) { + metrics.labels.emplace_back("source_type", "ffmpeg_video_input"); } else { assert(false); } @@ -1064,6 +1102,14 @@ void AudioMixer::set_input_mapping_lock_held(const InputMapping &new_input_mappi reset_resampler_mutex_held(device_spec); } } + for (unsigned card_index = 0; card_index < num_ffmpeg_inputs; ++card_index) { + const DeviceSpec device_spec{InputSourceType::FFMPEG_VIDEO_INPUT, card_index}; + AudioDevice *device = find_audio_device(device_spec); + if (device->interesting_channels != interesting_channels[device_spec]) { + device->interesting_channels = interesting_channels[device_spec]; + reset_resampler_mutex_held(device_spec); + } + } input_mapping = new_input_mapping; }