Skip to content

Commit 0bd2182

Browse files
committed
aplay: Account for delay of frames in fifo and read buffer.
1 parent 741badc commit 0bd2182

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

utils/aplay/aplay.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <string.h>
2828
#include <syslog.h>
2929
#include <sys/eventfd.h>
30+
#include <sys/ioctl.h>
3031
#include <sys/param.h>
3132
#include <sys/time.h>
3233
#include <unistd.h>
@@ -820,10 +821,15 @@ static void *io_worker_routine(struct io_worker *w) {
820821
ffb_shift(&buffer, frames * w->ba_pcm.channels);
821822

822823
int ret;
823-
if ((ret = snd_pcm_delay(w->snd_pcm,
824-
&pcm_delay_frames[pcm_delay_frames_i++ % ARRAYSIZE(pcm_delay_frames)])) != 0)
824+
snd_pcm_sframes_t delay_frames = 0;
825+
if ((ret = snd_pcm_delay(w->snd_pcm, &delay_frames)) != 0)
825826
warn("Couldn't get PCM delay: %s", snd_strerror(ret));
826827
else {
828+
unsigned int buffered = 0;
829+
ioctl(w->ba_pcm_fd, FIONREAD, &buffered);
830+
buffered += ffb_blen_out(&buffer);
831+
delay_frames += buffered / (w->ba_pcm.channels * pcm_format_size);
832+
pcm_delay_frames[pcm_delay_frames_i++ % ARRAYSIZE(pcm_delay_frames)] = delay_frames;
827833

828834
struct timespec ts_now;
829835
/* Rate limit delay updates to 1 update per second. */

0 commit comments

Comments
 (0)