Mercurial > mplayer.hg
annotate libao2/ao_oss.c @ 5794:d9c211c2907f
fix timer for audio only files
author | pontscho |
---|---|
date | Tue, 23 Apr 2002 13:07:58 +0000 |
parents | d141f1e9cc36 |
children | 02576893af2a |
rev | line source |
---|---|
954 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include <sys/ioctl.h> | |
5 #include <unistd.h> | |
6 #include <sys/time.h> | |
7 #include <sys/types.h> | |
8 #include <sys/stat.h> | |
9 #include <fcntl.h> | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
10 #include <errno.h> |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
11 #include <string.h> |
1532 | 12 //#include <sys/soundcard.h> |
954 | 13 |
14 #include "../config.h" | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
15 #include "../mixer.h" |
954 | 16 |
1532 | 17 #include "afmt.h" |
18 | |
954 | 19 #include "audio_out.h" |
20 #include "audio_out_internal.h" | |
21 | |
1191 | 22 extern int verbose; |
23 | |
954 | 24 static ao_info_t info = |
25 { | |
26 "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
|
27 "oss", |
954 | 28 "A'rpi", |
29 "" | |
30 }; | |
31 | |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
32 /* Support for >2 output channels added 2001-11-25 - Steve Davies <steve@daviesfam.org> */ |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
33 |
954 | 34 LIBAO_EXTERN(oss) |
35 | |
4803 | 36 static char *dsp=PATH_DEV_DSP; |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
37 static audio_buf_info zz; |
954 | 38 static int audio_fd=-1; |
39 | |
4803 | 40 char *oss_mixer_device = PATH_DEV_MIXER; |
1191 | 41 |
954 | 42 // to set/get/query special features/parameters |
43 static int control(int cmd,int arg){ | |
44 switch(cmd){ | |
45 case AOCONTROL_SET_DEVICE: | |
46 dsp=(char*)arg; | |
47 return CONTROL_OK; | |
48 case AOCONTROL_QUERY_FORMAT: | |
49 return CONTROL_TRUE; | |
1191 | 50 case AOCONTROL_GET_VOLUME: |
51 case AOCONTROL_SET_VOLUME: | |
52 { | |
53 ao_control_vol_t *vol = (ao_control_vol_t *)arg; | |
54 int fd, v, mcmd, devs; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
55 |
3095 | 56 if(ao_data.format == AFMT_AC3) |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
57 return CONTROL_TRUE; |
1191 | 58 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
59 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0) |
1191 | 60 { |
61 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
62 if (devs & SOUND_MASK_PCM) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
63 { |
1191 | 64 if (cmd == AOCONTROL_GET_VOLUME) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
65 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
66 ioctl(fd, SOUND_MIXER_READ_PCM, &v); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
67 vol->right = (v & 0xFF00) >> 8; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
68 vol->left = v & 0x00FF; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
69 } |
1191 | 70 else |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
71 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
72 v = ((int)vol->right << 8) | (int)vol->left; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
73 ioctl(fd, SOUND_MIXER_WRITE_PCM, &v); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
74 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
75 } |
1191 | 76 else |
77 { | |
78 close(fd); | |
79 return CONTROL_ERROR; | |
80 } | |
81 close(fd); | |
82 return CONTROL_OK; | |
83 } | |
84 } | |
85 return CONTROL_ERROR; | |
954 | 86 } |
87 return CONTROL_UNKNOWN; | |
88 } | |
89 | |
90 // open & setup audio device | |
91 // return: 1=success 0=fail | |
92 static int init(int rate,int channels,int format,int flags){ | |
93 | |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
94 printf("ao2: %d Hz %d chans %s\n",rate,channels, |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
95 audio_out_format_name(format)); |
954 | 96 |
1191 | 97 if (ao_subdevice) |
98 dsp = ao_subdevice; | |
99 | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
100 if(mixer_device) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
101 oss_mixer_device=mixer_device; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
102 |
1191 | 103 if (verbose) |
104 printf("audio_setup: using '%s' dsp device\n", dsp); | |
105 | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
106 audio_fd=open(dsp, O_WRONLY | O_NONBLOCK); |
954 | 107 if(audio_fd<0){ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
108 printf("Can't open audio device %s: %s -> no sound\n", dsp, strerror(errno)); |
954 | 109 return 0; |
110 } | |
111 | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
112 /* Remove the non-blocking flag */ |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
113 if(fcntl(audio_fd, F_SETFL, 0) < 0) { |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
114 printf("Can't make filedescriptor non-blocking: %s -> no sound\n", strerror(errno)); |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
115 return 0; |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
116 } |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
117 |
3137 | 118 ao_data.bps=channels*rate; |
3095 | 119 if(format != AFMT_U8 && format != AFMT_S8) |
120 ao_data.bps*=2; | |
121 | |
4184
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
122 if(format == AFMT_AC3) { |
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
123 ao_data.samplerate=rate; |
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
124 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
125 } |
5790 | 126 |
127 ac3_retry: | |
3095 | 128 ao_data.format=format; |
5790 | 129 if( ioctl(audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format)<0 || |
130 ao_data.format != format) if(format == AFMT_AC3){ | |
131 printf("Can't set audio device %s to AC3 output, trying S16...\n", dsp); | |
132 #ifdef WORDS_BIGENDIAN | |
133 format=AFMT_S16_BE; | |
134 #else | |
135 format=AFMT_S16_LE; | |
136 #endif | |
137 goto ac3_retry; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
138 } |
1079 | 139 printf("audio_setup: sample format: %s (requested: %s)\n", |
3095 | 140 audio_out_format_name(ao_data.format), audio_out_format_name(format)); |
954 | 141 |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
142 if(format != AFMT_AC3) { |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
143 // We only use SNDCTL_DSP_CHANNELS for >2 channels, in case some drivers don't have it |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
144 ao_data.channels = channels; |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
145 if (ao_data.channels > 2) { |
3319
66134af21278
fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents:
3181
diff
changeset
|
146 if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels) == -1 || |
66134af21278
fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents:
3181
diff
changeset
|
147 ao_data.channels != channels ) { |
66134af21278
fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents:
3181
diff
changeset
|
148 printf("audio_setup: Failed to set audio device to %d channels\n", channels); |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
149 return 0; |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
150 } |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
151 } |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
152 else { |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
153 int c = ao_data.channels-1; |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
154 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) { |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
155 printf("audio_setup: Failed to set audio device to %d channels\n", ao_data.channels); |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
156 return 0; |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
157 } |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
158 } |
3319
66134af21278
fixed to check that SNDCTL_DSP_CHANNELS actually grants the requested number of channels
steve
parents:
3181
diff
changeset
|
159 printf("audio_setup: using %d channels (requested: %d)\n", ao_data.channels, channels); |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
160 // set rate |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
161 ao_data.samplerate=rate; |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
162 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
163 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
164 } |
954 | 165 |
166 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ | |
167 int r=0; | |
168 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"); | |
169 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){ | |
3095 | 170 printf("audio_setup: %d bytes/frag (config.h)\n",ao_data.outburst); |
954 | 171 } else { |
3095 | 172 ao_data.outburst=r; |
173 printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); | |
954 | 174 } |
175 } else { | |
176 printf("audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n", | |
177 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes); | |
3095 | 178 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes; |
179 ao_data.outburst=zz.fragsize; | |
954 | 180 } |
181 | |
3095 | 182 if(ao_data.buffersize==-1){ |
954 | 183 // Measuring buffer size: |
184 void* data; | |
3095 | 185 ao_data.buffersize=0; |
954 | 186 #ifdef HAVE_AUDIO_SELECT |
3095 | 187 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst); |
188 while(ao_data.buffersize<0x40000){ | |
954 | 189 fd_set rfds; |
190 struct timeval tv; | |
191 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
192 tv.tv_sec=0; tv.tv_usec = 0; | |
193 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; | |
3095 | 194 write(audio_fd,data,ao_data.outburst); |
195 ao_data.buffersize+=ao_data.outburst; | |
954 | 196 } |
197 free(data); | |
3095 | 198 if(ao_data.buffersize==0){ |
954 | 199 printf("\n *** Your audio driver DOES NOT support select() ***\n"); |
200 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"); | |
201 return 0; | |
202 } | |
203 #endif | |
204 } | |
205 | |
206 return 1; | |
207 } | |
208 | |
209 // close audio device | |
210 static void uninit(){ | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
211 #ifdef SNDCTL_DSP_RESET |
954 | 212 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
|
213 #endif |
954 | 214 close(audio_fd); |
215 } | |
216 | |
217 // stop playing and empty buffers (for seeking/pause) | |
218 static void reset(){ | |
219 uninit(); | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
220 audio_fd=open(dsp, O_WRONLY | O_NONBLOCK); |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
221 if(audio_fd < 0 || fcntl(audio_fd, F_SETFL, 0) < 0){ |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
222 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE *** %s\n", strerror(errno)); |
954 | 223 return; |
224 } | |
225 | |
3095 | 226 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format); |
227 if(ao_data.format != AFMT_AC3) { | |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
228 if (ao_data.channels > 2) |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
229 ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels); |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
230 else { |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
231 int c = ao_data.channels-1; |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
232 ioctl (audio_fd, SNDCTL_DSP_STEREO, &c); |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
233 } |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3137
diff
changeset
|
234 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
235 } |
954 | 236 } |
237 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
238 // 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
|
239 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
240 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
241 // 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
|
242 reset(); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
243 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
244 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
245 // 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
|
246 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
247 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
248 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
249 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
250 |
954 | 251 // return: how many bytes can be played without blocking |
252 static int get_space(){ | |
3095 | 253 int playsize=ao_data.outburst; |
954 | 254 |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
255 #ifdef SNDCTL_DSP_GETOSPACE |
954 | 256 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){ |
257 // calculate exact buffer space: | |
3455
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
258 playsize = zz.fragments*zz.fragsize; |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
259 if (playsize > MAX_OUTBURST) |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
260 playsize = (MAX_OUTBURST / zz.fragsize) * zz.fragsize; |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
261 return playsize; |
954 | 262 } |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
263 #endif |
954 | 264 |
265 // check buffer | |
266 #ifdef HAVE_AUDIO_SELECT | |
267 { fd_set rfds; | |
268 struct timeval tv; | |
269 FD_ZERO(&rfds); | |
270 FD_SET(audio_fd, &rfds); | |
271 tv.tv_sec = 0; | |
272 tv.tv_usec = 0; | |
273 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! | |
274 } | |
275 #endif | |
276 | |
3095 | 277 return ao_data.outburst; |
954 | 278 } |
279 | |
280 // plays 'len' bytes of 'data' | |
281 // it should round it down to outburst*n | |
282 // return: number of bytes played | |
283 static int play(void* data,int len,int flags){ | |
3095 | 284 len/=ao_data.outburst; |
285 len=write(audio_fd,data,len*ao_data.outburst); | |
954 | 286 return len; |
287 } | |
288 | |
289 static int audio_delay_method=2; | |
290 | |
3095 | 291 // return: delay in seconds between first and last sample in buffer |
292 static float get_delay(){ | |
293 /* Calculate how many bytes/second is sent out */ | |
954 | 294 if(audio_delay_method==2){ |
295 int r=0; | |
296 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1) | |
3095 | 297 return ((float)r)/(float)ao_data.bps; |
954 | 298 audio_delay_method=1; // fallback if not supported |
299 } | |
300 if(audio_delay_method==1){ | |
301 // SNDCTL_DSP_GETOSPACE | |
302 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1) | |
3095 | 303 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps; |
954 | 304 audio_delay_method=0; // fallback if not supported |
305 } | |
3095 | 306 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
954 | 307 } |