Skip to content

Commit

Permalink
Simplify getting OpenAL default device
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Feb 2, 2024
1 parent 36230b6 commit 5493af6
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions webrtc/details/webrtc_environment_openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,6 @@ void EnumerateDevices(DeviceType type, Callback &&callback) {
}
}

[[nodiscard]] QString ComputeDefaultPlaybackDeviceId() {
[[maybe_unused]] const auto reenumerate = alcGetString(
nullptr,
ALC_ALL_DEVICES_SPECIFIER);

const auto result = alcIsExtensionPresent({}, "ALC_ENUMERATE_ALL_EXT")
? alcGetString(
nullptr,
alcGetEnumValue(nullptr, "ALC_DEFAULT_ALL_DEVICES_SPECIFIER"))
: alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
return result ? QString::fromUtf8(result) : QString();
}

[[nodiscard]] QString ComputeDefaultCaptureDeviceId() {
[[maybe_unused]] auto reenumerate = alcGetString(
nullptr,
ALC_CAPTURE_DEVICE_SPECIFIER);

const auto result = alcGetString(
nullptr,
ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
return result ? QString::fromUtf8(result) : QString();
}

[[nodiscard]] DeviceInfo DeviceFromOpenAL(
DeviceType type,
const char *device) {
Expand Down Expand Up @@ -85,9 +61,16 @@ QString EnvironmentOpenAL::defaultId(DeviceType type) {
QString EnvironmentOpenAL::DefaultId(DeviceType type) {
Expects(type == DeviceType::Playback || type == DeviceType::Capture);

return (type == DeviceType::Playback)
? ComputeDefaultPlaybackDeviceId()
: ComputeDefaultCaptureDeviceId();
[[maybe_unused]] const auto reenumerate = alcGetString(
nullptr,
(type == DeviceType::Capture)
? ALC_CAPTURE_DEVICE_SPECIFIER
: ALC_ALL_DEVICES_SPECIFIER);

return QString::fromUtf8(
alcGetString(nullptr, (type == DeviceType::Capture)
? ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
: ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
}

DeviceResolvedId EnvironmentOpenAL::DefaultResolvedId(DeviceType type) {
Expand Down

0 comments on commit 5493af6

Please sign in to comment.