Mercurial > mplayer.hg
comparison libao2/ao_jack.c @ 18808:cb83184bdc70
respect AOPLAY_FINAL_CHUNK and do not discard samples read from buffer
on underrun.
author | reimar |
---|---|
date | Sun, 25 Jun 2006 09:02:47 +0000 |
parents | 30959018e908 |
children | 5c8acc972551 |
comparison
equal
deleted
inserted
replaced
18807:30959018e908 | 18808:cb83184bdc70 |
---|---|
128 * \return number of samples read per channel, equals cnt unless there was too | 128 * \return number of samples read per channel, equals cnt unless there was too |
129 * little data in the buffer | 129 * little data in the buffer |
130 * | 130 * |
131 * Assumes the data in the buffer is of type float, the number of bytes | 131 * Assumes the data in the buffer is of type float, the number of bytes |
132 * read is res * num_bufs * sizeof(float), where res is the return value. | 132 * read is res * num_bufs * sizeof(float), where res is the return value. |
133 * If there is not enough data in the buffer remaining parts will be filled | |
134 * with silence. | |
133 */ | 135 */ |
134 static int read_buffer(float **bufs, int cnt, int num_bufs) { | 136 static int read_buffer(float **bufs, int cnt, int num_bufs) { |
135 int buffered = buf_used(); | 137 int buffered = buf_used(); |
136 int i, j; | 138 int i, j; |
139 int orig_cnt = cnt; | |
137 if (cnt * sizeof(float) * num_bufs > buffered) | 140 if (cnt * sizeof(float) * num_bufs > buffered) |
138 cnt = buffered / sizeof(float) / num_bufs; | 141 cnt = buffered / sizeof(float) / num_bufs; |
139 for (i = 0; i < cnt; i++) { | 142 for (i = 0; i < cnt; i++) { |
140 for (j = 0; j < num_bufs; j++) { | 143 for (j = 0; j < num_bufs; j++) { |
141 bufs[j][i] = *((float *)(&buffer[read_pos])); | 144 bufs[j][i] = *((float *)(&buffer[read_pos])); |
142 read_pos = (read_pos + sizeof(float)) % BUFFSIZE; | 145 read_pos = (read_pos + sizeof(float)) % BUFFSIZE; |
143 } | 146 } |
144 } | 147 } |
148 for (i = cnt; i < orig_cnt; i++) | |
149 for (j = 0; j < num_bufs; j++) | |
150 bufs[j][i] = 0; | |
145 return cnt; | 151 return cnt; |
146 } | 152 } |
147 | 153 |
148 // end ring buffer stuff | 154 // end ring buffer stuff |
149 | 155 |
175 static int outputaudio(jack_nframes_t nframes, void *arg) { | 181 static int outputaudio(jack_nframes_t nframes, void *arg) { |
176 float *bufs[MAX_CHANS]; | 182 float *bufs[MAX_CHANS]; |
177 int i; | 183 int i; |
178 for (i = 0; i < num_ports; i++) | 184 for (i = 0; i < num_ports; i++) |
179 bufs[i] = jack_port_get_buffer(ports[i], nframes); | 185 bufs[i] = jack_port_get_buffer(ports[i], nframes); |
180 if (!paused && !underrun) | 186 if (paused || underrun) |
187 silence(bufs, nframes, num_ports); | |
188 else | |
181 if (read_buffer(bufs, nframes, num_ports) < nframes) | 189 if (read_buffer(bufs, nframes, num_ports) < nframes) |
182 underrun = 1; | 190 underrun = 1; |
183 if (paused || underrun) | |
184 silence(bufs, nframes, num_ports); | |
185 if (estimate) { | 191 if (estimate) { |
186 float now = (float)GetTimer() / 1000000.0; | 192 float now = (float)GetTimer() / 1000000.0; |
187 float diff = callback_time + callback_interval - now; | 193 float diff = callback_time + callback_interval - now; |
188 if ((diff > -0.002) && (diff < 0.002)) | 194 if ((diff > -0.002) && (diff < 0.002)) |
189 callback_time += callback_interval; | 195 callback_time += callback_interval; |
347 | 353 |
348 /** | 354 /** |
349 * \brief write data into buffer and reset underrun flag | 355 * \brief write data into buffer and reset underrun flag |
350 */ | 356 */ |
351 static int play(void *data, int len, int flags) { | 357 static int play(void *data, int len, int flags) { |
358 if (!(flags & AOPLAY_FINAL_CHUNK)) | |
352 len -= len % ao_data.outburst; | 359 len -= len % ao_data.outburst; |
353 underrun = 0; | 360 underrun = 0; |
354 return write_buffer(data, len); | 361 return write_buffer(data, len); |
355 } | 362 } |
356 | 363 |