summaryrefslogtreecommitdiff
path: root/libavformat/audio.c
diff options
context:
space:
mode:
authorPhilip Gladstone <philipjsg@users.sourceforge.net>2003-02-05 01:59:52 +0000
committerPhilip Gladstone <philipjsg@users.sourceforge.net>2003-02-05 01:59:52 +0000
commit79134973d862af5e22cf8909df690e3e1d4b256e (patch)
tree0fad003bad330a19b1135dd20adfe4aa71124047 /libavformat/audio.c
parent85a57296ccf4beffb485762a38fc927f51033574 (diff)
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. Originally committed as revision 1546 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/audio.c')
-rw-r--r--libavformat/audio.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libavformat/audio.c b/libavformat/audio.c
index 05055a1781..737b79cd15 100644
--- a/libavformat/audio.c
+++ b/libavformat/audio.c
@@ -244,6 +244,18 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
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;