2015-06-21 15:33:46 +00:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2019-01-05 06:01:14 +00:00
|
|
|
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
#include "../SDL_internal.h"
|
|
|
|
|
2016-11-21 05:34:54 +00:00
|
|
|
#ifndef SDL_sysaudio_h_
|
|
|
|
#define SDL_sysaudio_h_
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
#include "SDL_mutex.h"
|
|
|
|
#include "SDL_thread.h"
|
2016-12-06 07:23:54 +00:00
|
|
|
#include "../SDL_dataqueue.h"
|
2017-01-06 00:45:57 +00:00
|
|
|
#include "./SDL_audio_c.h"
|
2015-06-21 15:33:46 +00:00
|
|
|
|
2016-08-06 07:39:15 +00:00
|
|
|
/* !!! FIXME: These are wordy and unlocalized... */
|
|
|
|
#define DEFAULT_OUTPUT_DEVNAME "System audio output device"
|
|
|
|
#define DEFAULT_INPUT_DEVNAME "System audio capture device"
|
|
|
|
|
2015-06-21 15:33:46 +00:00
|
|
|
/* The SDL audio driver */
|
|
|
|
typedef struct SDL_AudioDevice SDL_AudioDevice;
|
|
|
|
#define _THIS SDL_AudioDevice *_this
|
|
|
|
|
|
|
|
/* Audio targets should call this as devices are added to the system (such as
|
|
|
|
a USB headset being plugged in), and should also be called for
|
|
|
|
for every device found during DetectDevices(). */
|
|
|
|
extern void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle);
|
|
|
|
|
|
|
|
/* Audio targets should call this as devices are removed, so SDL can update
|
|
|
|
its list of available devices. */
|
|
|
|
extern void SDL_RemoveAudioDevice(const int iscapture, void *handle);
|
|
|
|
|
|
|
|
/* Audio targets should call this if an opened audio device is lost while
|
|
|
|
being used. This can happen due to i/o errors, or a device being unplugged,
|
|
|
|
etc. If the device is totally gone, please also call SDL_RemoveAudioDevice()
|
|
|
|
as appropriate so SDL's list of devices is accurate. */
|
|
|
|
extern void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device);
|
|
|
|
|
|
|
|
/* This is the size of a packet when using SDL_QueueAudio(). We allocate
|
|
|
|
these as necessary and pool them, under the assumption that we'll
|
|
|
|
eventually end up with a handful that keep recycling, meeting whatever
|
|
|
|
the app needs. We keep packing data tightly as more arrives to avoid
|
|
|
|
wasting space, and if we get a giant block of data, we'll split them
|
|
|
|
into multiple packets behind the scenes. My expectation is that most
|
|
|
|
apps will have 2-3 of these in the pool. 8k should cover most needs, but
|
|
|
|
if this is crippling for some embedded system, we can #ifdef this.
|
|
|
|
The system preallocates enough packets for 2 callbacks' worth of data. */
|
|
|
|
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN (8 * 1024)
|
|
|
|
|
|
|
|
typedef struct SDL_AudioDriverImpl
|
|
|
|
{
|
|
|
|
void (*DetectDevices) (void);
|
|
|
|
int (*OpenDevice) (_THIS, void *handle, const char *devname, int iscapture);
|
|
|
|
void (*ThreadInit) (_THIS); /* Called by audio thread at start */
|
2017-02-19 20:05:09 +00:00
|
|
|
void (*ThreadDeinit) (_THIS); /* Called by audio thread at end */
|
2017-12-06 17:24:32 +00:00
|
|
|
void (*BeginLoopIteration)(_THIS); /* Called by audio thread at top of loop */
|
2015-06-21 15:33:46 +00:00
|
|
|
void (*WaitDevice) (_THIS);
|
|
|
|
void (*PlayDevice) (_THIS);
|
|
|
|
int (*GetPendingBytes) (_THIS);
|
|
|
|
Uint8 *(*GetDeviceBuf) (_THIS);
|
2016-08-02 17:50:21 +00:00
|
|
|
int (*CaptureFromDevice) (_THIS, void *buffer, int buflen);
|
|
|
|
void (*FlushCapture) (_THIS);
|
2016-10-07 19:13:46 +00:00
|
|
|
void (*PrepareToClose) (_THIS); /**< Called between run and draining wait for playback devices */
|
2015-06-21 15:33:46 +00:00
|
|
|
void (*CloseDevice) (_THIS);
|
|
|
|
void (*LockDevice) (_THIS);
|
|
|
|
void (*UnlockDevice) (_THIS);
|
|
|
|
void (*FreeDeviceHandle) (void *handle); /**< SDL is done with handle from SDL_AddAudioDevice() */
|
|
|
|
void (*Deinitialize) (void);
|
|
|
|
|
|
|
|
/* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */
|
|
|
|
|
|
|
|
/* Some flags to push duplicate code into the core and reduce #ifdefs. */
|
|
|
|
/* !!! FIXME: these should be SDL_bool */
|
|
|
|
int ProvidesOwnCallbackThread;
|
2016-10-07 18:35:25 +00:00
|
|
|
int SkipMixerLock;
|
2015-06-21 15:33:46 +00:00
|
|
|
int HasCaptureSupport;
|
|
|
|
int OnlyHasDefaultOutputDevice;
|
2016-08-05 06:04:48 +00:00
|
|
|
int OnlyHasDefaultCaptureDevice;
|
2015-06-21 15:33:46 +00:00
|
|
|
int AllowsArbitraryDeviceNames;
|
|
|
|
} SDL_AudioDriverImpl;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct SDL_AudioDeviceItem
|
|
|
|
{
|
|
|
|
void *handle;
|
2018-10-10 19:20:56 +00:00
|
|
|
char *name;
|
|
|
|
char *original_name;
|
|
|
|
int dupenum;
|
2015-06-21 15:33:46 +00:00
|
|
|
struct SDL_AudioDeviceItem *next;
|
|
|
|
} SDL_AudioDeviceItem;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct SDL_AudioDriver
|
|
|
|
{
|
|
|
|
/* * * */
|
|
|
|
/* The name of this audio driver */
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
/* * * */
|
|
|
|
/* The description of this audio driver */
|
|
|
|
const char *desc;
|
|
|
|
|
|
|
|
SDL_AudioDriverImpl impl;
|
|
|
|
|
|
|
|
/* A mutex for device detection */
|
|
|
|
SDL_mutex *detectionLock;
|
|
|
|
SDL_bool captureDevicesRemoved;
|
|
|
|
SDL_bool outputDevicesRemoved;
|
|
|
|
int outputDeviceCount;
|
|
|
|
int inputDeviceCount;
|
|
|
|
SDL_AudioDeviceItem *outputDevices;
|
|
|
|
SDL_AudioDeviceItem *inputDevices;
|
|
|
|
} SDL_AudioDriver;
|
|
|
|
|
|
|
|
|
|
|
|
/* Define the SDL audio driver structure */
|
|
|
|
struct SDL_AudioDevice
|
|
|
|
{
|
|
|
|
/* * * */
|
|
|
|
/* Data common to all devices */
|
|
|
|
SDL_AudioDeviceID id;
|
|
|
|
|
2017-01-06 00:29:38 +00:00
|
|
|
/* The device's current audio specification */
|
2015-06-21 15:33:46 +00:00
|
|
|
SDL_AudioSpec spec;
|
|
|
|
|
2017-01-06 00:29:38 +00:00
|
|
|
/* The callback's expected audio specification (converted vs device's spec). */
|
|
|
|
SDL_AudioSpec callbackspec;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
2017-01-06 00:29:38 +00:00
|
|
|
/* Stream that converts and resamples. NULL if not needed. */
|
|
|
|
SDL_AudioStream *stream;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
/* Current state flags */
|
2016-08-01 15:45:45 +00:00
|
|
|
SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */
|
2016-08-02 17:48:52 +00:00
|
|
|
SDL_atomic_t enabled; /* true if device is functioning and connected. */
|
|
|
|
SDL_atomic_t paused;
|
|
|
|
SDL_bool iscapture;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
2017-01-06 06:07:34 +00:00
|
|
|
/* Scratch buffer used in the bridge between SDL and the user callback. */
|
|
|
|
Uint8 *work_buffer;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
2017-01-06 06:07:34 +00:00
|
|
|
/* Size, in bytes, of work_buffer. */
|
|
|
|
Uint32 work_buffer_len;
|
2017-01-06 00:29:38 +00:00
|
|
|
|
2015-06-21 15:33:46 +00:00
|
|
|
/* A mutex for locking the mixing buffers */
|
|
|
|
SDL_mutex *mixer_lock;
|
|
|
|
|
|
|
|
/* A thread to feed the audio device */
|
|
|
|
SDL_Thread *thread;
|
|
|
|
SDL_threadID threadid;
|
|
|
|
|
|
|
|
/* Queued buffers (if app not using callback). */
|
2016-12-06 07:23:54 +00:00
|
|
|
SDL_DataQueue *buffer_queue;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
/* * * */
|
|
|
|
/* Data private to this driver */
|
|
|
|
struct SDL_PrivateAudioData *hidden;
|
2016-10-04 13:48:07 +00:00
|
|
|
|
|
|
|
void *handle;
|
2015-06-21 15:33:46 +00:00
|
|
|
};
|
|
|
|
#undef _THIS
|
|
|
|
|
|
|
|
typedef struct AudioBootStrap
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *desc;
|
|
|
|
int (*init) (SDL_AudioDriverImpl * impl);
|
|
|
|
int demand_only; /* 1==request explicitly, or it won't be available. */
|
|
|
|
} AudioBootStrap;
|
|
|
|
|
2017-02-13 21:59:02 +00:00
|
|
|
/* Not all of these are available in a given build. Use #ifdefs, etc. */
|
2016-11-14 06:57:41 +00:00
|
|
|
extern AudioBootStrap PULSEAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap ALSA_bootstrap;
|
2017-06-08 17:27:58 +00:00
|
|
|
extern AudioBootStrap JACK_bootstrap;
|
2016-11-14 06:57:41 +00:00
|
|
|
extern AudioBootStrap SNDIO_bootstrap;
|
2017-05-24 23:56:59 +00:00
|
|
|
extern AudioBootStrap NETBSDAUDIO_bootstrap;
|
2016-11-14 06:57:41 +00:00
|
|
|
extern AudioBootStrap DSP_bootstrap;
|
|
|
|
extern AudioBootStrap QSAAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap SUNAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap ARTS_bootstrap;
|
|
|
|
extern AudioBootStrap ESD_bootstrap;
|
|
|
|
extern AudioBootStrap NACLAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap NAS_bootstrap;
|
2017-02-14 08:12:09 +00:00
|
|
|
extern AudioBootStrap WASAPI_bootstrap;
|
2016-11-14 06:57:41 +00:00
|
|
|
extern AudioBootStrap DSOUND_bootstrap;
|
|
|
|
extern AudioBootStrap WINMM_bootstrap;
|
|
|
|
extern AudioBootStrap PAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap HAIKUAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap COREAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap DISKAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap DUMMYAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap FUSIONSOUND_bootstrap;
|
|
|
|
extern AudioBootStrap ANDROIDAUDIO_bootstrap;
|
2019-01-12 20:18:44 +00:00
|
|
|
extern AudioBootStrap openslES_bootstrap;
|
2016-11-14 06:57:41 +00:00
|
|
|
extern AudioBootStrap PSPAUDIO_bootstrap;
|
|
|
|
extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap;
|
|
|
|
|
2016-11-21 05:34:54 +00:00
|
|
|
#endif /* SDL_sysaudio_h_ */
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|