Enable real-time priority for ALSA, OSS, and DirectSound mixing loops
This commit is contained in:
parent
15aad09ce7
commit
f63d8dbf38
16
Alc/alsa.c
16
Alc/alsa.c
@ -271,6 +271,8 @@ static ALuint ALSAProc(ALvoid *ptr)
|
||||
char *WritePtr;
|
||||
int err;
|
||||
|
||||
EnableRTPrio();
|
||||
|
||||
while(!data->killNow)
|
||||
{
|
||||
int state = verify_state(data->pcmHandle);
|
||||
@ -343,6 +345,8 @@ static ALuint ALSANoMMapProc(ALvoid *ptr)
|
||||
snd_pcm_sframes_t avail;
|
||||
char *WritePtr;
|
||||
|
||||
EnableRTPrio();
|
||||
|
||||
while(!data->killNow)
|
||||
{
|
||||
int state = verify_state(data->pcmHandle);
|
||||
@ -396,6 +400,8 @@ static ALuint ALSANoMMapCaptureProc(ALvoid *ptr)
|
||||
alsa_data *data = (alsa_data*)pDevice->ExtraData;
|
||||
snd_pcm_sframes_t avail;
|
||||
|
||||
EnableRTPrio();
|
||||
|
||||
while(!data->killNow)
|
||||
{
|
||||
int state = verify_state(data->pcmHandle);
|
||||
@ -669,6 +675,9 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
|
||||
AL_PRINT("buffer malloc failed\n");
|
||||
return ALC_FALSE;
|
||||
}
|
||||
device->UpdateSize = periodSizeInFrames;
|
||||
device->NumUpdates = periods;
|
||||
device->Frequency = rate;
|
||||
data->thread = StartThread(ALSANoMMapProc, device);
|
||||
}
|
||||
else
|
||||
@ -679,6 +688,9 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
|
||||
AL_PRINT("prepare error: %s\n", psnd_strerror(i));
|
||||
return ALC_FALSE;
|
||||
}
|
||||
device->UpdateSize = periodSizeInFrames;
|
||||
device->NumUpdates = periods;
|
||||
device->Frequency = rate;
|
||||
data->thread = StartThread(ALSAProc, device);
|
||||
}
|
||||
if(data->thread == NULL)
|
||||
@ -689,10 +701,6 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->UpdateSize = periodSizeInFrames;
|
||||
device->NumUpdates = periods;
|
||||
device->Frequency = rate;
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,8 @@ static ALuint DSoundProc(ALvoid *ptr)
|
||||
DWORD avail;
|
||||
HRESULT err;
|
||||
|
||||
EnableRTPrio();
|
||||
|
||||
memset(&DSBCaps, 0, sizeof(DSBCaps));
|
||||
DSBCaps.dwSize = sizeof(DSBCaps);
|
||||
err = IDirectSoundBuffer_GetCaps(pData->DSsbuffer, &DSBCaps);
|
||||
@ -413,6 +415,7 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device)
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
device->ExtraData = pData;
|
||||
device->Format = format;
|
||||
pData->thread = StartThread(DSoundProc, device);
|
||||
if(!pData->thread)
|
||||
hr = E_FAIL;
|
||||
@ -429,8 +432,6 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device)
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->Format = format;
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,8 @@ static ALuint OSSProc(ALvoid *ptr)
|
||||
ALint frameSize;
|
||||
ssize_t wrote;
|
||||
|
||||
EnableRTPrio();
|
||||
|
||||
frameSize = aluChannelsFromFormat(pDevice->Format) *
|
||||
aluBytesFromFormat(pDevice->Format);
|
||||
|
||||
@ -122,6 +124,8 @@ static ALuint OSSCaptureProc(ALvoid *ptr)
|
||||
int frameSize;
|
||||
int amt;
|
||||
|
||||
EnableRTPrio();
|
||||
|
||||
frameSize = aluBytesFromFormat(pDevice->Format);
|
||||
frameSize *= aluChannelsFromFormat(pDevice->Format);
|
||||
|
||||
|
@ -181,6 +181,22 @@ static __inline ALuint NextPowerOf2(ALuint value)
|
||||
return powerOf2;
|
||||
}
|
||||
|
||||
static __inline void EnableRTPrio()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
||||
#elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
|
||||
struct sched_param param;
|
||||
|
||||
/* Use the minimum real-time priority possible for now (on Linux this
|
||||
* should be 1 for SCHED_RR) */
|
||||
param.sched_priority = sched_get_priority_min(SCHED_RR);
|
||||
pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
||||
#else
|
||||
/* Real-time priority not available */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
|
||||
|
Loading…
x
Reference in New Issue
Block a user