misc: Improve defaults for macOS and handling of missing audio backends. (#7273)
* misc: Improve backend defaults for macOS. * audio_core: Improve handling of missing audio backends.
This commit is contained in:
@ -20,24 +20,10 @@
|
||||
|
||||
namespace AudioCore {
|
||||
namespace {
|
||||
struct InputDetails {
|
||||
using FactoryFn = std::unique_ptr<Input> (*)(std::string_view);
|
||||
using ListDevicesFn = std::vector<std::string> (*)();
|
||||
|
||||
/// Type of this input.
|
||||
InputType type;
|
||||
/// Name for this input.
|
||||
std::string_view name;
|
||||
/// A method to call to construct an instance of this type of input.
|
||||
FactoryFn factory;
|
||||
/// A method to call to list available devices.
|
||||
ListDevicesFn list_devices;
|
||||
};
|
||||
|
||||
// input_details is ordered in terms of desirability, with the best choice at the top.
|
||||
constexpr std::array input_details = {
|
||||
#ifdef HAVE_CUBEB
|
||||
InputDetails{InputType::Cubeb, "Real Device (Cubeb)",
|
||||
InputDetails{InputType::Cubeb, "Real Device (Cubeb)", true,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
if (!Core::System::GetInstance().HasMicPermission()) {
|
||||
LOG_WARNING(Audio,
|
||||
@ -49,7 +35,7 @@ constexpr std::array input_details = {
|
||||
&ListCubebInputDevices},
|
||||
#endif
|
||||
#ifdef HAVE_OPENAL
|
||||
InputDetails{InputType::OpenAL, "Real Device (OpenAL)",
|
||||
InputDetails{InputType::OpenAL, "Real Device (OpenAL)", true,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
if (!Core::System::GetInstance().HasMicPermission()) {
|
||||
LOG_WARNING(Audio,
|
||||
@ -60,17 +46,22 @@ constexpr std::array input_details = {
|
||||
},
|
||||
&ListOpenALInputDevices},
|
||||
#endif
|
||||
InputDetails{InputType::Static, "Static Noise",
|
||||
InputDetails{InputType::Static, "Static Noise", false,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
return std::make_unique<StaticInput>();
|
||||
},
|
||||
[] { return std::vector<std::string>{"Static Noise"}; }},
|
||||
InputDetails{InputType::Null, "None",
|
||||
InputDetails{InputType::Null, "None", false,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
return std::make_unique<NullInput>();
|
||||
},
|
||||
[] { return std::vector<std::string>{"None"}; }},
|
||||
};
|
||||
} // Anonymous namespace
|
||||
|
||||
std::vector<InputDetails> ListInputs() {
|
||||
return {input_details.begin(), input_details.end()};
|
||||
}
|
||||
|
||||
const InputDetails& GetInputDetails(InputType input_type) {
|
||||
auto iter = std::find_if(
|
||||
@ -88,21 +79,5 @@ const InputDetails& GetInputDetails(InputType input_type) {
|
||||
|
||||
return *iter;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string_view GetInputName(InputType input_type) {
|
||||
if (input_type == InputType::Auto) {
|
||||
return "Auto";
|
||||
}
|
||||
return GetInputDetails(input_type).name;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetDeviceListForInput(InputType input_type) {
|
||||
return GetInputDetails(input_type).list_devices();
|
||||
}
|
||||
|
||||
std::unique_ptr<Input> CreateInputFromID(InputType input_type, std::string_view device_id) {
|
||||
return GetInputDetails(input_type).factory(device_id);
|
||||
}
|
||||
|
||||
} // namespace AudioCore
|
||||
|
Reference in New Issue
Block a user