21 #include "../SDL_internal.h" 29 #include "../thread/SDL_systhread.h" 31 #define _THIS SDL_AudioDevice *_this 68 #if SDL_AUDIO_DRIVER_PULSEAUDIO 71 #if SDL_AUDIO_DRIVER_ALSA 74 #if SDL_AUDIO_DRIVER_SNDIO 77 #if SDL_AUDIO_DRIVER_BSD 80 #if SDL_AUDIO_DRIVER_OSS 83 #if SDL_AUDIO_DRIVER_QSA 86 #if SDL_AUDIO_DRIVER_SUNAUDIO 89 #if SDL_AUDIO_DRIVER_ARTS 92 #if SDL_AUDIO_DRIVER_ESD 95 #if SDL_AUDIO_DRIVER_NACL 98 #if SDL_AUDIO_DRIVER_NAS 101 #if SDL_AUDIO_DRIVER_XAUDIO2 104 #if SDL_AUDIO_DRIVER_DSOUND 107 #if SDL_AUDIO_DRIVER_WINMM 110 #if SDL_AUDIO_DRIVER_PAUDIO 113 #if SDL_AUDIO_DRIVER_HAIKU 116 #if SDL_AUDIO_DRIVER_COREAUDIO 119 #if SDL_AUDIO_DRIVER_DISK 122 #if SDL_AUDIO_DRIVER_DUMMY 125 #if SDL_AUDIO_DRIVER_FUSIONSOUND 128 #if SDL_AUDIO_DRIVER_ANDROID 131 #if SDL_AUDIO_DRIVER_PSP 134 #if SDL_AUDIO_DRIVER_EMSCRIPTEN 149 return open_devices[
id];
284 #define FILL_STUB(x) \ 285 if (current_audio.impl.x == NULL) { \ 286 current_audio.impl.x = SDL_Audio##x##_Default; \ 325 item->
next = *devices;
327 retval = (*devCount)++;
350 for (item = *devices; item !=
NULL; item = next) {
367 if (device_index != -1) {
373 event.adevice.which = device_index;
374 event.adevice.iscapture = iscapture;
400 event.adevice.which = device->
id;
401 event.adevice.iscapture = device->
iscapture ? 1 : 0;
411 for (item = devices; item !=
NULL; item = item->
next) {
412 if (item->
handle == handle) {
433 for (device_index = 0; device_index <
SDL_arraysize(open_devices); device_index++)
435 device = open_devices[device_index];
436 if (device !=
NULL && device->
handle == handle)
473 origlen = origtail ? origtail->
datalen : 0;
481 if (packet !=
NULL) {
487 if (packet ==
NULL) {
492 packet = origtail->
next;
577 len -= (int) written;
610 return SDL_SetError(
"This is a capture device, queueing not allowed");
612 return SDL_SetError(
"Audio device has a callback, queueing not allowed");
759 (*callback) (udata,
stream, stream_len);
826 still_need = stream_len;
838 while (still_need > 0) {
850 if (still_need > 0) {
864 (*callback)(udata,
stream, stream_len);
878 #define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x 897 #undef CHECK_FMT_STRING 921 int tried_to_init = 0;
931 if (driver_name ==
NULL) {
935 for (i = 0; (!initialized) && (bootstrap[i]); ++
i) {
947 initialized = backend->
init(¤t_audio.
impl);
952 if (!tried_to_init) {
954 SDL_SetError(
"Audio target '%s' not available", driver_name);
980 return current_audio.
name;
1061 for (i--; i >
index; i--, item = item->
next) {
1065 retval = item->name;
1070 if (retval ==
NULL) {
1085 if (device->
id > 0) {
1088 if (opendev == device) {
1089 open_devices[device->
id - 1] =
NULL;
1126 if (orig->
freq == 0) {
1127 const char *env =
SDL_getenv(
"SDL_AUDIO_FREQUENCY");
1128 if ((!env) || ((prepared->
freq =
SDL_atoi(env)) == 0)) {
1129 prepared->
freq = 22050;
1134 const char *env =
SDL_getenv(
"SDL_AUDIO_FORMAT");
1142 const char *env =
SDL_getenv(
"SDL_AUDIO_CHANNELS");
1159 const char *env =
SDL_getenv(
"SDL_AUDIO_SAMPLES");
1165 while (power2 < samples) {
1181 int allowed_changes,
int min_id)
1188 void *handle =
NULL;
1203 for (
id = min_id - 1;
id <
SDL_arraysize(open_devices);
id++) {
1204 if (open_devices[
id] ==
NULL) {
1215 obtained = &_obtained;
1222 if (devname ==
NULL) {
1223 devname =
SDL_getenv(
"SDL_AUDIO_DEVICE_NAME");
1244 if ((open_devices[i]) && (open_devices[
i]->
iscapture)) {
1257 if ((open_devices[i]) && (!open_devices[
i]->
iscapture)) {
1262 }
else if (devname !=
NULL) {
1282 if ((handle ==
NULL) && (devname !=
NULL)) {
1289 if (device ==
NULL) {
1293 device->
id =
id + 1;
1294 device->
spec = *obtained;
1312 if (current_audio.
impl.
OpenDevice(device, handle, devname, iscapture) < 0) {
1383 const int wantpackets = (wantbytes / packetlen) + ((wantbytes % packetlen) ? packetlen : 0);
1384 for (i = 0; i < wantpackets; i++) {
1399 open_devices[
id] = device;
1406 const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;
1407 char threadname[64];
1411 if (device->
spec.
size > stream_len) {
1423 SDL_snprintf(threadname,
sizeof (threadname),
"SDLAudioDev%d", (
int) device->
id);
1450 if (open_devices[0] !=
NULL) {
1463 return (
id == 0) ? -1 : 0;
1469 int allowed_changes)
1472 allowed_changes, 2);
1564 if (!current_audio.
name) {
1584 #define NUM_FORMATS 10 1657 if (device !=
NULL) {
static SDL_AudioDevice * open_devices[16]
struct SDL_PrivateAudioData * hidden
static int format_idx_sub
void SDL_LockAudioDevice(SDL_AudioDeviceID devid)
static int queue_audio_to_device(SDL_AudioDevice *device, const Uint8 *data, Uint32 len)
#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE
void SDL_UnlockAudio(void)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static int SDL_CaptureAudio(void *devicep)
AudioBootStrap PSPAUDIO_bootstrap
AudioBootStrap SUNAUDIO_bootstrap
GLuint GLfloat GLfloat GLfloat x1
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
SDL_bool captureDevicesRemoved
AudioBootStrap PULSEAUDIO_bootstrap
void(* DetectDevices)(void)
int SDL_GetNumAudioDrivers(void)
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
const char * SDL_GetCurrentAudioDriver()
static void mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
const char * SDL_GetAudioDriver(int index)
#define SDL_BuildAudioCVT
struct SDL_AudioDeviceItem * next
static void clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
AudioBootStrap QSAAUDIO_bootstrap
static SDL_INLINE int add_output_device(const char *name, void *handle)
static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS]
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int ProvidesOwnCallbackThread
SDL_AudioDeviceID SDL_OpenAudioDevice(const char *device, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes)
void(* PlayDevice)(_THIS)
SDL_AudioBufferQueue * buffer_queue_pool
void(* WaitDevice)(_THIS)
void SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
#define SDL_InitSubSystem
static int SDL_RunAudio(void *devicep)
#define SDL_MixAudioFormat
Uint16 SDL_AudioFormat
Audio format flags.
Uint32 SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
static Uint8 * SDL_AudioGetDeviceBuf_Default(_THIS)
GLuint const GLchar * name
AudioBootStrap DSOUND_bootstrap
static void SDL_AudioUnlockDevice_Default(SDL_AudioDevice *device)
uint32_t Uint32
An unsigned 32-bit integer type.
static SDL_AudioDriver current_audio
void(* UnlockDevice)(_THIS)
int OnlyHasDefaultCaptureDevice
AudioBootStrap ARTS_bootstrap
AudioBootStrap WINMM_bootstrap
AudioBootStrap BSD_AUDIO_bootstrap
SDL_AudioFormat SDL_NextAudioFormat(void)
#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE
SDL_mutex * detectionLock
SDL_AudioBufferQueue * buffer_queue_head
AudioBootStrap ANDROIDAUDIO_bootstrap
SDL_AudioBufferQueue * buffer_queue_tail
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
void * SDL_calloc(size_t nmemb, size_t size)
static void SDL_AudioDeinitialize_Default(void)
struct SDL_AudioBufferQueue * next
void(* ThreadInit)(_THIS)
int OnlyHasDefaultOutputDevice
SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
#define SDL_GetEventState(type)
void SDL_RemoveAudioDevice(const int iscapture, void *handle)
uint8_t Uint8
An unsigned 8-bit integer type.
static void SDL_AudioWaitDevice_Default(_THIS)
static void SDL_AudioLockOrUnlockDeviceWithNoMixerLock(SDL_AudioDevice *device)
AudioBootStrap DISKAUDIO_bootstrap
#define SDL_AUDIO_BITSIZE(x)
void(* PrepareToClose)(_THIS)
AudioBootStrap PAUDIO_bootstrap
#define SDL_AUDIO_ALLOW_ANY_CHANGE
void(* Deinitialize)(void)
static int prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
void SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
static int SDL_AudioOpenDevice_Default(_THIS, void *handle, const char *devname, int iscapture)
static Uint32 dequeue_audio_from_device(SDL_AudioDevice *device, Uint8 *stream, Uint32 len)
AudioBootStrap COREAUDIO_bootstrap
static Uint32 callback(Uint32 interval, void *param)
void SDL_PauseAudio(int pause_on)
AudioBootStrap ALSA_bootstrap
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
SDL_AudioStatus SDL_GetAudioStatus(void)
SDL_AudioCallback callback
SDL_AudioFormat src_format
static void SDL_AudioThreadInit_Default(_THIS)
static void SDL_AudioDetectDevices_Default(void)
static int SDL_AudioCaptureFromDevice_Default(_THIS, void *buffer, int buflen)
int SDL_QueueAudio(SDL_AudioDeviceID devid, const void *data, Uint32 len)
static int add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
AudioBootStrap NAS_bootstrap
void(* LockDevice)(_THIS)
const char * SDL_GetAudioDeviceName(int index, int iscapture)
static void SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int len)
SDL_AudioDeviceItem * outputDevices
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
static int SDL_AudioGetPendingBytes_Default(_THIS)
#define SDL_assert(condition)
static const AudioBootStrap *const bootstrap[]
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
static void SDL_AudioPlayDevice_Default(_THIS)
#define SDL_OutOfMemory()
SDL_bool outputDevicesRemoved
int(* CaptureFromDevice)(_THIS, void *buffer, int buflen)
static void free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
AudioBootStrap DSP_bootstrap
static void SDL_BufferQueueFillCallback(void *userdata, Uint8 *stream, int len)
static SDL_AudioDeviceID open_audio_device(const char *devname, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes, int min_id)
AudioBootStrap DUMMYAUDIO_bootstrap
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
void(* CloseDevice)(_THIS)
int AllowsArbitraryDeviceNames
static SDL_INLINE int add_capture_device(const char *name, void *handle)
static void free_audio_queue(SDL_AudioBufferQueue *packet)
static void SDL_AudioLockDevice_Default(SDL_AudioDevice *device)
AudioBootStrap NACLAUDIO_bootstrap
void(* FreeDeviceHandle)(void *handle)
void(* FlushCapture)(_THIS)
AudioBootStrap XAUDIO2_bootstrap
AudioBootStrap HAIKUAUDIO_bootstrap
void SDL_CloseAudio(void)
Uint8 *(* GetDeviceBuf)(_THIS)
int SDL_GetNumAudioDevices(int iscapture)
AudioBootStrap EMSCRIPTENAUDIO_bootstrap
uint16_t Uint16
An unsigned 16-bit integer type.
#define DEFAULT_OUTPUT_DEVNAME
#define SDL_AUDIO_ALLOW_FORMAT_CHANGE
static SDL_AudioFormat SDL_ParseAudioFormat(const char *string)
#define DEFAULT_INPUT_DEVNAME
#define SDL_arraysize(array)
Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]
static void SDL_AudioPrepareToClose_Default(_THIS)
int(* init)(SDL_AudioDriverImpl *impl)
static void SDL_AudioCloseDevice_Default(_THIS)
int(* GetPendingBytes)(_THIS)
AudioBootStrap ESD_bootstrap
Uint32 SDL_DequeueAudio(SDL_AudioDeviceID devid, void *data, Uint32 len)
void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
#define SDL_AUDIOBUFFERQUEUE_PACKETLEN
static void SDL_AudioFlushCapture_Default(_THIS)
void SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume)
#define CHECK_FMT_STRING(x)
void SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
static SDL_AudioDevice * get_audio_device(SDL_AudioDeviceID id)
#define SDL_Unsupported()
static SDL_INLINE SDL_bool is_in_audio_device_thread(SDL_AudioDevice *device)
#define SDL_SetThreadPriority
static void finish_audio_entry_points_init(void)
SDL_AudioDeviceItem * inputDevices
static void SDL_AudioFreeDeviceHandle_Default(void *handle)
AudioBootStrap SNDIO_bootstrap
int SDL_AudioInit(const char *driver_name)
void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
static void close_audio_device(SDL_AudioDevice *device)
AudioBootStrap FUSIONSOUND_bootstrap