+ } 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);