Mercurial > mplayer.hg
annotate libao2/ao_oss.c @ 8293:f436f419e5ab
avifile sync (added only the new functions, all cosmetics ignored)
author | arpi |
---|---|
date | Tue, 26 Nov 2002 21:03:46 +0000 |
parents | b9da278e4c92 |
children | 322f1a91a5e7 |
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" | |
6296 | 15 #include "../mp_msg.h" |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
16 #include "../mixer.h" |
954 | 17 |
1532 | 18 #include "afmt.h" |
19 | |
954 | 20 #include "audio_out.h" |
21 #include "audio_out_internal.h" | |
22 | |
23 static ao_info_t info = | |
24 { | |
25 "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
|
26 "oss", |
954 | 27 "A'rpi", |
28 "" | |
29 }; | |
30 | |
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
|
31 /* 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
|
32 |
954 | 33 LIBAO_EXTERN(oss) |
34 | |
4803 | 35 static char *dsp=PATH_DEV_DSP; |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
36 static audio_buf_info zz; |
954 | 37 static int audio_fd=-1; |
38 | |
4803 | 39 char *oss_mixer_device = PATH_DEV_MIXER; |
1191 | 40 |
954 | 41 // to set/get/query special features/parameters |
42 static int control(int cmd,int arg){ | |
43 switch(cmd){ | |
44 case AOCONTROL_SET_DEVICE: | |
45 dsp=(char*)arg; | |
46 return CONTROL_OK; | |
6795 | 47 case AOCONTROL_GET_DEVICE: |
48 (char*)arg=dsp; | |
49 return CONTROL_OK; | |
954 | 50 case AOCONTROL_QUERY_FORMAT: |
51 return CONTROL_TRUE; | |
1191 | 52 case AOCONTROL_GET_VOLUME: |
53 case AOCONTROL_SET_VOLUME: | |
54 { | |
55 ao_control_vol_t *vol = (ao_control_vol_t *)arg; | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7118
diff
changeset
|
56 int fd, v, devs; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
57 |
3095 | 58 if(ao_data.format == AFMT_AC3) |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
59 return CONTROL_TRUE; |
1191 | 60 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
61 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0) |
1191 | 62 { |
63 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
|
64 if (devs & SOUND_MASK_PCM) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
65 { |
1191 | 66 if (cmd == AOCONTROL_GET_VOLUME) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
67 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
68 ioctl(fd, SOUND_MIXER_READ_PCM, &v); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
69 vol->right = (v & 0xFF00) >> 8; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
70 vol->left = v & 0x00FF; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
71 } |
1191 | 72 else |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
73 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
74 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
|
75 ioctl(fd, SOUND_MIXER_WRITE_PCM, &v); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
76 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
77 } |
1191 | 78 else |
79 { | |
80 close(fd); | |
81 return CONTROL_ERROR; | |
82 } | |
83 close(fd); | |
84 return CONTROL_OK; | |
85 } | |
86 } | |
87 return CONTROL_ERROR; | |
954 | 88 } |
89 return CONTROL_UNKNOWN; | |
90 } | |
91 | |
92 // open & setup audio device | |
93 // return: 1=success 0=fail | |
94 static int init(int rate,int channels,int format,int flags){ | |
95 | |
6296 | 96 mp_msg(MSGT_AO,MSGL_V,"ao2: %d Hz %d chans %s\n",rate,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
|
97 audio_out_format_name(format)); |
954 | 98 |
1191 | 99 if (ao_subdevice) |
100 dsp = ao_subdevice; | |
101 | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
102 if(mixer_device) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
103 oss_mixer_device=mixer_device; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
104 |
6296 | 105 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' dsp device\n", dsp); |
1191 | 106 |
5907
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
107 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
108 audio_fd=open(dsp, O_WRONLY | O_NONBLOCK); |
5907
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
109 #else |
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
110 audio_fd=open(dsp, O_WRONLY); |
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
111 #endif |
954 | 112 if(audio_fd<0){ |
6296 | 113 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Can't open audio device %s: %s\n", dsp, strerror(errno)); |
954 | 114 return 0; |
115 } | |
116 | |
5907
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
117 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
118 /* Remove the non-blocking flag */ |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
119 if(fcntl(audio_fd, F_SETFL, 0) < 0) { |
6296 | 120 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Can't make filedescriptor non-blocking: %s\n", strerror(errno)); |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
121 return 0; |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
122 } |
5907
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
123 #endif |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
124 |
6075
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
125 ao_data.bps=channels; |
3095 | 126 if(format != AFMT_U8 && format != AFMT_S8) |
127 ao_data.bps*=2; | |
128 | |
4184
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 } |
5790 | 133 |
134 ac3_retry: | |
3095 | 135 ao_data.format=format; |
5790 | 136 if( ioctl(audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format)<0 || |
137 ao_data.format != format) if(format == AFMT_AC3){ | |
6296 | 138 mp_msg(MSGT_AO,MSGL_WARN,"Can't set audio device %s to AC3 output, trying S16...\n", dsp); |
5790 | 139 #ifdef WORDS_BIGENDIAN |
140 format=AFMT_S16_BE; | |
141 #else | |
142 format=AFMT_S16_LE; | |
143 #endif | |
144 goto ac3_retry; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
145 } |
6296 | 146 mp_msg(MSGT_AO,MSGL_V,"audio_setup: sample format: %s (requested: %s)\n", |
3095 | 147 audio_out_format_name(ao_data.format), audio_out_format_name(format)); |
7668 | 148 #if 0 |
6899 | 149 if(ao_data.format!=format) |
150 mp_msg(MSGT_AO,MSGL_WARN,"WARNING! Your soundcard does NOT support %s sample format! Broken audio or bad playback speed are possible! Try with '-aop list=format'\n",audio_out_format_name(format)); | |
7668 | 151 #endif |
6899 | 152 |
954 | 153 |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
154 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
|
155 // 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
|
156 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
|
157 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
|
158 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
|
159 ao_data.channels != channels ) { |
6296 | 160 mp_msg(MSGT_AO,MSGL_ERR,"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
|
161 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
|
162 } |
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 } |
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
|
164 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
|
165 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
|
166 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) { |
6296 | 167 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Failed to set audio device to %d channels\n", ao_data.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
|
168 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
|
169 } |
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
|
170 } |
6296 | 171 mp_msg(MSGT_AO,MSGL_V,"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
|
172 // 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
|
173 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
|
174 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
6296 | 175 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); |
7668 | 176 #if 0 |
6296 | 177 if(ao_data.samplerate!=rate) |
6588
12826366a806
more informal warning and also fixed a 10l bug. Patch by tibcu
alex
parents:
6296
diff
changeset
|
178 mp_msg(MSGT_AO,MSGL_WARN,"WARNING! Your soundcard does NOT support %d Hz samplerate! A-V sync problems or wrong speed are possible! Try with '-aop list=resample:fout=%d'\n",rate,ao_data.samplerate); |
7668 | 179 #endif |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
180 } |
954 | 181 |
182 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ | |
183 int r=0; | |
6296 | 184 mp_msg(MSGT_AO,MSGL_WARN,"audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"); |
954 | 185 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){ |
6296 | 186 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (config.h)\n",ao_data.outburst); |
954 | 187 } else { |
3095 | 188 ao_data.outburst=r; |
6296 | 189 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); |
954 | 190 } |
191 } else { | |
6296 | 192 mp_msg(MSGT_AO,MSGL_V,"audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n", |
954 | 193 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes); |
3095 | 194 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes; |
195 ao_data.outburst=zz.fragsize; | |
954 | 196 } |
197 | |
3095 | 198 if(ao_data.buffersize==-1){ |
954 | 199 // Measuring buffer size: |
200 void* data; | |
3095 | 201 ao_data.buffersize=0; |
954 | 202 #ifdef HAVE_AUDIO_SELECT |
3095 | 203 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst); |
204 while(ao_data.buffersize<0x40000){ | |
954 | 205 fd_set rfds; |
206 struct timeval tv; | |
207 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
208 tv.tv_sec=0; tv.tv_usec = 0; | |
209 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; | |
3095 | 210 write(audio_fd,data,ao_data.outburst); |
211 ao_data.buffersize+=ao_data.outburst; | |
954 | 212 } |
213 free(data); | |
3095 | 214 if(ao_data.buffersize==0){ |
6296 | 215 mp_msg(MSGT_AO,MSGL_ERR,"\n *** Your audio driver DOES NOT support select() ***\n" |
216 "Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"); | |
954 | 217 return 0; |
218 } | |
219 #endif | |
220 } | |
221 | |
6075
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
222 ao_data.outburst-=ao_data.outburst % ao_data.bps; // round down |
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
223 ao_data.bps*=rate; |
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
224 |
954 | 225 return 1; |
226 } | |
227 | |
228 // close audio device | |
229 static void uninit(){ | |
7118
4332922afec4
release /dev/dsp on pause patch by Eric Lammerts <eric@lammerts.org> (and D Richard Felker III <dalias@aerifal.cx>)
alex
parents:
6899
diff
changeset
|
230 if(audio_fd == -1) return; |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
231 #ifdef SNDCTL_DSP_RESET |
954 | 232 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
|
233 #endif |
954 | 234 close(audio_fd); |
7118
4332922afec4
release /dev/dsp on pause patch by Eric Lammerts <eric@lammerts.org> (and D Richard Felker III <dalias@aerifal.cx>)
alex
parents:
6899
diff
changeset
|
235 audio_fd = -1; |
954 | 236 } |
237 | |
238 // stop playing and empty buffers (for seeking/pause) | |
239 static void reset(){ | |
240 uninit(); | |
5907
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
241 audio_fd=open(dsp, O_WRONLY); |
d8c34a35ccb9
nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents:
5872
diff
changeset
|
242 if(audio_fd < 0){ |
6296 | 243 mp_msg(MSGT_AO,MSGL_ERR,"\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE *** %s\n", strerror(errno)); |
954 | 244 return; |
245 } | |
246 | |
3095 | 247 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format); |
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 } |
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
|
255 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
|
256 } |
954 | 257 } |
258 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
259 // 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
|
260 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
261 { |
7118
4332922afec4
release /dev/dsp on pause patch by Eric Lammerts <eric@lammerts.org> (and D Richard Felker III <dalias@aerifal.cx>)
alex
parents:
6899
diff
changeset
|
262 uninit(); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
263 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
264 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
265 // 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
|
266 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
267 { |
7118
4332922afec4
release /dev/dsp on pause patch by Eric Lammerts <eric@lammerts.org> (and D Richard Felker III <dalias@aerifal.cx>)
alex
parents:
6899
diff
changeset
|
268 reset(); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
269 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
270 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
271 |
954 | 272 // return: how many bytes can be played without blocking |
273 static int get_space(){ | |
3095 | 274 int playsize=ao_data.outburst; |
954 | 275 |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
276 #ifdef SNDCTL_DSP_GETOSPACE |
954 | 277 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){ |
278 // calculate exact buffer space: | |
3455
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
279 playsize = zz.fragments*zz.fragsize; |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
280 if (playsize > MAX_OUTBURST) |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
281 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
|
282 return playsize; |
954 | 283 } |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
284 #endif |
954 | 285 |
286 // check buffer | |
287 #ifdef HAVE_AUDIO_SELECT | |
288 { fd_set rfds; | |
289 struct timeval tv; | |
290 FD_ZERO(&rfds); | |
291 FD_SET(audio_fd, &rfds); | |
292 tv.tv_sec = 0; | |
293 tv.tv_usec = 0; | |
294 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! | |
295 } | |
296 #endif | |
297 | |
3095 | 298 return ao_data.outburst; |
954 | 299 } |
300 | |
301 // plays 'len' bytes of 'data' | |
302 // it should round it down to outburst*n | |
303 // return: number of bytes played | |
304 static int play(void* data,int len,int flags){ | |
3095 | 305 len/=ao_data.outburst; |
306 len=write(audio_fd,data,len*ao_data.outburst); | |
954 | 307 return len; |
308 } | |
309 | |
310 static int audio_delay_method=2; | |
311 | |
3095 | 312 // return: delay in seconds between first and last sample in buffer |
313 static float get_delay(){ | |
314 /* Calculate how many bytes/second is sent out */ | |
954 | 315 if(audio_delay_method==2){ |
5872 | 316 #ifdef SNDCTL_DSP_GETODELAY |
954 | 317 int r=0; |
318 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1) | |
3095 | 319 return ((float)r)/(float)ao_data.bps; |
5872 | 320 #endif |
954 | 321 audio_delay_method=1; // fallback if not supported |
322 } | |
323 if(audio_delay_method==1){ | |
324 // SNDCTL_DSP_GETOSPACE | |
325 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1) | |
3095 | 326 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps; |
954 | 327 audio_delay_method=0; // fallback if not supported |
328 } | |
3095 | 329 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
954 | 330 } |