mirror of
https://github.com/libretro/RetroArch
synced 2025-02-22 03:40:43 +00:00
(rsound) Cleanups
This commit is contained in:
parent
67867311d9
commit
9a989462f1
@ -55,6 +55,7 @@ static void err_cb(void *userdata)
|
|||||||
|
|
||||||
static void *rs_init(const char *device, unsigned rate, unsigned latency)
|
static void *rs_init(const char *device, unsigned rate, unsigned latency)
|
||||||
{
|
{
|
||||||
|
int channels, format;
|
||||||
rsd_t *rsd = (rsd_t*)calloc(1, sizeof(rsd_t));
|
rsd_t *rsd = (rsd_t*)calloc(1, sizeof(rsd_t));
|
||||||
if (!rsd)
|
if (!rsd)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -72,8 +73,8 @@ static void *rs_init(const char *device, unsigned rate, unsigned latency)
|
|||||||
|
|
||||||
rsd->buffer = fifo_new(1024 * 4);
|
rsd->buffer = fifo_new(1024 * 4);
|
||||||
|
|
||||||
int channels = 2;
|
channels = 2;
|
||||||
int format = RSD_S16_NE;
|
format = RSD_S16_NE;
|
||||||
|
|
||||||
rsd_set_param(rd, RSD_CHANNELS, &channels);
|
rsd_set_param(rd, RSD_CHANNELS, &channels);
|
||||||
rsd_set_param(rd, RSD_SAMPLERATE, &rate);
|
rsd_set_param(rd, RSD_SAMPLERATE, &rate);
|
||||||
@ -106,9 +107,13 @@ static ssize_t rs_write(void *data, const void *buf, size_t size)
|
|||||||
|
|
||||||
if (rsd->nonblock)
|
if (rsd->nonblock)
|
||||||
{
|
{
|
||||||
|
size_t avail, write_amt;
|
||||||
|
|
||||||
rsd_callback_lock(rsd->rd);
|
rsd_callback_lock(rsd->rd);
|
||||||
size_t avail = fifo_write_avail(rsd->buffer);
|
|
||||||
size_t write_amt = avail > size ? size : avail;
|
avail = fifo_write_avail(rsd->buffer);
|
||||||
|
write_amt = avail > size ? size : avail;
|
||||||
|
|
||||||
fifo_write(rsd->buffer, buf, write_amt);
|
fifo_write(rsd->buffer, buf, write_amt);
|
||||||
rsd_callback_unlock(rsd->rd);
|
rsd_callback_unlock(rsd->rd);
|
||||||
return write_amt;
|
return write_amt;
|
||||||
@ -118,8 +123,10 @@ static ssize_t rs_write(void *data, const void *buf, size_t size)
|
|||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
while (written < size && !rsd->has_error)
|
while (written < size && !rsd->has_error)
|
||||||
{
|
{
|
||||||
|
size_t avail;
|
||||||
rsd_callback_lock(rsd->rd);
|
rsd_callback_lock(rsd->rd);
|
||||||
size_t avail = fifo_write_avail(rsd->buffer);
|
|
||||||
|
avail = fifo_write_avail(rsd->buffer);
|
||||||
|
|
||||||
if (avail == 0)
|
if (avail == 0)
|
||||||
{
|
{
|
||||||
|
@ -87,10 +87,9 @@ extern "C" {
|
|||||||
#define RSD_SET_CALLBACK RSD_SET_CALLBACK
|
#define RSD_SET_CALLBACK RSD_SET_CALLBACK
|
||||||
#define RSD_CALLBACK_LOCK RSD_CALLBACK_LOCK
|
#define RSD_CALLBACK_LOCK RSD_CALLBACK_LOCK
|
||||||
#define RSD_CALLBACK_UNLOCK RSD_CALLBACK_UNLOCK
|
#define RSD_CALLBACK_UNLOCK RSD_CALLBACK_UNLOCK
|
||||||
|
|
||||||
/* End feature tests */
|
/* End feature tests */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Defines sample formats available. Defaults to S16_LE should it never be set. */
|
/* Defines sample formats available. Defaults to S16_LE should it never be set. */
|
||||||
enum rsd_format
|
enum rsd_format
|
||||||
{
|
{
|
||||||
@ -129,13 +128,15 @@ extern "C" {
|
|||||||
/* Audio callback for rsd_set_callback. Return -1 to trigger an error in the stream. */
|
/* Audio callback for rsd_set_callback. Return -1 to trigger an error in the stream. */
|
||||||
typedef ssize_t (*rsd_audio_callback_t)(void *data, size_t bytes, void *userdata);
|
typedef ssize_t (*rsd_audio_callback_t)(void *data, size_t bytes, void *userdata);
|
||||||
|
|
||||||
/* Error callback. Signals caller that stream has been stopped, either by audio callback returning -1 or stream was hung up. */
|
/* Error callback. Signals caller that stream has been stopped,
|
||||||
|
* either by audio callback returning -1 or stream was hung up. */
|
||||||
typedef void (*rsd_error_callback_t)(void *userdata);
|
typedef void (*rsd_error_callback_t)(void *userdata);
|
||||||
|
|
||||||
/* Defines the main structure for use with the API. */
|
/* Defines the main structure for use with the API. */
|
||||||
typedef struct rsound
|
typedef struct rsound
|
||||||
{
|
{
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
volatile int socket;
|
volatile int socket;
|
||||||
volatile int ctl_socket;
|
volatile int ctl_socket;
|
||||||
} conn;
|
} conn;
|
||||||
@ -158,7 +159,8 @@ extern "C" {
|
|||||||
int delay_offset;
|
int delay_offset;
|
||||||
int max_latency;
|
int max_latency;
|
||||||
|
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
uint32_t latency;
|
uint32_t latency;
|
||||||
uint32_t chunk_size;
|
uint32_t chunk_size;
|
||||||
} backend_info;
|
} backend_info;
|
||||||
@ -170,7 +172,8 @@ extern "C" {
|
|||||||
uint16_t format;
|
uint16_t format;
|
||||||
int samplesize;
|
int samplesize;
|
||||||
|
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
sthread_t *thread;
|
sthread_t *thread;
|
||||||
slock_t *mutex;
|
slock_t *mutex;
|
||||||
slock_t *cond_mutex;
|
slock_t *cond_mutex;
|
||||||
@ -202,7 +205,6 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
int rsd_init (rsound_t **rd);
|
int rsd_init (rsound_t **rd);
|
||||||
|
|
||||||
|
|
||||||
/* This is a simpler function that initializes an rsound struct, sets params as given,
|
/* This is a simpler function that initializes an rsound struct, sets params as given,
|
||||||
and starts the stream. Should this function fail, the structure will stay uninitialized.
|
and starts the stream. Should this function fail, the structure will stay uninitialized.
|
||||||
Should NULL be passed in either host, port or ident, defaults will be used. */
|
Should NULL be passed in either host, port or ident, defaults will be used. */
|
||||||
@ -210,7 +212,6 @@ extern "C" {
|
|||||||
int rsd_simple_start (rsound_t **rd, const char* host, const char* port, const char* ident,
|
int rsd_simple_start (rsound_t **rd, const char* host, const char* port, const char* ident,
|
||||||
int rate, int channels, enum rsd_format format);
|
int rate, int channels, enum rsd_format format);
|
||||||
|
|
||||||
|
|
||||||
/* Sets params associated with an rsound_t. These options (int options) include:
|
/* Sets params associated with an rsound_t. These options (int options) include:
|
||||||
|
|
||||||
RSD_HOST: Server to connect to. Expects (char *) in param.
|
RSD_HOST: Server to connect to. Expects (char *) in param.
|
||||||
@ -265,6 +266,7 @@ extern "C" {
|
|||||||
The lock should be held for as short period as possible.
|
The lock should be held for as short period as possible.
|
||||||
Try to avoid calling code that may block when holding the lock. */
|
Try to avoid calling code that may block when holding the lock. */
|
||||||
void rsd_callback_lock (rsound_t *rd);
|
void rsd_callback_lock (rsound_t *rd);
|
||||||
|
|
||||||
void rsd_callback_unlock (rsound_t *rd);
|
void rsd_callback_unlock (rsound_t *rd);
|
||||||
|
|
||||||
/* Establishes connection to server. Might fail if connection can't be established or that one of
|
/* Establishes connection to server. Might fail if connection can't be established or that one of
|
||||||
@ -312,7 +314,6 @@ extern "C" {
|
|||||||
with RSD_LATENCY, this function will do nothing. */
|
with RSD_LATENCY, this function will do nothing. */
|
||||||
void rsd_delay_wait(rsound_t *rd);
|
void rsd_delay_wait(rsound_t *rd);
|
||||||
|
|
||||||
|
|
||||||
/* Pauses or unpauses a stream. pause -> enable = 1
|
/* Pauses or unpauses a stream. pause -> enable = 1
|
||||||
This function essentially calls on start() and stop(). This behavior might be changed later. */
|
This function essentially calls on start() and stop(). This behavior might be changed later. */
|
||||||
int rsd_pause (rsound_t *rd, int enable);
|
int rsd_pause (rsound_t *rd, int enable);
|
||||||
@ -320,15 +321,6 @@ extern "C" {
|
|||||||
/* Frees an rsound_t struct. Make sure that the stream is properly closed down with rsd_stop() before calling rsd_free(). */
|
/* Frees an rsound_t struct. Make sure that the stream is properly closed down with rsd_stop() before calling rsd_free(). */
|
||||||
int rsd_free (rsound_t *rd);
|
int rsd_free (rsound_t *rd);
|
||||||
|
|
||||||
#ifndef HAVE_STRL
|
|
||||||
// Avoid possible naming collisions during link since we prefer to use the actual name.
|
|
||||||
#define strlcpy(dst, src, size) strlcpy_rarch__(dst, src, size)
|
|
||||||
#define strlcat(dst, src, size) strlcat_rarch__(dst, src, size)
|
|
||||||
|
|
||||||
size_t strlcpy(char *dest, const char *source, size_t size);
|
|
||||||
size_t strlcat(char *dest, const char *source, size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <compat/strl.h>
|
||||||
#include <retro_inline.h>
|
#include <retro_inline.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user