Atlas - SDL_sysaudio.h
Home / ext / SDL2 / src / audio Lines: 1 | Size: 7594 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2018 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "../SDL_internal.h" 22 23#ifndef SDL_sysaudio_h_ 24#define SDL_sysaudio_h_ 25 26#include "SDL_mutex.h" 27#include "SDL_thread.h" 28#include "../SDL_dataqueue.h" 29#include "./SDL_audio_c.h" 30 31/* !!! FIXME: These are wordy and unlocalized... */ 32#define DEFAULT_OUTPUT_DEVNAME "System audio output device" 33#define DEFAULT_INPUT_DEVNAME "System audio capture device" 34 35/* The SDL audio driver */ 36typedef struct SDL_AudioDevice SDL_AudioDevice; 37#define _THIS SDL_AudioDevice *_this 38 39/* Audio targets should call this as devices are added to the system (such as 40 a USB headset being plugged in), and should also be called for 41 for every device found during DetectDevices(). */ 42extern void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle); 43 44/* Audio targets should call this as devices are removed, so SDL can update 45 its list of available devices. */ 46extern void SDL_RemoveAudioDevice(const int iscapture, void *handle); 47 48/* Audio targets should call this if an opened audio device is lost while 49 being used. This can happen due to i/o errors, or a device being unplugged, 50 etc. If the device is totally gone, please also call SDL_RemoveAudioDevice() 51 as appropriate so SDL's list of devices is accurate. */ 52extern void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device); 53 54/* This is the size of a packet when using SDL_QueueAudio(). We allocate 55 these as necessary and pool them, under the assumption that we'll 56 eventually end up with a handful that keep recycling, meeting whatever 57 the app needs. We keep packing data tightly as more arrives to avoid 58 wasting space, and if we get a giant block of data, we'll split them 59 into multiple packets behind the scenes. My expectation is that most 60 apps will have 2-3 of these in the pool. 8k should cover most needs, but 61 if this is crippling for some embedded system, we can #ifdef this. 62 The system preallocates enough packets for 2 callbacks' worth of data. */ 63#define SDL_AUDIOBUFFERQUEUE_PACKETLEN (8 * 1024) 64 65typedef struct SDL_AudioDriverImpl 66{ 67 void (*DetectDevices) (void); 68 int (*OpenDevice) (_THIS, void *handle, const char *devname, int iscapture); 69 void (*ThreadInit) (_THIS); /* Called by audio thread at start */ 70 void (*ThreadDeinit) (_THIS); /* Called by audio thread at end */ 71 void (*BeginLoopIteration)(_THIS); /* Called by audio thread at top of loop */ 72 void (*WaitDevice) (_THIS); 73 void (*PlayDevice) (_THIS); 74 int (*GetPendingBytes) (_THIS); 75 Uint8 *(*GetDeviceBuf) (_THIS); 76 int (*CaptureFromDevice) (_THIS, void *buffer, int buflen); 77 void (*FlushCapture) (_THIS); 78 void (*PrepareToClose) (_THIS); /**< Called between run and draining wait for playback devices */ 79 void (*CloseDevice) (_THIS); 80 void (*LockDevice) (_THIS); 81 void (*UnlockDevice) (_THIS); 82 void (*FreeDeviceHandle) (void *handle); /**< SDL is done with handle from SDL_AddAudioDevice() */ 83 void (*Deinitialize) (void); 84 85 /* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */ 86 87 /* Some flags to push duplicate code into the core and reduce #ifdefs. */ 88 /* !!! FIXME: these should be SDL_bool */ 89 int ProvidesOwnCallbackThread; 90 int SkipMixerLock; 91 int HasCaptureSupport; 92 int OnlyHasDefaultOutputDevice; 93 int OnlyHasDefaultCaptureDevice; 94 int AllowsArbitraryDeviceNames; 95} SDL_AudioDriverImpl; 96 97 98typedef struct SDL_AudioDeviceItem 99{ 100 void *handle; 101 struct SDL_AudioDeviceItem *next; 102 char name[SDL_VARIABLE_LENGTH_ARRAY]; 103} SDL_AudioDeviceItem; 104 105 106typedef struct SDL_AudioDriver 107{ 108 /* * * */ 109 /* The name of this audio driver */ 110 const char *name; 111 112 /* * * */ 113 /* The description of this audio driver */ 114 const char *desc; 115 116 SDL_AudioDriverImpl impl; 117 118 /* A mutex for device detection */ 119 SDL_mutex *detectionLock; 120 SDL_bool captureDevicesRemoved; 121 SDL_bool outputDevicesRemoved; 122 int outputDeviceCount; 123 int inputDeviceCount; 124 SDL_AudioDeviceItem *outputDevices; 125 SDL_AudioDeviceItem *inputDevices; 126} SDL_AudioDriver; 127 128 129/* Define the SDL audio driver structure */ 130struct SDL_AudioDevice 131{ 132 /* * * */ 133 /* Data common to all devices */ 134 SDL_AudioDeviceID id; 135 136 /* The device's current audio specification */ 137 SDL_AudioSpec spec; 138 139 /* The callback's expected audio specification (converted vs device's spec). */ 140 SDL_AudioSpec callbackspec; 141 142 /* Stream that converts and resamples. NULL if not needed. */ 143 SDL_AudioStream *stream; 144 145 /* Current state flags */ 146 SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */ 147 SDL_atomic_t enabled; /* true if device is functioning and connected. */ 148 SDL_atomic_t paused; 149 SDL_bool iscapture; 150 151 /* Scratch buffer used in the bridge between SDL and the user callback. */ 152 Uint8 *work_buffer; 153 154 /* Size, in bytes, of work_buffer. */ 155 Uint32 work_buffer_len; 156 157 /* A mutex for locking the mixing buffers */ 158 SDL_mutex *mixer_lock; 159 160 /* A thread to feed the audio device */ 161 SDL_Thread *thread; 162 SDL_threadID threadid; 163 164 /* Queued buffers (if app not using callback). */ 165 SDL_DataQueue *buffer_queue; 166 167 /* * * */ 168 /* Data private to this driver */ 169 struct SDL_PrivateAudioData *hidden; 170 171 void *handle; 172}; 173#undef _THIS 174 175typedef struct AudioBootStrap 176{ 177 const char *name; 178 const char *desc; 179 int (*init) (SDL_AudioDriverImpl * impl); 180 int demand_only; /* 1==request explicitly, or it won't be available. */ 181} AudioBootStrap; 182 183/* Not all of these are available in a given build. Use #ifdefs, etc. */ 184extern AudioBootStrap PULSEAUDIO_bootstrap; 185extern AudioBootStrap ALSA_bootstrap; 186extern AudioBootStrap JACK_bootstrap; 187extern AudioBootStrap SNDIO_bootstrap; 188extern AudioBootStrap NETBSDAUDIO_bootstrap; 189extern AudioBootStrap DSP_bootstrap; 190extern AudioBootStrap QSAAUDIO_bootstrap; 191extern AudioBootStrap SUNAUDIO_bootstrap; 192extern AudioBootStrap ARTS_bootstrap; 193extern AudioBootStrap ESD_bootstrap; 194extern AudioBootStrap NACLAUDIO_bootstrap; 195extern AudioBootStrap NAS_bootstrap; 196extern AudioBootStrap WASAPI_bootstrap; 197extern AudioBootStrap DSOUND_bootstrap; 198extern AudioBootStrap WINMM_bootstrap; 199extern AudioBootStrap PAUDIO_bootstrap; 200extern AudioBootStrap HAIKUAUDIO_bootstrap; 201extern AudioBootStrap COREAUDIO_bootstrap; 202extern AudioBootStrap DISKAUDIO_bootstrap; 203extern AudioBootStrap DUMMYAUDIO_bootstrap; 204extern AudioBootStrap FUSIONSOUND_bootstrap; 205extern AudioBootStrap ANDROIDAUDIO_bootstrap; 206extern AudioBootStrap PSPAUDIO_bootstrap; 207extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap; 208 209#endif /* SDL_sysaudio_h_ */ 210 211/* vi: set ts=4 sw=4 expandtab: */ 212[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.