mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 22:13:51 +00:00
Avoid menu deadlocks in Pulse and ALSA. (#8265)
Buggy menu code most likely, but audio backends can be defensive about it.
This commit is contained in:
parent
2ccc6534ee
commit
b3e2df53d2
@ -180,6 +180,7 @@ error:
|
||||
#define BYTES_TO_FRAMES(bytes, frame_bits) ((bytes) * 8 / frame_bits)
|
||||
#define FRAMES_TO_BYTES(frames, frame_bits) ((frames) * frame_bits / 8)
|
||||
|
||||
static bool alsa_start(void *data, bool is_shutdown);
|
||||
static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
||||
{
|
||||
alsa_t *alsa = (alsa_t*)data;
|
||||
@ -188,6 +189,12 @@ static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
||||
snd_pcm_sframes_t size = BYTES_TO_FRAMES(size_, alsa->frame_bits);
|
||||
size_t frames_size = alsa->has_float ? sizeof(float) : sizeof(int16_t);
|
||||
|
||||
/* Workaround buggy menu code.
|
||||
* If a write happens while we're paused, we might never progress. */
|
||||
if (alsa->is_paused)
|
||||
if (!alsa_start(alsa, false))
|
||||
return -1;
|
||||
|
||||
if (alsa->nonblock)
|
||||
{
|
||||
while (size)
|
||||
@ -269,6 +276,8 @@ static bool alsa_alive(void *data)
|
||||
static bool alsa_stop(void *data)
|
||||
{
|
||||
alsa_t *alsa = (alsa_t*)data;
|
||||
if (alsa->is_paused)
|
||||
return true;
|
||||
|
||||
if (alsa->can_pause
|
||||
&& !alsa->is_paused)
|
||||
@ -293,6 +302,8 @@ static void alsa_set_nonblock_state(void *data, bool state)
|
||||
static bool alsa_start(void *data, bool is_shutdown)
|
||||
{
|
||||
alsa_t *alsa = (alsa_t*)data;
|
||||
if (!alsa->is_paused)
|
||||
return true;
|
||||
|
||||
if (alsa->can_pause
|
||||
&& alsa->is_paused)
|
||||
|
@ -237,12 +237,19 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool pulse_start(void *data, bool is_shutdown);
|
||||
static ssize_t pulse_write(void *data, const void *buf_, size_t size)
|
||||
{
|
||||
pa_t *pa = (pa_t*)data;
|
||||
const uint8_t *buf = (const uint8_t*)buf_;
|
||||
size_t written = 0;
|
||||
|
||||
/* Workaround buggy menu code.
|
||||
* If a write happens while we're paused, we might never progress. */
|
||||
if (pa->is_paused)
|
||||
if (!pulse_start(pa, false))
|
||||
return -1;
|
||||
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
while (size)
|
||||
{
|
||||
@ -270,6 +277,8 @@ static bool pulse_stop(void *data)
|
||||
{
|
||||
bool ret;
|
||||
pa_t *pa = (pa_t*)data;
|
||||
if (pa->is_paused)
|
||||
return true;
|
||||
|
||||
RARCH_LOG("[PulseAudio]: Pausing.\n");
|
||||
|
||||
@ -296,6 +305,8 @@ static bool pulse_start(void *data, bool is_shutdown)
|
||||
{
|
||||
bool ret;
|
||||
pa_t *pa = (pa_t*)data;
|
||||
if (!pa->is_paused)
|
||||
return true;
|
||||
|
||||
RARCH_LOG("[PulseAudio]: Unpausing.\n");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user