annotate libao2/ao_oss.c @ 36011:277882d42938

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