[FFmpeg-devel] [PATCH 2/6] Implement IOCTL_ERROR macro and use it.

Stefano Sabatini stefano.sabatini-lala
Sat Apr 24 20:53:21 CEST 2010


Provide consistency and slightly improve readability.
---
 libavdevice/v4l2.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index ce339a6..c5b1768 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -149,6 +149,8 @@ static struct fmt_map fmt_conversion_table[] = {
     },
 };
 
+#define IOCTL_ERROR(ctx__, ioctl__) av_log(ctx__, AV_LOG_ERROR, "ioctl(" #ioctl__ "): %s\n", strerror(errno))
+
 static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
 {
     struct v4l2_capability cap;
@@ -177,8 +179,7 @@ static int device_open(AVFormatContext *ctx, uint32_t *capabilities)
         return AVERROR(errno);
     }
     if (res < 0) {
-        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
-                 strerror(errno));
+        IOCTL_ERROR(ctx, VIDIOC_QUERYCAP);
         close(fd);
 
         return AVERROR(errno);
@@ -296,7 +297,7 @@ static int mmap_init(AVFormatContext *ctx)
         if (errno == EINVAL) {
             av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
         } else {
-            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
+            IOCTL_ERROR(ctx, VIDIOC_REQBUFS);
         }
 
         return AVERROR(errno);
@@ -331,7 +332,7 @@ static int mmap_init(AVFormatContext *ctx)
         buf.index = i;
         res = ioctl (s->fd, VIDIOC_QUERYBUF, &buf);
         if (res < 0) {
-            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
+            IOCTL_ERROR(ctx, VIDIOC_QUERYBUF);
 
             return AVERROR(errno);
         }
@@ -378,7 +379,7 @@ static void mmap_release_buffer(AVPacket *pkt)
 
     res = ioctl (fd, VIDIOC_QBUF, &buf);
     if (res < 0) {
-        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
+        IOCTL_ERROR(NULL, VIDIOC_QBUF);
     }
     pkt->data = NULL;
     pkt->size = 0;
@@ -403,7 +404,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
 
             return AVERROR(EAGAIN);
         }
-        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));
+        IOCTL_ERROR(ctx, VIDIOC_DQBUF);
 
         return AVERROR(errno);
     }
@@ -457,7 +458,7 @@ static int mmap_start(AVFormatContext *ctx)
 
         res = ioctl (s->fd, VIDIOC_QBUF, &buf);
         if (res < 0) {
-            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno));
+            IOCTL_ERROR(ctx, VIDIOC_QBUF);
 
             return AVERROR(errno);
         }
@@ -466,7 +467,7 @@ static int mmap_start(AVFormatContext *ctx)
     type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     res = ioctl (s->fd, VIDIOC_STREAMON, &type);
     if (res < 0) {
-        av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno));
+        IOCTL_ERROR(ctx, VIDIOC_STREAMON);
 
         return AVERROR(errno);
     }
-- 
1.7.0




More information about the ffmpeg-devel mailing list