changeset 56:01d48dc59dab libavformat

Fix the 'hard cpu loop' problem when capturing audio from /dev/dsp. This code now waits for up to 30ms before reporting that no packet is available.
author philipjsg
date Wed, 05 Feb 2003 01:59:52 +0000
parents bde449e6b743
children 821a7facb3e4
files audio.c
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/audio.c	Tue Feb 04 23:44:26 2003 +0000
+++ b/audio.c	Wed Feb 05 01:59:52 2003 +0000
@@ -244,6 +244,18 @@
     if (av_new_packet(pkt, s->frame_size) < 0)
         return -EIO;
     for(;;) {
+        struct timeval tv;
+        fd_set fds;
+
+        tv.tv_sec = 0;
+        tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */
+
+        FD_ZERO(&fds);
+        FD_SET(s->fd, &fds);
+
+        /* This will block until data is available or we get a timeout */
+        (void) select(s->fd + 1, &fds, 0, 0, &tv);
+
         ret = read(s->fd, pkt->data, pkt->size);
         if (ret > 0)
             break;