[FFmpeg-devel] [libav-devel] [PATCH] lavfi: add audio channel packing negotiation fields

Stefano Sabatini stefano.sabatini-lala at poste.it
Thu Jul 14 00:34:54 CEST 2011


On date Wednesday 2011-07-13 19:01:55 +0300, Mina Nagy Zaki encoded:
> ---
>  libavfilter/avfilter.h      |   16 +++++++++++++++-
>  libavfilter/avfiltergraph.c |    6 ++++++
>  libavfilter/defaults.c      |    8 ++++++++
>  libavfilter/formats.c       |   11 +++++++++++
>  4 files changed, 40 insertions(+), 1 deletions(-)
> 
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 0b8f2d4..a67cf8a 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -261,6 +261,11 @@ AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
>  AVFilterFormats *avfilter_all_channel_layouts(void);
>  
>  /**
> + * Return a list of all audio packing formats.
> + */
> +AVFilterFormats *avfilter_all_packing_formats(void);
> +
> +/**
>   * Return a format list which contains the intersection of the formats of
>   * a and b. Also, all the references of a, all the references of b, and
>   * a and b themselves will be deallocated.
> @@ -478,6 +483,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
>  void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats);
>  void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats);
>  void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats);
> +void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats);
>  
>  /** Default handler for query_formats() */
>  int avfilter_default_query_formats(AVFilterContext *ctx);
> @@ -566,6 +572,11 @@ struct AVFilterContext {
>      void *priv;                     ///< private data for use by the filter
>  };
>  

> +enum AVFilterPacking {
> +    AVFILTER_PACKED = 1,
> +    AVFILTER_PLANAR,
> +};

As you already noted:
AVFILTER_PACKED = 0,

> +
>  /**
>   * A link between two filters. This contains pointers to the source and
>   * destination filters between which this link exists, and the indexes of
> @@ -593,9 +604,10 @@ struct AVFilterLink {
>      int w;                      ///< agreed upon image width
>      int h;                      ///< agreed upon image height
>      AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio

> -    /* These two parameters apply only to audio */
> +    /* These three parameters apply only to audio */

=> The following parameters...

updating the numeral for each new added field is silly.

>      int64_t channel_layout;     ///< channel layout of current buffer (see libavutil/audioconvert.h)
>      int64_t sample_rate;        ///< samples per second
> +    int planar;                 ///< agreed upon packing mode of audio buffers. true if planar.
>  
>      int format;                 ///< agreed upon media format
>  
> @@ -611,6 +623,8 @@ struct AVFilterLink {
>  
>      AVFilterFormats *in_chlayouts;
>      AVFilterFormats *out_chlayouts;
> +    AVFilterFormats *in_packing;
> +    AVFilterFormats *out_packing;
>  
>      /**
>       * The buffer reference currently being sent across the link by the source
> diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
> index 0476861..2561587 100644
> --- a/libavfilter/avfiltergraph.c
> +++ b/libavfilter/avfiltergraph.c
> @@ -200,9 +200,15 @@ static void pick_format(AVFilterLink *link)
>  
>      if (link->type == AVMEDIA_TYPE_AUDIO) {
>          link->in_chlayouts->format_count = 1;
> +        link->in_packing->format_count = 1;
> +
>          link->channel_layout = link->in_chlayouts->formats[0];
> +        link->planar = link->in_packing->formats[0] == AVFILTER_PLANAR;
> +

Nit+: keep togheter channel/packing stuff, I mean:

        link->in_chlayouts->format_count = 1;
        link->channel_layout = link->in_chlayouts->formats[0];

        link->in_packing->format_count = 1;
        link->planar = link->in_packing->formats[0] == AVFILTER_PLANAR;

>          avfilter_formats_unref(&link->in_chlayouts);
>          avfilter_formats_unref(&link->out_chlayouts);
> +        avfilter_formats_unref(&link->in_packing);
> +        avfilter_formats_unref(&link->out_packing);
>      }
>  
>  }
> diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
> index b03816d..a7bff48 100644
> --- a/libavfilter/defaults.c
> +++ b/libavfilter/defaults.c
> @@ -239,11 +239,19 @@ void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *
>                         offsetof(AVFilterLink, out_chlayouts));
>  }
>  

> +void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats)
> +{
> +    set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO,
> +                      offsetof(AVFilterLink, in_packing),
> +                      offsetof(AVFilterLink, out_packing));
> +}

Nit++: weird indent

> +
>  int avfilter_default_query_formats(AVFilterContext *ctx)
>  {
>      avfilter_set_common_pixel_formats(ctx, avfilter_all_formats(AVMEDIA_TYPE_VIDEO));
>      avfilter_set_common_sample_formats(ctx, avfilter_all_formats(AVMEDIA_TYPE_AUDIO));
>      avfilter_set_common_channel_layouts(ctx, avfilter_all_channel_layouts());
> +    avfilter_set_common_packing_formats(ctx, avfilter_all_packing_formats());
>  
>      return 0;
>  }
> diff --git a/libavfilter/formats.c b/libavfilter/formats.c
> index b6e30e7..81e48f0 100644
> --- a/libavfilter/formats.c
> +++ b/libavfilter/formats.c
> @@ -173,6 +173,17 @@ AVFilterFormats *avfilter_all_channel_layouts(void)
>      return avfilter_make_format64_list(chlayouts);
>  }
>  
> +AVFilterFormats *avfilter_all_packing_formats(void)
> +{
> +    static int packing[] = {
> +        AVFILTER_PLANAR,
> +        AVFILTER_PACKED,
> +        -1,
> +    };
> +
> +    return avfilter_make_format_list(packing);
> +}
> +
>  void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
>  {
>      *ref = f;

Note to the reader: the use of AVFilterFormats for packing modes may
seem overkill (indeed we have only two modes), but after some failed
attempts at reinventing the wheel it seemed like a sane solution,
indeed it reuses the same well-tested code and allows more
consistency.


More information about the ffmpeg-devel mailing list