[FFmpeg-devel] [PATCH] Generalize pixel format enum fields to int formats

Stefano Sabatini stefano.sabatini-lala
Mon Jul 19 13:23:07 CEST 2010


On date Monday 2010-07-19 02:44:07 -0700, S.N. Hemanth Meenakshisundaram encoded:
> 
> avfilter_add_colorspace and avfilter_add_sampleformat merged,
> avfilter_all_colorspaces and avfilter_all_sampleformats merged.
> 
> Also patched vf_scale since it uses avfilter_add_colorspace and wouldn't
> compile with this change.
> 
> Using a union in place of enum PixelFormat formats would require nearly
> all the existing filters to be patched. For the moment, int works for
> both video and audio filters, so keeping it as int. I can generalize
> this later on if other types of filters are introduced and its format
> isn't an int.

Agreed.
 
> Regards,
> 
> ---
>  libavfilter/avfilter.h |   18 +++++++++---------
>  libavfilter/defaults.c |    2 +-
>  libavfilter/formats.c  |   30 +++++++++++++++---------------
>  libavfilter/vf_scale.c |    4 ++--
>  4 files changed, 27 insertions(+), 27 deletions(-)
> 
> 
> 

> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 3737d46..5c6fbe7 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -68,7 +68,7 @@ typedef struct AVFilterBuffer
>  {
>      uint8_t *data[4];           ///< buffer data for each plane
>      int linesize[4];            ///< number of bytes per line
> -    enum PixelFormat format;    ///< colorspace
> +    int format;                 ///< colorspace

While at it please also update the doxy, this should make the lavfi
audio framework patch smaller.

>  
>      unsigned refcount;          ///< number of references to this buffer
>  
> @@ -190,7 +190,7 @@ typedef struct AVFilterFormats AVFilterFormats;
>  struct AVFilterFormats
>  {
>      unsigned format_count;      ///< number of formats
> -    enum PixelFormat *formats;  ///< list of pixel formats

> +    int *formats;               ///< list of pixel formats

same here

>  
>      unsigned refcount;          ///< number of references to this list
>      AVFilterFormats ***refs;    ///< references to this list
> @@ -199,25 +199,25 @@ struct AVFilterFormats
>  /**
>   * Create a list of supported formats. This is intended for use in
>   * AVFilter->query_formats().

> - * @param pix_fmts list of pixel formats, terminated by PIX_FMT_NONE
> + * @param fmts list of pixel formats, terminated by PIX_FMT_NONE

fmts a list of integer representing audio/video formats, terminated by -1

>   * @return the format list, with no existing references
>   */
> -AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts);
> +AVFilterFormats *avfilter_make_format_list(const int *fmts);
>  
>  /**
> - * Add pix_fmt to the list of pixel formats contained in *avff.
> + * Add fmt to the list of pixel formats contained in *avff.
                             ^^^^^^^^^^^^^

pixel formats doesn't look anymore correct.

>   * If *avff is NULL the function allocates the filter formats struct
>   * and puts its pointer in *avff.
>   *
>   * @return a non negative value in case of success, or a negative
>   * value corresponding to an AVERROR code in case of error
>   */
> -int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt);
> +int avfilter_add_format(AVFilterFormats **avff, int fmt);
>  
>  /**

> - * Return a list of all colorspaces supported by FFmpeg.
> + * Return a list of all pixel formats supported by FFmpeg.
>   */
> -AVFilterFormats *avfilter_all_colorspaces(void);
> +AVFilterFormats *avfilter_all_formats(void);

You have two options here:
implement a distinct avfilter_all_sampleformats() function, mainly
duplicating the avfilter_all_colorspaces()

or generalize the function, for example implementing:
avfilter_all_formats(enum AVMediaType type);

Note that this can be done in a successive step if you prefer.

>  
>  /**
>   * Return a format list which contains the intersection of the formats of
> @@ -509,7 +509,7 @@ struct AVFilterLink
>  
>      int w;                      ///< agreed upon image width
>      int h;                      ///< agreed upon image height

> -    enum PixelFormat format;    ///< agreed upon image colorspace
> +    int format;                 ///< agreed upon image colorspace

update doxy

>  
>      /**
>       * Lists of formats supported by the input and output filters respectively.
> diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
> index ed1db94..b4f5c62 100644
> --- a/libavfilter/defaults.c
> +++ b/libavfilter/defaults.c
> @@ -160,7 +160,7 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
>  
>  int avfilter_default_query_formats(AVFilterContext *ctx)
>  {
> -    avfilter_set_common_formats(ctx, avfilter_all_colorspaces());
> +    avfilter_set_common_formats(ctx, avfilter_all_formats());
>      return 0;
>  }
>  
> diff --git a/libavfilter/formats.c b/libavfilter/formats.c
> index 2a9bdb0..b57ea32 100644
> --- a/libavfilter/formats.c
> +++ b/libavfilter/formats.c
> @@ -70,47 +70,47 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
>      return ret;
>  }
>  
> -AVFilterFormats *avfilter_make_format_list(const enum PixelFormat *pix_fmts)
> +AVFilterFormats *avfilter_make_format_list(const int *fmts)
>  {
>      AVFilterFormats *formats;
>      int count;
>  

> -    for (count = 0; pix_fmts[count] != PIX_FMT_NONE; count++)
> +    for (count = 0; fmts[count] != PIX_FMT_NONE; count++)
>          ;

s/PIX_FMT_NONE/-1

>  
>      formats               = av_mallocz(sizeof(AVFilterFormats));
>      formats->formats      = av_malloc(sizeof(*formats->formats) * count);
>      formats->format_count = count;
> -    memcpy(formats->formats, pix_fmts, sizeof(*formats->formats) * count);
> +    memcpy(formats->formats, fmts, sizeof(*formats->formats) * count);
>  
>      return formats;
>  }
>  
> -int avfilter_add_colorspace(AVFilterFormats **avff, enum PixelFormat pix_fmt)
> +int avfilter_add_format(AVFilterFormats **avff, int fmt)
>  {
> -    enum PixelFormat *pix_fmts;
> +    int *fmts;
>  
>      if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats))))
>          return AVERROR(ENOMEM);
>  
> -    pix_fmts = av_realloc((*avff)->formats,
> -                          sizeof((*avff)->formats) * ((*avff)->format_count+1));
> -    if (!pix_fmts)
> +    fmts = av_realloc((*avff)->formats,
> +                      sizeof((*avff)->formats) * ((*avff)->format_count+1));
> +    if (!fmts)
>          return AVERROR(ENOMEM);
>  
> -    (*avff)->formats = pix_fmts;
> -    (*avff)->formats[(*avff)->format_count++] = pix_fmt;
> +    (*avff)->formats = fmts;
> +    (*avff)->formats[(*avff)->format_count++] = fmt;
>      return 0;
>  }
>  
> -AVFilterFormats *avfilter_all_colorspaces(void)
> +AVFilterFormats *avfilter_all_formats(void)
>  {
>      AVFilterFormats *ret = NULL;
> -    enum PixelFormat pix_fmt;
> +    int fmt;
>  
> -    for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
> -        if (!(av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL))
> -            avfilter_add_colorspace(&ret, pix_fmt);
> +    for (fmt = 0; fmt < PIX_FMT_NB; fmt++)
> +        if (!(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_HWACCEL))
> +            avfilter_add_format(&ret, fmt);
>  
>      return ret;
>  }
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index 29fd3fe..56b1cf6 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -83,7 +83,7 @@ static int query_formats(AVFilterContext *ctx)
>          formats = NULL;
>          for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
>              if (   sws_isSupportedInput(pix_fmt)
> -                && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) {
> +                && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) {
>                  avfilter_formats_unref(&formats);
>                  return ret;
>              }
> @@ -93,7 +93,7 @@ static int query_formats(AVFilterContext *ctx)
>          formats = NULL;
>          for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
>              if (    sws_isSupportedOutput(pix_fmt)
> -                && (ret = avfilter_add_colorspace(&formats, pix_fmt)) < 0) {
> +                && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) {
>                  avfilter_formats_unref(&formats);
>                  return ret;
>              }

Regards.



More information about the ffmpeg-devel mailing list