Skip to content

Latest commit

 

History

History
255 lines (215 loc) · 7.93 KB

SDL_sysaudio.h

File metadata and controls

255 lines (215 loc) · 7.93 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 2, 2017
Jan 2, 2017
3
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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"
Nov 21, 2016
Nov 21, 2016
23
24
#ifndef SDL_sysaudio_h_
#define SDL_sysaudio_h_
25
26
27
#include "SDL_mutex.h"
#include "SDL_thread.h"
Dec 6, 2016
Dec 6, 2016
28
#include "../SDL_dataqueue.h"
Jan 6, 2017
Jan 6, 2017
29
#include "./SDL_audio_c.h"
Aug 6, 2016
Aug 6, 2016
31
32
33
34
/* !!! FIXME: These are wordy and unlocalized... */
#define DEFAULT_OUTPUT_DEVNAME "System audio output device"
#define DEFAULT_INPUT_DEVNAME "System audio capture device"
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* 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 */
void (*WaitDevice) (_THIS);
void (*PlayDevice) (_THIS);
int (*GetPendingBytes) (_THIS);
Uint8 *(*GetDeviceBuf) (_THIS);
Aug 2, 2016
Aug 2, 2016
74
75
int (*CaptureFromDevice) (_THIS, void *buffer, int buflen);
void (*FlushCapture) (_THIS);
Oct 7, 2016
Oct 7, 2016
76
void (*PrepareToClose) (_THIS); /**< Called between run and draining wait for playback devices */
77
78
79
80
81
82
83
84
85
86
87
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;
Oct 7, 2016
Oct 7, 2016
88
int SkipMixerLock;
89
90
int HasCaptureSupport;
int OnlyHasDefaultOutputDevice;
Aug 5, 2016
Aug 5, 2016
91
int OnlyHasDefaultCaptureDevice;
92
93
94
95
96
97
98
99
int AllowsArbitraryDeviceNames;
} SDL_AudioDriverImpl;
typedef struct SDL_AudioDeviceItem
{
void *handle;
struct SDL_AudioDeviceItem *next;
Dec 6, 2016
Dec 6, 2016
100
char name[SDL_VARIABLE_LENGTH_ARRAY];
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
} 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;
Jan 6, 2017
Jan 6, 2017
134
/* The device's current audio specification */
135
136
SDL_AudioSpec spec;
Jan 6, 2017
Jan 6, 2017
137
138
/* The callback's expected audio specification (converted vs device's spec). */
SDL_AudioSpec callbackspec;
Jan 6, 2017
Jan 6, 2017
140
141
/* Stream that converts and resamples. NULL if not needed. */
SDL_AudioStream *stream;
142
143
/* Current state flags */
Aug 1, 2016
Aug 1, 2016
144
SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */
Aug 2, 2016
Aug 2, 2016
145
146
147
SDL_atomic_t enabled; /* true if device is functioning and connected. */
SDL_atomic_t paused;
SDL_bool iscapture;
Jan 6, 2017
Jan 6, 2017
149
150
/* Scratch buffer used in the bridge between SDL and the user callback. */
Uint8 *work_buffer;
Jan 6, 2017
Jan 6, 2017
152
153
/* Size, in bytes, of work_buffer. */
Uint32 work_buffer_len;
Jan 6, 2017
Jan 6, 2017
154
155
156
157
158
159
160
161
162
/* 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). */
Dec 6, 2016
Dec 6, 2016
163
SDL_DataQueue *buffer_queue;
164
165
166
167
/* * * */
/* Data private to this driver */
struct SDL_PrivateAudioData *hidden;
Oct 4, 2016
Oct 4, 2016
168
169
void *handle;
170
171
172
173
174
175
176
177
178
179
180
};
#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;
Nov 14, 2016
Nov 14, 2016
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#if SDL_AUDIO_DRIVER_PULSEAUDIO
extern AudioBootStrap PULSEAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_ALSA
extern AudioBootStrap ALSA_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_SNDIO
extern AudioBootStrap SNDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_BSD
extern AudioBootStrap BSD_AUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_OSS
extern AudioBootStrap DSP_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_QSA
extern AudioBootStrap QSAAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_SUNAUDIO
extern AudioBootStrap SUNAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_ARTS
extern AudioBootStrap ARTS_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_ESD
extern AudioBootStrap ESD_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_NACL
extern AudioBootStrap NACLAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_NAS
extern AudioBootStrap NAS_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_XAUDIO2
extern AudioBootStrap XAUDIO2_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_DSOUND
extern AudioBootStrap DSOUND_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_WINMM
extern AudioBootStrap WINMM_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_PAUDIO
extern AudioBootStrap PAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_HAIKU
extern AudioBootStrap HAIKUAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_COREAUDIO
extern AudioBootStrap COREAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_DISK
extern AudioBootStrap DISKAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_DUMMY
extern AudioBootStrap DUMMYAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_FUSIONSOUND
extern AudioBootStrap FUSIONSOUND_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_ANDROID
extern AudioBootStrap ANDROIDAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_PSP
extern AudioBootStrap PSPAUDIO_bootstrap;
#endif
#if SDL_AUDIO_DRIVER_EMSCRIPTEN
extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap;
#endif
Nov 21, 2016
Nov 21, 2016
253
#endif /* SDL_sysaudio_h_ */
254
255
/* vi: set ts=4 sw=4 expandtab: */