]> git.sesse.net Git - nageru/blobdiff - audio_mixer.cpp
Add a comment about hotswapping issues.
[nageru] / audio_mixer.cpp
index 88ca8c617a8559ce771e21f1e337133bba51296c..426125f888061a17546de06c4d3338b90098892a 100644 (file)
@@ -252,6 +252,9 @@ vector<float> AudioMixer::get_output(double pts, unsigned num_samples, Resamplin
        lock_guard<mutex> lock(audio_mutex);
 
        // Pick out all the interesting channels from all the cards.
+       // TODO: If the card has been hotswapped, the number of channels
+       // might have changed; if so, we need to do some sort of remapping
+       // to silence.
        for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
                AudioDevice *device = &cards[card_index];
                if (!device->interesting_channels.empty()) {
@@ -396,13 +399,14 @@ vector<float> AudioMixer::get_output(double pts, unsigned num_samples, Resamplin
        return samples_out;
 }
 
-vector<string> AudioMixer::get_names() const
+map<DeviceSpec, string> AudioMixer::get_names() const
 {
        lock_guard<mutex> lock(audio_mutex);
-       vector<string> names;
+       map<DeviceSpec, string> names;
        for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+               const DeviceSpec spec{ InputSourceType::CAPTURE_CARD, card_index };
                const AudioDevice *device = &cards[card_index];
-               names.push_back(device->name);
+               names.insert(make_pair(spec, device->name));
        }
        return names;
 }
@@ -419,13 +423,12 @@ void AudioMixer::set_input_mapping(const InputMapping &new_input_mapping)
 {
        lock_guard<mutex> lock(audio_mutex);
 
-       // FIXME: This needs to be keyed on DeviceSpec.
-       map<unsigned, set<unsigned>> interesting_channels;
+       map<DeviceSpec, set<unsigned>> interesting_channels;
        for (const InputMapping::Bus &bus : new_input_mapping.buses) {
                if (bus.device.type == InputSourceType::CAPTURE_CARD) {
                        for (unsigned channel = 0; channel < 2; ++channel) {
                                if (bus.source_channel[channel] != -1) {
-                                       interesting_channels[bus.device.index].insert(bus.source_channel[channel]);
+                                       interesting_channels[bus.device].insert(bus.source_channel[channel]);
                                }
                        }
                }
@@ -433,9 +436,10 @@ void AudioMixer::set_input_mapping(const InputMapping &new_input_mapping)
 
        // Reset resamplers for all cards that don't have the exact same state as before.
        for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+               DeviceSpec device_spec{InputSourceType::CAPTURE_CARD, card_index};
                AudioDevice *device = &cards[card_index];
-               if (device->interesting_channels != interesting_channels[card_index]) {
-                       device->interesting_channels = interesting_channels[card_index];
+               if (device->interesting_channels != interesting_channels[device_spec]) {
+                       device->interesting_channels = interesting_channels[device_spec];
                        reset_device_mutex_held(DeviceSpec{InputSourceType::CAPTURE_CARD, card_index});
                }
        }