annotate libao2/ao_oss.c @ 1215:9b44aca2ab63

*** empty log message ***
author gabucino
date Sat, 23 Jun 2001 22:42:38 +0000
parents f9a46e7843ee
children 8c57a5a3c645
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
3
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
4 #include <sys/ioctl.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
7 #include <sys/types.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
8 #include <sys/stat.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
9 #include <fcntl.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
10 #include <sys/soundcard.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
11
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
12 #include "../config.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
13
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
14 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
15 #include "audio_out_internal.h"
1058
cab5ba9ffc6c fixed AFMT_ stuff (inclue afmt.h)
arpi_esp
parents: 1038
diff changeset
16 //#include "afmt.h"
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
17
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
18 extern int verbose;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
19
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
20 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
21 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
22 "OSS/ioctl audio output",
956
a6cecd9a1bad '-ao' switch (including '-ao help'), fixing Arpi's bug (short name 'null' for both of oss and null driver ;)
lgb
parents: 954
diff changeset
23 "oss",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
24 "A'rpi",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
25 ""
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
26 };
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
27
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
28 LIBAO_EXTERN(oss)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
29
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
30 // there are some globals:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
31 // ao_samplerate
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
32 // ao_channels
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
33 // ao_format
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
34 // ao_bps
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
35 // ao_outburst
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
36 // ao_buffersize
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
37
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
38 static char *dsp="/dev/dsp";
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
39 static audio_buf_info zz;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
40 static int audio_fd=-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
41
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
42 char *oss_mixer_device = "/dev/mixer";
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
43 int oss_mixer_usemaster = 0;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
44
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
45 // to set/get/query special features/parameters
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 static int control(int cmd,int arg){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47 switch(cmd){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
48 case AOCONTROL_SET_DEVICE:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
49 dsp=(char*)arg;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
50 return CONTROL_OK;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
51 case AOCONTROL_QUERY_FORMAT:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
52 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
53 case AOCONTROL_GET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
54 case AOCONTROL_SET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
55 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
56 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
57 int fd, v, mcmd, devs;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
58
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
59 if ((fd = open("/dev/mixer", O_RDONLY)) > 0)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
60 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
61 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
62 if ((devs & SOUND_MASK_PCM) && (oss_mixer_usemaster == 0))
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
63 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
64 mcmd = SOUND_MIXER_READ_PCM;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
65 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
66 mcmd = SOUND_MIXER_WRITE_PCM;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
67 else if ((devs & SOUND_MASK_VOLUME) && (oss_mixer_usemaster == 1))
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
68 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
69 mcmd = SOUND_MIXER_READ_VOLUME;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
70 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
71 mcmd = SOUND_MIXER_WRITE_VOLUME;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
72 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
73 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
74 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
75 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
76 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
77
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
78 if (cmd == AOCONTROL_GET_VOLUME)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
79 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
80 ioctl(fd, cmd, &v);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
81 vol->right = (v & 0xFF00) >> 8;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
82 vol->left = v & 0x00FF;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
83 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
84 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
85 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
86 v = ((int)vol->right << 8) | (int)vol->left;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
87 ioctl(fd, cmd, &v);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
88 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
89 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
90 return CONTROL_OK;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
91 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
92 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
93 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
94 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
95 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
96 default:
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
97 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
98 return CONTROL_UNKNOWN;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
99 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
100
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
101 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
102 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
103 static int init(int rate,int channels,int format,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
104
1079
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
105 printf("ao2: %d Hz %d chans %s\n",rate,channels,
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
106 audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
107
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
108 if (ao_subdevice)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
109 dsp = ao_subdevice;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
110
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
111 if (verbose)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
112 printf("audio_setup: using '%s' dsp device\n", dsp);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
113
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
114 audio_fd=open(dsp, O_WRONLY);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
115 if(audio_fd<0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
116 printf("Can't open audio device %s -> nosound\n",dsp);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
117 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
118 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
119
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
120 ao_format=format;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
121 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
1079
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
122 printf("audio_setup: sample format: %s (requested: %s)\n",
1e0da351feaa using audio_out_format_name
al3x
parents: 1058
diff changeset
123 audio_out_format_name(ao_format), audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
124
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
125 ao_channels=channels-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
126 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
127
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
128 // set rate
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
129 ao_samplerate=rate;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
130 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
131 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
132
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
133 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
134 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
135 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
136 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
137 printf("audio_setup: %d bytes/frag (config.h)\n",ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
138 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
139 ao_outburst=r;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
140 printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
141 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
142 } else {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
143 printf("audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
144 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
145 if(ao_buffersize==-1) ao_buffersize=zz.bytes;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
146 ao_outburst=zz.fragsize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
147 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
148
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
149 if(ao_buffersize==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
150 // Measuring buffer size:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
151 void* data;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
152 ao_buffersize=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
153 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
154 data=malloc(ao_outburst); memset(data,0,ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
155 while(ao_buffersize<0x40000){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
156 fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
157 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
158 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
159 tv.tv_sec=0; tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
160 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
161 write(audio_fd,data,ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
162 ao_buffersize+=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
163 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
164 free(data);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
165 if(ao_buffersize==0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
166 printf("\n *** Your audio driver DOES NOT support select() ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
167 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
168 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
169 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
170 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
171 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
172
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
173 return 1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
174 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
175
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
176 // close audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
177 static void uninit(){
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
178 #ifdef SNDCTL_DSP_RESET
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
179 ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
180 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
181 close(audio_fd);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
182 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
183
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
184 // stop playing and empty buffers (for seeking/pause)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
185 static void reset(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
186 uninit();
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
187 audio_fd=open(dsp, O_WRONLY);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
188 if(audio_fd<0){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
189 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
190 return;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
191 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
192
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
193 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
194 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
195 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
196
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
197 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
198
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
199 // stop playing, keep buffers (for pause)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
200 static void audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
201 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
202 // for now, just call reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
203 reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
204 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
205
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
206 // resume playing, after audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
207 static void audio_resume()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
208 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
209 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
210
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
211
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
212 // return: how many bytes can be played without blocking
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
213 static int get_space(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
214 int playsize=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
215
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
216 #ifdef SNDCTL_DSP_GETOSPACE
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
217 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
218 // calculate exact buffer space:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
219 return zz.fragments*zz.fragsize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
220 }
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
221 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
222
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
223 // check buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
224 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
225 { fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
226 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
227 FD_ZERO(&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
228 FD_SET(audio_fd, &rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
229 tv.tv_sec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
230 tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
231 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block!
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
232 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
233 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
234
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
235 return ao_outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
236 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
237
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
238 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
239 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
240 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
241 static int play(void* data,int len,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
242 len/=ao_outburst;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
243 len=write(audio_fd,data,len*ao_outburst);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
244 return len;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
245 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
246
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
247 static int audio_delay_method=2;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
248
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
249 // return: how many unplayed bytes are in the buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
250 static int get_delay(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
251 if(audio_delay_method==2){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
252 //
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
253 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
254 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
255 return r;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
256 audio_delay_method=1; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
257 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
258 if(audio_delay_method==1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
259 // SNDCTL_DSP_GETOSPACE
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
260 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
261 return ao_buffersize-zz.bytes;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
262 audio_delay_method=0; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
263 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
264 return ao_buffersize;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
265 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
266