annotate libao2/ao_sndio.c @ 36463:c6843e5bf166

libao2: Add sndio audio output module. Patch by Alexandre Ratchov [alex caoua org].
author reimar
date Tue, 31 Dec 2013 15:30:49 +0000
parents
children cae4a4a36016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
1 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
2 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
3 *
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
4 * This file is part of MPlayer.
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
5 *
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
9 * (at your option) any later version.
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
10 *
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
14 * GNU General Public License for more details.
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
15 *
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
19 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
20 #include <sys/types.h>
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
21 #include <poll.h>
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
22 #include <errno.h>
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
23 #include <sndio.h>
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
24 #include <stdlib.h>
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
25
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
26 #include "config.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
27 #include "mp_msg.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
28 #include "mixer.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
29 #include "help_mp.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
30
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
31 #include "libaf/af_format.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
32
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
33 #include "audio_out.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
34 #include "audio_out_internal.h"
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
35
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
36 static ao_info_t info = {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
37 "sndio audio output",
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
38 "sndio",
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
39 "Alexandre Ratchov <alex@caoua.org>",
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
40 ""
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
41 };
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
42
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
43 LIBAO_EXTERN(sndio)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
44
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
45 static struct sio_hdl *hdl = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
46 struct pollfd *pfds = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
47 static struct sio_par par;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
48 static int delay, vol, havevol;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
49 static int prepause_delay;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
50
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
51 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
52 * control misc parameters (only the volume for now)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
53 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
54 static int control(int cmd, void *arg)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
55 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
56 ao_control_vol_t *ctl = arg;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
57
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
58 switch (cmd) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
59 case AOCONTROL_GET_VOLUME:
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
60 if (!havevol)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
61 return CONTROL_FALSE;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
62 ctl->left = ctl->right = vol * 100 / SIO_MAXVOL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
63 break;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
64 case AOCONTROL_SET_VOLUME:
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
65 if (!havevol)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
66 return CONTROL_FALSE;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
67 sio_setvol(hdl, ctl->left * SIO_MAXVOL / 100);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
68 break;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
69 default:
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
70 return CONTROL_UNKNOWN;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
71 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
72 return CONTROL_OK;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
73 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
74
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
75 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
76 * call-back invoked whenever the the hardware position changes
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
77 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
78 static void movecb(void *addr, int delta)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
79 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
80 delay -= delta * (int)(par.bps * par.pchan);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
81 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
82
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
83 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
84 * call-back invoked whenever the volume changes
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
85 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
86 static void volcb(void *addr, unsigned newvol)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
87 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
88 vol = newvol;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
89 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
90
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
91 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
92 * open device and setup parameters
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
93 * return: 1 = success, 0 = failure
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
94 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
95 static int init(int rate, int channels, int format, int flags)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
96 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
97 int bpf;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
98
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
99 hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
100 if (hdl == NULL) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
101 mp_msg(MSGT_AO, MSGL_ERR, "ao2: can't open sndio\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
102 return 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
103 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
104 sio_initpar(&par);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
105 par.bits = af_fmt2bits(format);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
106 par.sig = (format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_SI;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
107 if (par.bits > 8)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
108 par.le = (format & AF_FORMAT_END_MASK) == AF_FORMAT_LE;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
109 par.rate = rate;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
110 par.pchan = channels;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
111 par.appbufsz = par.rate * 250 / 1000; /* 250ms buffer */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
112 par.round = par.rate * 10 / 1000; /* 10ms block size */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
113 if (!sio_setpar(hdl, &par)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
114 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't set params\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
115 goto bad_close;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
116 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
117 if (!sio_getpar(hdl, &par)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
118 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't get params\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
119 goto bad_close;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
120 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
121 if (par.bps != SIO_BPS(par.bits)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
122 mp_msg(MSGT_AO, MSGL_ERR, "ao2: unsupported format\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
123 goto bad_close;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
124 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
125 pfds = calloc(sio_nfds(hdl), sizeof(*pfds));
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
126 if (pfds == NULL) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
127 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't allocate poll fds\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
128 goto bad_close;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
129 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
130 bpf = par.bps * par.pchan;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
131 ao_data.format = af_bits2fmt(8 * par.bps);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
132 ao_data.format |= par.sig ? AF_FORMAT_SI : AF_FORMAT_US;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
133 if (par.bits > 8)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
134 ao_data.format |= par.le ? AF_FORMAT_LE : AF_FORMAT_BE;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
135 ao_data.channels = par.pchan;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
136 ao_data.bps = bpf * par.rate;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
137 ao_data.buffersize = par.bufsz * bpf;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
138 ao_data.outburst = par.round * bpf;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
139 ao_data.samplerate = rate;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
140 havevol = sio_onvol(hdl, volcb, NULL);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
141 sio_onmove(hdl, movecb, NULL);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
142
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
143 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
144 * prepare the device to start. It will start as soon there's enough
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
145 * data in the buffer to not underrun
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
146 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
147 delay = 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
148 if (!sio_start(hdl)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
149 mp_msg(MSGT_AO, MSGL_ERR, "ao2: init: couldn't start\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
150 goto bad_free;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
151 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
152 return 1;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
153 bad_free:
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
154 free(pfds);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
155 pfds = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
156 bad_close:
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
157 sio_close(hdl);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
158 hdl = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
159 return 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
160 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
161
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
162 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
163 * close device
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
164 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
165 static void uninit(int immed)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
166 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
167 if (hdl)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
168 sio_close(hdl);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
169 if (pfds)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
170 free(pfds);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
171 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
172
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
173 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
174 * stop playing and prepare to restart
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
175 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
176 static void reset(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
177 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
178 if (!sio_stop(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
179 mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't stop\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
180 delay = 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
181 if (!sio_start(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
182 mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't start\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
183 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
184
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
185 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
186 * refresh the "delay" counter: call sio_revents() which keeps track of
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
187 * the hardware position
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
188 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
189 static void refresh(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
190 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
191 int n;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
192
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
193 n = sio_pollfd(hdl, pfds, POLLOUT);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
194 while (poll(pfds, n, 0) < 0 && errno == EINTR)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
195 ; /* nothing */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
196 sio_revents(hdl, pfds);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
197 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
198
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
199 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
200 * return the number of bytes available in the device buffer
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
201 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
202 static int get_space(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
203 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
204 refresh();
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
205 return par.bufsz * par.pchan * par.bps - delay;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
206 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
207
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
208 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
209 * delay in seconds between first and last sample in the buffer
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
210 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
211 static float get_delay(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
212 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
213 refresh();
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
214 return (float)delay / (par.bps * par.pchan * par.rate);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
215 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
216
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
217 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
218 * submit the given number of bytes to the device
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
219 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
220 static int play(void *data, int len, int flags)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
221 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
222 int n;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
223
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
224 n = sio_write(hdl, data, len);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
225 delay += n;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
226 return n;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
227 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
228
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
229 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
230 * pause playing
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
231 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
232 static void audio_pause(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
233 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
234 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
235 * sndio can't pause, so just stop
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
236 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
237 prepause_delay = delay;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
238 if (!sio_stop(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
239 mp_msg(MSGT_AO, MSGL_ERR, "ao2: pause: couldn't stop\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
240 delay = 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
241 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
242
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
243 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
244 * resume playing after audio_pause()
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
245 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
246 static void audio_resume(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
247 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
248 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
249 * prepare to start; then refill the buffer with the number of bytes
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
250 * audio_pause() consumed (this will trigger start)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
251 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
252 if (!sio_start(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
253 mp_msg(MSGT_AO, MSGL_ERR, "ao2: resume: couldn't start\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
254 mp_ao_resume_refill(&audio_out_sndio,
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
255 par.bufsz * par.pchan * par.bps - prepause_delay);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
256 }