annotate libao2/ao_sndio.c @ 37136:36638a3ccfe2

configure: add fma4 support to avoid breaking build
author michael
date Tue, 01 Jul 2014 23:53:51 +0000
parents 38234a308fd3
children
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);
36897
38234a308fd3 Fix sndio playback of 24 bit/sample audio.
reimar
parents: 36852
diff changeset
106 par.bps = (par.bits + 7) >> 3;
38234a308fd3 Fix sndio playback of 24 bit/sample audio.
reimar
parents: 36852
diff changeset
107 // normally bits == 8*bps so this makes no difference
38234a308fd3 Fix sndio playback of 24 bit/sample audio.
reimar
parents: 36852
diff changeset
108 // but we can support more formats for msb == 1, see "if" below
38234a308fd3 Fix sndio playback of 24 bit/sample audio.
reimar
parents: 36852
diff changeset
109 par.msb = 1;
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
110 par.sig = (format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_SI;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
111 if (par.bits > 8)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
112 par.le = (format & AF_FORMAT_END_MASK) == AF_FORMAT_LE;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
113 par.rate = rate;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
114 par.pchan = channels;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
115 par.appbufsz = par.rate * 250 / 1000; /* 250ms buffer */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
116 par.round = par.rate * 10 / 1000; /* 10ms block size */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
117 if (!sio_setpar(hdl, &par)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
118 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't set 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 (!sio_getpar(hdl, &par)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
122 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't get params\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 }
36897
38234a308fd3 Fix sndio playback of 24 bit/sample audio.
reimar
parents: 36852
diff changeset
125 // we do not care if LSBs are discarded
38234a308fd3 Fix sndio playback of 24 bit/sample audio.
reimar
parents: 36852
diff changeset
126 if (par.bits < 8 * par.bps && !par.msb) {
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
127 mp_msg(MSGT_AO, MSGL_ERR, "ao2: unsupported format\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 pfds = calloc(sio_nfds(hdl), sizeof(*pfds));
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
131 if (pfds == NULL) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
132 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
133 goto err_out;
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
134 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
135 bpf = par.bps * par.pchan;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
136 ao_data.format = af_bits2fmt(8 * par.bps);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
137 ao_data.format |= par.sig ? AF_FORMAT_SI : AF_FORMAT_US;
36852
145057e3f0ed ao_sndio: simplify, don't care about 8-bit endianness.
reimar
parents: 36467
diff changeset
138 ao_data.format |= par.le ? AF_FORMAT_LE : AF_FORMAT_BE;
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
139 ao_data.channels = par.pchan;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
140 ao_data.bps = bpf * par.rate;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
141 ao_data.buffersize = par.bufsz * bpf;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
142 ao_data.outburst = par.round * bpf;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
143 ao_data.samplerate = rate;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
144 havevol = sio_onvol(hdl, volcb, NULL);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
145 sio_onmove(hdl, movecb, NULL);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
146
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
147 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
148 * prepare the device to start. It will start as soon there's enough
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
149 * data in the buffer to not underrun
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
150 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
151 delay = 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
152 if (!sio_start(hdl)) {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
153 mp_msg(MSGT_AO, MSGL_ERR, "ao2: init: couldn't start\n");
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
154 goto err_out;
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
155 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
156 return 1;
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
157 err_out:
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
158 free(pfds);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
159 pfds = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
160 sio_close(hdl);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
161 hdl = NULL;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
162 return 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
163 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
164
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
165 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
166 * close device
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
167 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
168 static void uninit(int immed)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
169 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
170 if (hdl)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
171 sio_close(hdl);
36466
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
172 hdl = NULL;
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
173 free(pfds);
9824daf4a867 Simpler/more robust cleanup code.
reimar
parents: 36465
diff changeset
174 pfds = NULL;
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
175 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
176
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
177 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
178 * stop playing and prepare to restart
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
179 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
180 static void reset(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
181 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
182 if (!sio_stop(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
183 mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't stop\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
184 delay = 0;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
185 if (!sio_start(hdl))
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
186 mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't start\n");
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
187 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
188
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
189 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
190 * refresh the "delay" counter: call sio_revents() which keeps track of
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
191 * the hardware position
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
192 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
193 static void refresh(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
194 {
36467
645cbd086d2b Merge declaration and initialization.
reimar
parents: 36466
diff changeset
195 int n = sio_pollfd(hdl, pfds, POLLOUT);
36463
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
196 while (poll(pfds, n, 0) < 0 && errno == EINTR)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
197 ; /* nothing */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
198 sio_revents(hdl, pfds);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
199 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
200
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
201 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
202 * return the number of bytes available in the device buffer
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
203 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
204 static int get_space(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
205 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
206 refresh();
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
207 return par.bufsz * par.pchan * par.bps - delay;
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
208 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
209
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
210 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
211 * delay in seconds between first and last sample in the buffer
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
212 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
213 static float get_delay(void)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
214 {
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
215 refresh();
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
216 return (float)delay / (par.bps * par.pchan * par.rate);
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
217 }
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
218
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
219 /*
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
220 * submit the given number of bytes to the device
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
221 */
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
222 static int play(void *data, int len, int flags)
c6843e5bf166 libao2: Add sndio audio output module.
reimar
parents:
diff changeset
223 {
36467
645cbd086d2b Merge declaration and initialization.
reimar
parents: 36466
diff changeset
224 int n = sio_write(hdl, data, len);
36463
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 }