X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=alsa_input.cpp;h=0f8e99c95b9b0d536451f26c85bc1fa3142a9003;hb=5cb4274907d32fb8946558988461224196c2be59;hp=c53b24189da2f43a7335522aecf4aaaf81226a4a;hpb=a564f192f808841ad8dfa9a4aa6c8db3335bd6fd;p=nageru diff --git a/alsa_input.cpp b/alsa_input.cpp index c53b241..0f8e99c 100644 --- a/alsa_input.cpp +++ b/alsa_input.cpp @@ -1,9 +1,11 @@ #include "alsa_input.h" #include "audio_mixer.h" #include "defs.h" +#include "state.pb.h" #include +#include #include #include @@ -645,6 +647,43 @@ unsigned ALSAPool::find_free_device_index(const string &name, const string &info return devices.size() - 1; } +unsigned ALSAPool::create_dead_card(const string &name, const string &info, unsigned num_channels) +{ + lock_guard lock(mu); + + // See if there are any empty slots. If not, insert one at the end. + vector::iterator free_device = + find_if(devices.begin(), devices.end(), + [](const Device &device) { return device.state == Device::State::EMPTY; }); + if (free_device == devices.end()) { + devices.push_back(Device()); + inputs.emplace_back(nullptr); + free_device = devices.end() - 1; + } + + free_device->state = Device::State::DEAD; + free_device->name = name; + free_device->info = info; + free_device->num_channels = num_channels; + free_device->held = true; + + return distance(devices.begin(), free_device); +} + +void ALSAPool::serialize_device(unsigned index, DeviceSpecProto *serialized) +{ + lock_guard lock(mu); + assert(index < devices.size()); + assert(devices[index].held); + serialized->set_type(DeviceSpecProto::ALSA_INPUT); + serialized->set_index(index); + serialized->set_display_name(devices[index].display_name()); + serialized->set_alsa_name(devices[index].name); + serialized->set_alsa_info(devices[index].info); + serialized->set_num_channels(devices[index].num_channels); + serialized->set_address(devices[index].address); +} + void ALSAPool::free_card(unsigned index) { DeviceSpec spec{InputSourceType::ALSA_INPUT, index};