comparison src/alsa-ng/alsa-core.c @ 3184:b009fad90e92

alsa-ng: buffer timing cleanups
author Joris van Rantwijk <joris2822@xs4all.nl>
date Sun, 14 Jun 2009 23:10:04 -0500
parents 19e3ec80dac9
children 2e988f44b85d
comparison
equal deleted inserted replaced
3183:19e3ec80dac9 3184:b009fad90e92
313 } 313 }
314 314
315 bitwidth = snd_pcm_format_physical_width(afmt); 315 bitwidth = snd_pcm_format_physical_width(afmt);
316 bps = (rate * bitwidth * nch) >> 3; 316 bps = (rate * bitwidth * nch) >> 3;
317 ringbuf_size = aud_cfg->output_buffer_size * bps / 1000; 317 ringbuf_size = aud_cfg->output_buffer_size * bps / 1000;
318 alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size); 318 if (alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size) == -1) {
319 _ERROR("alsaplug_ringbuffer_init failed");
320 return -1;
321 }
319 pcm_going = TRUE; 322 pcm_going = TRUE;
320 flush_request = -1; 323 flush_request = -1;
321 324
322 audio_thread = g_thread_create(alsaplug_loop, NULL, TRUE, NULL); 325 audio_thread = g_thread_create(alsaplug_loop, NULL, TRUE, NULL);
323 return 1; 326 return 1;
369 372
370 g_mutex_lock(pcm_state_mutex); 373 g_mutex_lock(pcm_state_mutex);
371 374
372 if (pcm_going && pcm_handle != NULL) 375 if (pcm_going && pcm_handle != NULL)
373 { 376 {
377 guint d = alsaplug_ringbuffer_used(&pcm_ringbuf);
378
374 if (!snd_pcm_delay(pcm_handle, &delay)) 379 if (!snd_pcm_delay(pcm_handle, &delay))
375 { 380 d += snd_pcm_frames_to_bytes(pcm_handle, delay);
376 guint d = snd_pcm_frames_to_bytes(pcm_handle, delay); 381
377 if (bytes < d) 382 if (bytes < d)
378 bytes = 0; 383 bytes = 0;
379 else 384 else
380 bytes -= d; 385 bytes -= d;
381 }
382 386
383 ret = bytes * (long long) 1000 / bps; 387 ret = bytes * (long long) 1000 / bps;
384 } 388 }
385 389
386 g_mutex_unlock(pcm_state_mutex); 390 g_mutex_unlock(pcm_state_mutex);