(Rwebaudio) Get rid of static global variables, put it in struct

This commit is contained in:
twinaphex 2020-09-20 23:09:18 +02:00
parent 45c257e0dd
commit f8a71e8ea4

View File

@ -31,72 +31,68 @@ void RWebAudioFree(void);
size_t RWebAudioWriteAvail(void); size_t RWebAudioWriteAvail(void);
size_t RWebAudioBufferSize(void); size_t RWebAudioBufferSize(void);
/* TODO/FIXME - static global variable */ typedef struct rweb_audio
static bool rwebaudio_is_paused; {
bool is_paused;
} rweb_audio_t;
static void rwebaudio_free(void *data) static void rwebaudio_free(void *data)
{ {
RWebAudioFree(); RWebAudioFree();
free(data);
} }
static void *rwebaudio_init(const char *device, unsigned rate, unsigned latency, static void *rwebaudio_init(const char *device, unsigned rate, unsigned latency,
unsigned block_frames, unsigned block_frames,
unsigned *new_rate) unsigned *new_rate)
{ {
rweb_audio_t *rwebaudio = (rweb_audio_t*)calloc(1, sizeof(rweb_audio_t));
if (!rwebaudio)
return NULL;
if (RWebAudioInit(latency) == 1) if (RWebAudioInit(latency) == 1)
*new_rate = RWebAudioSampleRate(); *new_rate = RWebAudioSampleRate();
return (void*)-1; return rwebaudio;
} }
static ssize_t rwebaudio_write(void *data, const void *buf, size_t size) static ssize_t rwebaudio_write(void *data, const void *buf, size_t size)
{ {
(void)data;
return RWebAudioWrite(buf, size); return RWebAudioWrite(buf, size);
} }
static bool rwebaudio_stop(void *data) static bool rwebaudio_stop(void *data)
{ {
(void)data; rweb_audio_t *rwebaudio = (rweb_audio_t*)data;
rwebaudio_is_paused = true; if (!rwebaudio)
return false;
rwebaudio->is_paused = true;
return RWebAudioStop(); return RWebAudioStop();
} }
static void rwebaudio_set_nonblock_state(void *data, bool state) static void rwebaudio_set_nonblock_state(void *data, bool state)
{ {
(void)data;
RWebAudioSetNonblockState(state); RWebAudioSetNonblockState(state);
} }
static bool rwebaudio_alive(void *data) static bool rwebaudio_alive(void *data)
{ {
(void)data; rweb_audio_t *rwebaudio = (rweb_audio_t*)data;
return !rwebaudio_is_paused; if (!rwebaudio)
return false;
return !rwebaudio->is_paused;
} }
static bool rwebaudio_start(void *data, bool is_shutdown) static bool rwebaudio_start(void *data, bool is_shutdown)
{ {
(void)data; rweb_audio_t *rwebaudio = (rweb_audio_t*)data;
rwebaudio_is_paused = false; if (!rwebaudio)
return false;
rwebaudio->is_paused = false;
return RWebAudioStart(); return RWebAudioStart();
} }
static size_t rwebaudio_write_avail(void *data) static size_t rwebaudio_write_avail(void *data) {return RWebAudioWriteAvail();}
{ static size_t rwebaudio_buffer_size(void *data) {return RWebAudioBufferSize();}
(void)data; static bool rwebaudio_use_float(void *data) { return true; }
return RWebAudioWriteAvail();
}
static size_t rwebaudio_buffer_size(void *data)
{
(void)data;
return RWebAudioBufferSize();
}
static bool rwebaudio_use_float(void *data)
{
(void)data;
return true;
}
audio_driver_t audio_rwebaudio = { audio_driver_t audio_rwebaudio = {
rwebaudio_init, rwebaudio_init,