annotate libao2/ao_sndio.c @ 36726:ed1d856ec43d

Use DECLARE_ALIGNED helper macros. Patch by Matt Oliver [protogonoi gmail.com].
author reimar
date Sun, 09 Feb 2014 22:19:07 +0000
parents 645cbd086d2b
children 145057e3f0ed
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
36465
273702710048 Remove pointless explicit initialization.
reimar
parents: 36464
diff changeset
45 static struct sio_hdl *hdl;
273702710048 Remove pointless explicit initialization.
reimar
parents: 36464
diff changeset
46 static struct pollfd *pfds;
36463
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");
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
115 goto err_out;
36463
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");
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
119 goto err_out;
36463
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");
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
123 goto err_out;
36463
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");
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
128 goto err_out;
36463
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");
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
150 goto err_out;
36463
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;
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
153 err_out:
36463
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 sio_close(hdl);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
157 hdl = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
158 return 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
159 }
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 * close device
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
163 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
164 static void uninit(int immed)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
165 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
166 if (hdl)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
167 sio_close(hdl);
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
168 hdl = NULL;
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
169 free(pfds);
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
170 pfds = NULL;
36463
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 {
36467
645cbd086d2b Merge declaration and initialization.
reimar
parents: 36466
diff changeset
191 int n = sio_pollfd(hdl, pfds, POLLOUT);
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
192 while (poll(pfds, n, 0) < 0 && errno == EINTR)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
193 ; /* nothing */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
194 sio_revents(hdl, pfds);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
195 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
196
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
197 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
198 * return the number of bytes available in the device buffer
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
199 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
200 static int get_space(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
201 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
202 refresh();
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
203 return par.bufsz * par.pchan * par.bps - delay;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
204 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
205
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
206 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
207 * delay in seconds between first and last sample in the buffer
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
208 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
209 static float get_delay(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
210 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
211 refresh();
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
212 return (float)delay / (par.bps * par.pchan * par.rate);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
213 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
214
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
215 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
216 * submit the given number of bytes to the device
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
217 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
218 static int play(void *data, int len, int flags)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
219 {
36467
645cbd086d2b Merge declaration and initialization.
reimar
parents: 36466
diff changeset
220 int n = sio_write(hdl, data, len);
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
221 delay += n;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
222 return 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
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
225 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
226 * pause playing
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
227 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
228 static void audio_pause(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
229 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
230 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
231 * sndio can't pause, so just stop
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
232 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
233 prepause_delay = delay;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
234 if (!sio_stop(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
235 mp_msg(MSGT_AO, MSGL_ERR, "ao2: pause: couldn't stop\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
236 delay = 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
237 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
238
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
239 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
240 * resume playing after audio_pause()
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
241 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
242 static void audio_resume(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
243 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
244 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
245 * prepare to start; then refill the buffer with the number of bytes
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
246 * audio_pause() consumed (this will trigger start)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
247 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
248 if (!sio_start(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
249 mp_msg(MSGT_AO, MSGL_ERR, "ao2: resume: couldn't start\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
250 mp_ao_resume_refill(&audio_out_sndio,
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
251 par.bufsz * par.pchan * par.bps - prepause_delay);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
252 }