(RSound) Bake in rsound for Android port - should also be possible

to bake it in by default for PC now - made librsound.c crossplatform
This commit is contained in:
twinaphex 2013-11-01 00:07:52 +01:00
parent dd68d46b4c
commit a8696e2506
7 changed files with 112 additions and 1897 deletions

View File

@ -113,8 +113,7 @@ ifeq ($(HAVE_COMMAND), 1)
endif
ifeq ($(HAVE_RSOUND), 1)
OBJ += audio/rsound.o
LIBS += $(RSOUND_LIBS)
OBJ += audio/librsound.o audio/rsound.o
DEFINES += $(RSOUND_CFLAGS)
endif

View File

@ -47,7 +47,7 @@ ifeq ($(PERF_TEST), 1)
LOCAL_CFLAGS += -DPERF_TEST
endif
LOCAL_CFLAGS += -Wall -pthread -Wno-unused-function -O3 -fno-stack-protector -funroll-loops -DNDEBUG -DRARCH_MOBILE -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DHAVE_VID_CONTEXT -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_GLSL -DHAVE_RGUI -DHAVE_SCREENSHOTS -DWANT_MINIZ -DHAVE_ZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREADS -D__LIBRETRO__ -I../../../deps/miniz
LOCAL_CFLAGS += -Wall -pthread -Wno-unused-function -O3 -fno-stack-protector -funroll-loops -DNDEBUG -DRARCH_MOBILE -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DHAVE_VID_CONTEXT -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_GLSL -DHAVE_RGUI -DHAVE_SCREENSHOTS -DWANT_MINIZ -DHAVE_ZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREADS -D__LIBRETRO__ -I../../../deps/miniz -DHAVE_RSOUND
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -landroid -lEGL -lGLESv2 $(LOGGER_LDLIBS) -ldl

View File

@ -29,21 +29,22 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#define RSD_EXPOSE_STRUCT
#include "rsound.h"
#undef CONST_CAST
#define CONST_CAST
#ifdef __CELLOS_LV2__
#include <netex/net.h>
#include <netex/errno.h>
#endif
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <ctype.h>
#include <stdlib.h>
@ -53,13 +54,13 @@
#include <sys/poll.h>
#include <time.h>
#include <errno.h>
#include <sys/timer.h>
#include <sys/sys_time.h>
#include <arpa/inet.h>
#ifdef __CELLOS_LV2__
#include <cell/sysmodule.h>
#define close(x) socketclose(x)
#include <sys/timer.h>
#include <sys/sys_time.h>
#endif
/*
****************************************************************************
@ -110,18 +111,12 @@ static void rsnd_sleep(int msec);
static void* rsnd_cb_thread(void *thread_data);
static void* rsnd_thread(void *thread_data);
#ifdef __CELLOS_LV2__
static int init_count = 0;
static int init_cellsock(void)
{
if (init_count == 0)
{
cellSysmoduleLoadModule(CELL_SYSMODULE_NET);
sys_net_initialize_network();
init_count++;
}
return 0;
}
#else
#define socketclose(x) close(x)
#define socketpoll(x, y, z) poll(x, y, z)
#endif
/* Determine whether we're running big- or little endian */
static inline int rsnd_is_little_endian(void)
@ -187,6 +182,7 @@ static int rsnd_connect_server( rsound_t *rd )
struct sockaddr_in addr;
struct pollfd fd;
int i = 1;
(void)i;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
@ -216,8 +212,13 @@ static int rsnd_connect_server( rsound_t *rd )
/* Uses non-blocking IO since it performed more deterministic with poll()/send() */
#ifdef __CELLOS_LV2__
setsockopt(rd->conn.socket, SOL_SOCKET, SO_NBIO, &i, sizeof(int));
setsockopt(rd->conn.ctl_socket, SOL_SOCKET, SO_NBIO, &i, sizeof(int));
#else
fcntl(rd->conn.socket, F_SETFL, O_NONBLOCK);
fcntl(rd->conn.ctl_socket, F_SETFL, O_NONBLOCK);
#endif
/* Nonblocking connect with 3 second timeout */
connect(rd->conn.socket, (struct sockaddr*)&addr, sizeof(addr));
@ -444,16 +445,16 @@ static int rsnd_get_backend_info ( rsound_t *rd )
if (bufsiz > MAX_TCP_BUFSIZE)
bufsiz = MAX_TCP_BUFSIZE;
setsockopt(rd->conn.socket, SOL_SOCKET, SO_SNDBUF, CONST_CAST &bufsiz, sizeof(int));
setsockopt(rd->conn.socket, SOL_SOCKET, SO_SNDBUF, &bufsiz, sizeof(int));
bufsiz = rd->buffer_size;
setsockopt(rd->conn.ctl_socket, SOL_SOCKET, SO_SNDBUF, CONST_CAST &bufsiz, sizeof(int));
setsockopt(rd->conn.ctl_socket, SOL_SOCKET, SO_SNDBUF, &bufsiz, sizeof(int));
bufsiz = rd->buffer_size;
setsockopt(rd->conn.ctl_socket, SOL_SOCKET, SO_RCVBUF, CONST_CAST &bufsiz, sizeof(int));
setsockopt(rd->conn.ctl_socket, SOL_SOCKET, SO_RCVBUF, &bufsiz, sizeof(int));
int flag = 1;
setsockopt(rd->conn.socket, IPPROTO_TCP, TCP_NODELAY, CONST_CAST &flag, sizeof(int));
setsockopt(rd->conn.socket, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));
flag = 1;
setsockopt(rd->conn.ctl_socket, IPPROTO_TCP, TCP_NODELAY, CONST_CAST &flag, sizeof(int));
setsockopt(rd->conn.ctl_socket, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));
}
// Can we read the last 8 bytes so we can use the protocol interface?
@ -675,9 +676,58 @@ static int rsnd_poll(struct pollfd *fd, int numfd, int timeout)
}
}
static void rsnd_sleep(int msecs)
static int64_t rsnd_get_time_usec(void)
{
sys_timer_usleep(msecs * 1000);
#if defined(_WIN32)
static LARGE_INTEGER freq;
if (!freq.QuadPart && !QueryPerformanceFrequency(&freq)) // Frequency is guaranteed to not change.
return 0;
LARGE_INTEGER count;
if (!QueryPerformanceCounter(&count))
return 0;
return count.QuadPart * 1000000 / freq.QuadPart;
#elif defined(__CELLOS_LV2__)
return sys_time_get_system_time();
#elif defined(GEKKO)
return ticks_to_microsecs(gettime());
#elif defined(__MACH__) // OSX doesn't have clock_gettime ...
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
return mts.tv_sec * INT64_C(1000000) + (mts.tv_nsec + 500) / 1000;
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID)
struct timespec tv;
if (clock_gettime(CLOCK_MONOTONIC, &tv) < 0)
return 0;
return tv.tv_sec * INT64_C(1000000) + (tv.tv_nsec + 500) / 1000;
#elif defined(EMSCRIPTEN)
return emscripten_get_now() * 1000;
#else
#error "Your platform does not have a timer function implemented in rarch_get_time_usec(). Cannot continue."
#endif
}
static void rsnd_sleep(int msec)
{
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
sys_timer_usleep(1000 * msec);
#elif defined(PSP)
sceKernelDelayThread(1000 * msec);
#elif defined(_WIN32)
Sleep(msec);
#elif defined(XENON)
udelay(1000 * msec);
#elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__)
usleep(1000 * msec);
#else
struct timespec tv = {0};
tv.tv_sec = msec / 1000;
tv.tv_nsec = (msec % 1000) * 1000000;
nanosleep(&tv, NULL);
#endif
}
@ -691,7 +741,7 @@ static void rsnd_drain(rsound_t *rd)
if ( rd->has_written )
{
/* Calculates the amount of bytes that the server has consumed. */
int64_t time = sys_time_get_system_time();
int64_t time = rsnd_get_time_usec();
int64_t delta = time - rd->start_time;
delta *= rd->rate * rd->channels * rd->samplesize;
@ -913,7 +963,7 @@ static int rsnd_close_ctl(rsound_t *rd)
return -1;
}
close(rd->conn.ctl_socket);
socketclose(rd->conn.ctl_socket);
return 0;
}
@ -1087,7 +1137,7 @@ static void* rsnd_thread ( void * thread_data )
if ( !rd->has_written )
{
pthread_mutex_lock(&rd->thread.mutex);
rd->start_time = sys_time_get_system_time();
rd->start_time = rsnd_get_time_usec();
rd->has_written = 1;
pthread_mutex_unlock(&rd->thread.mutex);
}
@ -1130,6 +1180,7 @@ static void* rsnd_thread ( void * thread_data )
}
}
return NULL;
}
/* Callback thread */
@ -1194,7 +1245,7 @@ static void* rsnd_cb_thread(void *thread_data)
/* If this was the first write, set the start point for the timer. */
if (!rd->has_written)
{
rd->start_time = sys_time_get_system_time();
rd->start_time = rsnd_get_time_usec();
rd->has_written = 1;
}
@ -1216,10 +1267,10 @@ static void* rsnd_cb_thread(void *thread_data)
static int rsnd_reset(rsound_t *rd)
{
if ( rd->conn.socket != -1 )
close(rd->conn.socket);
socketclose(rd->conn.socket);
if ( rd->conn.socket != 1 )
close(rd->conn.ctl_socket);
socketclose(rd->conn.ctl_socket);
/* Pristine stuff, baby! */
pthread_mutex_lock(&rd->thread.mutex);
@ -1326,8 +1377,12 @@ int rsd_exec(rsound_t *rsound)
rsnd_stop_thread(rsound);
#if defined(__CELLOS_LV2__)
int i = 0;
setsockopt(rsound->conn.socket, SOL_SOCKET, SO_NBIO, &i, sizeof(int));
#else
fcntl(rsound->conn.socket, F_SETFL, O_NONBLOCK);
#endif
// Flush the buffer
@ -1338,7 +1393,7 @@ int rsd_exec(rsound_t *rsound)
if ( rsnd_send_chunk(fd, buffer, sizeof(buffer), 1) != (ssize_t)sizeof(buffer) )
{
RSD_DEBUG("[RSound] Failed flushing buffer.\n");
close(fd);
socketclose(fd);
return -1;
}
}
@ -1516,7 +1571,14 @@ int rsd_init(rsound_t** rsound)
rsd_set_param(*rsound, RSD_HOST, RSD_DEFAULT_HOST);
rsd_set_param(*rsound, RSD_PORT, RSD_DEFAULT_PORT);
init_cellsock();
#ifdef __CELLOS_LV2__
if (init_count == 0)
{
cellSysmoduleLoadModule(CELL_SYSMODULE_NET);
sys_net_initialize_network();
init_count++;
}
#endif
return 0;
}

View File

@ -16,12 +16,8 @@
#include "../driver.h"
#include <stdlib.h>
#if defined(RARCH_CONSOLE) || defined(HAVE_GRIFFIN)
#include "../deps/librsound/rsound.h"
#else
#include <rsound.h>
#endif
#include "fifo_buffer.h"
#include "rsound.h"
#include "../fifo_buffer.h"
#include "../boolean.h"
#include "../thread.h"

View File

@ -20,7 +20,6 @@
extern "C" {
#endif
#ifdef RSD_EXPOSE_STRUCT
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
@ -28,12 +27,8 @@ extern "C" {
#include <time.h>
#include <stdint.h>
#include <stddef.h>
#else
#include <stddef.h>
#include <sys/types.h>
#endif
#include "../../fifo_buffer.h"
#include "../fifo_buffer.h"
#ifdef _WIN32
#define RSD_DEFAULT_HOST "127.0.0.1" // Stupid Windows.
@ -135,9 +130,6 @@ extern "C" {
/* 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);
#ifdef RSD_EXPOSE_STRUCT
/* Defines the main structure for use with the API. */
typedef struct rsound
{
@ -191,9 +183,6 @@ extern "C" {
void *cb_data;
pthread_mutex_t cb_lock;
} rsound_t;
#else
typedef struct rsound rsound_t;
#endif
/* -- API --
All functions (except for rsd_write() return 0 for success, and -1 for error. errno is currently not set. */
@ -329,11 +318,17 @@ extern "C" {
/* 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);
#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
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -347,11 +347,7 @@ AUDIO RESAMPLER
RSOUND
============================================================ */
#ifdef HAVE_RSOUND
#ifdef __CELLOS_LV2__
#include "../deps/librsound/librsound.c"
#else
#include "../deps/librsound/librsound_orig.c"
#endif
#include "../audio/librsound.c"
#include "../audio/rsound.c"
#endif