Use a bitfield for the device flags
This commit is contained in:
+41
-43
@@ -1617,9 +1617,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
/* If a context is already running on the device, stop playback so
|
||||
* the device attributes can be updated.
|
||||
*/
|
||||
if((device->Flags&DEVICE_RUNNING))
|
||||
if(device->Flags.get(DeviceRunning))
|
||||
device->Backend->stop();
|
||||
device->Flags &= ~DEVICE_RUNNING;
|
||||
device->Flags.unset(DeviceRunning);
|
||||
}
|
||||
|
||||
auto numMono = static_cast<ALsizei>(device->NumMonoSources);
|
||||
@@ -1734,9 +1734,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
}
|
||||
}
|
||||
|
||||
if((device->Flags&DEVICE_RUNNING))
|
||||
if(device->Flags.get(DeviceRunning))
|
||||
device->Backend->stop();
|
||||
device->Flags &= ~DEVICE_RUNNING;
|
||||
device->Flags.unset(DeviceRunning);
|
||||
|
||||
UpdateClockBase(device);
|
||||
|
||||
@@ -1748,7 +1748,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
|
||||
ConfigValueUInt(devname, nullptr, "frequency", &freq);
|
||||
if(freq < 1)
|
||||
device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
|
||||
device->Flags.unset(FrequencyRequest);
|
||||
else
|
||||
{
|
||||
freq = maxi(freq, MIN_OUTPUT_RATE);
|
||||
@@ -1759,7 +1759,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
device->Frequency;
|
||||
|
||||
device->Frequency = freq;
|
||||
device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
||||
device->Flags.set(FrequencyRequest);
|
||||
}
|
||||
|
||||
ConfigValueUInt(devname, nullptr, "period_size", &device->UpdateSize);
|
||||
@@ -1807,7 +1807,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
new_sends = numSends;
|
||||
}
|
||||
|
||||
if((device->Flags&DEVICE_RUNNING))
|
||||
if(device->Flags.get(DeviceRunning))
|
||||
return ALC_NO_ERROR;
|
||||
|
||||
device->Uhj_Encoder = nullptr;
|
||||
@@ -1862,7 +1862,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
{
|
||||
device->FmtChans = DevFmtStereo;
|
||||
device->Frequency = hrtf->sampleRate;
|
||||
device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_FREQUENCY_REQUEST;
|
||||
device->Flags.set(ChannelsRequest, FrequencyRequest);
|
||||
if(HrtfEntry *oldhrtf{device->mHrtf})
|
||||
oldhrtf->DecRef();
|
||||
device->mHrtf = hrtf;
|
||||
@@ -1881,9 +1881,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
oldType = device->FmtType;
|
||||
|
||||
TRACE("Pre-reset: %s%s, %s%s, %s%uhz, %u / %u buffer\n",
|
||||
(device->Flags&DEVICE_CHANNELS_REQUEST)?"*":"", DevFmtChannelsString(device->FmtChans),
|
||||
(device->Flags&DEVICE_SAMPLE_TYPE_REQUEST)?"*":"", DevFmtTypeString(device->FmtType),
|
||||
(device->Flags&DEVICE_FREQUENCY_REQUEST)?"*":"", device->Frequency,
|
||||
device->Flags.get(ChannelsRequest)?"*":"", DevFmtChannelsString(device->FmtChans),
|
||||
device->Flags.get(SampleTypeRequest)?"*":"", DevFmtTypeString(device->FmtType),
|
||||
device->Flags.get(FrequencyRequest)?"*":"", device->Frequency,
|
||||
device->UpdateSize, device->BufferSize);
|
||||
|
||||
try {
|
||||
@@ -1895,22 +1895,22 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
return ALC_INVALID_DEVICE;
|
||||
}
|
||||
|
||||
if(device->FmtChans != oldChans && (device->Flags&DEVICE_CHANNELS_REQUEST))
|
||||
if(device->FmtChans != oldChans && device->Flags.get(ChannelsRequest))
|
||||
{
|
||||
ERR("Failed to set %s, got %s instead\n", DevFmtChannelsString(oldChans),
|
||||
DevFmtChannelsString(device->FmtChans));
|
||||
device->Flags &= ~DEVICE_CHANNELS_REQUEST;
|
||||
device->Flags.unset(ChannelsRequest);
|
||||
}
|
||||
if(device->FmtType != oldType && (device->Flags&DEVICE_SAMPLE_TYPE_REQUEST))
|
||||
if(device->FmtType != oldType && device->Flags.get(SampleTypeRequest))
|
||||
{
|
||||
ERR("Failed to set %s, got %s instead\n", DevFmtTypeString(oldType),
|
||||
DevFmtTypeString(device->FmtType));
|
||||
device->Flags &= ~DEVICE_SAMPLE_TYPE_REQUEST;
|
||||
device->Flags.unset(SampleTypeRequest);
|
||||
}
|
||||
if(device->Frequency != oldFreq && (device->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
if(device->Frequency != oldFreq && device->Flags.get(FrequencyRequest))
|
||||
{
|
||||
ERR("Failed to set %uhz, got %uhz instead\n", oldFreq, device->Frequency);
|
||||
device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
|
||||
device->Flags.unset(FrequencyRequest);
|
||||
}
|
||||
|
||||
if((device->UpdateSize&3) != 0)
|
||||
@@ -2181,11 +2181,11 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
if(update_failed)
|
||||
return ALC_INVALID_DEVICE;
|
||||
|
||||
if(!(device->Flags&DEVICE_PAUSED))
|
||||
if(!device->Flags.get(DevicePaused))
|
||||
{
|
||||
if(device->Backend->start() == ALC_FALSE)
|
||||
return ALC_INVALID_DEVICE;
|
||||
device->Flags |= DEVICE_RUNNING;
|
||||
device->Flags.set(DeviceRunning);
|
||||
}
|
||||
|
||||
return ALC_NO_ERROR;
|
||||
@@ -3525,10 +3525,10 @@ START_API_FUNC
|
||||
if(ALCdevice *Device{ctx->Device})
|
||||
{
|
||||
std::lock_guard<std::mutex> _{Device->StateLock};
|
||||
if(!ReleaseContext(ctx.get(), Device) && (Device->Flags&DEVICE_RUNNING))
|
||||
if(!ReleaseContext(ctx.get(), Device) && Device->Flags.get(DeviceRunning))
|
||||
{
|
||||
Device->Backend->stop();
|
||||
Device->Flags &= ~DEVICE_RUNNING;
|
||||
Device->Flags.unset(DeviceRunning);
|
||||
}
|
||||
}
|
||||
listlock.unlock();
|
||||
@@ -3731,7 +3731,7 @@ START_API_FUNC
|
||||
{
|
||||
device->FmtChans = iter->chans;
|
||||
device->mAmbiOrder = iter->order;
|
||||
device->Flags |= DEVICE_CHANNELS_REQUEST;
|
||||
device->Flags.set(ChannelsRequest);
|
||||
}
|
||||
}
|
||||
if(ConfigValueStr(deviceName, nullptr, "sample-type", &fmt))
|
||||
@@ -3758,7 +3758,7 @@ START_API_FUNC
|
||||
else
|
||||
{
|
||||
device->FmtType = iter->type;
|
||||
device->Flags |= DEVICE_SAMPLE_TYPE_REQUEST;
|
||||
device->Flags.set(SampleTypeRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3773,7 +3773,7 @@ START_API_FUNC
|
||||
device->UpdateSize = (device->UpdateSize*freq + device->Frequency/2) / device->Frequency;
|
||||
device->BufferSize = (device->BufferSize*freq + device->Frequency/2) / device->Frequency;
|
||||
device->Frequency = freq;
|
||||
device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
||||
device->Flags.set(FrequencyRequest);
|
||||
}
|
||||
|
||||
ConfigValueUInt(deviceName, nullptr, "period_size", &device->UpdateSize);
|
||||
@@ -3887,9 +3887,9 @@ START_API_FUNC
|
||||
ReleaseContext(ctx, device);
|
||||
ctx = next;
|
||||
}
|
||||
if((device->Flags&DEVICE_RUNNING))
|
||||
if(device->Flags.get(DeviceRunning))
|
||||
device->Backend->stop();
|
||||
device->Flags &= ~DEVICE_RUNNING;
|
||||
device->Flags.unset(DeviceRunning);
|
||||
statelock.unlock();
|
||||
|
||||
ALCdevice_DecRef(device);
|
||||
@@ -3925,14 +3925,12 @@ START_API_FUNC
|
||||
DeviceRef device{new ALCdevice{Capture}};
|
||||
|
||||
device->Frequency = frequency;
|
||||
device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
||||
|
||||
if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
|
||||
{
|
||||
alcSetError(nullptr, ALC_INVALID_ENUM);
|
||||
return nullptr;
|
||||
}
|
||||
device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_SAMPLE_TYPE_REQUEST;
|
||||
device->Flags.set(FrequencyRequest, ChannelsRequest, SampleTypeRequest);
|
||||
|
||||
device->UpdateSize = samples;
|
||||
device->BufferSize = samples;
|
||||
@@ -3989,9 +3987,9 @@ START_API_FUNC
|
||||
listlock.unlock();
|
||||
|
||||
{ std::lock_guard<std::mutex> _{device->StateLock};
|
||||
if((device->Flags&DEVICE_RUNNING))
|
||||
if(device->Flags.get(DeviceRunning))
|
||||
device->Backend->stop();
|
||||
device->Flags &= ~DEVICE_RUNNING;
|
||||
device->Flags.unset(DeviceRunning);
|
||||
}
|
||||
|
||||
ALCdevice_DecRef(device);
|
||||
@@ -4013,10 +4011,10 @@ START_API_FUNC
|
||||
std::lock_guard<std::mutex> _{dev->StateLock};
|
||||
if(!dev->Connected.load(std::memory_order_acquire))
|
||||
alcSetError(dev.get(), ALC_INVALID_DEVICE);
|
||||
else if(!(dev->Flags&DEVICE_RUNNING))
|
||||
else if(!dev->Flags.get(DeviceRunning))
|
||||
{
|
||||
if(dev->Backend->start())
|
||||
dev->Flags |= DEVICE_RUNNING;
|
||||
dev->Flags.set(DeviceRunning);
|
||||
else
|
||||
{
|
||||
aluHandleDisconnect(dev.get(), "Device start failure");
|
||||
@@ -4035,9 +4033,9 @@ START_API_FUNC
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> _{dev->StateLock};
|
||||
if((dev->Flags&DEVICE_RUNNING))
|
||||
if(dev->Flags.get(DeviceRunning))
|
||||
dev->Backend->stop();
|
||||
dev->Flags &= ~DEVICE_RUNNING;
|
||||
dev->Flags.unset(DeviceRunning);
|
||||
}
|
||||
}
|
||||
END_API_FUNC
|
||||
@@ -4199,10 +4197,10 @@ START_API_FUNC
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> _{dev->StateLock};
|
||||
if((dev->Flags&DEVICE_RUNNING))
|
||||
if(dev->Flags.get(DeviceRunning))
|
||||
dev->Backend->stop();
|
||||
dev->Flags &= ~DEVICE_RUNNING;
|
||||
dev->Flags |= DEVICE_PAUSED;
|
||||
dev->Flags.unset(DeviceRunning);
|
||||
dev->Flags.set(DevicePaused);
|
||||
}
|
||||
}
|
||||
END_API_FUNC
|
||||
@@ -4222,9 +4220,9 @@ START_API_FUNC
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> _{dev->StateLock};
|
||||
if(!(dev->Flags&DEVICE_PAUSED))
|
||||
if(!dev->Flags.get(DevicePaused))
|
||||
return;
|
||||
dev->Flags &= ~DEVICE_PAUSED;
|
||||
dev->Flags.unset(DevicePaused);
|
||||
if(dev->ContextList.load() == nullptr)
|
||||
return;
|
||||
|
||||
@@ -4234,7 +4232,7 @@ START_API_FUNC
|
||||
alcSetError(dev.get(), ALC_INVALID_DEVICE);
|
||||
return;
|
||||
}
|
||||
dev->Flags |= DEVICE_RUNNING;
|
||||
dev->Flags.set(DeviceRunning);
|
||||
}
|
||||
END_API_FUNC
|
||||
|
||||
@@ -4291,9 +4289,9 @@ START_API_FUNC
|
||||
/* Force the backend to stop mixing first since we're resetting. Also reset
|
||||
* the connected state so lost devices can attempt recover.
|
||||
*/
|
||||
if((dev->Flags&DEVICE_RUNNING))
|
||||
if(dev->Flags.get(DeviceRunning))
|
||||
dev->Backend->stop();
|
||||
dev->Flags &= ~DEVICE_RUNNING;
|
||||
dev->Flags.unset(DeviceRunning);
|
||||
device->Connected.store(true);
|
||||
|
||||
ALCenum err{UpdateDeviceParams(dev.get(), attribs)};
|
||||
|
||||
@@ -725,7 +725,7 @@ ALCboolean AlsaPlayback::reset()
|
||||
CHECK(snd_pcm_hw_params_set_channels(mPcmHandle, hp, mDevice->channelsFromFmt()));
|
||||
/* set rate (implicitly constrains period/buffer parameters) */
|
||||
if(!GetConfigValueBool(mDevice->DeviceName.c_str(), "alsa", "allow-resampler", 0) ||
|
||||
!(mDevice->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
!mDevice->Flags.get(FrequencyRequest))
|
||||
{
|
||||
if(snd_pcm_hw_params_set_rate_resample(mPcmHandle, hp, 0) < 0)
|
||||
ERR("Failed to disable ALSA resampler\n");
|
||||
|
||||
@@ -359,7 +359,7 @@ ALCboolean DSoundPlayback::reset()
|
||||
mDevice->FmtType = DevFmtUByte;
|
||||
break;
|
||||
case DevFmtFloat:
|
||||
if((mDevice->Flags&DEVICE_SAMPLE_TYPE_REQUEST))
|
||||
if(mDevice->Flags.get(SampleTypeRequest))
|
||||
break;
|
||||
/* fall-through */
|
||||
case DevFmtUShort:
|
||||
@@ -380,7 +380,7 @@ ALCboolean DSoundPlayback::reset()
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
speakers = DSSPEAKER_CONFIG(speakers);
|
||||
if(!(mDevice->Flags&DEVICE_CHANNELS_REQUEST))
|
||||
if(!mDevice->Flags.get(ChannelsRequest))
|
||||
{
|
||||
if(speakers == DSSPEAKER_MONO)
|
||||
mDevice->FmtChans = DevFmtMono;
|
||||
|
||||
@@ -361,7 +361,7 @@ ALCboolean OpenSLPlayback::reset()
|
||||
mRing = nullptr;
|
||||
|
||||
#if 0
|
||||
if(!(mDevice->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
if(!mDevice->Flags.get(FrequencyRequest))
|
||||
{
|
||||
/* FIXME: Disabled until I figure out how to get the Context needed for
|
||||
* the getSystemService call.
|
||||
|
||||
@@ -779,7 +779,7 @@ void PulsePlayback::sinkInfoCallback(pa_context* UNUSED(context), const pa_sink_
|
||||
);
|
||||
if(chanmap != chanmaps.cend())
|
||||
{
|
||||
if(!(mDevice->Flags&DEVICE_CHANNELS_REQUEST))
|
||||
if(!mDevice->Flags.get(ChannelsRequest))
|
||||
mDevice->FmtChans = chanmap->chans;
|
||||
}
|
||||
else
|
||||
@@ -910,7 +910,7 @@ ALCboolean PulsePlayback::reset()
|
||||
flags |= PA_STREAM_ADJUST_LATENCY;
|
||||
}
|
||||
if(GetConfigValueBool(mDevice->DeviceName.c_str(), "pulse", "fix-rate", 0) ||
|
||||
!(mDevice->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
!mDevice->Flags.get(FrequencyRequest))
|
||||
flags |= PA_STREAM_FIX_RATE;
|
||||
|
||||
pa_channel_map chanmap{};
|
||||
|
||||
@@ -787,9 +787,9 @@ HRESULT WasapiPlayback::resetProxy()
|
||||
const REFERENCE_TIME per_time{mDevice->UpdateSize * REFTIME_PER_SEC / mDevice->Frequency};
|
||||
const REFERENCE_TIME buf_time{mDevice->BufferSize * REFTIME_PER_SEC / mDevice->Frequency};
|
||||
|
||||
if(!(mDevice->Flags&DEVICE_FREQUENCY_REQUEST))
|
||||
if(!mDevice->Flags.get(FrequencyRequest))
|
||||
mDevice->Frequency = OutputType.Format.nSamplesPerSec;
|
||||
if(!(mDevice->Flags&DEVICE_CHANNELS_REQUEST))
|
||||
if(!mDevice->Flags.get(ChannelsRequest))
|
||||
{
|
||||
if(OutputType.Format.nChannels == 1 && OutputType.dwChannelMask == MONO)
|
||||
mDevice->FmtChans = DevFmtMono;
|
||||
|
||||
+18
-15
@@ -26,6 +26,7 @@
|
||||
#include "inprogext.h"
|
||||
#include "atomic.h"
|
||||
#include "vector.h"
|
||||
#include "albyte.h"
|
||||
#include "almalloc.h"
|
||||
#include "alnumeric.h"
|
||||
#include "alspan.h"
|
||||
@@ -322,6 +323,22 @@ struct RealMixParams {
|
||||
|
||||
using POSTPROCESS = void(*)(ALCdevice *device, const ALsizei SamplesToDo);
|
||||
|
||||
enum {
|
||||
// Frequency was requested by the app or config file
|
||||
FrequencyRequest,
|
||||
// Channel configuration was requested by the config file
|
||||
ChannelsRequest,
|
||||
// Sample type was requested by the config file
|
||||
SampleTypeRequest,
|
||||
|
||||
// Specifies if the DSP is paused at user request
|
||||
DevicePaused,
|
||||
// Specifies if the device is currently running
|
||||
DeviceRunning,
|
||||
|
||||
DeviceFlagsCount
|
||||
};
|
||||
|
||||
struct ALCdevice {
|
||||
RefCount ref{1u};
|
||||
|
||||
@@ -347,7 +364,7 @@ struct ALCdevice {
|
||||
std::string DeviceName;
|
||||
|
||||
// Device flags
|
||||
ALuint Flags{0u};
|
||||
al::bitfield<DeviceFlagsCount> Flags{};
|
||||
|
||||
std::string HrtfName;
|
||||
al::vector<EnumeratedHrtf> HrtfList;
|
||||
@@ -466,20 +483,6 @@ struct ALCdevice {
|
||||
DEF_NEWDEL(ALCdevice)
|
||||
};
|
||||
|
||||
// Frequency was requested by the app or config file
|
||||
#define DEVICE_FREQUENCY_REQUEST (1u<<1)
|
||||
// Channel configuration was requested by the config file
|
||||
#define DEVICE_CHANNELS_REQUEST (1u<<2)
|
||||
// Sample type was requested by the config file
|
||||
#define DEVICE_SAMPLE_TYPE_REQUEST (1u<<3)
|
||||
|
||||
// Specifies if the DSP is paused at user request
|
||||
#define DEVICE_PAUSED (1u<<30)
|
||||
|
||||
// Specifies if the device is currently running
|
||||
#define DEVICE_RUNNING (1u<<31)
|
||||
|
||||
|
||||
/* Must be less than 15 characters (16 including terminating null) for
|
||||
* compatibility with pthread_setname_np limitations. */
|
||||
#define MIXER_THREAD_NAME "alsoft-mixer"
|
||||
|
||||
Reference in New Issue
Block a user