[FFmpeg-cvslog] v4l2: avoid pointless indirection.

Anton Khirnov git at videolan.org
Mon Jan 14 14:05:25 CET 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Jan  7 18:35:48 2013 +0100| [246da0b13551b1f80f067e4f258e5bd691f5ab33] | committer: Anton Khirnov

v4l2: avoid pointless indirection.

v4l2_read_header() does no cleanup, so it can return directly, without
any need for goto.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=246da0b13551b1f80f067e4f258e5bd691f5ab33
---

 libavdevice/v4l2.c |   35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 9e71f1d..fd2ab38 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -687,21 +687,16 @@ static int v4l2_read_header(AVFormatContext *s1)
     enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
 
     st = avformat_new_stream(s1, NULL);
-    if (!st) {
-        res = AVERROR(ENOMEM);
-        goto out;
-    }
+    if (!st)
+        return AVERROR(ENOMEM);
 
     s->fd = device_open(s1);
-    if (s->fd < 0) {
-        res = s->fd;
-        goto out;
-    }
+    if (s->fd < 0)
+        return s->fd;
 
     if (s->list_format) {
         list_formats(s1, s->fd, s->list_format);
-        res = AVERROR_EXIT;
-        goto out;
+        return AVERROR_EXIT;
     }
 
     avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
@@ -710,7 +705,7 @@ static int v4l2_read_header(AVFormatContext *s1)
         (res = av_parse_video_size(&s->width, &s->height, s->video_size)) < 0) {
         av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n",
                s->video_size);
-        goto out;
+        return res;
     }
 
     if (s->pixel_format) {
@@ -725,8 +720,7 @@ static int v4l2_read_header(AVFormatContext *s1)
             av_log(s1, AV_LOG_ERROR, "No such input format: %s.\n",
                    s->pixel_format);
 
-            res = AVERROR(EINVAL);
-            goto out;
+            return AVERROR(EINVAL);
         }
     }
 
@@ -739,8 +733,7 @@ static int v4l2_read_header(AVFormatContext *s1)
         if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) {
             av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n",
                    strerror(errno));
-            res = AVERROR(errno);
-            goto out;
+            return AVERROR(errno);
         }
 
         s->width  = fmt.fmt.pix.width;
@@ -756,17 +749,16 @@ static int v4l2_read_header(AVFormatContext *s1)
                "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, pix_fmt);
         close(s->fd);
 
-        res = AVERROR(EIO);
-        goto out;
+        return AVERROR(EIO);
     }
 
     if ((res = av_image_check_size(s->width, s->height, 0, s1) < 0))
-        goto out;
+        return res;
 
     s->frame_format = desired_format;
 
     if ((res = v4l2_set_parameters(s1) < 0))
-        goto out;
+        return res;
 
     st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id);
     s->frame_size =
@@ -775,7 +767,7 @@ static int v4l2_read_header(AVFormatContext *s1)
     if ((res = mmap_init(s1)) ||
         (res = mmap_start(s1)) < 0) {
         close(s->fd);
-        goto out;
+        return res;
     }
 
     s->top_field_first = first_field(s->fd);
@@ -789,8 +781,7 @@ static int v4l2_read_header(AVFormatContext *s1)
     st->codec->height = s->height;
     st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;
 
-out:
-    return res;
+    return 0;
 }
 
 static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt)



More information about the ffmpeg-cvslog mailing list