[FFmpeg-devel] [PATCH] v4l2: replace memset() with explicit struct initialization

Stefano Sabatini stefano.sabatini-lala at poste.it
Sat May 28 21:21:13 CEST 2011


---
 libavdevice/v4l2.c |   24 ++++++++----------------
 1 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 29ca01e..aea7e53 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -151,10 +151,9 @@ static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t p
 {
     struct video_data *s = ctx->priv_data;
     int fd = s->fd;
-    struct v4l2_format fmt;
+    struct v4l2_format fmt = {0};
     int res;
 
-    memset(&fmt, 0, sizeof(struct v4l2_format));
     fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     fmt.fmt.pix.width = *width;
     fmt.fmt.pix.height = *height;
@@ -237,10 +236,9 @@ static enum CodecID fmt_v4l2codec(uint32_t v4l2_fmt)
 static int mmap_init(AVFormatContext *ctx)
 {
     struct video_data *s = ctx->priv_data;
-    struct v4l2_requestbuffers req;
+    struct v4l2_requestbuffers req = {0};
     int i, res;
 
-    memset(&req, 0, sizeof(struct v4l2_requestbuffers));
     req.count = desired_video_buffers;
     req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     req.memory = V4L2_MEMORY_MMAP;
@@ -272,9 +270,8 @@ static int mmap_init(AVFormatContext *ctx)
     }
 
     for (i = 0; i < req.count; i++) {
-        struct v4l2_buffer buf;
+        struct v4l2_buffer buf = {0};
 
-        memset(&buf, 0, sizeof(struct v4l2_buffer));
         buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
         buf.memory = V4L2_MEMORY_MMAP;
         buf.index = i;
@@ -308,7 +305,7 @@ static int read_init(AVFormatContext *ctx)
 
 static void mmap_release_buffer(AVPacket *pkt)
 {
-    struct v4l2_buffer buf;
+    struct v4l2_buffer buf = {0};
     int res, fd;
     struct buff_data *buf_descriptor = pkt->priv;
 
@@ -316,7 +313,6 @@ static void mmap_release_buffer(AVPacket *pkt)
          return;
     }
 
-    memset(&buf, 0, sizeof(struct v4l2_buffer));
     buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     buf.memory = V4L2_MEMORY_MMAP;
     buf.index = buf_descriptor->index;
@@ -334,11 +330,10 @@ static void mmap_release_buffer(AVPacket *pkt)
 static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
 {
     struct video_data *s = ctx->priv_data;
-    struct v4l2_buffer buf;
+    struct v4l2_buffer buf = {0};
     struct buff_data *buf_descriptor;
     int res;
 
-    memset(&buf, 0, sizeof(struct v4l2_buffer));
     buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     buf.memory = V4L2_MEMORY_MMAP;
 
@@ -393,9 +388,8 @@ static int mmap_start(AVFormatContext *ctx)
     int i, res;
 
     for (i = 0; i < s->buffers; i++) {
-        struct v4l2_buffer buf;
+        struct v4l2_buffer buf = {0};
 
-        memset(&buf, 0, sizeof(struct v4l2_buffer));
         buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
         buf.memory = V4L2_MEMORY_MMAP;
         buf.index  = i;
@@ -437,8 +431,8 @@ static void mmap_close(struct video_data *s)
 static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
 {
     struct video_data *s = s1->priv_data;
-    struct v4l2_input input;
-    struct v4l2_standard standard;
+    struct v4l2_input input = {0};
+    struct v4l2_standard standard = {0};
     struct v4l2_streamparm streamparm = { 0 };
     struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;
     int i;
@@ -451,7 +445,6 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
 #endif
 
     /* set tv video input */
-    memset (&input, 0, sizeof (input));
     input.index = s->channel;
     if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
         av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
@@ -477,7 +470,6 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
         av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
                s->standard);
         /* set tv standard */
-        memset (&standard, 0, sizeof (standard));
         for(i=0;;i++) {
             standard.index = i;
             if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list