Mercurial > mplayer.hg
annotate libao2/ao_oss.c @ 16752:425863aab3df
fix mencoder multi-file with some files having audio but others dont
author | ods15 |
---|---|
date | Thu, 13 Oct 2005 19:30:07 +0000 |
parents | a45af202818f |
children | 832a93fc5deb |
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> |
954 | 12 |
14123 | 13 #include "config.h" |
14 #include "mp_msg.h" | |
15 #include "mixer.h" | |
16 #include "help_mp.h" | |
954 | 17 |
14245 | 18 #ifdef HAVE_SYS_SOUNDCARD_H |
19 #include <sys/soundcard.h> | |
20 #else | |
21 #ifdef HAVE_SOUNDCARD_H | |
22 #include <soundcard.h> | |
23 #endif | |
24 #endif | |
25 | |
26 #include "../libaf/af_format.h" | |
1532 | 27 |
954 | 28 #include "audio_out.h" |
29 #include "audio_out_internal.h" | |
30 | |
31 static ao_info_t info = | |
32 { | |
33 "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
|
34 "oss", |
954 | 35 "A'rpi", |
36 "" | |
37 }; | |
38 | |
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
|
39 /* 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
|
40 |
954 | 41 LIBAO_EXTERN(oss) |
42 | |
14245 | 43 static int format2oss(int format) |
44 { | |
45 switch(format) | |
46 { | |
47 case AF_FORMAT_U8: return AFMT_U8; | |
48 case AF_FORMAT_S8: return AFMT_S8; | |
49 case AF_FORMAT_U16_LE: return AFMT_U16_LE; | |
50 case AF_FORMAT_U16_BE: return AFMT_U16_BE; | |
51 case AF_FORMAT_S16_LE: return AFMT_S16_LE; | |
52 case AF_FORMAT_S16_BE: return AFMT_S16_BE; | |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
53 #ifdef AFMT_U24_LE |
14245 | 54 case AF_FORMAT_U24_LE: return AFMT_U24_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
55 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
56 #ifdef AFMT_U24_BE |
14245 | 57 case AF_FORMAT_U24_BE: return AFMT_U24_BE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
58 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
59 #ifdef AFMT_S24_LE |
14245 | 60 case AF_FORMAT_S24_LE: return AFMT_S24_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
61 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
62 #ifdef AFMT_S24_BE |
14245 | 63 case AF_FORMAT_S24_BE: return AFMT_S24_BE; |
64 #endif | |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
65 #ifdef AFMT_U32_LE |
14245 | 66 case AF_FORMAT_U32_LE: return AFMT_U32_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
67 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
68 #ifdef AFMT_U32_BE |
14245 | 69 case AF_FORMAT_U32_BE: return AFMT_U32_BE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
70 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
71 #ifdef AFMT_S32_LE |
14245 | 72 case AF_FORMAT_S32_LE: return AFMT_S32_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
73 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
74 #ifdef AFMT_S32_BE |
14245 | 75 case AF_FORMAT_S32_BE: return AFMT_S32_BE; |
76 #endif | |
77 #ifdef AFMT_FLOAT | |
78 case AF_FORMAT_FLOAT_NE: return AFMT_FLOAT; | |
79 #endif | |
80 // SPECIALS | |
81 case AF_FORMAT_MU_LAW: return AFMT_MU_LAW; | |
82 case AF_FORMAT_A_LAW: return AFMT_A_LAW; | |
83 case AF_FORMAT_IMA_ADPCM: return AFMT_IMA_ADPCM; | |
84 #ifdef AFMT_MPEG | |
85 case AF_FORMAT_MPEG2: return AFMT_MPEG; | |
86 #endif | |
87 #ifdef AFMT_AC3 | |
88 case AF_FORMAT_AC3: return AFMT_AC3; | |
89 #endif | |
90 } | |
14609
082177fb93b1
print "Unknown/not supported internal format" message only with -v as it
reimar
parents:
14404
diff
changeset
|
91 mp_msg(MSGT_AO, MSGL_V, "OSS: Unknown/not supported internal format: %s\n", af_fmt2str_short(format)); |
14245 | 92 return -1; |
93 } | |
94 | |
95 static int oss2format(int format) | |
96 { | |
97 switch(format) | |
98 { | |
99 case AFMT_U8: return AF_FORMAT_U8; | |
100 case AFMT_S8: return AF_FORMAT_S8; | |
101 case AFMT_U16_LE: return AF_FORMAT_U16_LE; | |
102 case AFMT_U16_BE: return AF_FORMAT_U16_BE; | |
103 case AFMT_S16_LE: return AF_FORMAT_S16_LE; | |
104 case AFMT_S16_BE: return AF_FORMAT_S16_BE; | |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
105 #ifdef AFMT_U24_LE |
14245 | 106 case AFMT_U24_LE: return AF_FORMAT_U24_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
107 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
108 #ifdef AFMT_U24_BE |
14245 | 109 case AFMT_U24_BE: return AF_FORMAT_U24_BE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
110 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
111 #ifdef AFMT_S24_LE |
14245 | 112 case AFMT_S24_LE: return AF_FORMAT_S24_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
113 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
114 #ifdef AFMT_S24_BE |
14245 | 115 case AFMT_S24_BE: return AF_FORMAT_S24_BE; |
116 #endif | |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
117 #ifdef AFMT_U32_LE |
14245 | 118 case AFMT_U32_LE: return AF_FORMAT_U32_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
119 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
120 #ifdef AFMT_U32_BE |
14245 | 121 case AFMT_U32_BE: return AF_FORMAT_U32_BE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
122 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
123 #ifdef AFMT_S32_LE |
14245 | 124 case AFMT_S32_LE: return AF_FORMAT_S32_LE; |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
125 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
126 #ifdef AFMT_S32_BE |
14245 | 127 case AFMT_S32_BE: return AF_FORMAT_S32_BE; |
128 #endif | |
129 #ifdef AFMT_FLOAT | |
130 case AFMT_FLOAT: return AF_FORMAT_FLOAT_NE; | |
131 #endif | |
132 // SPECIALS | |
133 case AFMT_MU_LAW: return AF_FORMAT_MU_LAW; | |
134 case AFMT_A_LAW: return AF_FORMAT_A_LAW; | |
135 case AFMT_IMA_ADPCM: return AF_FORMAT_IMA_ADPCM; | |
136 #ifdef AFMT_MPEG | |
137 case AFMT_MPEG: return AF_FORMAT_MPEG2; | |
138 #endif | |
139 #ifdef AFMT_AC3 | |
140 case AFMT_AC3: return AF_FORMAT_AC3; | |
141 #endif | |
142 } | |
14273 | 143 printf("Unknown/not supported OSS format: %x\n", format); |
14245 | 144 return -1; |
145 } | |
146 | |
4803 | 147 static char *dsp=PATH_DEV_DSP; |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
148 static audio_buf_info zz; |
954 | 149 static int audio_fd=-1; |
150 | |
4803 | 151 char *oss_mixer_device = PATH_DEV_MIXER; |
11837 | 152 int oss_mixer_channel = SOUND_MIXER_PCM; |
1191 | 153 |
954 | 154 // to set/get/query special features/parameters |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9141
diff
changeset
|
155 static int control(int cmd,void *arg){ |
954 | 156 switch(cmd){ |
157 case AOCONTROL_SET_DEVICE: | |
158 dsp=(char*)arg; | |
159 return CONTROL_OK; | |
6795 | 160 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
|
161 *(char**)arg=dsp; |
6795 | 162 return CONTROL_OK; |
15898 | 163 #ifdef SNDCTL_DSP_GETFMTS |
954 | 164 case AOCONTROL_QUERY_FORMAT: |
15898 | 165 { |
166 int format; | |
167 if (!ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &format)) | |
168 if (format & (int)arg) | |
169 return CONTROL_TRUE; | |
170 return CONTROL_FALSE; | |
171 } | |
172 #endif | |
1191 | 173 case AOCONTROL_GET_VOLUME: |
174 case AOCONTROL_SET_VOLUME: | |
175 { | |
176 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
|
177 int fd, v, devs; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
178 |
14245 | 179 if(ao_data.format == AF_FORMAT_AC3) |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
180 return CONTROL_TRUE; |
1191 | 181 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
182 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0) |
1191 | 183 { |
184 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
11837 | 185 if (devs & (1 << oss_mixer_channel)) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
186 { |
1191 | 187 if (cmd == AOCONTROL_GET_VOLUME) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
188 { |
11837 | 189 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
|
190 vol->right = (v & 0xFF00) >> 8; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
191 vol->left = v & 0x00FF; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
192 } |
1191 | 193 else |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
194 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
195 v = ((int)vol->right << 8) | (int)vol->left; |
11837 | 196 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
|
197 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
198 } |
1191 | 199 else |
200 { | |
201 close(fd); | |
202 return CONTROL_ERROR; | |
203 } | |
204 close(fd); | |
205 return CONTROL_OK; | |
206 } | |
207 } | |
208 return CONTROL_ERROR; | |
954 | 209 } |
210 return CONTROL_UNKNOWN; | |
211 } | |
212 | |
213 // open & setup audio device | |
214 // return: 1=success 0=fail | |
215 static int init(int rate,int channels,int format,int flags){ | |
11837 | 216 char *mixer_channels [SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; |
14245 | 217 int oss_format; |
954 | 218 |
14264 | 219 mp_msg(MSGT_AO,MSGL_V,"ao2: %d Hz %d chans %s\n",rate,channels, |
220 af_fmt2str_short(format)); | |
954 | 221 |
1191 | 222 if (ao_subdevice) |
223 dsp = ao_subdevice; | |
224 | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
225 if(mixer_device) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
226 oss_mixer_device=mixer_device; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
227 |
11837 | 228 if(mixer_channel){ |
229 int fd, devs, i; | |
230 | |
231 if ((fd = open(oss_mixer_device, O_RDONLY)) == -1){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
232 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenMixer, |
11837 | 233 oss_mixer_device, strerror(errno)); |
234 }else{ | |
235 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
236 close(fd); | |
237 | |
238 for (i=0; i<SOUND_MIXER_NRDEVICES; i++){ | |
239 if(!strcasecmp(mixer_channels[i], mixer_channel)){ | |
240 if(!(devs & (1 << i))){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
241 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_ChanNotFound, |
11837 | 242 mixer_channel); |
243 i = SOUND_MIXER_NRDEVICES+1; | |
244 break; | |
245 } | |
246 oss_mixer_channel = i; | |
247 break; | |
248 } | |
249 } | |
250 if(i==SOUND_MIXER_NRDEVICES){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
251 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_ChanNotFound, |
11837 | 252 mixer_channel); |
253 } | |
254 } | |
255 } | |
256 | |
6296 | 257 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' dsp device\n", dsp); |
11837 | 258 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' mixer device\n", oss_mixer_device); |
259 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' mixer device\n", mixer_channels[oss_mixer_channel]); | |
1191 | 260 |
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
|
261 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
262 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
|
263 #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
|
264 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
|
265 #endif |
954 | 266 if(audio_fd<0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
267 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenDev, dsp, strerror(errno)); |
954 | 268 return 0; |
269 } | |
270 | |
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
|
271 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
272 /* Remove the non-blocking flag */ |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
273 if(fcntl(audio_fd, F_SETFL, 0) < 0) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
274 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
|
275 return 0; |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
276 } |
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
|
277 #endif |
8303 | 278 |
279 #if defined(FD_CLOEXEC) && defined(F_SETFD) | |
280 fcntl(audio_fd, F_SETFD, FD_CLOEXEC); | |
281 #endif | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
282 |
14245 | 283 if(format == AF_FORMAT_AC3) { |
4184
f648f699eda6
hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents:
3455
diff
changeset
|
284 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
|
285 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
|
286 } |
5790 | 287 |
288 ac3_retry: | |
3095 | 289 ao_data.format=format; |
14245 | 290 oss_format=format2oss(format); |
14260
7f3c14830dcd
100l set default format for AF_FORMATs not supported by sound card
rtognimp
parents:
14245
diff
changeset
|
291 if (oss_format == -1) { |
5790 | 292 #ifdef WORDS_BIGENDIAN |
14245 | 293 oss_format=AFMT_S16_BE; |
5790 | 294 #else |
14245 | 295 oss_format=AFMT_S16_LE; |
5790 | 296 #endif |
14404
e4a52af25ee4
Use AF_FORMAT_S16_NE instead of #ifdef WORDS_BIGENDIAN ...
reimar
parents:
14397
diff
changeset
|
297 format=AF_FORMAT_S16_NE; |
14260
7f3c14830dcd
100l set default format for AF_FORMATs not supported by sound card
rtognimp
parents:
14245
diff
changeset
|
298 } |
7f3c14830dcd
100l set default format for AF_FORMATs not supported by sound card
rtognimp
parents:
14245
diff
changeset
|
299 if( ioctl(audio_fd, SNDCTL_DSP_SETFMT, &oss_format)<0 || |
14834
2d919650990a
Have OSS audio out fall back to s16ne instead of u8 if it can't open the
ivo
parents:
14609
diff
changeset
|
300 oss_format != format2oss(format)) { |
2d919650990a
Have OSS audio out fall back to s16ne instead of u8 if it can't open the
ivo
parents:
14609
diff
changeset
|
301 mp_msg(MSGT_AO,MSGL_WARN, MSGTR_AO_OSS_CantSet, dsp, |
2d919650990a
Have OSS audio out fall back to s16ne instead of u8 if it can't open the
ivo
parents:
14609
diff
changeset
|
302 af_fmt2str_short(format), af_fmt2str_short(AF_FORMAT_S16_NE) ); |
14404
e4a52af25ee4
Use AF_FORMAT_S16_NE instead of #ifdef WORDS_BIGENDIAN ...
reimar
parents:
14397
diff
changeset
|
303 format=AF_FORMAT_S16_NE; |
5790 | 304 goto ac3_retry; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
305 } |
7668 | 306 #if 0 |
14245 | 307 if(oss_format!=format2oss(format)) |
6899 | 308 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 | 309 #endif |
14245 | 310 |
311 ao_data.format = oss2format(oss_format); | |
312 if (ao_data.format == -1) return 0; | |
14264 | 313 |
314 mp_msg(MSGT_AO,MSGL_V,"audio_setup: sample format: %s (requested: %s)\n", | |
315 af_fmt2str_short(ao_data.format), af_fmt2str_short(format)); | |
954 | 316 |
8848 | 317 ao_data.channels = channels; |
14245 | 318 if(format != AF_FORMAT_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
|
319 // 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
|
320 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
|
321 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
|
322 ao_data.channels != channels ) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
323 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
|
324 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
|
325 } |
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
|
326 } |
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
|
327 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
|
328 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
|
329 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
330 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
|
331 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
|
332 } |
9141
20793317e5ff
nice 10l bug, found by Balatoni Denes <pnis@coder.hu>
arpi
parents:
8848
diff
changeset
|
333 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
|
334 } |
6296 | 335 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
|
336 // 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
|
337 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
|
338 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
6296 | 339 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); |
7668 | 340 #if 0 |
6296 | 341 if(ao_data.samplerate!=rate) |
6588
12826366a806
more informal warning and also fixed a 10l bug. Patch by tibcu
alex
parents:
6296
diff
changeset
|
342 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 | 343 #endif |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
344 } |
954 | 345 |
346 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ | |
347 int r=0; | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
348 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_OSS_CantUseGetospace); |
954 | 349 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){ |
6296 | 350 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (config.h)\n",ao_data.outburst); |
954 | 351 } else { |
3095 | 352 ao_data.outburst=r; |
6296 | 353 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); |
954 | 354 } |
355 } else { | |
6296 | 356 mp_msg(MSGT_AO,MSGL_V,"audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n", |
954 | 357 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes); |
3095 | 358 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes; |
359 ao_data.outburst=zz.fragsize; | |
954 | 360 } |
361 | |
3095 | 362 if(ao_data.buffersize==-1){ |
954 | 363 // Measuring buffer size: |
364 void* data; | |
3095 | 365 ao_data.buffersize=0; |
954 | 366 #ifdef HAVE_AUDIO_SELECT |
3095 | 367 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst); |
368 while(ao_data.buffersize<0x40000){ | |
954 | 369 fd_set rfds; |
370 struct timeval tv; | |
371 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
372 tv.tv_sec=0; tv.tv_usec = 0; | |
373 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; | |
3095 | 374 write(audio_fd,data,ao_data.outburst); |
375 ao_data.buffersize+=ao_data.outburst; | |
954 | 376 } |
377 free(data); | |
3095 | 378 if(ao_data.buffersize==0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
379 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantUseSelect); |
954 | 380 return 0; |
381 } | |
382 #endif | |
383 } | |
384 | |
8603
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
385 ao_data.bps=ao_data.channels; |
14245 | 386 if(ao_data.format != AF_FORMAT_U8 && ao_data.format != AF_FORMAT_S8) |
8603
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
387 ao_data.bps*=2; |
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
388 |
6075
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
389 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
|
390 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
|
391 |
954 | 392 return 1; |
393 } | |
394 | |
395 // close audio device | |
12145 | 396 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
|
397 if(audio_fd == -1) return; |
12145 | 398 #ifdef SNDCTL_DSP_SYNC |
399 // to get the buffer played | |
400 if (!immed) | |
401 ioctl(audio_fd, SNDCTL_DSP_SYNC, NULL); | |
402 #endif | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
403 #ifdef SNDCTL_DSP_RESET |
12145 | 404 if (immed) |
405 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
|
406 #endif |
954 | 407 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
|
408 audio_fd = -1; |
954 | 409 } |
410 | |
411 // stop playing and empty buffers (for seeking/pause) | |
412 static void reset(){ | |
14245 | 413 int oss_format; |
12145 | 414 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
|
415 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
|
416 if(audio_fd < 0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
417 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantReopen, strerror(errno)); |
954 | 418 return; |
419 } | |
420 | |
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
|
421 #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
|
422 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
|
423 #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
|
424 |
14245 | 425 oss_format = format2oss(ao_data.format); |
426 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &oss_format); | |
427 if(ao_data.format != AF_FORMAT_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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 } |
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
|
434 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
|
435 } |
954 | 436 } |
437 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
438 // 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
|
439 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
440 { |
12145 | 441 uninit(1); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
442 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
443 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
444 // 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
|
445 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
446 { |
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
|
447 reset(); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
448 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
449 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
450 |
954 | 451 // return: how many bytes can be played without blocking |
452 static int get_space(){ | |
3095 | 453 int playsize=ao_data.outburst; |
954 | 454 |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
455 #ifdef SNDCTL_DSP_GETOSPACE |
954 | 456 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){ |
457 // calculate exact buffer space: | |
3455
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
458 playsize = zz.fragments*zz.fragsize; |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
459 if (playsize > MAX_OUTBURST) |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
460 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
|
461 return playsize; |
954 | 462 } |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
463 #endif |
954 | 464 |
465 // check buffer | |
466 #ifdef HAVE_AUDIO_SELECT | |
467 { fd_set rfds; | |
468 struct timeval tv; | |
469 FD_ZERO(&rfds); | |
470 FD_SET(audio_fd, &rfds); | |
471 tv.tv_sec = 0; | |
472 tv.tv_usec = 0; | |
473 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! | |
474 } | |
475 #endif | |
476 | |
3095 | 477 return ao_data.outburst; |
954 | 478 } |
479 | |
480 // plays 'len' bytes of 'data' | |
481 // it should round it down to outburst*n | |
482 // return: number of bytes played | |
483 static int play(void* data,int len,int flags){ | |
3095 | 484 len/=ao_data.outburst; |
485 len=write(audio_fd,data,len*ao_data.outburst); | |
954 | 486 return len; |
487 } | |
488 | |
489 static int audio_delay_method=2; | |
490 | |
3095 | 491 // return: delay in seconds between first and last sample in buffer |
492 static float get_delay(){ | |
493 /* Calculate how many bytes/second is sent out */ | |
954 | 494 if(audio_delay_method==2){ |
5872 | 495 #ifdef SNDCTL_DSP_GETODELAY |
954 | 496 int r=0; |
497 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1) | |
3095 | 498 return ((float)r)/(float)ao_data.bps; |
5872 | 499 #endif |
954 | 500 audio_delay_method=1; // fallback if not supported |
501 } | |
502 if(audio_delay_method==1){ | |
503 // SNDCTL_DSP_GETOSPACE | |
504 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1) | |
3095 | 505 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps; |
954 | 506 audio_delay_method=0; // fallback if not supported |
507 } | |
3095 | 508 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
954 | 509 } |