22 #include "../../SDL_internal.h" 24 #if SDL_AUDIO_DRIVER_SNDIO 40 #include "../SDL_audio_c.h" 43 #ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC 52 #define SIO_DEVANY "default" 55 static struct sio_hdl * (*SNDIO_sio_open)(
const char *,
unsigned int, int);
56 static void (*SNDIO_sio_close)(
struct sio_hdl *);
57 static int (*SNDIO_sio_setpar)(
struct sio_hdl *,
struct sio_par *);
58 static int (*SNDIO_sio_getpar)(
struct sio_hdl *,
struct sio_par *);
59 static int (*SNDIO_sio_start)(
struct sio_hdl *);
60 static int (*SNDIO_sio_stop)(
struct sio_hdl *);
61 static size_t (*SNDIO_sio_read)(
struct sio_hdl *,
void *,
size_t);
62 static size_t (*SNDIO_sio_write)(
struct sio_hdl *,
const void *,
size_t);
63 static int (*SNDIO_sio_nfds)(
struct sio_hdl *);
64 static int (*SNDIO_sio_pollfd)(
struct sio_hdl *,
struct pollfd *, int);
65 static int (*SNDIO_sio_revents)(
struct sio_hdl *,
struct pollfd *);
66 static int (*SNDIO_sio_eof)(
struct sio_hdl *);
67 static void (*SNDIO_sio_initpar)(
struct sio_par *);
69 #ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC 70 static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
71 static void *sndio_handle =
NULL;
74 load_sndio_sym(
const char *fn,
void **
addr)
86 #define SDL_SNDIO_SYM(x) \ 87 if (!load_sndio_sym(#x, (void **) (char *) &SNDIO_##x)) return -1 89 #define SDL_SNDIO_SYM(x) SNDIO_##x = x 95 SDL_SNDIO_SYM(sio_open);
96 SDL_SNDIO_SYM(sio_close);
97 SDL_SNDIO_SYM(sio_setpar);
98 SDL_SNDIO_SYM(sio_getpar);
99 SDL_SNDIO_SYM(sio_start);
100 SDL_SNDIO_SYM(sio_stop);
101 SDL_SNDIO_SYM(sio_read);
102 SDL_SNDIO_SYM(sio_write);
103 SDL_SNDIO_SYM(sio_nfds);
104 SDL_SNDIO_SYM(sio_pollfd);
105 SDL_SNDIO_SYM(sio_revents);
106 SDL_SNDIO_SYM(sio_eof);
107 SDL_SNDIO_SYM(sio_initpar);
113 #ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC 116 UnloadSNDIOLibrary(
void)
118 if (sndio_handle !=
NULL) {
125 LoadSNDIOLibrary(
void)
128 if (sndio_handle ==
NULL) {
130 if (sndio_handle ==
NULL) {
134 retval = load_sndio_syms();
136 UnloadSNDIOLibrary();
146 UnloadSNDIOLibrary(
void)
151 LoadSNDIOLibrary(
void)
163 SNDIO_WaitDevice(
_THIS)
169 SNDIO_PlayDevice(
_THIS)
171 const int written = SNDIO_sio_write(this->hidden->dev,
172 this->hidden->mixbuf,
173 this->hidden->mixlen);
176 if ( written == 0 ) {
180 fprintf(stderr,
"Wrote %d bytes of audio data\n", written);
185 SNDIO_CaptureFromDevice(
_THIS,
void *
buffer,
int buflen)
192 r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
193 while (r == 0 && !SNDIO_sio_eof(this->hidden->dev)) {
194 if ((nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN)) <= 0
195 || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
198 revents = SNDIO_sio_revents(this->hidden->dev, this->hidden->pfd);
199 if (revents & POLLIN) {
200 r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
202 if (revents & POLLHUP) {
210 SNDIO_FlushCapture(
_THIS)
214 while (SNDIO_sio_read(this->hidden->dev, buf,
sizeof(buf)) != 0) {
220 SNDIO_GetDeviceBuf(
_THIS)
222 return this->hidden->mixbuf;
226 SNDIO_CloseDevice(
_THIS)
228 if ( this->hidden->pfd !=
NULL ) {
231 if ( this->hidden->dev !=
NULL ) {
232 SNDIO_sio_stop(this->hidden->dev);
233 SNDIO_sio_close(this->hidden->dev);
240 SNDIO_OpenDevice(
_THIS,
void *
handle,
const char *devname,
int iscapture)
248 if (this->hidden ==
NULL) {
253 this->hidden->mixlen = this->
spec.
size;
256 if ((this->hidden->dev =
257 SNDIO_sio_open(devname !=
NULL ? devname : SIO_DEVANY,
258 iscapture ? SIO_REC : SIO_PLAY, iscapture)) ==
NULL) {
263 if (iscapture && (this->hidden->pfd =
264 SDL_malloc(
sizeof(
struct pollfd) * SNDIO_sio_nfds(this->hidden->dev))) ==
NULL) {
268 SNDIO_sio_initpar(&par);
273 par.appbufsz = par.round * 2;
277 while (test_format && (status < 0)) {
283 if (SNDIO_sio_setpar(this->hidden->dev, &par) == 0) {
286 if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
289 if (par.bps != SIO_BPS(par.bits)) {
292 if ((par.bits == 8 * par.bps) || (par.msb)) {
301 return SDL_SetError(
"sndio: Couldn't find any hardware audio formats");
304 if ((par.bps == 4) && (par.sig) && (par.le))
306 else if ((par.bps == 4) && (par.sig) && (!par.le))
308 else if ((par.bps == 2) && (par.sig) && (par.le))
310 else if ((par.bps == 2) && (par.sig) && (!par.le))
312 else if ((par.bps == 2) && (!par.sig) && (par.le))
314 else if ((par.bps == 2) && (!par.sig) && (!par.le))
316 else if ((par.bps == 1) && (par.sig))
318 else if ((par.bps == 1) && (!par.sig))
321 return SDL_SetError(
"sndio: Got unsupported hardware audio format.");
332 this->hidden->mixlen = this->
spec.
size;
334 if (this->hidden->mixbuf ==
NULL) {
337 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
339 if (!SNDIO_sio_start(this->hidden->dev)) {
348 SNDIO_Deinitialize(
void)
350 UnloadSNDIOLibrary();
356 if (LoadSNDIOLibrary() < 0) {
377 "sndio",
"OpenBSD sndio", SNDIO_Init, 0
#define SDL_AUDIO_ISLITTLEENDIAN(x)
GLdouble GLdouble GLdouble r
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
void(* PlayDevice)(_THIS)
void(* WaitDevice)(_THIS)
#define SDL_AUDIO_ISSIGNED(x)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Uint16 SDL_AudioFormat
Audio format flags.
AudioBootStrap SNDIO_bootstrap
SDL_AudioFormat SDL_NextAudioFormat(void)
#define SDL_AUDIO_ISFLOAT(x)
EGLImageKHR EGLint EGLint * handle
#define SDL_AUDIO_BITSIZE(x)
void(* Deinitialize)(void)
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
GLenum GLuint GLenum GLsizei const GLchar * buf
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
#define SDL_OutOfMemory()
int(* CaptureFromDevice)(_THIS, void *buffer, int buflen)
void(* CloseDevice)(_THIS)
int AllowsArbitraryDeviceNames
void(* FlushCapture)(_THIS)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Uint8 *(* GetDeviceBuf)(_THIS)
void * SDL_LoadFunction(void *handle, const char *name)