mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
(DirectSound) rewrite to use rthreads
This commit is contained in:
parent
27e984d5f2
commit
9e10e20b69
@ -20,6 +20,8 @@
|
||||
#endif
|
||||
|
||||
#include <retro_inline.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <rthreads/rthreads.h>
|
||||
|
||||
#ifdef _XBOX
|
||||
#define DSERR_BUFFERLOST MAKE_DSHRESULT(150)
|
||||
@ -65,8 +67,8 @@ typedef struct dsound
|
||||
fifo_buffer_t *buffer;
|
||||
CRITICAL_SECTION crit;
|
||||
|
||||
HANDLE event;
|
||||
HANDLE thread;
|
||||
slock_t *event;
|
||||
sthread_t *thread;
|
||||
|
||||
unsigned buffer_size;
|
||||
|
||||
@ -147,7 +149,7 @@ static INLINE void release_region(dsound_t *ds, const struct audio_lock *region)
|
||||
IDirectSoundBuffer_Unlock(ds->dsb, region->chunk1, region->size1, region->chunk2, region->size2);
|
||||
}
|
||||
|
||||
static DWORD CALLBACK dsound_thread(PVOID data)
|
||||
static void dsound_thread(void *data)
|
||||
{
|
||||
DWORD write_ptr;
|
||||
dsound_t *ds = (dsound_t*)data;
|
||||
@ -174,7 +176,7 @@ static DWORD CALLBACK dsound_thread(PVOID data)
|
||||
/* No space to write, or we don't have data in our fifo,
|
||||
* but we can wait some time before it underruns ... */
|
||||
|
||||
Sleep(1);
|
||||
rarch_sleep(1);
|
||||
|
||||
/* We could opt for using the notification interface,
|
||||
* but it is not guaranteed to work, so use high
|
||||
@ -189,7 +191,7 @@ static DWORD CALLBACK dsound_thread(PVOID data)
|
||||
if (!grab_region(ds, write_ptr, ®ion))
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
SetEvent(ds->event);
|
||||
scond_broadcast(ds->event);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -206,7 +208,7 @@ static DWORD CALLBACK dsound_thread(PVOID data)
|
||||
if (!grab_region(ds, write_ptr, ®ion))
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
SetEvent(ds->event);
|
||||
scond_broadcast(ds->event);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -220,7 +222,7 @@ static DWORD CALLBACK dsound_thread(PVOID data)
|
||||
release_region(ds, ®ion);
|
||||
write_ptr = (write_ptr + region.size1 + region.size2) % ds->buffer_size;
|
||||
|
||||
SetEvent(ds->event);
|
||||
scond_broadcast(ds->event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,8 +235,8 @@ static void dsound_stop_thread(dsound_t *ds)
|
||||
return;
|
||||
|
||||
ds->thread_alive = false;
|
||||
WaitForSingleObject(ds->thread, INFINITE);
|
||||
CloseHandle(ds->thread);
|
||||
|
||||
sthread_join(ds->thread);
|
||||
ds->thread = NULL;
|
||||
}
|
||||
|
||||
@ -243,8 +245,8 @@ static bool dsound_start_thread(dsound_t *ds)
|
||||
if (!ds->thread)
|
||||
{
|
||||
ds->thread_alive = true;
|
||||
ds->thread = CreateThread(NULL, 0, dsound_thread, ds, 0, NULL);
|
||||
if (ds->thread == NULL)
|
||||
ds->thread = sthread_create(dsound_thread, ds);
|
||||
if (!ds->thread)
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -275,8 +277,7 @@ static void dsound_free(void *data)
|
||||
if (ds->thread)
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
WaitForSingleObject(ds->thread, INFINITE);
|
||||
CloseHandle(ds->thread);
|
||||
sthread_join(ds->thread);
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&ds->crit);
|
||||
@ -290,8 +291,8 @@ static void dsound_free(void *data)
|
||||
if (ds->ds)
|
||||
IDirectSound_Release(ds->ds);
|
||||
|
||||
if (ds->event)
|
||||
CloseHandle(ds->event);
|
||||
slock_free(ds->event);
|
||||
ds->event = NULL;
|
||||
|
||||
if (ds->buffer)
|
||||
fifo_free(ds->buffer);
|
||||
@ -363,15 +364,14 @@ static void *dsound_init(const char *device, unsigned rate, unsigned latency)
|
||||
RARCH_LOG("[DirectSound]: Latency = %u ms\n", (unsigned)((1000 * ds->buffer_size) / wfx.nAvgBytesPerSec));
|
||||
|
||||
bufdesc.dwSize = sizeof(DSBUFFERDESC);
|
||||
#ifdef _XBOX
|
||||
bufdesc.dwFlags = 0;
|
||||
#else
|
||||
#ifndef _XBOX
|
||||
bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
|
||||
#endif
|
||||
bufdesc.dwBufferBytes = ds->buffer_size;
|
||||
bufdesc.lpwfxFormat = &wfx;
|
||||
|
||||
ds->event = CreateEvent(NULL, false, false, NULL);
|
||||
ds->event = scond_new();
|
||||
if (!ds->event)
|
||||
goto error;
|
||||
|
||||
@ -420,7 +420,8 @@ static bool dsound_start(void *data)
|
||||
if (!dsound_start_thread(ds))
|
||||
return false;
|
||||
|
||||
ds->is_paused = (IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) == DS_OK) ? false : true;
|
||||
ds->is_paused = (IDirectSoundBuffer_Play(
|
||||
ds->dsb, 0, 0, DSBPLAY_LOOPING) == DS_OK) ? false : true;
|
||||
return (ds->is_paused) ? false : true;
|
||||
}
|
||||
|
||||
@ -469,7 +470,7 @@ static ssize_t dsound_write(void *data, const void *buf_, size_t size)
|
||||
break;
|
||||
|
||||
if (avail == 0)
|
||||
WaitForSingleObject(ds->event, INFINITE);
|
||||
slock_lock(ds->event);
|
||||
}
|
||||
|
||||
return written;
|
||||
|
Loading…
x
Reference in New Issue
Block a user