zenilib: zenilib/jni/external/openal-soft/Alc/backends/solaris.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
solaris.c
Go to the documentation of this file.
1
21 #include "config.h"
22
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <memory.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <math.h>
33
34 #include "alMain.h"
35 #include "alu.h"
36
37 #include <sys/audioio.h>
38
39
40 static const ALCchar solaris_device[] = "Solaris Default";
41
42 static const char *solaris_driver = "/dev/audio";
43
44 typedef struct {
45 int fd;
46 volatile int killNow;
47 ALvoid *thread;
48
49 ALubyte *mix_data;
50 int data_size;
51 } solaris_data;
52
53
54 static ALuint SolarisProc(ALvoid *ptr)
55 {
56 ALCdevice *Device = (ALCdevice*)ptr;
57 solaris_data *data = (solaris_data*)Device->ExtraData;
58 ALint frameSize;
59 int wrote;
60
61 SetRTPriority();
62
63 frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType);
64
65 while(!data->killNow && Device->Connected)
66 {
67 ALint len = data->data_size;
68 ALubyte *WritePtr = data->mix_data;
69
70 aluMixData(Device, WritePtr, len/frameSize);
71 while(len > 0 && !data->killNow)
72 {
73 wrote = write(data->fd, WritePtr, len);
74 if(wrote < 0)
75 {
76 if(errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
77 {
78 ERR("write failed: %s\n", strerror(errno));
79 ALCdevice_Lock(Device);
80 aluHandleDisconnect(Device);
81 ALCdevice_Unlock(Device);
82 break;
83 }
84
85 Sleep(1);
86 continue;
87 }
88
89 len -= wrote;
90 WritePtr += wrote;
91 }
92 }
93
94 return 0;
95 }
96
97
98 static ALCenum solaris_open_playback(ALCdevice *device, const ALCchar *deviceName)
99 {
100 solaris_data *data;
101
102 if(!deviceName)
103 deviceName = solaris_device;
104 else if(strcmp(deviceName, solaris_device) != 0)
105 return ALC_INVALID_VALUE;
106
107 data = (solaris_data*)calloc(1, sizeof(solaris_data));
108 data->killNow = 0;
109
110 data->fd = open(solaris_driver, O_WRONLY);
111 if(data->fd == -1)
112 {
113 free(data);
114 ERR("Could not open %s: %s\n", solaris_driver, strerror(errno));
115 return ALC_INVALID_VALUE;
116 }
117
118 device->DeviceName = strdup(deviceName);
119 device->ExtraData = data;
120 return ALC_NO_ERROR;
121 }
122
123 static void solaris_close_playback(ALCdevice *device)
124 {
125 solaris_data *data = (solaris_data*)device->ExtraData;
126
127 close(data->fd);
128 free(data);
129 device->ExtraData = NULL;
130 }
131
132 static ALCboolean solaris_reset_playback(ALCdevice *device)
133 {
134 solaris_data *data = (solaris_data*)device->ExtraData;
135 audio_info_t info;
136 ALuint frameSize;
137 int numChannels;
138
139 AUDIO_INITINFO(&info);
140
141 info.play.sample_rate = device->Frequency;
142
143 if(device->FmtChans != DevFmtMono)
144 device->FmtChans = DevFmtStereo;
145 numChannels = ChannelsFromDevFmt(device->FmtChans);
146 info.play.channels = numChannels;
147
148 switch(device->FmtType)
149 {
150 case DevFmtByte:
151 info.play.precision = 8;
152 info.play.encoding = AUDIO_ENCODING_LINEAR;
153 break;
154 case DevFmtUByte:
155 info.play.precision = 8;
156 info.play.encoding = AUDIO_ENCODING_LINEAR8;
157 break;
158 case DevFmtUShort:
159 case DevFmtInt:
160 case DevFmtUInt:
161 case DevFmtFloat:
162 device->FmtType = DevFmtShort;
163 /* fall-through */
164 case DevFmtShort:
165 info.play.precision = 16;
166 info.play.encoding = AUDIO_ENCODING_LINEAR;
167 break;
168 }
169
170 frameSize = numChannels * BytesFromDevFmt(device->FmtType);
171 info.play.buffer_size = device->UpdateSize*device->NumUpdates * frameSize;
172
173 if(ioctl(data->fd, AUDIO_SETINFO, &info) < 0)
174 {
175 ERR("ioctl failed: %s\n", strerror(errno));
176 return ALC_FALSE;
177 }
178
179 if(ChannelsFromDevFmt(device->FmtChans) != info.play.channels)
180 {
181 ERR("Could not set %d channels, got %d instead\n", ChannelsFromDevFmt(device->FmtChans), info.play.channels);
182 return ALC_FALSE;
183 }
184
185 if(!((info.play.precision == 8 && info.play.encoding == AUDIO_ENCODING_LINEAR8 && device->FmtType == DevFmtUByte) ||
186 (info.play.precision == 8 && info.play.encoding == AUDIO_ENCODING_LINEAR && device->FmtType == DevFmtByte) ||
187 (info.play.precision == 16 && info.play.encoding == AUDIO_ENCODING_LINEAR && device->FmtType == DevFmtShort) ||
188 (info.play.precision == 32 && info.play.encoding == AUDIO_ENCODING_LINEAR && device->FmtType == DevFmtInt)))
189 {
190 ERR("Could not set %s samples, got %d (0x%x)\n", DevFmtTypeString(device->FmtType),
191 info.play.precision, info.play.encoding);
192 return ALC_FALSE;
193 }
194
195 device->Frequency = info.play.sample_rate;
196 device->UpdateSize = (info.play.buffer_size/device->NumUpdates) + 1;
197
198 SetDefaultChannelOrder(device);
199
200 return ALC_TRUE;
201 }
202
203 static ALCboolean solaris_start_playback(ALCdevice *device)
204 {
205 solaris_data *data = (solaris_data*)device->ExtraData;
206
207 data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
208 data->mix_data = calloc(1, data->data_size);
209
210 data->thread = StartThread(SolarisProc, device);
211 if(data->thread == NULL)
212 {
213 free(data->mix_data);
214 data->mix_data = NULL;
215 return ALC_FALSE;
216 }
217
218 return ALC_TRUE;
219 }
220
221 static void solaris_stop_playback(ALCdevice *device)
222 {
223 solaris_data *data = (solaris_data*)device->ExtraData;
224
225 if(!data->thread)
226 return;
227
228 data->killNow = 1;
229 StopThread(data->thread);
230 data->thread = NULL;
231
232 data->killNow = 0;
233 if(ioctl(data->fd, AUDIO_DRAIN) < 0)
234 ERR("Error draining device: %s\n", strerror(errno));
235
236 free(data->mix_data);
237 data->mix_data = NULL;
238 }
239
240
241 static const BackendFuncs solaris_funcs = {
242 solaris_open_playback,
243 solaris_close_playback,
244 solaris_reset_playback,
245 solaris_start_playback,
246 solaris_stop_playback,
247 NULL,
248 NULL,
249 NULL,
250 NULL,
251 NULL,
252 NULL,
253 ALCdevice_LockDefault,
254 ALCdevice_UnlockDefault,
255 ALCdevice_GetLatencyDefault
256 };
257
258 ALCboolean alc_solaris_init(BackendFuncs *func_list)
259 {
260 ConfigValueStr("solaris", "device", &solaris_driver);
261
262 *func_list = solaris_funcs;
263 return ALC_TRUE;
264 }
265
266 void alc_solaris_deinit(void)
267 {
268 }
269
270 void alc_solaris_probe(enum DevProbe type)
271 {
272 switch(type)
273 {
274 case ALL_DEVICE_PROBE:
275 {
276 #ifdef HAVE_STAT
277 struct stat buf;
278 if(stat(solaris_driver, &buf) == 0)
279 #endif
280 AppendAllDevicesList(solaris_device);
281 }
282 break;
283
284 case CAPTURE_DEVICE_PROBE:
285 break;
286 }
287 }
ConfigValueStr
int ConfigValueStr(const char *blockName, const char *keyName, const char **ret)
Definition: alcConfig.c:316
ALubyte
unsigned char ALubyte
Definition: al.h:47
ALCdevice_struct::Connected
ALCboolean Connected
Definition: alMain.h:564
ALvoid
void ALvoid
Definition: al.h:74
ALC_TRUE
#define ALC_TRUE
Definition: alc.h:84
type
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
BackendFuncs
Definition: alMain.h:388
DevFmtUShort
Definition: alMain.h:500
strdup
char * strdup(const char *inStr)
Definition: strdup.c:6
NULL
#define NULL
Definition: ftobjs.h:61
alu.h
free
SDL_EventEntry * free
Definition: SDL_events.c:80
ALCdevice_struct::Frequency
ALuint Frequency
Definition: alMain.h:569
alc_solaris_probe
void alc_solaris_probe(enum DevProbe type)
Definition: solaris.c:270
ALCdevice_struct
Definition: alMain.h:560
ALint
int ALint
Definition: al.h:56
solaris_stop_playback
static void solaris_stop_playback(ALCdevice *device)
Definition: solaris.c:221
aluMixData
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
Definition: ALu.c:970
ALCdevice_GetLatencyDefault
ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device)
Definition: ALc.c:1285
solaris_close_playback
static void solaris_close_playback(ALCdevice *device)
Definition: solaris.c:123
len
GLenum GLsizei len
Definition: glew.h:7035
SetDefaultChannelOrder
void SetDefaultChannelOrder(ALCdevice *device)
Definition: ALc.c:1352
solaris_open_playback
static ALCenum solaris_open_playback(ALCdevice *device, const ALCchar *deviceName)
Definition: solaris.c:98
calloc
#define calloc
Definition: SDL_malloc.c:636
aluHandleDisconnect
ALvoid aluHandleDisconnect(ALCdevice *device)
Definition: ALu.c:1176
ALCchar
char ALCchar
Definition: alc.h:42
DevFmtByte
Definition: alMain.h:497
Sleep
#define Sleep(x)
Definition: allatency.c:34
ALCdevice_Unlock
#define ALCdevice_Unlock(a)
Definition: alMain.h:647
ALL_DEVICE_PROBE
Definition: alMain.h:384
DevFmtStereo
Definition: alMain.h:509
ALCdevice_struct::ExtraData
void * ExtraData
Definition: alMain.h:630
ALC_FALSE
#define ALC_FALSE
Definition: alc.h:81
DevFmtFloat
Definition: alMain.h:503
DevFmtInt
Definition: alMain.h:501
StopThread
ALuint StopThread(ALvoid *thread)
Definition: alcThread.c:131
alMain.h
DevFmtShort
Definition: alMain.h:499
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
SolarisProc
static ALuint SolarisProc(ALvoid *ptr)
Definition: solaris.c:54
solaris_driver
static const char * solaris_driver
Definition: solaris.c:42
ALuint
unsigned int ALuint
Definition: al.h:59
SetRTPriority
void SetRTPriority(void)
Definition: helpers.c:470
ALCdevice_struct::FmtChans
enum DevFmtChannels FmtChans
Definition: alMain.h:572
thread
static SDL_Thread * thread
Definition: SDL_sysjoystick.c:41
CAPTURE_DEVICE_PROBE
Definition: alMain.h:385
ALC_NO_ERROR
#define ALC_NO_ERROR
Definition: alc.h:102
ALCdevice_LockDefault
void ALCdevice_LockDefault(ALCdevice *device)
Definition: ALc.c:1277
solaris_reset_playback
static ALCboolean solaris_reset_playback(ALCdevice *device)
Definition: solaris.c:132
ALCboolean
char ALCboolean
Definition: alc.h:39
DevFmtUInt
Definition: alMain.h:502
solaris_funcs
static const BackendFuncs solaris_funcs
Definition: solaris.c:241
DevFmtMono
Definition: alMain.h:508
ERR
#define ERR(...)
Definition: alMain.h:816
ALCdevice_struct::UpdateSize
ALuint UpdateSize
Definition: alMain.h:570
ALCdevice_struct::NumUpdates
ALuint NumUpdates
Definition: alMain.h:571
ALCdevice_struct::FmtType
enum DevFmtType FmtType
Definition: alMain.h:573
ALCdevice_struct::DeviceName
ALCchar * DeviceName
Definition: alMain.h:575
ALC_INVALID_VALUE
#define ALC_INVALID_VALUE
Definition: alc.h:114
alc_solaris_init
ALCboolean alc_solaris_init(BackendFuncs *func_list)
Definition: solaris.c:258
types.h
ALCenum
int ALCenum
Definition: alc.h:66
DevFmtTypeString
const ALCchar * DevFmtTypeString(enum DevFmtType type)
Definition: ALc.c:1136
DevFmtUByte
Definition: alMain.h:498
solaris_device
static const ALCchar solaris_device[]
Definition: solaris.c:40
BytesFromDevFmt
ALuint BytesFromDevFmt(enum DevFmtType type)
Definition: ALc.c:1165
solaris_start_playback
static ALCboolean solaris_start_playback(ALCdevice *device)
Definition: solaris.c:203
ALCdevice_UnlockDefault
void ALCdevice_UnlockDefault(ALCdevice *device)
Definition: ALc.c:1281
ChannelsFromDevFmt
ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
Definition: ALc.c:1179
ALCdevice_Lock
#define ALCdevice_Lock(a)
Definition: alMain.h:646
alc_solaris_deinit
void alc_solaris_deinit(void)
Definition: solaris.c:266
AppendAllDevicesList
void AppendAllDevicesList(const ALCchar *name)
StartThread
ALvoid * StartThread(ALuint(*func)(ALvoid *), ALvoid *ptr)
Definition: alcThread.c:100
DevProbe
DevProbe
Definition: alMain.h:383
FrameSizeFromDevFmt
static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type)
Definition: alMain.h:523