comparison src/alsa-ng/alsa-core.c @ 3165:087abc78516e

alsa-ng: implement pause stuff. not perfect yet.
author William Pitcock <nenolod@atheme.org>
date Thu, 14 May 2009 23:14:50 -0500
parents adec82db531c
children 8cbf077ba5d0
comparison
equal deleted inserted replaced
3164:adec82db531c 3165:087abc78516e
27 static gint bps; 27 static gint bps;
28 28
29 static gsize wr_total = 0; 29 static gsize wr_total = 0;
30 static gsize wr_hwframes = 0; 30 static gsize wr_hwframes = 0;
31 31
32 static gint flush_request; 32 static gint flush_request, pause_request, paused;
33 static gboolean can_pause;
33 34
34 /******************************************************************************** 35 /********************************************************************************
35 * ALSA Mixer setting functions. * 36 * ALSA Mixer setting functions. *
36 ********************************************************************************/ 37 ********************************************************************************/
37 38
77 { 78 {
78 snd_pcm_drop(pcm_handle); 79 snd_pcm_drop(pcm_handle);
79 snd_pcm_prepare(pcm_handle); 80 snd_pcm_prepare(pcm_handle);
80 wr_total = flush_request * (bps / 1000); 81 wr_total = flush_request * (bps / 1000);
81 flush_request = -1; 82 flush_request = -1;
83 }
84
85 if (pause_request != paused)
86 {
87 snd_pcm_pause(pcm_handle, pause_request);
88 paused = pause_request;
89 continue;
82 } 90 }
83 91
84 if (alsaplug_ringbuffer_read(&pcm_ringbuf, buf, 2048) == -1) 92 if (alsaplug_ringbuffer_read(&pcm_ringbuf, buf, 2048) == -1)
85 { 93 {
86 /* less than 2048 bytes to go...? */ 94 /* less than 2048 bytes to go...? */
147 { 155 {
148 _ERROR("snd_pcm_hw_params failed: %s", snd_strerror(err)); 156 _ERROR("snd_pcm_hw_params failed: %s", snd_strerror(err));
149 return -1; 157 return -1;
150 } 158 }
151 159
160 can_pause = snd_pcm_hw_params_can_pause(hwparams);
152 bitwidth = snd_pcm_format_physical_width(afmt); 161 bitwidth = snd_pcm_format_physical_width(afmt);
153 bps = (rate * bitwidth * nch) >> 3; 162 bps = (rate * bitwidth * nch) >> 3;
154 ringbuf_size = aud_cfg->output_buffer_size * bps / 1000; 163 ringbuf_size = aud_cfg->output_buffer_size * bps / 1000;
155 alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size); 164 alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size);
156 pcm_going = TRUE; 165 pcm_going = TRUE;
229 238
230 static gint 239 static gint
231 alsaplug_buffer_playing(void) 240 alsaplug_buffer_playing(void)
232 { 241 {
233 return alsaplug_ringbuffer_used(&pcm_ringbuf) != 0; 242 return alsaplug_ringbuffer_used(&pcm_ringbuf) != 0;
243 }
244
245 static void
246 alsaplug_pause(short p)
247 {
248 pause_request = p;
234 } 249 }
235 250
236 /******************************************************************************** 251 /********************************************************************************
237 * Plugin glue. * 252 * Plugin glue. *
238 ********************************************************************************/ 253 ********************************************************************************/
247 .output_time = alsaplug_output_time, 262 .output_time = alsaplug_output_time,
248 .written_time = alsaplug_written_time, 263 .written_time = alsaplug_written_time,
249 .buffer_free = alsaplug_buffer_free, 264 .buffer_free = alsaplug_buffer_free,
250 .buffer_playing = alsaplug_buffer_playing, 265 .buffer_playing = alsaplug_buffer_playing,
251 .flush = alsaplug_flush, 266 .flush = alsaplug_flush,
267 .pause = alsaplug_pause,
252 }; 268 };
253 269
254 OutputPlugin *alsa_oplist[] = { &alsa_op, NULL }; 270 OutputPlugin *alsa_oplist[] = { &alsa_op, NULL };
255 SIMPLE_OUTPUT_PLUGIN(alsa, alsa_oplist); 271 SIMPLE_OUTPUT_PLUGIN(alsa, alsa_oplist);