# HG changeset patch # User lucabe # Date 1183706305 0 # Node ID efb7b615d57c71c850284b4c4d56be16069bb104 # Parent 0d93ef692caafb36bde2a1ca3a76fc6c5cc12353 Support for the AVFMT_FLAG_NONBLOCK flag (non-blocking input) in v4l2.c diff -r 0d93ef692caa -r efb7b615d57c v4l2.c --- a/v4l2.c Fri Jul 06 07:16:47 2007 +0000 +++ b/v4l2.c Fri Jul 06 07:18:25 2007 +0000 @@ -119,8 +119,12 @@ struct v4l2_capability cap; int fd; int res; + int flags = O_RDWR; - fd = open(ctx->filename, O_RDWR /*| O_NONBLOCK*/, 0); + if (ctx->flags & AVFMT_FLAG_NONBLOCK) { + flags |= O_NONBLOCK; + } + fd = open(ctx->filename, flags, 0); if (fd < 0) { av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n", ctx->filename, strerror(errno)); @@ -331,9 +335,13 @@ buf.memory = V4L2_MEMORY_MMAP; /* FIXME: Some special treatment might be needed in case of loss of signal... */ - while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && - ((errno == EAGAIN) || (errno == EINTR))); + while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR)); if (res < 0) { + if (errno == EAGAIN) { + pkt->size = 0; + + return AVERROR(EAGAIN); + } av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno)); return -1;