On Mon, Jan 09, 2012 at 09:37:06AM +0100, Luca Barbato wrote:
> Remove some unneeded memsets.
> ---
>  libavdevice/v4l2.c |   58 ++++++++++++++++++++++-----------------------------
>  1 files changed, 25 insertions(+), 33 deletions(-)

Previously the structures had all their fields initialized to 0,
now you just initialize a few select fields.  If you are confident
this will not create sideeffects, then patch is OK, some nits below.

> --- a/libavdevice/v4l2.c
> +++ b/libavdevice/v4l2.c
> @@ -334,14 +331,14 @@ static void list_formats(AVFormatContext *ctx, int fd, 
> int type)
>  
>  static int mmap_init(AVFormatContext *ctx)
>  {
> -    struct video_data *s = ctx->priv_data;
> -    struct v4l2_requestbuffers req;
>      int i, res;
> +    struct video_data *s = ctx->priv_data;
> +    struct v4l2_requestbuffers req = {
> +        .count = desired_video_buffers,
> +        .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
> +        .memory = V4L2_MEMORY_MMAP
> +    };

nit: align

> @@ -374,12 +371,12 @@ static int mmap_init(AVFormatContext *ctx)
>      for (i = 0; i < req.count; i++) {
> -        struct v4l2_buffer buf;
> +        struct v4l2_buffer buf = {
> +            .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
> +            .memory = V4L2_MEMORY_MMAP,
> +            .index = i
> +        };

ditto

> @@ -437,15 +433,14 @@ 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 = {
> +        .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
> +        .memory = V4L2_MEMORY_MMAP
> +    };

ditto

> @@ -504,12 +499,11 @@ static int mmap_start(AVFormatContext *ctx)
>  
>      for (i = 0; i < s->buffers; i++) {
> -        struct v4l2_buffer buf;
> -
> -        memset(&buf, 0, sizeof(struct v4l2_buffer));
> -        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> -        buf.memory = V4L2_MEMORY_MMAP;
> -        buf.index  = i;
> +        struct v4l2_buffer buf = {
> +            .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
> +            .memory = V4L2_MEMORY_MMAP,
> +            .index  = i
> +        };

nit: align

> @@ -552,12 +546,12 @@ 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;
> +    AVRational framerate_q = { 0 };
>      int i, ret;
> -    AVRational framerate_q;

framerate_q was not previously memset to zero - is that on purpose?

Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to