Cubeb: Add a default device to the selection (#1017)

This commit is contained in:
Squall Leonhart 2024-02-18 15:51:00 +11:00 committed by GitHub
parent ca01e923bf
commit 81acd80a97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 8 deletions

View File

@ -188,15 +188,20 @@ std::vector<IAudioAPI::DeviceDescriptionPtr> CubebAPI::GetDevices()
return {}; return {};
std::vector<DeviceDescriptionPtr> result; std::vector<DeviceDescriptionPtr> result;
result.reserve(devices.count); result.reserve(devices.count + 1); // Reserve space for the default device
// Add the default device to the list
auto defaultDevice = std::make_shared<CubebDeviceDescription>(nullptr, "default", L"Default Device");
result.emplace_back(defaultDevice);
for (size_t i = 0; i < devices.count; ++i) for (size_t i = 0; i < devices.count; ++i)
{ {
//const auto& device = devices.device[i]; // const auto& device = devices.device[i];
if (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED) if (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED)
{ {
auto device = std::make_shared<CubebDeviceDescription>(devices.device[i].devid, devices.device[i].device_id, auto device = std::make_shared<CubebDeviceDescription>(devices.device[i].devid, devices.device[i].device_id,
boost::nowide::widen( boost::nowide::widen(
devices.device[i].friendly_name)); devices.device[i].friendly_name));
result.emplace_back(device); result.emplace_back(device);
} }
} }

View File

@ -180,15 +180,20 @@ std::vector<IAudioInputAPI::DeviceDescriptionPtr> CubebInputAPI::GetDevices()
return {}; return {};
std::vector<DeviceDescriptionPtr> result; std::vector<DeviceDescriptionPtr> result;
result.reserve(devices.count); result.reserve(devices.count + 1); // Reserve space for the default device
// Add the default device to the list
auto defaultDevice = std::make_shared<CubebDeviceDescription>(nullptr, "default", L"Default Device");
result.emplace_back(defaultDevice);
for (size_t i = 0; i < devices.count; ++i) for (size_t i = 0; i < devices.count; ++i)
{ {
//const auto& device = devices.device[i]; // const auto& device = devices.device[i];
if (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED) if (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED)
{ {
auto device = std::make_shared<CubebDeviceDescription>(devices.device[i].devid, devices.device[i].device_id, auto device = std::make_shared<CubebDeviceDescription>(devices.device[i].devid, devices.device[i].device_id,
boost::nowide::widen( boost::nowide::widen(
devices.device[i].friendly_name)); devices.device[i].friendly_name));
result.emplace_back(device); result.emplace_back(device);
} }
} }