v4l2: Fix white-space issue and compile warning
authorBenoit Parrot <bparrot@ti.com>
Mon, 24 Jul 2017 19:23:02 +0000 (19:23 +0000)
committerNikhil Devshatwar <nikhil.nd@ti.com>
Wed, 26 Jul 2017 08:11:34 +0000 (13:41 +0530)
Signed-off-by: Benoit Parrot <bparrot@ti.com>
util/v4l2.c

index 5e5e5bf7db03133c4b87aeb62748d77300b90bb4..7d16eafa41e499f40d8010b041dc568c50285948 100644 (file)
@@ -36,8 +36,7 @@ struct v4l2 {
        struct buffer **bufs;
 };
 
-void
-v4l2_usage(void)
+void v4l2_usage(void)
 {
        MSG("V4L2 Capture Options:");
        MSG("\t-c WxH@fourcc\tset capture dimensions/format");
@@ -112,9 +111,8 @@ MSG("\tfound entity: %s type=%08x, flags=%08x, group_id=%d, pads=%d, links=%d",
 entity->name, entity->type, entity->flags, entity->group_id,
 entity->pads, entity->links);
 
-               if ((entity->type == type) || (entity->id == entity_id)) {
+               if ((entity->type == type) || (entity->id == entity_id))
                        return 0;
-               }
        }
 
        return ret;
@@ -139,16 +137,16 @@ media_configure(struct media_entity_desc *entity,
 
        fd = media_open_entity(entity);
        if (fd < 0) {
-               ERROR("could not open media device: \"%s\" (%d:%d)", entity->name,
-                               entity->v4l.major, entity->v4l.minor);
+               ERROR("could not open media device: \"%s\" (%d:%d)",
+                       entity->name,
+                       entity->v4l.major, entity->v4l.minor);
                return;
        }
 
        MSG("Setting format for: \"%s\" (%d)", entity->name, pad);
        ret = ioctl(fd, VIDIOC_SUBDEV_S_FMT, &ent_format);
-       if (ret) {
+       if (ret)
                MSG("Could not configure: %s (%d)", strerror(errno), ret);
-       }
 }
 
 /* walk the graph and attempt to configure all the nodes to the same settings.
@@ -164,14 +162,14 @@ media_setup(struct v4l2_format *format)
 
        fd = open("/dev/media0", O_RDWR);
        if (fd < 0) {
-               ERROR("could not open MCF: %s (%d)", strerror(errno), ret);
+               ERROR("could not open MCF: %s (%d)", strerror(errno), errno);
                return fd;
        }
 
-       ret = media_find_entity(fd, &entity, MEDIA_ENT_T_V4L2_SUBDEV_SENSOR, ~0);
-       if (ret) {
+       ret = media_find_entity(fd, &entity,
+                               MEDIA_ENT_T_V4L2_SUBDEV_SENSOR, ~0);
+       if (ret)
                return ret;
-       }
 
        /* now walk the graph to the output, configure everything on the way: */
        do {
@@ -191,27 +189,30 @@ media_setup(struct v4l2_format *format)
 
                for (i = 0; i < entity.links; i++) {
                        if (links[i].source.entity == entity.id) {
-                               // XXX maybe if there are multiple links, we should prefer
-                               // an enabled link, otherwise just pick one..
-
-                               media_configure(&entity, format, links[i].source.index);
-                               media_configure(&entity, format, links[i].sink.index);
+                               /*
+                                * XXX maybe if there are multiple links, we
+                                * should prefer an enabled link, otherwise
+                                * just pick one..
+                                */
+                               media_configure(&entity, format,
+                                               links[i].source.index);
+                               media_configure(&entity, format,
+                                               links[i].sink.index);
 
                                /* lets take this link.. */
                                if (!(links[i].flags & MEDIA_LNK_FL_ENABLED)) {
                                        links[i].flags |= MEDIA_LNK_FL_ENABLED;
-                                       ret = ioctl(fd, MEDIA_IOC_SETUP_LINK, &links[i]);
-                                       if (ret) {
+                                       ret = ioctl(fd, MEDIA_IOC_SETUP_LINK,
+                                                   &links[i]);
+                                       if (ret)
                                                ERROR("MEDIA_IOC_SETUP_LINK failed: %s (%d)",
-                                                               strerror(errno), errno);
-//                                             return ret;
-                                       }
+                                                       strerror(errno), errno);
                                }
 
-                               ret = media_find_entity(fd, &entity, ~0, links[i].sink.entity);
-                               if (ret) {
+                               ret = media_find_entity(fd, &entity, ~0,
+                                                       links[i].sink.entity);
+                               if (ret)
                                        return ret;
-                               }
 
                                break;
                        }
@@ -233,6 +234,7 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
        int i, ret;
        bool mcf = false, user_format = false, user_dev = false;
        char devname[20] = "/dev/video1";
+       char fourccstr[5];
 
        v4l2 = calloc(1, sizeof(*v4l2));
 
@@ -240,11 +242,10 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
         * that it is already parsed (since the arg parsing is decentralized)
         */
        for (i = 1; i < argc; i++) {
-               if (!argv[i]) {
+               if (!argv[i])
                        continue;
-               }
                if (!strcmp("-d", argv[i])) {
-                       if(user_dev)
+                       if (user_dev)
                                continue;
 
                        argv[i++] = NULL;
@@ -254,10 +255,9 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
                        }
                        user_dev = true;
                } else if (!strcmp("-c", argv[i])) {
-                       if(user_format)
+                       if (user_format)
                                continue;
 
-                       char fourccstr[5];
                        argv[i++] = NULL;
                        if (sscanf(argv[i], "%ux%u@%4s",
                                        width,
@@ -288,7 +288,7 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
                format.fmt.pix.pixelformat = *fourcc;
                format.fmt.pix.width = *width;
                format.fmt.pix.height = *height;
-               if(*fourcc == FOURCC_STR("AR24"))
+               if (*fourcc == FOURCC_STR("AR24"))
                        format.fmt.pix.pixelformat = FOURCC_STR("RGB4");
 
        }
@@ -304,9 +304,8 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
 
        if (mcf) {
                ret = media_setup(&format);
-               if (ret < 0) {
+               if (ret < 0)
                        goto fail;
-               }
        }
 
        ret = ioctl(v4l2->fd, VIDIOC_S_FMT, &format);
@@ -318,7 +317,6 @@ v4l2_open(int argc, char **argv, uint32_t *fourcc,
        return v4l2;
 
 fail:
-       // XXX cleanup
        return NULL;
 }
 
@@ -331,10 +329,10 @@ v4l2_reqbufs(struct v4l2 *v4l2, struct buffer **bufs, uint32_t n)
                        .count = n,
        };
        uint32_t i;
-       int ret,dmafd;
+       int ret, dmafd;
 
        if (v4l2->v4l2bufs) {
-               // maybe eventually need to support this?
+               /* maybe eventually need to support this? */
                ERROR("already reqbuf'd");
                return -1;
        }
@@ -379,7 +377,8 @@ v4l2_reqbufs(struct v4l2 *v4l2, struct buffer **bufs, uint32_t n)
                ret = ioctl(v4l2->fd, VIDIOC_QUERYBUF, &v4l2->v4l2bufs[i]);
                v4l2->v4l2bufs[i].m.fd = dmafd;
                if (ret) {
-                       ERROR("VIDIOC_QUERYBUF failed: %s (%d)", strerror(errno), ret);
+                       ERROR("VIDIOC_QUERYBUF failed: %s (%d)",
+                             strerror(errno), ret);
                        return ret;
                }
        }
@@ -393,13 +392,12 @@ v4l2_streamon(struct v4l2 *v4l2)
        enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        int ret;
 
-    ret = ioctl(v4l2->fd, VIDIOC_STREAMON, &type);
+       ret = ioctl(v4l2->fd, VIDIOC_STREAMON, &type);
 
-    if (ret) {
+       if (ret)
                ERROR("VIDIOC_STREAMON failed: %s (%d)", strerror(errno), ret);
-    }
 
-    return ret;
+       return ret;
 }
 
 int
@@ -408,13 +406,12 @@ v4l2_streamoff(struct v4l2 *v4l2)
        enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        int ret;
 
-    ret = ioctl(v4l2->fd, VIDIOC_STREAMOFF, &type);
+           ret = ioctl(v4l2->fd, VIDIOC_STREAMOFF, &type);
 
-    if (ret) {
+           if (ret)
                ERROR("VIDIOC_STREAMOFF failed: %s (%d)", strerror(errno), ret);
-    }
 
-    return ret;
+           return ret;
 }
 
 int
@@ -433,9 +430,8 @@ v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf)
        fd = buf->fd[0];
 
        for (i = 0; i < v4l2->nbufs; i++) {
-               if (v4l2->v4l2bufs[i].m.fd == fd) {
+               if (v4l2->v4l2bufs[i].m.fd == fd)
                        v4l2buf = &v4l2->v4l2bufs[i];
-               }
        }
 
        tid = pthread_self();
@@ -444,7 +440,7 @@ v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf)
        disp_time.tv_usec = now.tv_nsec / 1000;
        timersub(&disp_time, &v4l2buf->timestamp, &disp_lat);
        if(v4l2buf->timestamp.tv_sec)
-               DBG("%x: DISP latency = %d.%6d", tid, disp_lat.tv_sec, disp_lat.tv_usec);
+               DBG("%lx: DISP latency = %ld.%6ld", tid, disp_lat.tv_sec, disp_lat.tv_usec);
 
        if (!v4l2buf) {
                ERROR("invalid buffer");
@@ -453,9 +449,8 @@ v4l2_qbuf(struct v4l2 *v4l2, struct buffer *buf)
 
        ret = ioctl(v4l2->fd, VIDIOC_QBUF, v4l2buf);
        v4l2buf->m.fd = buf->fd[0];
-       if (ret) {
+       if (ret)
                ERROR("VIDIOC_QBUF failed: %s (%d)", strerror(errno), ret);
-       }
 
        return ret;
 }
@@ -476,9 +471,8 @@ v4l2_dqbuf(struct v4l2 *v4l2)
        int ret;
 
        ret = ioctl(v4l2->fd, VIDIOC_DQBUF, &v4l2buf);
-       if (ret) {
+       if (ret)
                ERROR("VIDIOC_DQBUF failed: %s (%d)", strerror(errno), ret);
-       }
 
        buf = v4l2->bufs[v4l2buf.index];
        v4l2->v4l2bufs[v4l2buf.index].timestamp = v4l2buf.timestamp;
@@ -490,7 +484,7 @@ v4l2_dqbuf(struct v4l2 *v4l2)
        dq_time.tv_sec = now.tv_sec;
        dq_time.tv_usec = now.tv_nsec / 1000;
        timersub(&dq_time, &v4l2buf.timestamp, &dq_lat);
-       DBG("%x: DQ latency = %d.%6d", tid, dq_lat.tv_sec, dq_lat.tv_usec);
+       DBG("%lx: DQ latency = %ld.%6ld", tid, dq_lat.tv_sec, dq_lat.tv_usec);
 
        return buf;
 }