diff options
author | Luca Abeni <lucabe72@email.it> | 2007-07-06 07:18:25 +0000 |
---|---|---|
committer | Luca Abeni <lucabe72@email.it> | 2007-07-06 07:18:25 +0000 |
commit | 653387d8f03ccd0df5374de00c1969eca211c9cf (patch) | |
tree | 4d7a94403d2c96315aff322102d9ecdd18e62085 /libavformat/v4l2.c | |
parent | bf09c2e2a6e668b34ef777a38381b330d89448d1 (diff) | |
download | ffmpeg-653387d8f03ccd0df5374de00c1969eca211c9cf.tar.gz |
Support for the AVFMT_FLAG_NONBLOCK flag (non-blocking input) in v4l2.c
Originally committed as revision 9496 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/v4l2.c')
-rw-r--r-- | libavformat/v4l2.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libavformat/v4l2.c b/libavformat/v4l2.c index b3d7e01cf5..956d7c7509 100644 --- a/libavformat/v4l2.c +++ b/libavformat/v4l2.c @@ -119,8 +119,12 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities) 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 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) 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; |