comparison audio.c @ 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 90fd30dd68b3
children a58a8a53eb46
comparison
equal deleted inserted replaced
55:bde449e6b743 56:01d48dc59dab
242 struct audio_buf_info abufi; 242 struct audio_buf_info abufi;
243 243
244 if (av_new_packet(pkt, s->frame_size) < 0) 244 if (av_new_packet(pkt, s->frame_size) < 0)
245 return -EIO; 245 return -EIO;
246 for(;;) { 246 for(;;) {
247 struct timeval tv;
248 fd_set fds;
249
250 tv.tv_sec = 0;
251 tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */
252
253 FD_ZERO(&fds);
254 FD_SET(s->fd, &fds);
255
256 /* This will block until data is available or we get a timeout */
257 (void) select(s->fd + 1, &fds, 0, 0, &tv);
258
247 ret = read(s->fd, pkt->data, pkt->size); 259 ret = read(s->fd, pkt->data, pkt->size);
248 if (ret > 0) 260 if (ret > 0)
249 break; 261 break;
250 if (ret == -1 && (errno == EAGAIN || errno == EINTR)) { 262 if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
251 av_free_packet(pkt); 263 av_free_packet(pkt);