mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 04:05:09 +02:00
update OpenAL-Soft to 1.24.3.
This commit is contained in:
@@ -20,32 +20,25 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "portaudio.h"
|
||||
#include "portaudio.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "albit.h"
|
||||
#include "alc/alconfig.h"
|
||||
#include "alnumeric.h"
|
||||
#include "alstring.h"
|
||||
#include "core/device.h"
|
||||
#include "core/logging.h"
|
||||
#include "dynload.h"
|
||||
#include "ringbuffer.h"
|
||||
|
||||
#include <portaudio.h> /* NOLINT(*-duplicate-include) Not the same header. */
|
||||
#include <portaudio.h>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
[[nodiscard]] constexpr auto GetDefaultName() noexcept { return "PortAudio Default"sv; }
|
||||
|
||||
|
||||
#ifdef HAVE_DYNLOAD
|
||||
#if HAVE_DYNLOAD
|
||||
void *pa_handle;
|
||||
#define MAKE_FUNC(x) decltype(x) * p##x
|
||||
MAKE_FUNC(Pa_Initialize);
|
||||
@@ -55,6 +48,8 @@ MAKE_FUNC(Pa_StartStream);
|
||||
MAKE_FUNC(Pa_StopStream);
|
||||
MAKE_FUNC(Pa_OpenStream);
|
||||
MAKE_FUNC(Pa_CloseStream);
|
||||
MAKE_FUNC(Pa_GetDeviceCount);
|
||||
MAKE_FUNC(Pa_GetDeviceInfo);
|
||||
MAKE_FUNC(Pa_GetDefaultOutputDevice);
|
||||
MAKE_FUNC(Pa_GetDefaultInputDevice);
|
||||
MAKE_FUNC(Pa_GetStreamInfo);
|
||||
@@ -68,35 +63,72 @@ MAKE_FUNC(Pa_GetStreamInfo);
|
||||
#define Pa_StopStream pPa_StopStream
|
||||
#define Pa_OpenStream pPa_OpenStream
|
||||
#define Pa_CloseStream pPa_CloseStream
|
||||
#define Pa_GetDeviceCount pPa_GetDeviceCount
|
||||
#define Pa_GetDeviceInfo pPa_GetDeviceInfo
|
||||
#define Pa_GetDefaultOutputDevice pPa_GetDefaultOutputDevice
|
||||
#define Pa_GetDefaultInputDevice pPa_GetDefaultInputDevice
|
||||
#define Pa_GetStreamInfo pPa_GetStreamInfo
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct DeviceEntry {
|
||||
std::string mName;
|
||||
uint mPlaybackChannels{};
|
||||
uint mCaptureChannels{};
|
||||
};
|
||||
std::vector<DeviceEntry> DeviceNames;
|
||||
|
||||
void EnumerateDevices()
|
||||
{
|
||||
const auto devcount = Pa_GetDeviceCount();
|
||||
if(devcount < 0)
|
||||
{
|
||||
ERR("Error getting device count: {}", Pa_GetErrorText(devcount));
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<DeviceEntry>(static_cast<uint>(devcount)).swap(DeviceNames);
|
||||
PaDeviceIndex idx{0};
|
||||
for(auto &entry : DeviceNames)
|
||||
{
|
||||
if(auto info = Pa_GetDeviceInfo(idx); info && info->name)
|
||||
{
|
||||
entry.mName = info->name;
|
||||
entry.mPlaybackChannels = static_cast<uint>(std::max(info->maxOutputChannels, 0));
|
||||
entry.mCaptureChannels = static_cast<uint>(std::max(info->maxInputChannels, 0));
|
||||
TRACE("Device {} \"{}\": {} playback, {} capture channels", idx, entry.mName,
|
||||
info->maxOutputChannels, info->maxInputChannels);
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
struct StreamParamsExt : public PaStreamParameters { uint updateSize; };
|
||||
|
||||
struct PortPlayback final : public BackendBase {
|
||||
PortPlayback(DeviceBase *device) noexcept : BackendBase{device} { }
|
||||
explicit PortPlayback(DeviceBase *device) noexcept : BackendBase{device} { }
|
||||
~PortPlayback() override;
|
||||
|
||||
int writeCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
|
||||
const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags) noexcept;
|
||||
|
||||
void createStream(PaDeviceIndex deviceid);
|
||||
|
||||
void open(std::string_view name) override;
|
||||
bool reset() override;
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
PaStream *mStream{nullptr};
|
||||
PaStreamParameters mParams{};
|
||||
uint mUpdateSize{0u};
|
||||
StreamParamsExt mParams{};
|
||||
PaDeviceIndex mDeviceIdx{-1};
|
||||
};
|
||||
|
||||
PortPlayback::~PortPlayback()
|
||||
{
|
||||
PaError err{mStream ? Pa_CloseStream(mStream) : paNoError};
|
||||
if(err != paNoError)
|
||||
ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
|
||||
ERR("Error closing stream: {}", Pa_GetErrorText(err));
|
||||
mStream = nullptr;
|
||||
}
|
||||
|
||||
@@ -110,45 +142,29 @@ int PortPlayback::writeCallback(const void*, void *outputBuffer, unsigned long f
|
||||
}
|
||||
|
||||
|
||||
void PortPlayback::open(std::string_view name)
|
||||
void PortPlayback::createStream(PaDeviceIndex deviceid)
|
||||
{
|
||||
if(name.empty())
|
||||
name = GetDefaultName();
|
||||
else if(name != GetDefaultName())
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found",
|
||||
al::sizei(name), name.data()};
|
||||
auto &devinfo = DeviceNames.at(static_cast<uint>(deviceid));
|
||||
|
||||
PaStreamParameters params{};
|
||||
auto devidopt = ConfigValueInt({}, "port", "device");
|
||||
if(devidopt && *devidopt >= 0) params.device = *devidopt;
|
||||
else params.device = Pa_GetDefaultOutputDevice();
|
||||
params.suggestedLatency = mDevice->BufferSize / static_cast<double>(mDevice->Frequency);
|
||||
auto params = StreamParamsExt{};
|
||||
params.device = deviceid;
|
||||
params.suggestedLatency = mDevice->mBufferSize / static_cast<double>(mDevice->mSampleRate);
|
||||
params.hostApiSpecificStreamInfo = nullptr;
|
||||
|
||||
params.channelCount = ((mDevice->FmtChans == DevFmtMono) ? 1 : 2);
|
||||
|
||||
params.channelCount = static_cast<int>(std::min(devinfo.mPlaybackChannels,
|
||||
mDevice->channelsFromFmt()));
|
||||
switch(mDevice->FmtType)
|
||||
{
|
||||
case DevFmtByte:
|
||||
params.sampleFormat = paInt8;
|
||||
break;
|
||||
case DevFmtUByte:
|
||||
params.sampleFormat = paUInt8;
|
||||
break;
|
||||
case DevFmtUShort:
|
||||
/* fall-through */
|
||||
case DevFmtShort:
|
||||
params.sampleFormat = paInt16;
|
||||
break;
|
||||
case DevFmtUInt:
|
||||
/* fall-through */
|
||||
case DevFmtInt:
|
||||
params.sampleFormat = paInt32;
|
||||
break;
|
||||
case DevFmtFloat:
|
||||
params.sampleFormat = paFloat32;
|
||||
break;
|
||||
case DevFmtByte: params.sampleFormat = paInt8; break;
|
||||
case DevFmtUByte: params.sampleFormat = paUInt8; break;
|
||||
case DevFmtUShort: [[fallthrough]];
|
||||
case DevFmtShort: params.sampleFormat = paInt16; break;
|
||||
case DevFmtUInt: [[fallthrough]];
|
||||
case DevFmtInt: params.sampleFormat = paInt32; break;
|
||||
case DevFmtFloat: params.sampleFormat = paFloat32; break;
|
||||
}
|
||||
params.updateSize = mDevice->mUpdateSize;
|
||||
|
||||
auto srate = uint{mDevice->mSampleRate};
|
||||
|
||||
static constexpr auto writeCallback = [](const void *inputBuffer, void *outputBuffer,
|
||||
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
|
||||
@@ -157,55 +173,103 @@ void PortPlayback::open(std::string_view name)
|
||||
return static_cast<PortPlayback*>(userData)->writeCallback(inputBuffer, outputBuffer,
|
||||
framesPerBuffer, timeInfo, statusFlags);
|
||||
};
|
||||
PaStream *stream{};
|
||||
while(PaError err{Pa_OpenStream(&stream, nullptr, ¶ms, mDevice->Frequency,
|
||||
mDevice->UpdateSize, paNoFlag, writeCallback, this)})
|
||||
while(PaError err{Pa_OpenStream(&mStream, nullptr, ¶ms, srate, params.updateSize, paNoFlag,
|
||||
writeCallback, this)})
|
||||
{
|
||||
if(params.sampleFormat != paFloat32)
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Failed to open stream: %s",
|
||||
if(params.updateSize != DefaultUpdateSize)
|
||||
params.updateSize = DefaultUpdateSize;
|
||||
else if(srate != 48000u)
|
||||
srate = (srate != 44100u) ? 44100u : 48000u;
|
||||
else if(params.sampleFormat != paInt16)
|
||||
params.sampleFormat = paInt16;
|
||||
else if(params.channelCount != 2)
|
||||
params.channelCount = 2;
|
||||
else
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Failed to open stream: {}",
|
||||
Pa_GetErrorText(err)};
|
||||
params.sampleFormat = paInt16;
|
||||
}
|
||||
|
||||
Pa_CloseStream(mStream);
|
||||
mStream = stream;
|
||||
mParams = params;
|
||||
mUpdateSize = mDevice->UpdateSize;
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
void PortPlayback::open(std::string_view name)
|
||||
{
|
||||
if(DeviceNames.empty())
|
||||
EnumerateDevices();
|
||||
|
||||
PaDeviceIndex deviceid{-1};
|
||||
if(name.empty())
|
||||
{
|
||||
if(auto devidopt = ConfigValueInt({}, "port", "device"))
|
||||
deviceid = *devidopt;
|
||||
if(deviceid < 0 || static_cast<uint>(deviceid) >= DeviceNames.size())
|
||||
deviceid = Pa_GetDefaultOutputDevice();
|
||||
name = DeviceNames.at(static_cast<uint>(deviceid)).mName;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto iter = std::find_if(DeviceNames.cbegin(), DeviceNames.cend(),
|
||||
[name](const DeviceEntry &entry)
|
||||
{ return entry.mPlaybackChannels > 0 && name == entry.mName; });
|
||||
if(iter == DeviceNames.cend())
|
||||
throw al::backend_exception{al::backend_error::NoDevice,
|
||||
"Device name \"{}\" not found", name};
|
||||
deviceid = static_cast<int>(std::distance(DeviceNames.cbegin(), iter));
|
||||
}
|
||||
|
||||
createStream(deviceid);
|
||||
mDeviceIdx = deviceid;
|
||||
|
||||
mDeviceName = name;
|
||||
}
|
||||
|
||||
bool PortPlayback::reset()
|
||||
{
|
||||
if(mStream)
|
||||
{
|
||||
auto err = Pa_CloseStream(mStream);
|
||||
if(err != paNoError)
|
||||
ERR("Error closing stream: {}", Pa_GetErrorText(err));
|
||||
mStream = nullptr;
|
||||
}
|
||||
|
||||
createStream(mDeviceIdx);
|
||||
|
||||
switch(mParams.sampleFormat)
|
||||
{
|
||||
case paFloat32: mDevice->FmtType = DevFmtFloat; break;
|
||||
case paInt32: mDevice->FmtType = DevFmtInt; break;
|
||||
case paInt16: mDevice->FmtType = DevFmtShort; break;
|
||||
case paInt8: mDevice->FmtType = DevFmtByte; break;
|
||||
case paUInt8: mDevice->FmtType = DevFmtUByte; break;
|
||||
default:
|
||||
ERR("Unexpected PortAudio sample format: {}", mParams.sampleFormat);
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Invalid sample format: {}",
|
||||
mParams.sampleFormat};
|
||||
}
|
||||
|
||||
if(mParams.channelCount != static_cast<int>(mDevice->channelsFromFmt()))
|
||||
{
|
||||
if(mParams.channelCount >= 2)
|
||||
mDevice->FmtChans = DevFmtStereo;
|
||||
else if(mParams.channelCount == 1)
|
||||
mDevice->FmtChans = DevFmtMono;
|
||||
mDevice->mAmbiOrder = 0;
|
||||
}
|
||||
|
||||
const PaStreamInfo *streamInfo{Pa_GetStreamInfo(mStream)};
|
||||
mDevice->Frequency = static_cast<uint>(streamInfo->sampleRate);
|
||||
mDevice->UpdateSize = mUpdateSize;
|
||||
|
||||
if(mParams.sampleFormat == paInt8)
|
||||
mDevice->FmtType = DevFmtByte;
|
||||
else if(mParams.sampleFormat == paUInt8)
|
||||
mDevice->FmtType = DevFmtUByte;
|
||||
else if(mParams.sampleFormat == paInt16)
|
||||
mDevice->FmtType = DevFmtShort;
|
||||
else if(mParams.sampleFormat == paInt32)
|
||||
mDevice->FmtType = DevFmtInt;
|
||||
else if(mParams.sampleFormat == paFloat32)
|
||||
mDevice->FmtType = DevFmtFloat;
|
||||
else
|
||||
mDevice->mSampleRate = static_cast<uint>(std::lround(streamInfo->sampleRate));
|
||||
mDevice->mUpdateSize = mParams.updateSize;
|
||||
mDevice->mBufferSize = mDevice->mUpdateSize * 2;
|
||||
if(streamInfo->outputLatency > 0.0f)
|
||||
{
|
||||
ERR("Unexpected sample format: 0x%lx\n", mParams.sampleFormat);
|
||||
return false;
|
||||
const double sampleLatency{streamInfo->outputLatency * streamInfo->sampleRate};
|
||||
TRACE("Reported stream latency: {:f} sec ({:f} samples)", streamInfo->outputLatency,
|
||||
sampleLatency);
|
||||
mDevice->mBufferSize = static_cast<uint>(std::clamp(sampleLatency,
|
||||
double(mDevice->mBufferSize), double{std::numeric_limits<int>::max()}));
|
||||
}
|
||||
|
||||
if(mParams.channelCount >= 2)
|
||||
mDevice->FmtChans = DevFmtStereo;
|
||||
else if(mParams.channelCount == 1)
|
||||
mDevice->FmtChans = DevFmtMono;
|
||||
else
|
||||
{
|
||||
ERR("Unexpected channel count: %u\n", mParams.channelCount);
|
||||
return false;
|
||||
}
|
||||
setDefaultChannelOrder();
|
||||
|
||||
return true;
|
||||
@@ -213,22 +277,20 @@ bool PortPlayback::reset()
|
||||
|
||||
void PortPlayback::start()
|
||||
{
|
||||
const PaError err{Pa_StartStream(mStream)};
|
||||
if(err != paNoError)
|
||||
throw al::backend_exception{al::backend_error::DeviceError, "Failed to start playback: %s",
|
||||
if(const PaError err{Pa_StartStream(mStream)}; err != paNoError)
|
||||
throw al::backend_exception{al::backend_error::DeviceError, "Failed to start playback: {}",
|
||||
Pa_GetErrorText(err)};
|
||||
}
|
||||
|
||||
void PortPlayback::stop()
|
||||
{
|
||||
PaError err{Pa_StopStream(mStream)};
|
||||
if(err != paNoError)
|
||||
ERR("Error stopping stream: %s\n", Pa_GetErrorText(err));
|
||||
if(PaError err{Pa_StopStream(mStream)}; err != paNoError)
|
||||
ERR("Error stopping stream: {}", Pa_GetErrorText(err));
|
||||
}
|
||||
|
||||
|
||||
struct PortCapture final : public BackendBase {
|
||||
PortCapture(DeviceBase *device) noexcept : BackendBase{device} { }
|
||||
explicit PortCapture(DeviceBase *device) noexcept : BackendBase{device} { }
|
||||
~PortCapture() override;
|
||||
|
||||
int readCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
|
||||
@@ -250,7 +312,7 @@ PortCapture::~PortCapture()
|
||||
{
|
||||
PaError err{mStream ? Pa_CloseStream(mStream) : paNoError};
|
||||
if(err != paNoError)
|
||||
ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
|
||||
ERR("Error closing stream: {}", Pa_GetErrorText(err));
|
||||
mStream = nullptr;
|
||||
}
|
||||
|
||||
@@ -265,20 +327,35 @@ int PortCapture::readCallback(const void *inputBuffer, void*, unsigned long fram
|
||||
|
||||
void PortCapture::open(std::string_view name)
|
||||
{
|
||||
if(name.empty())
|
||||
name = GetDefaultName();
|
||||
else if(name != GetDefaultName())
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found",
|
||||
al::sizei(name), name.data()};
|
||||
if(DeviceNames.empty())
|
||||
EnumerateDevices();
|
||||
|
||||
const uint samples{std::max(mDevice->BufferSize, mDevice->Frequency/10u)};
|
||||
int deviceid{};
|
||||
if(name.empty())
|
||||
{
|
||||
if(auto devidopt = ConfigValueInt({}, "port", "capture"))
|
||||
deviceid = *devidopt;
|
||||
if(deviceid < 0 || static_cast<uint>(deviceid) >= DeviceNames.size())
|
||||
deviceid = Pa_GetDefaultInputDevice();
|
||||
name = DeviceNames.at(static_cast<uint>(deviceid)).mName;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto iter = std::find_if(DeviceNames.cbegin(), DeviceNames.cend(),
|
||||
[name](const DeviceEntry &entry)
|
||||
{ return entry.mCaptureChannels > 0 && name == entry.mName; });
|
||||
if(iter == DeviceNames.cend())
|
||||
throw al::backend_exception{al::backend_error::NoDevice,
|
||||
"Device name \"{}\" not found", name};
|
||||
deviceid = static_cast<int>(std::distance(DeviceNames.cbegin(), iter));
|
||||
}
|
||||
|
||||
const uint samples{std::max(mDevice->mBufferSize, mDevice->mSampleRate/10u)};
|
||||
const uint frame_size{mDevice->frameSizeFromFmt()};
|
||||
|
||||
mRing = RingBuffer::Create(samples, frame_size, false);
|
||||
|
||||
auto devidopt = ConfigValueInt({}, "port", "capture");
|
||||
if(devidopt && *devidopt >= 0) mParams.device = *devidopt;
|
||||
else mParams.device = Pa_GetDefaultOutputDevice();
|
||||
mParams.device = deviceid;
|
||||
mParams.suggestedLatency = 0.0f;
|
||||
mParams.hostApiSpecificStreamInfo = nullptr;
|
||||
|
||||
@@ -301,7 +378,7 @@ void PortCapture::open(std::string_view name)
|
||||
break;
|
||||
case DevFmtUInt:
|
||||
case DevFmtUShort:
|
||||
throw al::backend_exception{al::backend_error::DeviceError, "%s samples not supported",
|
||||
throw al::backend_exception{al::backend_error::DeviceError, "{} samples not supported",
|
||||
DevFmtTypeString(mDevice->FmtType)};
|
||||
}
|
||||
mParams.channelCount = static_cast<int>(mDevice->channelsFromFmt());
|
||||
@@ -313,29 +390,27 @@ void PortCapture::open(std::string_view name)
|
||||
return static_cast<PortCapture*>(userData)->readCallback(inputBuffer, outputBuffer,
|
||||
framesPerBuffer, timeInfo, statusFlags);
|
||||
};
|
||||
PaError err{Pa_OpenStream(&mStream, &mParams, nullptr, mDevice->Frequency,
|
||||
PaError err{Pa_OpenStream(&mStream, &mParams, nullptr, mDevice->mSampleRate,
|
||||
paFramesPerBufferUnspecified, paNoFlag, readCallback, this)};
|
||||
if(err != paNoError)
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Failed to open stream: %s",
|
||||
throw al::backend_exception{al::backend_error::NoDevice, "Failed to open stream: {}",
|
||||
Pa_GetErrorText(err)};
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
mDeviceName = name;
|
||||
}
|
||||
|
||||
|
||||
void PortCapture::start()
|
||||
{
|
||||
const PaError err{Pa_StartStream(mStream)};
|
||||
if(err != paNoError)
|
||||
if(const PaError err{Pa_StartStream(mStream)}; err != paNoError)
|
||||
throw al::backend_exception{al::backend_error::DeviceError,
|
||||
"Failed to start recording: %s", Pa_GetErrorText(err)};
|
||||
"Failed to start recording: {}", Pa_GetErrorText(err)};
|
||||
}
|
||||
|
||||
void PortCapture::stop()
|
||||
{
|
||||
PaError err{Pa_StopStream(mStream)};
|
||||
if(err != paNoError)
|
||||
ERR("Error stopping stream: %s\n", Pa_GetErrorText(err));
|
||||
if(PaError err{Pa_StopStream(mStream)}; err != paNoError)
|
||||
ERR("Error stopping stream: {}", Pa_GetErrorText(err));
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +425,7 @@ void PortCapture::captureSamples(std::byte *buffer, uint samples)
|
||||
|
||||
bool PortBackendFactory::init()
|
||||
{
|
||||
#ifdef HAVE_DYNLOAD
|
||||
#if HAVE_DYNLOAD
|
||||
if(!pa_handle)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -383,6 +458,8 @@ bool PortBackendFactory::init()
|
||||
LOAD_FUNC(Pa_StopStream);
|
||||
LOAD_FUNC(Pa_OpenStream);
|
||||
LOAD_FUNC(Pa_CloseStream);
|
||||
LOAD_FUNC(Pa_GetDeviceCount);
|
||||
LOAD_FUNC(Pa_GetDeviceInfo);
|
||||
LOAD_FUNC(Pa_GetDefaultOutputDevice);
|
||||
LOAD_FUNC(Pa_GetDefaultInputDevice);
|
||||
LOAD_FUNC(Pa_GetStreamInfo);
|
||||
@@ -391,7 +468,7 @@ bool PortBackendFactory::init()
|
||||
const PaError err{Pa_Initialize()};
|
||||
if(err != paNoError)
|
||||
{
|
||||
ERR("Pa_Initialize() returned an error: %s\n", Pa_GetErrorText(err));
|
||||
ERR("Pa_Initialize() returned an error: {}", Pa_GetErrorText(err));
|
||||
CloseLib(pa_handle);
|
||||
pa_handle = nullptr;
|
||||
return false;
|
||||
@@ -401,7 +478,7 @@ bool PortBackendFactory::init()
|
||||
const PaError err{Pa_Initialize()};
|
||||
if(err != paNoError)
|
||||
{
|
||||
ERR("Pa_Initialize() returned an error: %s\n", Pa_GetErrorText(err));
|
||||
ERR("Pa_Initialize() returned an error: {}", Pa_GetErrorText(err));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@@ -411,16 +488,52 @@ bool PortBackendFactory::init()
|
||||
bool PortBackendFactory::querySupport(BackendType type)
|
||||
{ return (type == BackendType::Playback || type == BackendType::Capture); }
|
||||
|
||||
std::string PortBackendFactory::probe(BackendType type)
|
||||
auto PortBackendFactory::enumerate(BackendType type) -> std::vector<std::string>
|
||||
{
|
||||
std::vector<std::string> devices;
|
||||
|
||||
EnumerateDevices();
|
||||
int defaultid{-1};
|
||||
switch(type)
|
||||
{
|
||||
case BackendType::Playback:
|
||||
defaultid = Pa_GetDefaultOutputDevice();
|
||||
if(auto devidopt = ConfigValueInt({}, "port", "device"); devidopt && *devidopt >= 0
|
||||
&& static_cast<uint>(*devidopt) < DeviceNames.size())
|
||||
defaultid = *devidopt;
|
||||
|
||||
for(size_t i{0};i < DeviceNames.size();++i)
|
||||
{
|
||||
if(DeviceNames[i].mPlaybackChannels > 0)
|
||||
{
|
||||
if(defaultid >= 0 && static_cast<uint>(defaultid) == i)
|
||||
devices.emplace(devices.cbegin(), DeviceNames[i].mName);
|
||||
else
|
||||
devices.emplace_back(DeviceNames[i].mName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BackendType::Capture:
|
||||
/* Include null char. */
|
||||
return std::string{GetDefaultName()} + '\0';
|
||||
defaultid = Pa_GetDefaultInputDevice();
|
||||
if(auto devidopt = ConfigValueInt({}, "port", "capture"); devidopt && *devidopt >= 0
|
||||
&& static_cast<uint>(*devidopt) < DeviceNames.size())
|
||||
defaultid = *devidopt;
|
||||
|
||||
for(size_t i{0};i < DeviceNames.size();++i)
|
||||
{
|
||||
if(DeviceNames[i].mCaptureChannels > 0)
|
||||
{
|
||||
if(defaultid >= 0 && static_cast<uint>(defaultid) == i)
|
||||
devices.emplace(devices.cbegin(), DeviceNames[i].mName);
|
||||
else
|
||||
devices.emplace_back(DeviceNames[i].mName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return std::string{};
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
BackendPtr PortBackendFactory::createBackend(DeviceBase *device, BackendType type)
|
||||
|
||||
Reference in New Issue
Block a user