Mercurial > mplayer.hg
annotate libao2/ao_oss.c @ 13519:6bf63a7524d8
Sync with 1.759:
Documentation of x264 3-pass mode, and fixes on lavc's *_mask
options, pointed out by Jiri Heryan
author | gpoirier |
---|---|
date | Fri, 01 Oct 2004 15:53:09 +0000 |
parents | c1955840883d |
children | a92101a7eb49 |
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" |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
17 #include "../help_mp.h" |
954 | 18 |
1532 | 19 #include "afmt.h" |
20 | |
954 | 21 #include "audio_out.h" |
22 #include "audio_out_internal.h" | |
23 | |
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; |
11837 | 41 int oss_mixer_channel = SOUND_MIXER_PCM; |
1191 | 42 |
954 | 43 // to set/get/query special features/parameters |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9141
diff
changeset
|
44 static int control(int cmd,void *arg){ |
954 | 45 switch(cmd){ |
46 case AOCONTROL_SET_DEVICE: | |
47 dsp=(char*)arg; | |
48 return CONTROL_OK; | |
6795 | 49 case AOCONTROL_GET_DEVICE: |
12383
94ba609e53f7
ok this one is beyond stupid. the code didn't even do what was intended
rfelker
parents:
12145
diff
changeset
|
50 *(char**)arg=dsp; |
6795 | 51 return CONTROL_OK; |
954 | 52 case AOCONTROL_QUERY_FORMAT: |
53 return CONTROL_TRUE; | |
1191 | 54 case AOCONTROL_GET_VOLUME: |
55 case AOCONTROL_SET_VOLUME: | |
56 { | |
57 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
|
58 int fd, v, devs; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
59 |
3095 | 60 if(ao_data.format == AFMT_AC3) |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
61 return CONTROL_TRUE; |
1191 | 62 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
63 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0) |
1191 | 64 { |
65 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
11837 | 66 if (devs & (1 << oss_mixer_channel)) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
67 { |
1191 | 68 if (cmd == AOCONTROL_GET_VOLUME) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
69 { |
11837 | 70 ioctl(fd, MIXER_READ(oss_mixer_channel), &v); |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
71 vol->right = (v & 0xFF00) >> 8; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
72 vol->left = v & 0x00FF; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
73 } |
1191 | 74 else |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
75 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
76 v = ((int)vol->right << 8) | (int)vol->left; |
11837 | 77 ioctl(fd, MIXER_WRITE(oss_mixer_channel), &v); |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
78 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
79 } |
1191 | 80 else |
81 { | |
82 close(fd); | |
83 return CONTROL_ERROR; | |
84 } | |
85 close(fd); | |
86 return CONTROL_OK; | |
87 } | |
88 } | |
89 return CONTROL_ERROR; | |
954 | 90 } |
91 return CONTROL_UNKNOWN; | |
92 } | |
93 | |
94 // open & setup audio device | |
95 // return: 1=success 0=fail | |
96 static int init(int rate,int channels,int format,int flags){ | |
11837 | 97 char *mixer_channels [SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; |
954 | 98 |
6296 | 99 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
|
100 audio_out_format_name(format)); |
954 | 101 |
1191 | 102 if (ao_subdevice) |
103 dsp = ao_subdevice; | |
104 | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
105 if(mixer_device) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
106 oss_mixer_device=mixer_device; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
107 |
11837 | 108 if(mixer_channel){ |
109 int fd, devs, i; | |
110 | |
111 if ((fd = open(oss_mixer_device, O_RDONLY)) == -1){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
112 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenMixer, |
11837 | 113 oss_mixer_device, strerror(errno)); |
114 }else{ | |
115 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
116 close(fd); | |
117 | |
118 for (i=0; i<SOUND_MIXER_NRDEVICES; i++){ | |
119 if(!strcasecmp(mixer_channels[i], mixer_channel)){ | |
120 if(!(devs & (1 << i))){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
121 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_ChanNotFound, |
11837 | 122 mixer_channel); |
123 i = SOUND_MIXER_NRDEVICES+1; | |
124 break; | |
125 } | |
126 oss_mixer_channel = i; | |
127 break; | |
128 } | |
129 } | |
130 if(i==SOUND_MIXER_NRDEVICES){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
131 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_ChanNotFound, |
11837 | 132 mixer_channel); |
133 } | |
134 } | |
135 } | |
136 | |
6296 | 137 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' dsp device\n", dsp); |
11837 | 138 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' mixer device\n", oss_mixer_device); |
139 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' mixer device\n", mixer_channels[oss_mixer_channel]); | |
1191 | 140 |
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
|
141 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
142 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
|
143 #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
|
144 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
|
145 #endif |
954 | 146 if(audio_fd<0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
147 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenDev, dsp, strerror(errno)); |
954 | 148 return 0; |
149 } | |
150 | |
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
|
151 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
152 /* Remove the non-blocking flag */ |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
153 if(fcntl(audio_fd, F_SETFL, 0) < 0) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
154 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantMakeFd, strerror(errno)); |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
155 return 0; |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
156 } |
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
|
157 #endif |
8303 | 158 |
159 #if defined(FD_CLOEXEC) && defined(F_SETFD) | |
160 fcntl(audio_fd, F_SETFD, FD_CLOEXEC); | |
161 #endif | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
162 |
4184
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 } |
5790 | 167 |
168 ac3_retry: | |
3095 | 169 ao_data.format=format; |
5790 | 170 if( ioctl(audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format)<0 || |
171 ao_data.format != format) if(format == AFMT_AC3){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
172 mp_msg(MSGT_AO,MSGL_WARN, MSGTR_AO_OSS_CantSetAC3, dsp); |
5790 | 173 #ifdef WORDS_BIGENDIAN |
174 format=AFMT_S16_BE; | |
175 #else | |
176 format=AFMT_S16_LE; | |
177 #endif | |
178 goto ac3_retry; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
179 } |
6296 | 180 mp_msg(MSGT_AO,MSGL_V,"audio_setup: sample format: %s (requested: %s)\n", |
3095 | 181 audio_out_format_name(ao_data.format), audio_out_format_name(format)); |
7668 | 182 #if 0 |
6899 | 183 if(ao_data.format!=format) |
184 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 | 185 #endif |
954 | 186 |
8848 | 187 ao_data.channels = channels; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
188 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
|
189 // 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
|
190 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
|
191 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
|
192 ao_data.channels != channels ) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
193 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantSetChans, 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
|
194 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
|
195 } |
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
|
196 } |
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
|
197 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
|
198 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
|
199 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
200 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantSetChans, 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
|
201 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
|
202 } |
9141
20793317e5ff
nice 10l bug, found by Balatoni Denes <pnis@coder.hu>
arpi
parents:
8848
diff
changeset
|
203 ao_data.channels=c+1; |
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
|
204 } |
6296 | 205 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
|
206 // 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
|
207 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
|
208 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
6296 | 209 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); |
7668 | 210 #if 0 |
6296 | 211 if(ao_data.samplerate!=rate) |
6588
12826366a806
more informal warning and also fixed a 10l bug. Patch by tibcu
alex
parents:
6296
diff
changeset
|
212 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 | 213 #endif |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
214 } |
954 | 215 |
216 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ | |
217 int r=0; | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
218 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_OSS_CantUseGetospace); |
954 | 219 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){ |
6296 | 220 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (config.h)\n",ao_data.outburst); |
954 | 221 } else { |
3095 | 222 ao_data.outburst=r; |
6296 | 223 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); |
954 | 224 } |
225 } else { | |
6296 | 226 mp_msg(MSGT_AO,MSGL_V,"audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n", |
954 | 227 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes); |
3095 | 228 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes; |
229 ao_data.outburst=zz.fragsize; | |
954 | 230 } |
231 | |
3095 | 232 if(ao_data.buffersize==-1){ |
954 | 233 // Measuring buffer size: |
234 void* data; | |
3095 | 235 ao_data.buffersize=0; |
954 | 236 #ifdef HAVE_AUDIO_SELECT |
3095 | 237 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst); |
238 while(ao_data.buffersize<0x40000){ | |
954 | 239 fd_set rfds; |
240 struct timeval tv; | |
241 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
242 tv.tv_sec=0; tv.tv_usec = 0; | |
243 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; | |
3095 | 244 write(audio_fd,data,ao_data.outburst); |
245 ao_data.buffersize+=ao_data.outburst; | |
954 | 246 } |
247 free(data); | |
3095 | 248 if(ao_data.buffersize==0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
249 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantUseSelect); |
954 | 250 return 0; |
251 } | |
252 #endif | |
253 } | |
254 | |
8603
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
255 ao_data.bps=ao_data.channels; |
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
256 if(ao_data.format != AFMT_U8 && ao_data.format != AFMT_S8) |
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
257 ao_data.bps*=2; |
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
258 |
6075
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
259 ao_data.outburst-=ao_data.outburst % ao_data.bps; // round down |
8603
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
260 ao_data.bps*=ao_data.samplerate; |
6075
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
261 |
954 | 262 return 1; |
263 } | |
264 | |
265 // close audio device | |
12145 | 266 static void uninit(int immed){ |
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
|
267 if(audio_fd == -1) return; |
12145 | 268 #ifdef SNDCTL_DSP_SYNC |
269 // to get the buffer played | |
270 if (!immed) | |
271 ioctl(audio_fd, SNDCTL_DSP_SYNC, NULL); | |
272 #endif | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
273 #ifdef SNDCTL_DSP_RESET |
12145 | 274 if (immed) |
275 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
|
276 #endif |
954 | 277 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
|
278 audio_fd = -1; |
954 | 279 } |
280 | |
281 // stop playing and empty buffers (for seeking/pause) | |
282 static void reset(){ | |
12145 | 283 uninit(1); |
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
|
284 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
|
285 if(audio_fd < 0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
286 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantReopen, strerror(errno)); |
954 | 287 return; |
288 } | |
289 | |
10600
3cf428b56cde
Set close-on-exec after newer open (in reset func). Patch by Andriy Gapon <agapon@cv-nj.com>
alex
parents:
9633
diff
changeset
|
290 #if defined(FD_CLOEXEC) && defined(F_SETFD) |
3cf428b56cde
Set close-on-exec after newer open (in reset func). Patch by Andriy Gapon <agapon@cv-nj.com>
alex
parents:
9633
diff
changeset
|
291 fcntl(audio_fd, F_SETFD, FD_CLOEXEC); |
3cf428b56cde
Set close-on-exec after newer open (in reset func). Patch by Andriy Gapon <agapon@cv-nj.com>
alex
parents:
9633
diff
changeset
|
292 #endif |
3cf428b56cde
Set close-on-exec after newer open (in reset func). Patch by Andriy Gapon <agapon@cv-nj.com>
alex
parents:
9633
diff
changeset
|
293 |
3095 | 294 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format); |
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 } |
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
|
302 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
|
303 } |
954 | 304 } |
305 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
306 // 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
|
307 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
308 { |
12145 | 309 uninit(1); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
310 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
311 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
312 // 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
|
313 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
314 { |
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
|
315 reset(); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
316 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
317 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
318 |
954 | 319 // return: how many bytes can be played without blocking |
320 static int get_space(){ | |
3095 | 321 int playsize=ao_data.outburst; |
954 | 322 |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
323 #ifdef SNDCTL_DSP_GETOSPACE |
954 | 324 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){ |
325 // calculate exact buffer space: | |
3455
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
326 playsize = zz.fragments*zz.fragsize; |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
327 if (playsize > MAX_OUTBURST) |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
328 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
|
329 return playsize; |
954 | 330 } |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
331 #endif |
954 | 332 |
333 // check buffer | |
334 #ifdef HAVE_AUDIO_SELECT | |
335 { fd_set rfds; | |
336 struct timeval tv; | |
337 FD_ZERO(&rfds); | |
338 FD_SET(audio_fd, &rfds); | |
339 tv.tv_sec = 0; | |
340 tv.tv_usec = 0; | |
341 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! | |
342 } | |
343 #endif | |
344 | |
3095 | 345 return ao_data.outburst; |
954 | 346 } |
347 | |
348 // plays 'len' bytes of 'data' | |
349 // it should round it down to outburst*n | |
350 // return: number of bytes played | |
351 static int play(void* data,int len,int flags){ | |
3095 | 352 len/=ao_data.outburst; |
353 len=write(audio_fd,data,len*ao_data.outburst); | |
954 | 354 return len; |
355 } | |
356 | |
357 static int audio_delay_method=2; | |
358 | |
3095 | 359 // return: delay in seconds between first and last sample in buffer |
360 static float get_delay(){ | |
361 /* Calculate how many bytes/second is sent out */ | |
954 | 362 if(audio_delay_method==2){ |
5872 | 363 #ifdef SNDCTL_DSP_GETODELAY |
954 | 364 int r=0; |
365 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1) | |
3095 | 366 return ((float)r)/(float)ao_data.bps; |
5872 | 367 #endif |
954 | 368 audio_delay_method=1; // fallback if not supported |
369 } | |
370 if(audio_delay_method==1){ | |
371 // SNDCTL_DSP_GETOSPACE | |
372 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1) | |
3095 | 373 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps; |
954 | 374 audio_delay_method=0; // fallback if not supported |
375 } | |
3095 | 376 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
954 | 377 } |