annotate libao2/ao_jack.c @ 25661:293aeec83153

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