} // 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)
{
if (device->interesting_channels.empty()) {
device->resampling_queue.reset();
} else {
- // TODO: ResamplingQueue should probably take the full device spec.
- // (It's only used for console output, though.)
device->resampling_queue.reset(new ResamplingQueue(
- device_spec.index, device->capture_frequency, OUTPUT_FREQUENCY, device->interesting_channels.size(),
+ device_spec, device->capture_frequency, OUTPUT_FREQUENCY, device->interesting_channels.size(),
global_flags.audio_queue_length_ms * 0.001));
}
}
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);
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;
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;
}
{
lock_guard<mutex> lock(compressor_mutex);
for (unsigned bus_index = 0; bus_index < bus_levels.size(); ++bus_index) {
- bus_levels[bus_index].current_level_dbfs[0] = to_db(peak_history[bus_index][0].current_level);
- bus_levels[bus_index].current_level_dbfs[1] = to_db(peak_history[bus_index][1].current_level);
- bus_levels[bus_index].peak_level_dbfs[0] = to_db(peak_history[bus_index][0].current_peak);
- bus_levels[bus_index].peak_level_dbfs[1] = to_db(peak_history[bus_index][1].current_peak);
- bus_levels[bus_index].historic_peak_dbfs = to_db(
+ BusLevel &levels = bus_levels[bus_index];
+ BusMetrics &metrics = bus_metrics[bus_index];
+
+ levels.current_level_dbfs[0] = metrics.current_level_dbfs[0] = to_db(peak_history[bus_index][0].current_level);
+ levels.current_level_dbfs[1] = metrics.current_level_dbfs[1] = to_db(peak_history[bus_index][1].current_level);
+ levels.peak_level_dbfs[0] = metrics.peak_level_dbfs[0] = to_db(peak_history[bus_index][0].current_peak);
+ levels.peak_level_dbfs[1] = metrics.peak_level_dbfs[1] = to_db(peak_history[bus_index][1].current_peak);
+ levels.historic_peak_dbfs = metrics.historic_peak_dbfs = to_db(
max(peak_history[bus_index][0].historic_peak,
peak_history[bus_index][1].historic_peak));
- bus_levels[bus_index].gain_staging_db = gain_staging_db[bus_index];
+ levels.gain_staging_db = metrics.gain_staging_db = gain_staging_db[bus_index];
if (compressor_enabled[bus_index]) {
- bus_levels[bus_index].compressor_attenuation_db = -to_db(compressor[bus_index]->get_attenuation());
+ levels.compressor_attenuation_db = metrics.compressor_attenuation_db = -to_db(compressor[bus_index]->get_attenuation());
} else {
- bus_levels[bus_index].compressor_attenuation_db = 0.0;
+ levels.compressor_attenuation_db = 0.0;
+ metrics.compressor_attenuation_db = 0.0 / 0.0;
}
}
}
lock_guard<timed_mutex> lock(audio_mutex);
map<DeviceSpec, DeviceInfo> 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;
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;
}
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;
}
}
map<DeviceSpec, set<unsigned>> 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);
+ }
+ }
+
+ // Kill all the old metrics, and set up new ones.
+ for (unsigned bus_index = 0; bus_index < input_mapping.buses.size(); ++bus_index) {
+ BusMetrics &metrics = bus_metrics[bus_index];
+
+ vector<pair<string, string>> labels_left = metrics.labels;
+ labels_left.emplace_back("channel", "left");
+ vector<pair<string, string>> labels_right = metrics.labels;
+ labels_right.emplace_back("channel", "right");
+
+ global_metrics.remove("bus_current_level_dbfs", labels_left);
+ global_metrics.remove("bus_current_level_dbfs", labels_right);
+ global_metrics.remove("bus_peak_level_dbfs", labels_left);
+ global_metrics.remove("bus_peak_level_dbfs", labels_right);
+ global_metrics.remove("bus_historic_peak_dbfs", metrics.labels);
+ global_metrics.remove("bus_gain_staging_db", metrics.labels);
+ global_metrics.remove("bus_compressor_attenuation_db", metrics.labels);
+ }
+ bus_metrics.reset(new BusMetrics[new_input_mapping.buses.size()]);
+ for (unsigned bus_index = 0; bus_index < new_input_mapping.buses.size(); ++bus_index) {
+ const InputMapping::Bus &bus = new_input_mapping.buses[bus_index];
+ BusMetrics &metrics = bus_metrics[bus_index];
+
+ char bus_index_str[16], source_index_str[16], source_channels_str[64];
+ snprintf(bus_index_str, sizeof(bus_index_str), "%u", bus_index);
+ snprintf(source_index_str, sizeof(source_index_str), "%u", bus.device.index);
+ snprintf(source_channels_str, sizeof(source_channels_str), "%d:%d", bus.source_channel[0], bus.source_channel[1]);
+
+ vector<pair<string, string>> labels;
+ metrics.labels.emplace_back("index", bus_index_str);
+ metrics.labels.emplace_back("name", bus.name);
+ if (bus.device.type == InputSourceType::SILENCE) {
+ metrics.labels.emplace_back("source_type", "silence");
+ } else if (bus.device.type == InputSourceType::CAPTURE_CARD) {
+ 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);
}
+ metrics.labels.emplace_back("source_index", source_index_str);
+ metrics.labels.emplace_back("source_channels", source_channels_str);
+
+ vector<pair<string, string>> labels_left = metrics.labels;
+ labels_left.emplace_back("channel", "left");
+ vector<pair<string, string>> labels_right = metrics.labels;
+ labels_right.emplace_back("channel", "right");
+
+ global_metrics.add("bus_current_level_dbfs", labels_left, &metrics.current_level_dbfs[0], Metrics::TYPE_GAUGE);
+ global_metrics.add("bus_current_level_dbfs", labels_right, &metrics.current_level_dbfs[1], Metrics::TYPE_GAUGE);
+ global_metrics.add("bus_peak_level_dbfs", labels_left, &metrics.peak_level_dbfs[0], Metrics::TYPE_GAUGE);
+ global_metrics.add("bus_peak_level_dbfs", labels_right, &metrics.peak_level_dbfs[1], Metrics::TYPE_GAUGE);
+ global_metrics.add("bus_historic_peak_dbfs", metrics.labels, &metrics.historic_peak_dbfs, Metrics::TYPE_GAUGE);
+ global_metrics.add("bus_gain_staging_db", metrics.labels, &metrics.gain_staging_db, Metrics::TYPE_GAUGE);
+ global_metrics.add("bus_compressor_attenuation_db", metrics.labels, &metrics.compressor_attenuation_db, Metrics::TYPE_GAUGE);
}
// Reset resamplers for all cards that don't have the exact same state as before.
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;
}