Commit 192a84a1 authored by David Reid's avatar David Reid

Revert 2 PulseAudio related commits.

This reverts the following commits:

d46e19fb
  "PulseAudio: Attempt to fix a deadlock."

61586de2
  "PulseAudio: Default to a blocking main loop."
parent 0d0953aa
...@@ -7110,7 +7110,6 @@ struct ma_device_config ...@@ -7110,7 +7110,6 @@ struct ma_device_config
const char* pStreamNamePlayback; const char* pStreamNamePlayback;
const char* pStreamNameCapture; const char* pStreamNameCapture;
int channelMap; int channelMap;
ma_bool32 blockingMainLoop;
} pulse; } pulse;
struct struct
{ {
...@@ -7812,7 +7811,7 @@ struct ma_device ...@@ -7812,7 +7811,7 @@ struct ma_device
union union
{ {
#ifdef MA_SUPPORT_WASAPI #ifdef MA_SUPPORT_WASAPI
struct struct
{ {
/*IAudioClient**/ ma_ptr pAudioClientPlayback; /*IAudioClient**/ ma_ptr pAudioClientPlayback;
...@@ -7852,8 +7851,8 @@ struct ma_device ...@@ -7852,8 +7851,8 @@ struct ma_device
void* hAvrtHandle; void* hAvrtHandle;
ma_mutex rerouteLock; ma_mutex rerouteLock;
} wasapi; } wasapi;
#endif #endif
#ifdef MA_SUPPORT_DSOUND #ifdef MA_SUPPORT_DSOUND
struct struct
{ {
/*LPDIRECTSOUND*/ ma_ptr pPlayback; /*LPDIRECTSOUND*/ ma_ptr pPlayback;
...@@ -7862,8 +7861,8 @@ struct ma_device ...@@ -7862,8 +7861,8 @@ struct ma_device
/*LPDIRECTSOUNDCAPTURE*/ ma_ptr pCapture; /*LPDIRECTSOUNDCAPTURE*/ ma_ptr pCapture;
/*LPDIRECTSOUNDCAPTUREBUFFER*/ ma_ptr pCaptureBuffer; /*LPDIRECTSOUNDCAPTUREBUFFER*/ ma_ptr pCaptureBuffer;
} dsound; } dsound;
#endif #endif
#ifdef MA_SUPPORT_WINMM #ifdef MA_SUPPORT_WINMM
struct struct
{ {
/*HWAVEOUT*/ ma_handle hDevicePlayback; /*HWAVEOUT*/ ma_handle hDevicePlayback;
...@@ -7881,8 +7880,8 @@ struct ma_device ...@@ -7881,8 +7880,8 @@ struct ma_device
ma_uint8* pIntermediaryBufferCapture; ma_uint8* pIntermediaryBufferCapture;
ma_uint8* _pHeapData; /* Used internally and is used for the heap allocated data for the intermediary buffer and the WAVEHDR structures. */ ma_uint8* _pHeapData; /* Used internally and is used for the heap allocated data for the intermediary buffer and the WAVEHDR structures. */
} winmm; } winmm;
#endif #endif
#ifdef MA_SUPPORT_ALSA #ifdef MA_SUPPORT_ALSA
struct struct
{ {
/*snd_pcm_t**/ ma_ptr pPCMPlayback; /*snd_pcm_t**/ ma_ptr pPCMPlayback;
...@@ -7896,18 +7895,17 @@ struct ma_device ...@@ -7896,18 +7895,17 @@ struct ma_device
ma_bool8 isUsingMMapPlayback; ma_bool8 isUsingMMapPlayback;
ma_bool8 isUsingMMapCapture; ma_bool8 isUsingMMapCapture;
} alsa; } alsa;
#endif #endif
#ifdef MA_SUPPORT_PULSEAUDIO #ifdef MA_SUPPORT_PULSEAUDIO
struct struct
{ {
/*pa_mainloop**/ ma_ptr pMainLoop; /*pa_mainloop**/ ma_ptr pMainLoop;
/*pa_context**/ ma_ptr pPulseContext; /*pa_context**/ ma_ptr pPulseContext;
/*pa_stream**/ ma_ptr pStreamPlayback; /*pa_stream**/ ma_ptr pStreamPlayback;
/*pa_stream**/ ma_ptr pStreamCapture; /*pa_stream**/ ma_ptr pStreamCapture;
ma_bool32 blockingMainLoop;
} pulse; } pulse;
#endif #endif
#ifdef MA_SUPPORT_JACK #ifdef MA_SUPPORT_JACK
struct struct
{ {
/*jack_client_t**/ ma_ptr pClient; /*jack_client_t**/ ma_ptr pClient;
...@@ -7916,8 +7914,8 @@ struct ma_device ...@@ -7916,8 +7914,8 @@ struct ma_device
float* pIntermediaryBufferPlayback; /* Typed as a float because JACK is always floating point. */ float* pIntermediaryBufferPlayback; /* Typed as a float because JACK is always floating point. */
float* pIntermediaryBufferCapture; float* pIntermediaryBufferCapture;
} jack; } jack;
#endif #endif
#ifdef MA_SUPPORT_COREAUDIO #ifdef MA_SUPPORT_COREAUDIO
struct struct
{ {
ma_uint32 deviceObjectIDPlayback; ma_uint32 deviceObjectIDPlayback;
...@@ -7937,8 +7935,8 @@ struct ma_device ...@@ -7937,8 +7935,8 @@ struct ma_device
ma_bool32 isSwitchingCaptureDevice; /* <-- Set to true when the default device has changed and miniaudio is in the process of switching. */ ma_bool32 isSwitchingCaptureDevice; /* <-- Set to true when the default device has changed and miniaudio is in the process of switching. */
void* pNotificationHandler; /* Only used on mobile platforms. Obj-C object for handling route changes. */ void* pNotificationHandler; /* Only used on mobile platforms. Obj-C object for handling route changes. */
} coreaudio; } coreaudio;
#endif #endif
#ifdef MA_SUPPORT_SNDIO #ifdef MA_SUPPORT_SNDIO
struct struct
{ {
ma_ptr handlePlayback; ma_ptr handlePlayback;
...@@ -7946,22 +7944,22 @@ struct ma_device ...@@ -7946,22 +7944,22 @@ struct ma_device
ma_bool32 isStartedPlayback; ma_bool32 isStartedPlayback;
ma_bool32 isStartedCapture; ma_bool32 isStartedCapture;
} sndio; } sndio;
#endif #endif
#ifdef MA_SUPPORT_AUDIO4 #ifdef MA_SUPPORT_AUDIO4
struct struct
{ {
int fdPlayback; int fdPlayback;
int fdCapture; int fdCapture;
} audio4; } audio4;
#endif #endif
#ifdef MA_SUPPORT_OSS #ifdef MA_SUPPORT_OSS
struct struct
{ {
int fdPlayback; int fdPlayback;
int fdCapture; int fdCapture;
} oss; } oss;
#endif #endif
#ifdef MA_SUPPORT_AAUDIO #ifdef MA_SUPPORT_AAUDIO
struct struct
{ {
/*AAudioStream**/ ma_ptr pStreamPlayback; /*AAudioStream**/ ma_ptr pStreamPlayback;
...@@ -7972,8 +7970,8 @@ struct ma_device ...@@ -7972,8 +7970,8 @@ struct ma_device
ma_aaudio_allowed_capture_policy allowedCapturePolicy; ma_aaudio_allowed_capture_policy allowedCapturePolicy;
ma_bool32 noAutoStartAfterReroute; ma_bool32 noAutoStartAfterReroute;
} aaudio; } aaudio;
#endif #endif
#ifdef MA_SUPPORT_OPENSL #ifdef MA_SUPPORT_OPENSL
struct struct
{ {
/*SLObjectItf*/ ma_ptr pOutputMixObj; /*SLObjectItf*/ ma_ptr pOutputMixObj;
...@@ -7991,8 +7989,8 @@ struct ma_device ...@@ -7991,8 +7989,8 @@ struct ma_device
ma_uint8* pBufferPlayback; /* This is malloc()'d and is used for storing audio data. Typed as ma_uint8 for easy offsetting. */ ma_uint8* pBufferPlayback; /* This is malloc()'d and is used for storing audio data. Typed as ma_uint8 for easy offsetting. */
ma_uint8* pBufferCapture; ma_uint8* pBufferCapture;
} opensl; } opensl;
#endif #endif
#ifdef MA_SUPPORT_WEBAUDIO #ifdef MA_SUPPORT_WEBAUDIO
struct struct
{ {
/* AudioWorklets path. */ /* AudioWorklets path. */
...@@ -8003,8 +8001,8 @@ struct ma_device ...@@ -8003,8 +8001,8 @@ struct ma_device
ma_result initResult; /* Set to MA_BUSY while initialization is in progress. */ ma_result initResult; /* Set to MA_BUSY while initialization is in progress. */
int deviceIndex; /* We store the device in a list on the JavaScript side. This is used to map our C object to the JS object. */ int deviceIndex; /* We store the device in a list on the JavaScript side. This is used to map our C object to the JS object. */
} webaudio; } webaudio;
#endif #endif
#ifdef MA_SUPPORT_NULL #ifdef MA_SUPPORT_NULL
struct struct
{ {
ma_thread deviceThread; ma_thread deviceThread;
...@@ -8021,7 +8019,7 @@ struct ma_device ...@@ -8021,7 +8019,7 @@ struct ma_device
ma_uint64 lastProcessedFrameCapture; ma_uint64 lastProcessedFrameCapture;
ma_atomic_bool32 isStarted; /* Read and written by multiple threads. Must be used atomically, and must be 32-bit for compiler compatibility. */ ma_atomic_bool32 isStarted; /* Read and written by multiple threads. Must be used atomically, and must be 32-bit for compiler compatibility. */
} null_device; } null_device;
#endif #endif
}; };
}; };
#if defined(_MSC_VER) && !defined(__clang__) #if defined(_MSC_VER) && !defined(__clang__)
...@@ -30475,7 +30473,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi ...@@ -30475,7 +30473,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
sampleRate = pDescriptorCapture->sampleRate; sampleRate = pDescriptorCapture->sampleRate;
} }
pDevice->pulse.blockingMainLoop = pConfig->pulse.blockingMainLoop;
result = ma_init_pa_mainloop_and_pa_context__pulse(pDevice->pContext, pDevice->pContext->pulse.pApplicationName, pDevice->pContext->pulse.pServerName, MA_FALSE, &pDevice->pulse.pMainLoop, &pDevice->pulse.pPulseContext); result = ma_init_pa_mainloop_and_pa_context__pulse(pDevice->pContext, pDevice->pContext->pulse.pApplicationName, pDevice->pContext->pulse.pServerName, MA_FALSE, &pDevice->pulse.pMainLoop, &pDevice->pulse.pPulseContext);
...@@ -30961,50 +30958,10 @@ static ma_result ma_device_data_loop__pulse(ma_device* pDevice) ...@@ -30961,50 +30958,10 @@ static ma_result ma_device_data_loop__pulse(ma_device* pDevice)
the callbacks deal with it. the callbacks deal with it.
*/ */
while (ma_device_get_state(pDevice) == ma_device_state_started) { while (ma_device_get_state(pDevice) == ma_device_state_started) {
int block = (pDevice->pulse.blockingMainLoop) ? 1 : 0; resultPA = ((ma_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL);
resultPA = ((ma_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, block, NULL);
if (resultPA < 0) { if (resultPA < 0) {
break; break;
} }
/* If we're not blocking we need to sleep for a bit to prevent the CPU core being pinned at 100% usage. */
if (!block) {
ma_uint32 sleepTimeInMilliseconds;
/*
My original idea was to sleep for an amount of time proportionate to the configured period size, but I
wasn't able to figure out how to make this work without glitching. Instead I'm just going to hardcode
it to 1ms and move on.
*/
#if 0
{
if (((ma_pa_stream_writable_size_proc)pDevice->pContext->pulse.pa_stream_writable_size)((ma_pa_stream*)pDevice->pulse.pStreamPlayback) == 0) {
/* The amount of time we spend sleeping should be proportionate to the size of a period. */
if (pDevice->type == ma_device_type_playback) {
sleepTimeInMilliseconds = (pDevice->playback.internalPeriodSizeInFrames * pDevice->playback.internalSampleRate) / 1000;
} else {
sleepTimeInMilliseconds = (pDevice->capture.internalPeriodSizeInFrames * pDevice->capture.internalSampleRate) / 1000;
}
/*
At this point the sleep time is equal to the period size in milliseconds. I'm going to divide this by 2
in an attempt to reduce latency as a result of sleeping.
*/
sleepTimeInMilliseconds /= 2;
/* Clamp the sleep time to within reasonable values just in case. */
sleepTimeInMilliseconds = ma_clamp(sleepTimeInMilliseconds, 1, 10);
}
}
#else
{
sleepTimeInMilliseconds = 1;
}
#endif
ma_sleep(sleepTimeInMilliseconds);
}
} }
/* NOTE: Don't stop the device here. It'll be done at a higher level. */ /* NOTE: Don't stop the device here. It'll be done at a higher level. */
...@@ -41874,14 +41831,10 @@ MA_API ma_bool32 ma_context_is_loopback_supported(ma_context* pContext) ...@@ -41874,14 +41831,10 @@ MA_API ma_bool32 ma_context_is_loopback_supported(ma_context* pContext)
MA_API ma_device_config ma_device_config_init(ma_device_type deviceType) MA_API ma_device_config ma_device_config_init(ma_device_type deviceType)
{ {
ma_device_config config; ma_device_config config;
MA_ZERO_OBJECT(&config); MA_ZERO_OBJECT(&config);
config.deviceType = deviceType; config.deviceType = deviceType;
config.resampling = ma_resampler_config_init(ma_format_unknown, 0, 0, 0, ma_resample_algorithm_linear); /* Format/channels/rate don't matter here. */ config.resampling = ma_resampler_config_init(ma_format_unknown, 0, 0, 0, ma_resample_algorithm_linear); /* Format/channels/rate don't matter here. */
/* Use a blocking PulseAudio loop by default. Non-blocking currently results in glitches with low period sizes. */
config.pulse.blockingMainLoop = MA_TRUE;
return config; return config;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment