Commit 09f25533 authored by Luca Barbato's avatar Luca Barbato
Browse files

v4l2: Preserve errno values

av_log usually resets it.
parent a1a25988
...@@ -138,8 +138,8 @@ static int device_open(AVFormatContext *ctx) ...@@ -138,8 +138,8 @@ static int device_open(AVFormatContext *ctx)
res = ioctl(fd, VIDIOC_QUERYCAP, &cap); res = ioctl(fd, VIDIOC_QUERYCAP, &cap);
if (res < 0) { if (res < 0) {
err = errno; err = AVERROR(errno);
av_strerror(AVERROR(err), errbuf, sizeof(errbuf)); av_strerror(err, errbuf, sizeof(errbuf));
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
errbuf); errbuf);
...@@ -151,7 +151,7 @@ static int device_open(AVFormatContext *ctx) ...@@ -151,7 +151,7 @@ static int device_open(AVFormatContext *ctx)
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n"); av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n");
err = ENODEV; err = AVERROR(ENODEV);
goto fail; goto fail;
} }
...@@ -159,7 +159,7 @@ static int device_open(AVFormatContext *ctx) ...@@ -159,7 +159,7 @@ static int device_open(AVFormatContext *ctx)
if (!(cap.capabilities & V4L2_CAP_STREAMING)) { if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"The device does not support the streaming I/O method.\n"); "The device does not support the streaming I/O method.\n");
err = ENOSYS; err = AVERROR(ENOSYS);
goto fail; goto fail;
} }
...@@ -168,7 +168,7 @@ static int device_open(AVFormatContext *ctx) ...@@ -168,7 +168,7 @@ static int device_open(AVFormatContext *ctx)
fail: fail:
close(fd); close(fd);
return AVERROR(err); return err;
} }
static int device_init(AVFormatContext *ctx, int *width, int *height, static int device_init(AVFormatContext *ctx, int *width, int *height,
...@@ -348,13 +348,14 @@ static int mmap_init(AVFormatContext *ctx) ...@@ -348,13 +348,14 @@ static int mmap_init(AVFormatContext *ctx)
res = ioctl(s->fd, VIDIOC_REQBUFS, &req); res = ioctl(s->fd, VIDIOC_REQBUFS, &req);
if (res < 0) { if (res < 0) {
res = errno;
if (errno == EINVAL) { if (errno == EINVAL) {
av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n"); av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
} else { } else {
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n"); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
} }
return AVERROR(errno); return AVERROR(res);
} }
if (req.count < 2) { if (req.count < 2) {
...@@ -386,9 +387,10 @@ static int mmap_init(AVFormatContext *ctx) ...@@ -386,9 +387,10 @@ static int mmap_init(AVFormatContext *ctx)
res = ioctl(s->fd, VIDIOC_QUERYBUF, &buf); res = ioctl(s->fd, VIDIOC_QUERYBUF, &buf);
if (res < 0) { if (res < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n"); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
return AVERROR(errno); return res;
} }
s->buf_len[i] = buf.length; s->buf_len[i] = buf.length;
...@@ -405,10 +407,11 @@ static int mmap_init(AVFormatContext *ctx) ...@@ -405,10 +407,11 @@ static int mmap_init(AVFormatContext *ctx)
if (s->buf_start[i] == MAP_FAILED) { if (s->buf_start[i] == MAP_FAILED) {
char errbuf[128]; char errbuf[128];
av_strerror(AVERROR(errno), errbuf, sizeof(errbuf)); res = AVERROR(errno);
av_strerror(res, errbuf, sizeof(errbuf));
av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", errbuf); av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", errbuf);
return AVERROR(errno); return res;
} }
} }
...@@ -471,11 +474,12 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) ...@@ -471,11 +474,12 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
} }
av_strerror(AVERROR(errno), errbuf, sizeof(errbuf)); res = AVERROR(errno);
av_strerror(res, errbuf, sizeof(errbuf));
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
errbuf); errbuf);
return AVERROR(errno); return res;
} }
if (buf.index >= s->buffers) { if (buf.index >= s->buffers) {
...@@ -506,9 +510,10 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) ...@@ -506,9 +510,10 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
res = ioctl(s->fd, VIDIOC_QBUF, &buf); res = ioctl(s->fd, VIDIOC_QBUF, &buf);
if (res < 0) { if (res < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n"); av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
av_free_packet(pkt); av_free_packet(pkt);
return AVERROR(errno); return res;
} }
avpriv_atomic_int_add_and_fetch(&s->buffers_queued, 1); avpriv_atomic_int_add_and_fetch(&s->buffers_queued, 1);
} else { } else {
...@@ -693,10 +698,11 @@ static int v4l2_set_parameters(AVFormatContext *s1) ...@@ -693,10 +698,11 @@ static int v4l2_set_parameters(AVFormatContext *s1)
} else { } else {
if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) { if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {
char errbuf[128]; char errbuf[128];
av_strerror(AVERROR(errno), errbuf, sizeof(errbuf)); ret = AVERROR(errno);
av_strerror(ret, errbuf, sizeof(errbuf));
av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n", av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n",
errbuf); errbuf);
return AVERROR(errno); return ret;
} }
} }
s1->streams[0]->avg_frame_rate.num = tpf->denominator; s1->streams[0]->avg_frame_rate.num = tpf->denominator;
...@@ -797,10 +803,11 @@ static int v4l2_read_header(AVFormatContext *s1) ...@@ -797,10 +803,11 @@ static int v4l2_read_header(AVFormatContext *s1)
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
char errbuf[128]; char errbuf[128];
av_strerror(AVERROR(errno), errbuf, sizeof(errbuf)); res = AVERROR(errno);
av_strerror(res, errbuf, sizeof(errbuf));
av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n",
errbuf); errbuf);
return AVERROR(errno); return res;
} }
s->width = fmt.fmt.pix.width; s->width = fmt.fmt.pix.width;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment