Mercurial > mplayer.hg
annotate libao2/ao_jack.c @ 28114:a1451877ff0e
Update links to RPM packages, now that Livna has merged into RPMFusion.
author | rathann |
---|---|
date | Sun, 14 Dec 2008 11:18:23 +0000 |
parents | d97a607821f1 |
children | 678a664a79ea |
rev | line source |
---|---|
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
1 /* |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
2 * JACK audio output driver for MPlayer |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
3 * |
23734 | 4 * Copyleft 2001 by Felix Bünemann (atmosfear@users.sf.net) |
5 * and Reimar Döffinger (Reimar.Doeffinger@stud.uni-karlsruhe.de) | |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
6 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
7 * This file is part of MPlayer. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
8 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
9 * MPlayer is free software; you can redistribute it and/or modify |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
12 * (at your option) any later version. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
13 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
14 * MPlayer is distributed in the hope that it will be useful, |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
17 * GNU General Public License for more details. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
18 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
19 * You should have received a copy of the GNU General Public License along |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
20 * along with MPlayer; if not, write to the Free Software |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25650
diff
changeset
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
22 */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
23 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
24 #include <stdio.h> |
15605 | 25 #include <stdlib.h> |
26 #include <string.h> | |
15641
1bb5111490cd
Create a unique client name so that multiple instances work.
reimar
parents:
15630
diff
changeset
|
27 #include <unistd.h> |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
28 |
14479 | 29 #include "config.h" |
15605 | 30 #include "mp_msg.h" |
31 #include "help_mp.h" | |
32 | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
33 #include "audio_out.h" |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
34 #include "audio_out_internal.h" |
14245 | 35 #include "libaf/af_format.h" |
15605 | 36 #include "osdep/timer.h" |
37 #include "subopt-helper.h" | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
38 |
15605 | 39 #include "libvo/fastmemcpy.h" |
40 | |
41 #include <jack/jack.h> | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
42 |
15605 | 43 static ao_info_t info = |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
44 { |
15605 | 45 "JACK audio output", |
46 "jack", | |
23734 | 47 "Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>", |
15605 | 48 "based on ao_sdl.c" |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
49 }; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
50 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
51 LIBAO_EXTERN(jack) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
52 |
15605 | 53 //! maximum number of channels supported, avoids lots of mallocs |
54 #define MAX_CHANS 6 | |
55 static jack_port_t *ports[MAX_CHANS]; | |
56 static int num_ports; ///< Number of used ports == number of channels | |
57 static jack_client_t *client; | |
15630 | 58 static float jack_latency; |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
59 static int estimate; |
15605 | 60 static volatile int paused = 0; ///< set if paused |
61 static volatile int underrun = 0; ///< signals if an underrun occured | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
62 |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
63 static volatile float callback_interval = 0; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
64 static volatile float callback_time = 0; |
15605 | 65 |
66 //! size of one chunk, if this is too small MPlayer will start to "stutter" | |
67 //! after a short time of playback | |
68 #define CHUNK_SIZE (16 * 1024) | |
69 //! number of "virtual" chunks the buffer consists of | |
70 #define NUM_CHUNKS 8 | |
71 // This type of ring buffer may never fill up completely, at least | |
72 // one byte must always be unused. | |
73 // For performance reasons (alignment etc.) one whole chunk always stays | |
74 // empty, not only one byte. | |
75 #define BUFFSIZE ((NUM_CHUNKS + 1) * CHUNK_SIZE) | |
76 | |
77 //! buffer for audio data | |
78 static unsigned char *buffer = NULL; | |
79 | |
80 //! buffer read position, may only be modified by playback thread or while it is stopped | |
81 static volatile int read_pos; | |
82 //! buffer write position, may only be modified by MPlayer's thread | |
83 static volatile int write_pos; | |
84 | |
85 /** | |
86 * \brief get the number of free bytes in the buffer | |
87 * \return number of free bytes in buffer | |
88 * | |
89 * may only be called by MPlayer's thread | |
90 * return value may change between immediately following two calls, | |
91 * and the real number of free bytes might be larger! | |
92 */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
93 static int buf_free(void) { |
15605 | 94 int free = read_pos - write_pos - CHUNK_SIZE; |
95 if (free < 0) free += BUFFSIZE; | |
96 return free; | |
97 } | |
98 | |
99 /** | |
100 * \brief get amount of data available in the buffer | |
101 * \return number of bytes available in buffer | |
102 * | |
103 * may only be called by the playback thread | |
104 * return value may change between immediately following two calls, | |
105 * and the real number of buffered bytes might be larger! | |
106 */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
107 static int buf_used(void) { |
15605 | 108 int used = write_pos - read_pos; |
109 if (used < 0) used += BUFFSIZE; | |
110 return used; | |
111 } | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
112 |
15605 | 113 /** |
114 * \brief insert len bytes into buffer | |
115 * \param data data to insert | |
116 * \param len length of data | |
117 * \return number of bytes inserted into buffer | |
118 * | |
119 * If there is not enough room, the buffer is filled up | |
120 */ | |
121 static int write_buffer(unsigned char* data, int len) { | |
122 int first_len = BUFFSIZE - write_pos; | |
123 int free = buf_free(); | |
124 if (len > free) len = free; | |
125 if (first_len > len) first_len = len; | |
126 // till end of buffer | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
18915
diff
changeset
|
127 fast_memcpy (&buffer[write_pos], data, first_len); |
15605 | 128 if (len > first_len) { // we have to wrap around |
129 // remaining part from beginning of buffer | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
18915
diff
changeset
|
130 fast_memcpy (buffer, &data[first_len], len - first_len); |
15605 | 131 } |
132 write_pos = (write_pos + len) % BUFFSIZE; | |
133 return len; | |
134 } | |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
135 |
25648
2438052a176e
Another small simplification. Slightly worse performance in the case
reimar
parents:
25647
diff
changeset
|
136 static void silence(float **bufs, int cnt, int num_bufs); |
2438052a176e
Another small simplification. Slightly worse performance in the case
reimar
parents:
25647
diff
changeset
|
137 |
15605 | 138 /** |
139 * \brief read data from buffer and splitting it into channels | |
140 * \param bufs num_bufs float buffers, each will contain the data of one channel | |
141 * \param cnt number of samples to read per channel | |
142 * \param num_bufs number of channels to split the data into | |
143 * \return number of samples read per channel, equals cnt unless there was too | |
144 * little data in the buffer | |
145 * | |
146 * Assumes the data in the buffer is of type float, the number of bytes | |
147 * read is res * num_bufs * sizeof(float), where res is the return value. | |
18808
cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
reimar
parents:
18807
diff
changeset
|
148 * If there is not enough data in the buffer remaining parts will be filled |
cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
reimar
parents:
18807
diff
changeset
|
149 * with silence. |
15605 | 150 */ |
151 static int read_buffer(float **bufs, int cnt, int num_bufs) { | |
152 int buffered = buf_used(); | |
153 int i, j; | |
25647 | 154 if (cnt * sizeof(float) * num_bufs > buffered) { |
25648
2438052a176e
Another small simplification. Slightly worse performance in the case
reimar
parents:
25647
diff
changeset
|
155 silence(bufs, cnt, num_bufs); |
15605 | 156 cnt = buffered / sizeof(float) / num_bufs; |
25647 | 157 } |
15605 | 158 for (i = 0; i < cnt; i++) { |
159 for (j = 0; j < num_bufs; j++) { | |
25647 | 160 bufs[j][i] = *(float *)&buffer[read_pos]; |
15605 | 161 read_pos = (read_pos + sizeof(float)) % BUFFSIZE; |
162 } | |
163 } | |
164 return cnt; | |
165 } | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
166 |
15605 | 167 // end ring buffer stuff |
168 | |
169 static int control(int cmd, void *arg) { | |
170 return CONTROL_UNKNOWN; | |
171 } | |
172 | |
173 /** | |
174 * \brief fill the buffers with silence | |
175 * \param bufs num_bufs float buffers, each will contain the data of one channel | |
176 * \param cnt number of samples in each buffer | |
177 * \param num_bufs number of buffers | |
178 */ | |
179 static void silence(float **bufs, int cnt, int num_bufs) { | |
25646 | 180 int i; |
181 for (i = 0; i < num_bufs; i++) | |
182 memset(bufs[i], 0, cnt * sizeof(float)); | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
183 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
184 |
15605 | 185 /** |
186 * \brief JACK Callback function | |
187 * \param nframes number of frames to fill into buffers | |
188 * \param arg unused | |
189 * \return currently always 0 | |
190 * | |
191 * Write silence into buffers if paused or an underrun occured | |
192 */ | |
193 static int outputaudio(jack_nframes_t nframes, void *arg) { | |
194 float *bufs[MAX_CHANS]; | |
195 int i; | |
196 for (i = 0; i < num_ports; i++) | |
197 bufs[i] = jack_port_get_buffer(ports[i], nframes); | |
18808
cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
reimar
parents:
18807
diff
changeset
|
198 if (paused || underrun) |
cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
reimar
parents:
18807
diff
changeset
|
199 silence(bufs, nframes, num_ports); |
cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
reimar
parents:
18807
diff
changeset
|
200 else |
15605 | 201 if (read_buffer(bufs, nframes, num_ports) < nframes) |
202 underrun = 1; | |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
203 if (estimate) { |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
204 float now = (float)GetTimer() / 1000000.0; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
205 float diff = callback_time + callback_interval - now; |
16140 | 206 if ((diff > -0.002) && (diff < 0.002)) |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
207 callback_time += callback_interval; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
208 else |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
209 callback_time = now; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
210 callback_interval = (float)nframes / (float)ao_data.samplerate; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
211 } |
15605 | 212 return 0; |
213 } | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
214 |
15605 | 215 /** |
216 * \brief print suboption usage help | |
217 */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
218 static void print_help (void) |
15605 | 219 { |
220 mp_msg (MSGT_AO, MSGL_FATAL, | |
221 "\n-ao jack commandline help:\n" | |
222 "Example: mplayer -ao jack:port=myout\n" | |
223 " connects MPlayer to the jack ports named myout\n" | |
224 "\nOptions:\n" | |
225 " port=<port name>\n" | |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
226 " Connects to the given ports instead of the default physical ones\n" |
16253 | 227 " name=<client name>\n" |
228 " Client name to pass to JACK\n" | |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
229 " estimate\n" |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
230 " Estimates the amount of data in buffers (experimental)\n"); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
231 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
232 |
15605 | 233 static int init(int rate, int channels, int format, int flags) { |
234 const char **matching_ports = NULL; | |
235 char *port_name = NULL; | |
16253 | 236 char *client_name = NULL; |
15605 | 237 opt_t subopts[] = { |
238 {"port", OPT_ARG_MSTRZ, &port_name, NULL}, | |
16253 | 239 {"name", OPT_ARG_MSTRZ, &client_name, NULL}, |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
240 {"estimate", OPT_ARG_BOOL, &estimate, NULL}, |
15605 | 241 {NULL} |
242 }; | |
243 int port_flags = JackPortIsInput; | |
244 int i; | |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
245 estimate = 1; |
15605 | 246 if (subopt_parse(ao_subdevice, subopts) != 0) { |
247 print_help(); | |
248 return 0; | |
249 } | |
250 if (channels > MAX_CHANS) { | |
251 mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] Invalid number of channels: %i\n", channels); | |
252 goto err_out; | |
253 } | |
16253 | 254 if (!client_name) { |
18885 | 255 client_name = malloc(40); |
25645 | 256 sprintf(client_name, "MPlayer [%d]", getpid()); |
16253 | 257 } |
15641
1bb5111490cd
Create a unique client name so that multiple instances work.
reimar
parents:
15630
diff
changeset
|
258 client = jack_client_new(client_name); |
15605 | 259 if (!client) { |
260 mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] cannot open server\n"); | |
261 goto err_out; | |
262 } | |
15868 | 263 reset(); |
15605 | 264 jack_set_process_callback(client, outputaudio, 0); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
265 |
15605 | 266 // list matching ports |
267 if (!port_name) | |
268 port_flags |= JackPortIsPhysical; | |
269 matching_ports = jack_get_ports(client, port_name, NULL, port_flags); | |
25649 | 270 if (!matching_ports || !matching_ports[0]) { |
15605 | 271 mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] no physical ports available\n"); |
272 goto err_out; | |
273 } | |
25650 | 274 i = 1; |
275 while (matching_ports[i]) i++; | |
276 if (channels > i) channels = i; | |
15605 | 277 num_ports = channels; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
278 |
15605 | 279 // create out output ports |
280 for (i = 0; i < num_ports; i++) { | |
281 char pname[30]; | |
282 snprintf(pname, 30, "out_%d", i); | |
283 ports[i] = jack_port_register(client, pname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); | |
284 if (!ports[i]) { | |
285 mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] not enough ports available\n"); | |
286 goto err_out; | |
287 } | |
288 } | |
289 if (jack_activate(client)) { | |
290 mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] activate failed\n"); | |
291 goto err_out; | |
292 } | |
293 for (i = 0; i < num_ports; i++) { | |
294 if (jack_connect(client, jack_port_name(ports[i]), matching_ports[i])) { | |
295 mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] connecting failed\n"); | |
296 goto err_out; | |
297 } | |
298 } | |
15630 | 299 rate = jack_get_sample_rate(client); |
300 jack_latency = (float)(jack_port_get_total_latency(client, ports[0]) + | |
301 jack_get_buffer_size(client)) / (float)rate; | |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
302 callback_interval = 0; |
25644 | 303 buffer = malloc(BUFFSIZE); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
304 |
15605 | 305 ao_data.channels = channels; |
15630 | 306 ao_data.samplerate = rate; |
15605 | 307 ao_data.format = AF_FORMAT_FLOAT_NE; |
308 ao_data.bps = channels * rate * sizeof(float); | |
15630 | 309 ao_data.buffersize = CHUNK_SIZE * NUM_CHUNKS; |
15605 | 310 ao_data.outburst = CHUNK_SIZE; |
311 free(matching_ports); | |
312 free(port_name); | |
16253 | 313 free(client_name); |
15605 | 314 return 1; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
315 |
15605 | 316 err_out: |
317 free(matching_ports); | |
318 free(port_name); | |
16253 | 319 free(client_name); |
15605 | 320 if (client) |
321 jack_client_close(client); | |
322 free(buffer); | |
323 buffer = NULL; | |
324 return 0; | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
325 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
326 |
15605 | 327 // close audio device |
328 static void uninit(int immed) { | |
329 if (!immed) | |
330 usec_sleep(get_delay() * 1000 * 1000); | |
331 // HACK, make sure jack doesn't loop-output dirty buffers | |
15868 | 332 reset(); |
15605 | 333 usec_sleep(100 * 1000); |
334 jack_client_close(client); | |
335 free(buffer); | |
336 buffer = NULL; | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
337 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
338 |
15605 | 339 /** |
340 * \brief stop playing and empty buffers (for seeking/pause) | |
341 */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
342 static void reset(void) { |
15605 | 343 paused = 1; |
344 read_pos = 0; | |
345 write_pos = 0; | |
346 paused = 0; | |
347 } | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
348 |
15605 | 349 /** |
350 * \brief stop playing, keep buffers (for pause) | |
351 */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
352 static void audio_pause(void) { |
15605 | 353 paused = 1; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
354 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
355 |
15605 | 356 /** |
357 * \brief resume playing, after audio_pause() | |
358 */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
359 static void audio_resume(void) { |
15605 | 360 paused = 0; |
361 } | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
362 |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
363 static int get_space(void) { |
15605 | 364 return buf_free(); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
365 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
366 |
15605 | 367 /** |
368 * \brief write data into buffer and reset underrun flag | |
369 */ | |
370 static int play(void *data, int len, int flags) { | |
18808
cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
reimar
parents:
18807
diff
changeset
|
371 if (!(flags & AOPLAY_FINAL_CHUNK)) |
25645 | 372 len -= len % ao_data.outburst; |
15605 | 373 underrun = 0; |
374 return write_buffer(data, len); | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
375 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
376 |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
377 static float get_delay(void) { |
15605 | 378 int buffered = BUFFSIZE - CHUNK_SIZE - buf_free(); // could be less |
15630 | 379 float in_jack = jack_latency; |
16104
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
380 if (estimate && callback_interval > 0) { |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
381 float elapsed = (float)GetTimer() / 1000000.0 - callback_time; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
382 in_jack += callback_interval - elapsed; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
383 if (in_jack < 0) in_jack = 0; |
fc2459a18bf3
improved audio delay estimation, supposed to help make the video smoother
reimar
parents:
15868
diff
changeset
|
384 } |
15605 | 385 return (float)buffered / (float)ao_data.bps + in_jack; |
386 } | |
387 |