Browse Source

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
tags/v0.5
Philip Gladstone 23 years ago
parent
commit
79134973d8
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      libavformat/audio.c

+ 12
- 0
libavformat/audio.c View File

@@ -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;


Loading…
Cancel
Save