Mercurial > mplayer.hg
annotate libao2/ao_oss.c @ 29002:b7367b035fdd
Add forgotten "static" to new data_length variable in ao_pcm
author | reimar |
---|---|
date | Sun, 22 Mar 2009 14:28:13 +0000 |
parents | 9a5b8c2ed6de |
children | 0f1b5b68af32 |
rev | line source |
---|---|
28343 | 1 /* |
2 * OSS audio output driver | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
20 | |
954 | 21 #include <stdio.h> |
22 #include <stdlib.h> | |
23 | |
24 #include <sys/ioctl.h> | |
25 #include <unistd.h> | |
26 #include <sys/time.h> | |
27 #include <sys/types.h> | |
28 #include <sys/stat.h> | |
29 #include <fcntl.h> | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
30 #include <errno.h> |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
31 #include <string.h> |
954 | 32 |
14123 | 33 #include "config.h" |
34 #include "mp_msg.h" | |
35 #include "mixer.h" | |
36 #include "help_mp.h" | |
954 | 37 |
14245 | 38 #ifdef HAVE_SYS_SOUNDCARD_H |
39 #include <sys/soundcard.h> | |
40 #else | |
41 #ifdef HAVE_SOUNDCARD_H | |
42 #include <soundcard.h> | |
43 #endif | |
44 #endif | |
45 | |
17020 | 46 #include "libaf/af_format.h" |
1532 | 47 |
954 | 48 #include "audio_out.h" |
49 #include "audio_out_internal.h" | |
50 | |
28823 | 51 static const ao_info_t info = |
954 | 52 { |
53 "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
|
54 "oss", |
954 | 55 "A'rpi", |
56 "" | |
57 }; | |
58 | |
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
|
59 /* 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
|
60 |
954 | 61 LIBAO_EXTERN(oss) |
62 | |
14245 | 63 static int format2oss(int format) |
64 { | |
65 switch(format) | |
66 { | |
67 case AF_FORMAT_U8: return AFMT_U8; | |
68 case AF_FORMAT_S8: return AFMT_S8; | |
69 case AF_FORMAT_U16_LE: return AFMT_U16_LE; | |
70 case AF_FORMAT_U16_BE: return AFMT_U16_BE; | |
71 case AF_FORMAT_S16_LE: return AFMT_S16_LE; | |
72 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
|
73 #ifdef AFMT_U24_LE |
14245 | 74 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
|
75 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
76 #ifdef AFMT_U24_BE |
14245 | 77 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
|
78 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
79 #ifdef AFMT_S24_LE |
14245 | 80 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
|
81 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
82 #ifdef AFMT_S24_BE |
14245 | 83 case AF_FORMAT_S24_BE: return AFMT_S24_BE; |
84 #endif | |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
85 #ifdef AFMT_U32_LE |
14245 | 86 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
|
87 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
88 #ifdef AFMT_U32_BE |
14245 | 89 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
|
90 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
91 #ifdef AFMT_S32_LE |
14245 | 92 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
|
93 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
94 #ifdef AFMT_S32_BE |
14245 | 95 case AF_FORMAT_S32_BE: return AFMT_S32_BE; |
96 #endif | |
97 #ifdef AFMT_FLOAT | |
98 case AF_FORMAT_FLOAT_NE: return AFMT_FLOAT; | |
99 #endif | |
100 // SPECIALS | |
101 case AF_FORMAT_MU_LAW: return AFMT_MU_LAW; | |
102 case AF_FORMAT_A_LAW: return AFMT_A_LAW; | |
103 case AF_FORMAT_IMA_ADPCM: return AFMT_IMA_ADPCM; | |
104 #ifdef AFMT_MPEG | |
105 case AF_FORMAT_MPEG2: return AFMT_MPEG; | |
106 #endif | |
107 #ifdef AFMT_AC3 | |
108 case AF_FORMAT_AC3: return AFMT_AC3; | |
109 #endif | |
110 } | |
14609
082177fb93b1
print "Unknown/not supported internal format" message only with -v as it
reimar
parents:
14404
diff
changeset
|
111 mp_msg(MSGT_AO, MSGL_V, "OSS: Unknown/not supported internal format: %s\n", af_fmt2str_short(format)); |
14245 | 112 return -1; |
113 } | |
114 | |
115 static int oss2format(int format) | |
116 { | |
117 switch(format) | |
118 { | |
119 case AFMT_U8: return AF_FORMAT_U8; | |
120 case AFMT_S8: return AF_FORMAT_S8; | |
121 case AFMT_U16_LE: return AF_FORMAT_U16_LE; | |
122 case AFMT_U16_BE: return AF_FORMAT_U16_BE; | |
123 case AFMT_S16_LE: return AF_FORMAT_S16_LE; | |
124 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
|
125 #ifdef AFMT_U24_LE |
14245 | 126 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
|
127 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
128 #ifdef AFMT_U24_BE |
14245 | 129 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
|
130 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
131 #ifdef AFMT_S24_LE |
14245 | 132 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
|
133 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
134 #ifdef AFMT_S24_BE |
14245 | 135 case AFMT_S24_BE: return AF_FORMAT_S24_BE; |
136 #endif | |
14397
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
137 #ifdef AFMT_U32_LE |
14245 | 138 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
|
139 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
140 #ifdef AFMT_U32_BE |
14245 | 141 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
|
142 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
143 #ifdef AFMT_S32_LE |
14245 | 144 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
|
145 #endif |
d862ff282815
Check for every 24 and 32 bit AFMT_ separately if it is defined.
reimar
parents:
14273
diff
changeset
|
146 #ifdef AFMT_S32_BE |
14245 | 147 case AFMT_S32_BE: return AF_FORMAT_S32_BE; |
148 #endif | |
149 #ifdef AFMT_FLOAT | |
150 case AFMT_FLOAT: return AF_FORMAT_FLOAT_NE; | |
151 #endif | |
152 // SPECIALS | |
153 case AFMT_MU_LAW: return AF_FORMAT_MU_LAW; | |
154 case AFMT_A_LAW: return AF_FORMAT_A_LAW; | |
155 case AFMT_IMA_ADPCM: return AF_FORMAT_IMA_ADPCM; | |
156 #ifdef AFMT_MPEG | |
157 case AFMT_MPEG: return AF_FORMAT_MPEG2; | |
158 #endif | |
159 #ifdef AFMT_AC3 | |
160 case AFMT_AC3: return AF_FORMAT_AC3; | |
161 #endif | |
162 } | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17566
diff
changeset
|
163 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_AO_OSS_UnknownUnsupportedFormat, format); |
14245 | 164 return -1; |
165 } | |
166 | |
4803 | 167 static char *dsp=PATH_DEV_DSP; |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
168 static audio_buf_info zz; |
954 | 169 static int audio_fd=-1; |
23809
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
170 static int prepause_space; |
954 | 171 |
18966
0662e5119de2
two variables are made static, one of them additionaly modified to const char*. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18842
diff
changeset
|
172 static const char *oss_mixer_device = PATH_DEV_MIXER; |
0662e5119de2
two variables are made static, one of them additionaly modified to const char*. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18842
diff
changeset
|
173 static int oss_mixer_channel = SOUND_MIXER_PCM; |
1191 | 174 |
954 | 175 // to set/get/query special features/parameters |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9141
diff
changeset
|
176 static int control(int cmd,void *arg){ |
954 | 177 switch(cmd){ |
178 case AOCONTROL_SET_DEVICE: | |
179 dsp=(char*)arg; | |
180 return CONTROL_OK; | |
6795 | 181 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
|
182 *(char**)arg=dsp; |
6795 | 183 return CONTROL_OK; |
15898 | 184 #ifdef SNDCTL_DSP_GETFMTS |
954 | 185 case AOCONTROL_QUERY_FORMAT: |
15898 | 186 { |
187 int format; | |
188 if (!ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &format)) | |
27450
4da9ce4d8327
Fix 'cast from pointer to integer of different size' on 64bit architectures. Casting to long should work for 32bit and 64bit and not make a difference to the boolean operation (since 'format' is always 32bit (int) the upper 32bit of 'arg' won't matter, but the compiler should be happy now. Casting both to unsigned makes sure the compiler isn't messing things up by sign-extending 'format' to 64bit before masking)
ranma
parents:
23809
diff
changeset
|
189 if ((unsigned int)format & (unsigned long)arg) |
15898 | 190 return CONTROL_TRUE; |
191 return CONTROL_FALSE; | |
192 } | |
193 #endif | |
1191 | 194 case AOCONTROL_GET_VOLUME: |
195 case AOCONTROL_SET_VOLUME: | |
196 { | |
197 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
|
198 int fd, v, devs; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
199 |
14245 | 200 if(ao_data.format == AF_FORMAT_AC3) |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
201 return CONTROL_TRUE; |
1191 | 202 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
203 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0) |
1191 | 204 { |
205 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
11837 | 206 if (devs & (1 << oss_mixer_channel)) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
207 { |
1191 | 208 if (cmd == AOCONTROL_GET_VOLUME) |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
209 { |
11837 | 210 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
|
211 vol->right = (v & 0xFF00) >> 8; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
212 vol->left = v & 0x00FF; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
213 } |
1191 | 214 else |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
215 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
216 v = ((int)vol->right << 8) | (int)vol->left; |
11837 | 217 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
|
218 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4184
diff
changeset
|
219 } |
1191 | 220 else |
221 { | |
222 close(fd); | |
223 return CONTROL_ERROR; | |
224 } | |
225 close(fd); | |
226 return CONTROL_OK; | |
227 } | |
228 } | |
229 return CONTROL_ERROR; | |
954 | 230 } |
231 return CONTROL_UNKNOWN; | |
232 } | |
233 | |
234 // open & setup audio device | |
235 // return: 1=success 0=fail | |
236 static int init(int rate,int channels,int format,int flags){ | |
11837 | 237 char *mixer_channels [SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; |
14245 | 238 int oss_format; |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
239 char *mdev = mixer_device, *mchan = mixer_channel; |
954 | 240 |
14264 | 241 mp_msg(MSGT_AO,MSGL_V,"ao2: %d Hz %d chans %s\n",rate,channels, |
242 af_fmt2str_short(format)); | |
954 | 243 |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
244 if (ao_subdevice) { |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
245 char *m,*c; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
246 m = strchr(ao_subdevice,':'); |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
247 if(m) { |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
248 c = strchr(m+1,':'); |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
249 if(c) { |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
250 mchan = c+1; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
251 c[0] = '\0'; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
252 } |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
253 mdev = m+1; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
254 m[0] = '\0'; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
255 } |
1191 | 256 dsp = ao_subdevice; |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
257 } |
1191 | 258 |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
259 if(mdev) |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
260 oss_mixer_device=mdev; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
261 else |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
262 oss_mixer_device=PATH_DEV_MIXER; |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
263 |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
264 if(mchan){ |
11837 | 265 int fd, devs, i; |
266 | |
267 if ((fd = open(oss_mixer_device, O_RDONLY)) == -1){ | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
268 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenMixer, |
11837 | 269 oss_mixer_device, strerror(errno)); |
270 }else{ | |
271 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
272 close(fd); | |
273 | |
274 for (i=0; i<SOUND_MIXER_NRDEVICES; i++){ | |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
275 if(!strcasecmp(mixer_channels[i], mchan)){ |
11837 | 276 if(!(devs & (1 << i))){ |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
277 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_ChanNotFound,mchan); |
11837 | 278 i = SOUND_MIXER_NRDEVICES+1; |
279 break; | |
280 } | |
281 oss_mixer_channel = i; | |
282 break; | |
283 } | |
284 } | |
285 if(i==SOUND_MIXER_NRDEVICES){ | |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
286 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_ChanNotFound,mchan); |
11837 | 287 } |
288 } | |
16959
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
289 } else |
832a93fc5deb
Allow setting the mixer per instance so one can fallback between
albeu
parents:
15898
diff
changeset
|
290 oss_mixer_channel = SOUND_MIXER_PCM; |
11837 | 291 |
6296 | 292 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' dsp device\n", dsp); |
11837 | 293 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' mixer device\n", oss_mixer_device); |
294 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using '%s' mixer device\n", mixer_channels[oss_mixer_channel]); | |
1191 | 295 |
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
|
296 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
297 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
|
298 #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
|
299 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
|
300 #endif |
954 | 301 if(audio_fd<0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
302 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenDev, dsp, strerror(errno)); |
954 | 303 return 0; |
304 } | |
305 | |
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
|
306 #ifdef __linux__ |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
307 /* Remove the non-blocking flag */ |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
308 if(fcntl(audio_fd, F_SETFL, 0) < 0) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
309 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
|
310 return 0; |
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
311 } |
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
|
312 #endif |
8303 | 313 |
314 #if defined(FD_CLOEXEC) && defined(F_SETFD) | |
315 fcntl(audio_fd, F_SETFD, FD_CLOEXEC); | |
316 #endif | |
5204
6bbf3271a694
non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4803
diff
changeset
|
317 |
14245 | 318 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
|
319 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
|
320 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
|
321 } |
5790 | 322 |
323 ac3_retry: | |
3095 | 324 ao_data.format=format; |
14245 | 325 oss_format=format2oss(format); |
14260
7f3c14830dcd
100l set default format for AF_FORMATs not supported by sound card
rtognimp
parents:
14245
diff
changeset
|
326 if (oss_format == -1) { |
5790 | 327 #ifdef WORDS_BIGENDIAN |
14245 | 328 oss_format=AFMT_S16_BE; |
5790 | 329 #else |
14245 | 330 oss_format=AFMT_S16_LE; |
5790 | 331 #endif |
14404
e4a52af25ee4
Use AF_FORMAT_S16_NE instead of #ifdef WORDS_BIGENDIAN ...
reimar
parents:
14397
diff
changeset
|
332 format=AF_FORMAT_S16_NE; |
14260
7f3c14830dcd
100l set default format for AF_FORMATs not supported by sound card
rtognimp
parents:
14245
diff
changeset
|
333 } |
7f3c14830dcd
100l set default format for AF_FORMATs not supported by sound card
rtognimp
parents:
14245
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 format=AF_FORMAT_S16_NE; |
5790 | 339 goto ac3_retry; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1456
diff
changeset
|
340 } |
7668 | 341 #if 0 |
14245 | 342 if(oss_format!=format2oss(format)) |
17058 | 343 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 '-af format'\n",audio_out_format_name(format)); |
7668 | 344 #endif |
14245 | 345 |
346 ao_data.format = oss2format(oss_format); | |
347 if (ao_data.format == -1) return 0; | |
14264 | 348 |
349 mp_msg(MSGT_AO,MSGL_V,"audio_setup: sample format: %s (requested: %s)\n", | |
350 af_fmt2str_short(ao_data.format), af_fmt2str_short(format)); | |
954 | 351 |
8848 | 352 ao_data.channels = channels; |
14245 | 353 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
|
354 // 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
|
355 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
|
356 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
|
357 ao_data.channels != channels ) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
358 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
|
359 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
|
360 } |
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
|
361 } |
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
|
362 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
|
363 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
|
364 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
365 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
|
366 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
|
367 } |
9141
20793317e5ff
nice 10l bug, found by Balatoni Denes <pnis@coder.hu>
arpi
parents:
8848
diff
changeset
|
368 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
|
369 } |
6296 | 370 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
|
371 // 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
|
372 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
|
373 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
6296 | 374 mp_msg(MSGT_AO,MSGL_V,"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
|
375 } |
954 | 376 |
377 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ | |
378 int r=0; | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
379 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_OSS_CantUseGetospace); |
954 | 380 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){ |
6296 | 381 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (config.h)\n",ao_data.outburst); |
954 | 382 } else { |
3095 | 383 ao_data.outburst=r; |
6296 | 384 mp_msg(MSGT_AO,MSGL_V,"audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_data.outburst); |
954 | 385 } |
386 } else { | |
6296 | 387 mp_msg(MSGT_AO,MSGL_V,"audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n", |
954 | 388 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes); |
3095 | 389 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes; |
390 ao_data.outburst=zz.fragsize; | |
954 | 391 } |
392 | |
3095 | 393 if(ao_data.buffersize==-1){ |
954 | 394 // Measuring buffer size: |
395 void* data; | |
3095 | 396 ao_data.buffersize=0; |
954 | 397 #ifdef HAVE_AUDIO_SELECT |
3095 | 398 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst); |
399 while(ao_data.buffersize<0x40000){ | |
954 | 400 fd_set rfds; |
401 struct timeval tv; | |
402 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
403 tv.tv_sec=0; tv.tv_usec = 0; | |
404 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; | |
3095 | 405 write(audio_fd,data,ao_data.outburst); |
406 ao_data.buffersize+=ao_data.outburst; | |
954 | 407 } |
408 free(data); | |
3095 | 409 if(ao_data.buffersize==0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
410 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantUseSelect); |
954 | 411 return 0; |
412 } | |
413 #endif | |
414 } | |
415 | |
8603
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
416 ao_data.bps=ao_data.channels; |
14245 | 417 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
|
418 ao_data.bps*=2; |
30bef3c97b8b
ao_oss was not using the channel & format returned by the soundcard
arpi
parents:
8304
diff
changeset
|
419 |
6075
0b3b6d03779c
fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents:
5907
diff
changeset
|
420 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
|
421 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
|
422 |
954 | 423 return 1; |
424 } | |
425 | |
426 // close audio device | |
12145 | 427 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
|
428 if(audio_fd == -1) return; |
12145 | 429 #ifdef SNDCTL_DSP_SYNC |
430 // to get the buffer played | |
431 if (!immed) | |
432 ioctl(audio_fd, SNDCTL_DSP_SYNC, NULL); | |
433 #endif | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
434 #ifdef SNDCTL_DSP_RESET |
12145 | 435 if (immed) |
436 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
|
437 #endif |
954 | 438 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
|
439 audio_fd = -1; |
954 | 440 } |
441 | |
442 // stop playing and empty buffers (for seeking/pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17058
diff
changeset
|
443 static void reset(void){ |
14245 | 444 int oss_format; |
12145 | 445 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
|
446 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
|
447 if(audio_fd < 0){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12383
diff
changeset
|
448 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantReopen, strerror(errno)); |
954 | 449 return; |
450 } | |
451 | |
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
|
452 #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
|
453 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
|
454 #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
|
455 |
14245 | 456 oss_format = format2oss(ao_data.format); |
28605
65e49c604b25
Set samplerate in reset also for AC3, and set it before the format in that
reimar
parents:
28579
diff
changeset
|
457 if(ao_data.format == AF_FORMAT_AC3) |
65e49c604b25
Set samplerate in reset also for AC3, and set it before the format in that
reimar
parents:
28579
diff
changeset
|
458 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); |
14245 | 459 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &oss_format); |
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 } |
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
|
467 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
|
468 } |
954 | 469 } |
470 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
471 // stop playing, keep buffers (for pause) |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17058
diff
changeset
|
472 static void audio_pause(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
473 { |
23809
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
474 prepause_space = get_space(); |
12145 | 475 uninit(1); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
476 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
477 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
478 // resume playing, after audio_pause() |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17058
diff
changeset
|
479 static void audio_resume(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
480 { |
23809
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
481 int fillcnt; |
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
|
482 reset(); |
23809
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
483 fillcnt = get_space() - prepause_space; |
28579
0405513156d1
100l, do 0-filling on resume (to avoid desync after pause) in ao_oss only when
reimar
parents:
28343
diff
changeset
|
484 if (fillcnt > 0 && !(ao_data.format & AF_FORMAT_SPECIAL_MASK)) { |
23809
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
485 void *silence = calloc(fillcnt, 1); |
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
486 play(silence, fillcnt, 0); |
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
487 free(silence); |
6c348181fb20
Somewhat hackish fix for A-V desync with ao_oss and frame stepping:
reimar
parents:
21547
diff
changeset
|
488 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
489 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
490 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
491 |
954 | 492 // return: how many bytes can be played without blocking |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17058
diff
changeset
|
493 static int get_space(void){ |
3095 | 494 int playsize=ao_data.outburst; |
954 | 495 |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
496 #ifdef SNDCTL_DSP_GETOSPACE |
954 | 497 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){ |
498 // calculate exact buffer space: | |
3455
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
499 playsize = zz.fragments*zz.fragsize; |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
500 if (playsize > MAX_OUTBURST) |
921a78c7b4aa
limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents:
3319
diff
changeset
|
501 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
|
502 return playsize; |
954 | 503 } |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
956
diff
changeset
|
504 #endif |
954 | 505 |
506 // check buffer | |
507 #ifdef HAVE_AUDIO_SELECT | |
508 { fd_set rfds; | |
509 struct timeval tv; | |
510 FD_ZERO(&rfds); | |
511 FD_SET(audio_fd, &rfds); | |
512 tv.tv_sec = 0; | |
513 tv.tv_usec = 0; | |
514 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! | |
515 } | |
516 #endif | |
517 | |
3095 | 518 return ao_data.outburst; |
954 | 519 } |
520 | |
521 // plays 'len' bytes of 'data' | |
522 // it should round it down to outburst*n | |
523 // return: number of bytes played | |
524 static int play(void* data,int len,int flags){ | |
18842 | 525 if(len==0) |
526 return len; | |
527 if(len>ao_data.outburst || !(flags & AOPLAY_FINAL_CHUNK)) { | |
528 len/=ao_data.outburst; | |
529 len*=ao_data.outburst; | |
530 } | |
531 len=write(audio_fd,data,len); | |
954 | 532 return len; |
533 } | |
534 | |
535 static int audio_delay_method=2; | |
536 | |
3095 | 537 // return: delay in seconds between first and last sample in buffer |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17058
diff
changeset
|
538 static float get_delay(void){ |
3095 | 539 /* Calculate how many bytes/second is sent out */ |
954 | 540 if(audio_delay_method==2){ |
5872 | 541 #ifdef SNDCTL_DSP_GETODELAY |
954 | 542 int r=0; |
543 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1) | |
3095 | 544 return ((float)r)/(float)ao_data.bps; |
5872 | 545 #endif |
954 | 546 audio_delay_method=1; // fallback if not supported |
547 } | |
548 if(audio_delay_method==1){ | |
549 // SNDCTL_DSP_GETOSPACE | |
550 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1) | |
3095 | 551 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps; |
954 | 552 audio_delay_method=0; // fallback if not supported |
553 } | |
3095 | 554 return ((float)ao_data.buffersize)/(float)ao_data.bps; |
954 | 555 } |