annotate libao2/ao_oss.c @ 11859:b8bee4f4b8bb

if the user wants fast, use fast code! otherwise the user has to put af=resample=44100:0:0 in the config file, which will resample all files, not just ones that need it. libaf still sux!
author rfelker
date Tue, 27 Jan 2004 06:45:43 +0000
parents 4e8f8efb6906
children 99798c3cdb93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
3
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
4 #include <sys/ioctl.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
7 #include <sys/types.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
8 #include <sys/stat.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
9 #include <fcntl.h>
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
10 #include <errno.h>
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
11 #include <string.h>
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
12 //#include <sys/soundcard.h>
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
13
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
14 #include "../config.h"
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
15 #include "../mp_msg.h"
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
16 #include "../mixer.h"
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
17
1532
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
18 #include "afmt.h"
cb9bc07f3d4c AFMT_AC3 fixed
arpi
parents: 1528
diff changeset
19
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
20 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
21 #include "audio_out_internal.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
22
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
23 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
24 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
25 "OSS/ioctl audio output",
956
a6cecd9a1bad '-ao' switch (including '-ao help'), fixing Arpi's bug (short name 'null' for both of oss and null driver ;)
lgb
parents: 954
diff changeset
26 "oss",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
27 "A'rpi",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
28 ""
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
29 };
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
30
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
31 /* Support for >2 output channels added 2001-11-25 - Steve Davies <steve@daviesfam.org> */
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
32
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
33 LIBAO_EXTERN(oss)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
34
4803
5b4fd881200a using PATH_DEV_*
alex
parents: 4788
diff changeset
35 static char *dsp=PATH_DEV_DSP;
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
36 static audio_buf_info zz;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
37 static int audio_fd=-1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
38
4803
5b4fd881200a using PATH_DEV_*
alex
parents: 4788
diff changeset
39 char *oss_mixer_device = PATH_DEV_MIXER;
11837
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
40 int oss_mixer_channel = SOUND_MIXER_PCM;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
41
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
42 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 9141
diff changeset
43 static int control(int cmd,void *arg){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
44 switch(cmd){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
45 case AOCONTROL_SET_DEVICE:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 dsp=(char*)arg;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47 return CONTROL_OK;
6795
776b686069af - add some control (ao_oss, pl_extrastereo)
pontscho
parents: 6588
diff changeset
48 case AOCONTROL_GET_DEVICE:
776b686069af - add some control (ao_oss, pl_extrastereo)
pontscho
parents: 6588
diff changeset
49 (char*)arg=dsp;
776b686069af - add some control (ao_oss, pl_extrastereo)
pontscho
parents: 6588
diff changeset
50 return CONTROL_OK;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
51 case AOCONTROL_QUERY_FORMAT:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
52 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
53 case AOCONTROL_GET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
54 case AOCONTROL_SET_VOLUME:
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
55 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
56 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
57 int fd, v, devs;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
58
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
59 if(ao_data.format == AFMT_AC3)
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
60 return CONTROL_TRUE;
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
61
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
62 if ((fd = open(oss_mixer_device, O_RDONLY)) > 0)
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
63 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
64 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
11837
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
65 if (devs & (1 << oss_mixer_channel))
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
66 {
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
67 if (cmd == AOCONTROL_GET_VOLUME)
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
68 {
11837
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
69 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
70 vol->right = (v & 0xFF00) >> 8;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
71 vol->left = v & 0x00FF;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
72 }
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
73 else
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
74 {
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
75 v = ((int)vol->right << 8) | (int)vol->left;
11837
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
76 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
77 }
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
78 }
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
79 else
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
80 {
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
81 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
82 return CONTROL_ERROR;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
83 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
84 close(fd);
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
85 return CONTROL_OK;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
86 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
87 }
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
88 return CONTROL_ERROR;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
89 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
90 return CONTROL_UNKNOWN;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
91 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
92
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
93 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
94 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
95 static int init(int rate,int channels,int format,int flags){
11837
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
96 char *mixer_channels [SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
97
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
98 mp_msg(MSGT_AO,MSGL_V,"ao2: %d Hz %d chans %s\n",rate,channels,
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
99 audio_out_format_name(format));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
100
1191
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
101 if (ao_subdevice)
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
102 dsp = ao_subdevice;
f9a46e7843ee ao_subdevice support
al3x
parents: 1079
diff changeset
103
4788
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
104 if(mixer_device)
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
105 oss_mixer_device=mixer_device;
d678ce495a75 Moved HW dependent mixer stuff to libao and removed master switch
anders
parents: 4184
diff changeset
106
11837
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
107 if(mixer_channel){
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
108 int fd, devs, i;
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
109
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
110 if ((fd = open(oss_mixer_device, O_RDONLY)) == -1){
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
111 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Can't open mixer device %s: %s\n",
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
112 oss_mixer_device, strerror(errno));
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
113 }else{
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
114 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
115 close(fd);
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
116
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
117 for (i=0; i<SOUND_MIXER_NRDEVICES; i++){
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
118 if(!strcasecmp(mixer_channels[i], mixer_channel)){
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
119 if(!(devs & (1 << i))){
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
120 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Audio card mixer does not have channel '%s' using default\n",
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
121 mixer_channel);
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
122 i = SOUND_MIXER_NRDEVICES+1;
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
123 break;
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
124 }
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
125 oss_mixer_channel = i;
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
126 break;
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
127 }
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
128 }
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
129 if(i==SOUND_MIXER_NRDEVICES){
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
130 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Can't find mixer channel '%s' using default\n",
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
131 mixer_channel);
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
132 }
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
133 }
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
134 }
4e8f8efb6906 add option to select mixer channel
attila
parents: 10600
diff changeset
135
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
136 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
137 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
138 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
139
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
140 #ifdef __linux__
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
141 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
142 #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
143 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
144 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
145 if(audio_fd<0){
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
146 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Can't open audio device %s: %s\n", dsp, strerror(errno));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
147 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
148 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
149
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
150 #ifdef __linux__
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
151 /* Remove the non-blocking flag */
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
152 if(fcntl(audio_fd, F_SETFL, 0) < 0) {
8304
2dcdd2ae333f 1l, opposite meaning of what's intended!
rfelker
parents: 8303
diff changeset
153 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Can't make filedescriptor blocking: %s\n", strerror(errno));
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
154 return 0;
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
155 }
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
156 #endif
8303
322f1a91a5e7 avoid giving a /dev/dsp fd to child processes!!
rfelker
parents: 8027
diff changeset
157
322f1a91a5e7 avoid giving a /dev/dsp fd to child processes!!
rfelker
parents: 8027
diff changeset
158 #if defined(FD_CLOEXEC) && defined(F_SETFD)
322f1a91a5e7 avoid giving a /dev/dsp fd to child processes!!
rfelker
parents: 8027
diff changeset
159 fcntl(audio_fd, F_SETFD, FD_CLOEXEC);
322f1a91a5e7 avoid giving a /dev/dsp fd to child processes!!
rfelker
parents: 8027
diff changeset
160 #endif
5204
6bbf3271a694 non-blocking open - patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents: 4803
diff changeset
161
4184
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
162 if(format == AFMT_AC3) {
f648f699eda6 hwac3 fix for cmedia 8738 by Hans-Peter Raschke <Hans-Peter.Raschke@wintermann-datenservice.de>
arpi
parents: 3455
diff changeset
163 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
164 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
165 }
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
166
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
167 ac3_retry:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
168 ao_data.format=format;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
169 if( ioctl(audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format)<0 ||
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
170 ao_data.format != format) if(format == AFMT_AC3){
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
171 mp_msg(MSGT_AO,MSGL_WARN,"Can't set audio device %s to AC3 output, trying S16...\n", dsp);
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
172 #ifdef WORDS_BIGENDIAN
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
173 format=AFMT_S16_BE;
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
174 #else
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
175 format=AFMT_S16_LE;
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
176 #endif
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 5204
diff changeset
177 goto ac3_retry;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
178 }
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
179 mp_msg(MSGT_AO,MSGL_V,"audio_setup: sample format: %s (requested: %s)\n",
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
180 audio_out_format_name(ao_data.format), audio_out_format_name(format));
7668
76bd62c375e8 remove nonsense warnings now that libaf is used
rfelker
parents: 7472
diff changeset
181 #if 0
6899
4a45ce284efc format incompatibility warning
arpi
parents: 6795
diff changeset
182 if(ao_data.format!=format)
4a45ce284efc format incompatibility warning
arpi
parents: 6795
diff changeset
183 mp_msg(MSGT_AO,MSGL_WARN,"WARNING! Your soundcard does NOT support %s sample format! Broken audio or bad playback speed are possible! Try with '-aop list=format'\n",audio_out_format_name(format));
7668
76bd62c375e8 remove nonsense warnings now that libaf is used
rfelker
parents: 7472
diff changeset
184 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
185
8848
arpi
parents: 8603
diff changeset
186 ao_data.channels = channels;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
187 if(format != AFMT_AC3) {
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
188 // 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
189 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
190 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
191 ao_data.channels != channels ) {
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
192 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Failed to set audio device to %d channels\n", channels);
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
193 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
194 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
195 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
196 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
197 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
198 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) {
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
199 mp_msg(MSGT_AO,MSGL_ERR,"audio_setup: Failed to set audio device to %d channels\n", ao_data.channels);
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
200 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
201 }
9141
20793317e5ff nice 10l bug, found by Balatoni Denes <pnis@coder.hu>
arpi
parents: 8848
diff changeset
202 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
203 }
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
204 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
205 // 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
206 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
207 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
208 mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
7668
76bd62c375e8 remove nonsense warnings now that libaf is used
rfelker
parents: 7472
diff changeset
209 #if 0
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
210 if(ao_data.samplerate!=rate)
6588
12826366a806 more informal warning and also fixed a 10l bug. Patch by tibcu
alex
parents: 6296
diff changeset
211 mp_msg(MSGT_AO,MSGL_WARN,"WARNING! Your soundcard does NOT support %d Hz samplerate! A-V sync problems or wrong speed are possible! Try with '-aop list=resample:fout=%d'\n",rate,ao_data.samplerate);
7668
76bd62c375e8 remove nonsense warnings now that libaf is used
rfelker
parents: 7472
diff changeset
212 #endif
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1456
diff changeset
213 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
214
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
215 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
216 int r=0;
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
217 mp_msg(MSGT_AO,MSGL_WARN,"audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
218 if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
219 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
220 } else {
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
221 ao_data.outburst=r;
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
222 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
223 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
224 } else {
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
225 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
226 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
227 if(ao_data.buffersize==-1) ao_data.buffersize=zz.bytes;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
228 ao_data.outburst=zz.fragsize;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
229 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
230
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
231 if(ao_data.buffersize==-1){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
232 // Measuring buffer size:
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
233 void* data;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
234 ao_data.buffersize=0;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
235 #ifdef HAVE_AUDIO_SELECT
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
236 data=malloc(ao_data.outburst); memset(data,0,ao_data.outburst);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
237 while(ao_data.buffersize<0x40000){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
238 fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
239 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
240 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
241 tv.tv_sec=0; tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
242 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
243 write(audio_fd,data,ao_data.outburst);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
244 ao_data.buffersize+=ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
245 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
246 free(data);
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
247 if(ao_data.buffersize==0){
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
248 mp_msg(MSGT_AO,MSGL_ERR,"\n *** Your audio driver DOES NOT support select() ***\n"
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
249 "Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
250 return 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
251 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
252 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
253 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
254
8603
30bef3c97b8b ao_oss was not using the channel & format returned by the soundcard
arpi
parents: 8304
diff changeset
255 ao_data.bps=ao_data.channels;
30bef3c97b8b ao_oss was not using the channel & format returned by the soundcard
arpi
parents: 8304
diff changeset
256 if(ao_data.format != AFMT_U8 && ao_data.format != AFMT_S8)
30bef3c97b8b ao_oss was not using the channel & format returned by the soundcard
arpi
parents: 8304
diff changeset
257 ao_data.bps*=2;
30bef3c97b8b ao_oss was not using the channel & format returned by the soundcard
arpi
parents: 8304
diff changeset
258
6075
0b3b6d03779c fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents: 5907
diff changeset
259 ao_data.outburst-=ao_data.outburst % ao_data.bps; // round down
8603
30bef3c97b8b ao_oss was not using the channel & format returned by the soundcard
arpi
parents: 8304
diff changeset
260 ao_data.bps*=ao_data.samplerate;
6075
0b3b6d03779c fix for L<->R swap with 6ch playback - based on patch by Eric Lammerts <eric@lammerts.org>
arpi
parents: 5907
diff changeset
261
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
262 return 1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
263 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
264
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
265 // close audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
266 static void uninit(){
7118
4332922afec4 release /dev/dsp on pause patch by Eric Lammerts <eric@lammerts.org> (and D Richard Felker III <dalias@aerifal.cx>)
alex
parents: 6899
diff changeset
267 if(audio_fd == -1) return;
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
268 #ifdef SNDCTL_DSP_RESET
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
269 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
270 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
271 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
272 audio_fd = -1;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
273 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
274
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
275 // stop playing and empty buffers (for seeking/pause)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
276 static void reset(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
277 uninit();
5907
d8c34a35ccb9 nonblock open is not legal for OSS (see OSS api docs), and causes problems on freebsd (and maybe other OSs)
arpi
parents: 5872
diff changeset
278 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
279 if(audio_fd < 0){
6296
74115095d9fe msg/i18n fixes and some printf->mp_msg
arpi
parents: 6138
diff changeset
280 mp_msg(MSGT_AO,MSGL_ERR,"\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE *** %s\n", strerror(errno));
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
281 return;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
282 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
283
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
284 #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
285 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
286 #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
287
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
288 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format);
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
289 if(ao_data.format != AFMT_AC3) {
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
290 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
291 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
292 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
293 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
294 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
295 }
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3137
diff changeset
296 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
297 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
298 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
299
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
300 // stop playing, keep buffers (for pause)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
301 static void audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
302 {
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
303 uninit();
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
304 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
305
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
306 // resume playing, after audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
307 static void audio_resume()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
308 {
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
309 reset();
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
310 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
311
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
312
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
313 // return: how many bytes can be played without blocking
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
314 static int get_space(){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
315 int playsize=ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
316
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
317 #ifdef SNDCTL_DSP_GETOSPACE
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
318 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
319 // calculate exact buffer space:
3455
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
320 playsize = zz.fragments*zz.fragsize;
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
321 if (playsize > MAX_OUTBURST)
921a78c7b4aa limit get_space return <= MAX_OUTBURST, whilst always an exact number of fragments
steve
parents: 3319
diff changeset
322 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
323 return playsize;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
324 }
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 956
diff changeset
325 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
326
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
327 // check buffer
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
328 #ifdef HAVE_AUDIO_SELECT
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
329 { fd_set rfds;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
330 struct timeval tv;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
331 FD_ZERO(&rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
332 FD_SET(audio_fd, &rfds);
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
333 tv.tv_sec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
334 tv.tv_usec = 0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
335 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block!
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
336 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
337 #endif
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
338
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
339 return ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
340 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
341
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
342 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
343 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
344 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
345 static int play(void* data,int len,int flags){
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
346 len/=ao_data.outburst;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
347 len=write(audio_fd,data,len*ao_data.outburst);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
348 return len;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
349 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
350
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
351 static int audio_delay_method=2;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
352
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
353 // return: delay in seconds between first and last sample in buffer
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
354 static float get_delay(){
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
355 /* Calculate how many bytes/second is sent out */
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
356 if(audio_delay_method==2){
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5790
diff changeset
357 #ifdef SNDCTL_DSP_GETODELAY
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
358 int r=0;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
359 if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1)
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
360 return ((float)r)/(float)ao_data.bps;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents: 5790
diff changeset
361 #endif
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
362 audio_delay_method=1; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
363 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
364 if(audio_delay_method==1){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
365 // SNDCTL_DSP_GETOSPACE
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
366 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1)
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
367 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
368 audio_delay_method=0; // fallback if not supported
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
369 }
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2080
diff changeset
370 return ((float)ao_data.buffersize)/(float)ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
371 }