[FFmpeg-devel] [PATCH 3/4] avdevice/fbdev: move common code to separate file

Stefano Sabatini stefasab at gmail.com
Sun Oct 20 20:55:54 CEST 2013


On date Sunday 2013-10-20 00:15:40 +0200, Lukasz M encoded:
> On 19 October 2013 22:35, Michael Niedermayer <michaelni at gmx.at> wrote:
> 
> > On Sat, Oct 19, 2013 at 09:38:39PM +0200, Lukasz Marek wrote:
> > > Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> > > ---
> > >  libavdevice/Makefile       |    6 +++--
> > >  libavdevice/fbdev_common.c |   57
> > ++++++++++++++++++++++++++++++++++++++++++++
> > >  libavdevice/fbdev_common.h |   31 ++++++++++++++++++++++++
> > >  libavdevice/fbdev_dec.c    |   36 ++--------------------------
> > >  libavdevice/fbdev_enc.c    |   34 +-------------------------
> > >  5 files changed, 95 insertions(+), 69 deletions(-)
> > >  create mode 100644 libavdevice/fbdev_common.c
> > >  create mode 100644 libavdevice/fbdev_common.h
> > >
> > > diff --git a/libavdevice/Makefile b/libavdevice/Makefile
> > > index cf6cac2..21ca954 100644
> > > --- a/libavdevice/Makefile
> > > +++ b/libavdevice/Makefile
> > > @@ -23,8 +23,10 @@ OBJS-$(CONFIG_DSHOW_INDEV)               += dshow.o
> > dshow_enummediatypes.o \
> > >                                              dshow_enumpins.o
> > dshow_filter.o \
> > >                                              dshow_pin.o dshow_common.o
> > >  OBJS-$(CONFIG_DV1394_INDEV)              += dv1394.o
> > > -OBJS-$(CONFIG_FBDEV_INDEV)               += fbdev_dec.o
> > > -OBJS-$(CONFIG_FBDEV_OUTDEV)              += fbdev_enc.o
> > > +OBJS-$(CONFIG_FBDEV_INDEV)               += fbdev_dec.o \
> > > +                                            fbdev_common.o
> > > +OBJS-$(CONFIG_FBDEV_OUTDEV)              += fbdev_enc.o \
> > > +                                            fbdev_common.o
> > >  OBJS-$(CONFIG_IEC61883_INDEV)            += iec61883.o
> > >  OBJS-$(CONFIG_JACK_INDEV)                += jack_audio.o timefilter.o
> > >  OBJS-$(CONFIG_LAVFI_INDEV)               += lavfi.o
> > > diff --git a/libavdevice/fbdev_common.c b/libavdevice/fbdev_common.c
> > > new file mode 100644
> > > index 0000000..34603a9
> > > --- /dev/null
> > > +++ b/libavdevice/fbdev_common.c
> > > @@ -0,0 +1,57 @@
> > > +/*
> > > + * Copyright (c) 2011 Stefano Sabatini
> > > + * Copyright (c) 2009 Giliard B. de Freitas <giliarde at gmail.com>
> > > + * Copyright (C) 2002 Gunnar Monell <gmo at linux.nu>
> > > + *
> > > + * This file is part of FFmpeg.
> > > + *
> > > + * FFmpeg is free software; you can redistribute it and/or
> > > + * modify it under the terms of the GNU Lesser General Public
> > > + * License as published by the Free Software Foundation; either
> > > + * version 2.1 of the License, or (at your option) any later version.
> > > + *
> > > + * FFmpeg is distributed in the hope that it will be useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > > + * Lesser General Public License for more details.
> > > + *
> > > + * You should have received a copy of the GNU Lesser General Public
> > > + * License along with FFmpeg; if not, write to the Free Software
> > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> > 02110-1301 USA
> > > + */
> > > +
> > > +#include "fbdev_common.h"
> > > +#include "libavutil/common.h"
> > > +
> > > +struct rgb_pixfmt_map_entry {
> > > +    int bits_per_pixel;
> > > +    int red_offset, green_offset, blue_offset, alpha_offset;
> > > +    enum AVPixelFormat pixfmt;
> > > +};
> > > +
> > > +static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
> > > +    // bpp, red_offset,  green_offset, blue_offset, alpha_offset, pixfmt
> > > +    {  32,       0,           8,          16,           24,
> > AV_PIX_FMT_RGBA  },
> > > +    {  32,      16,           8,           0,           24,
> > AV_PIX_FMT_BGRA  },
> > > +    {  32,       8,          16,          24,            0,
> > AV_PIX_FMT_ARGB  },
> > > +    {  32,       3,           2,           8,            0,
> > AV_PIX_FMT_ABGR  },
> > > +    {  24,       0,           8,          16,            0,
> > AV_PIX_FMT_RGB24 },
> > > +    {  24,      16,           8,           0,            0,
> > AV_PIX_FMT_BGR24 },
> > > +    {  16,      11,           5,           0,           16,
> > AV_PIX_FMT_RGB565 },
> > > +};
> > > +
> > > +enum AVPixelFormat get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo
> > *varinfo)
> >
> > needs ff_ prefix
> >
> > otherwise LGTM
> >
> > Fixed patch attached.

> From 5fe65f4e3aab3d4c2bd328fbda25be3401b58739 Mon Sep 17 00:00:00 2001
> From: Lukasz Marek <lukasz.m.luki at gmail.com>
> Date: Sat, 19 Oct 2013 21:12:51 +0200
> Subject: [PATCH] avdevice/fbdev: move common code to separate file
> 
> Move common fbdev dec/enc for separate file.
> 
> Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> ---
>  libavdevice/Makefile       |    6 +++--
>  libavdevice/fbdev_common.c |   57 ++++++++++++++++++++++++++++++++++++++++++++
>  libavdevice/fbdev_common.h |   31 ++++++++++++++++++++++++
>  libavdevice/fbdev_dec.c    |   38 +++--------------------------
>  libavdevice/fbdev_enc.c    |   38 +++--------------------------
>  5 files changed, 98 insertions(+), 72 deletions(-)
>  create mode 100644 libavdevice/fbdev_common.c
>  create mode 100644 libavdevice/fbdev_common.h
> 
> diff --git a/libavdevice/Makefile b/libavdevice/Makefile
> index cf6cac2..21ca954 100644
> --- a/libavdevice/Makefile
> +++ b/libavdevice/Makefile
> @@ -23,8 +23,10 @@ OBJS-$(CONFIG_DSHOW_INDEV)               += dshow.o dshow_enummediatypes.o \
>                                              dshow_enumpins.o dshow_filter.o \
>                                              dshow_pin.o dshow_common.o
>  OBJS-$(CONFIG_DV1394_INDEV)              += dv1394.o
> -OBJS-$(CONFIG_FBDEV_INDEV)               += fbdev_dec.o
> -OBJS-$(CONFIG_FBDEV_OUTDEV)              += fbdev_enc.o
> +OBJS-$(CONFIG_FBDEV_INDEV)               += fbdev_dec.o \
> +                                            fbdev_common.o
> +OBJS-$(CONFIG_FBDEV_OUTDEV)              += fbdev_enc.o \
> +                                            fbdev_common.o
>  OBJS-$(CONFIG_IEC61883_INDEV)            += iec61883.o
>  OBJS-$(CONFIG_JACK_INDEV)                += jack_audio.o timefilter.o
>  OBJS-$(CONFIG_LAVFI_INDEV)               += lavfi.o
> diff --git a/libavdevice/fbdev_common.c b/libavdevice/fbdev_common.c
> new file mode 100644
> index 0000000..eb8f3d2
> --- /dev/null
> +++ b/libavdevice/fbdev_common.c
> @@ -0,0 +1,57 @@
> +/*
> + * Copyright (c) 2011 Stefano Sabatini
> + * Copyright (c) 2009 Giliard B. de Freitas <giliarde at gmail.com>
> + * Copyright (C) 2002 Gunnar Monell <gmo at linux.nu>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "fbdev_common.h"
> +#include "libavutil/common.h"
> +
> +struct rgb_pixfmt_map_entry {
> +    int bits_per_pixel;
> +    int red_offset, green_offset, blue_offset, alpha_offset;
> +    enum AVPixelFormat pixfmt;
> +};
> +
> +static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
> +    // bpp, red_offset,  green_offset, blue_offset, alpha_offset, pixfmt
> +    {  32,       0,           8,          16,           24,   AV_PIX_FMT_RGBA  },
> +    {  32,      16,           8,           0,           24,   AV_PIX_FMT_BGRA  },
> +    {  32,       8,          16,          24,            0,   AV_PIX_FMT_ARGB  },
> +    {  32,       3,           2,           8,            0,   AV_PIX_FMT_ABGR  },
> +    {  24,       0,           8,          16,            0,   AV_PIX_FMT_RGB24 },
> +    {  24,      16,           8,           0,            0,   AV_PIX_FMT_BGR24 },
> +    {  16,      11,           5,           0,           16,   AV_PIX_FMT_RGB565 },
> +};
> +
> +enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
> +{
> +    int i;
> +
> +    for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) {
> +        const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i];
> +        if (entry->bits_per_pixel == varinfo->bits_per_pixel &&
> +            entry->red_offset     == varinfo->red.offset     &&
> +            entry->green_offset   == varinfo->green.offset   &&
> +            entry->blue_offset    == varinfo->blue.offset)
> +            return entry->pixfmt;
> +    }
> +
> +    return AV_PIX_FMT_NONE;
> +}
> diff --git a/libavdevice/fbdev_common.h b/libavdevice/fbdev_common.h
> new file mode 100644
> index 0000000..ecbb825
> --- /dev/null
> +++ b/libavdevice/fbdev_common.h
> @@ -0,0 +1,31 @@
> +/*
> + * Copyright (c) 2011 Stefano Sabatini
> + * Copyright (c) 2009 Giliard B. de Freitas <giliarde at gmail.com>
> + * Copyright (C) 2002 Gunnar Monell <gmo at linux.nu>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVDEVICE_FBDEV_COMMON_H
> +#define AVDEVICE_FBDEV_COMMON_H
> +
> +#include <linux/fb.h>
> +#include "libavutil/pixfmt.h"
> +
> +enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo);
> +
> +#endif /* AVDEVICE_FBDEV_COMMON_H */
> diff --git a/libavdevice/fbdev_dec.c b/libavdevice/fbdev_dec.c
> index b49052e..14ebab3 100644
> --- a/libavdevice/fbdev_dec.c
> +++ b/libavdevice/fbdev_dec.c
> @@ -41,41 +41,9 @@
>  #include "libavutil/time.h"
>  #include "libavutil/parseutils.h"
>  #include "libavutil/pixdesc.h"
> -#include "avdevice.h"
>  #include "libavformat/internal.h"
> -
> -struct rgb_pixfmt_map_entry {
> -    int bits_per_pixel;
> -    int red_offset, green_offset, blue_offset, alpha_offset;
> -    enum AVPixelFormat pixfmt;
> -};
> -
> -static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
> -    // bpp, red_offset,  green_offset, blue_offset, alpha_offset, pixfmt
> -    {  32,       0,           8,          16,           24,   AV_PIX_FMT_RGBA  },
> -    {  32,      16,           8,           0,           24,   AV_PIX_FMT_BGRA  },
> -    {  32,       8,          16,          24,            0,   AV_PIX_FMT_ARGB  },
> -    {  32,       3,           2,           8,            0,   AV_PIX_FMT_ABGR  },
> -    {  24,       0,           8,          16,            0,   AV_PIX_FMT_RGB24 },
> -    {  24,      16,           8,           0,            0,   AV_PIX_FMT_BGR24 },
> -    {  16,      11,           5,           0,           16,   AV_PIX_FMT_RGB565 },
> -};
> -
> -static enum AVPixelFormat get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
> -{
> -    int i;
> -
> -    for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) {
> -        const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i];
> -        if (entry->bits_per_pixel == varinfo->bits_per_pixel &&
> -            entry->red_offset     == varinfo->red.offset     &&
> -            entry->green_offset   == varinfo->green.offset   &&
> -            entry->blue_offset    == varinfo->blue.offset)
> -            return entry->pixfmt;
> -    }
> -
> -    return AV_PIX_FMT_NONE;
> -}
> +#include "avdevice.h"
> +#include "fbdev_common.h"
>  
>  typedef struct {
>      AVClass *class;          ///< class for private options
> @@ -131,7 +99,7 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx)
>          goto fail;
>      }
>  
> -    pix_fmt = get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
> +    pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
>      if (pix_fmt == AV_PIX_FMT_NONE) {
>          ret = AVERROR(EINVAL);
>          av_log(avctx, AV_LOG_ERROR,
> diff --git a/libavdevice/fbdev_enc.c b/libavdevice/fbdev_enc.c
> index fa3d4f7..379ce1c 100644
> --- a/libavdevice/fbdev_enc.c
> +++ b/libavdevice/fbdev_enc.c
> @@ -28,6 +28,7 @@
>  #include "libavutil/mem.h"
>  #include "libavutil/opt.h"
>  #include "libavformat/avformat.h"
> +#include "fbdev_common.h"
>  
>  typedef struct {
>      AVClass *class;                   ///< class for private options
> @@ -44,39 +45,6 @@ typedef struct {
>      enum AVPixelFormat pix_fmt;       ///< pixel format of source video
>  } FBDevContext;
>  
> -struct rgb_pixfmt_map_entry {
> -    int bits_per_pixel;
> -    int red_offset, green_offset, blue_offset, alpha_offset;
> -    enum AVPixelFormat pixfmt;
> -};
> -
> -static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
> -    // bpp, red_offset,  green_offset, blue_offset, alpha_offset, pixfmt
> -    {  32,       0,           8,          16,           24,   AV_PIX_FMT_RGBA  },
> -    {  32,      16,           8,           0,           24,   AV_PIX_FMT_BGRA  },
> -    {  32,       8,          16,          24,            0,   AV_PIX_FMT_ARGB  },
> -    {  32,       3,           2,           8,            0,   AV_PIX_FMT_ABGR  },
> -    {  24,       0,           8,          16,            0,   AV_PIX_FMT_RGB24 },
> -    {  24,      16,           8,           0,            0,   AV_PIX_FMT_BGR24 },
> -    {  16,      11,           5,           0,           16,   AV_PIX_FMT_RGB565 },
> -};
> -
> -static enum AVPixelFormat get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
> -{
> -    int i;
> -
> -    for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) {
> -        const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i];
> -        if (entry->bits_per_pixel == varinfo->bits_per_pixel &&
> -            entry->red_offset     == varinfo->red.offset     &&
> -            entry->green_offset   == varinfo->green.offset   &&
> -            entry->blue_offset    == varinfo->blue.offset)
> -            return entry->pixfmt;
> -    }
> -
> -    return AV_PIX_FMT_NONE;
> -}
> -
>  static av_cold int fbdev_write_header(AVFormatContext *h)
>  {
>      FBDevContext *fbdev = h->priv_data;
> @@ -120,7 +88,7 @@ static av_cold int fbdev_write_header(AVFormatContext *h)
>          goto fail;
>      }
>  
> -    pix_fmt = get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
> +    pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
>      if (pix_fmt == AV_PIX_FMT_NONE) {
>          ret = AVERROR(EINVAL);
>          av_log(h, AV_LOG_ERROR, "Framebuffer pixel format not supported.\n");
> @@ -161,7 +129,7 @@ static int fbdev_write_packet(AVFormatContext *h, AVPacket *pkt)
>          av_log(h, AV_LOG_WARNING,
>                 "Error refreshing variable info: %s\n", strerror(errno));
>  
> -    pix_fmt = get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
> +    pix_fmt = ff_get_pixfmt_from_fb_varinfo(&fbdev->varinfo);
>  
>      //TODO: Consider mapping between formats
>      if (pix_fmt != fbdev->pix_fmt) {
> -- 
> 1.7.10.4
> 

LGTM, thanks.
-- 
FFmpeg = Fierce & Fascinating Multimedia Programmable Exxagerate Gnome


More information about the ffmpeg-devel mailing list