[FFmpeg-cvslog] lavfi/buffersink: accept parameters as options.

Michael Niedermayer michaelni at gmx.at
Sun Apr 21 03:02:20 CEST 2013


On Fri, Apr 12, 2013 at 12:18:43PM +0200, Nicolas George wrote:
> ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Thu Apr 11 14:58:07 2013 +0200| [e48ded8551172b58a78f30303a81dfce125344e0] | committer: Michael Niedermayer
> 
> lavfi/buffersink: accept parameters as options.
> 
> Move validation from init to query_formats().
> Accept the formats lists as binary options.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e48ded8551172b58a78f30303a81dfce125344e0
> ---
> 
>  doc/filters.texi         |   22 ++----
>  libavfilter/buffersink.c |  187 +++++++++++++++++++++++++++++-----------------
>  2 files changed, 127 insertions(+), 82 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 3819645..a10d2fc 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -1768,9 +1768,10 @@ Below is a description of the currently available audio sinks.
>  Buffer audio frames, and make them available to the end of filter chain.
>  
>  This sink is mainly intended for programmatic use, in particular
> -through the interface defined in @file{libavfilter/buffersink.h}.
> +through the interface defined in @file{libavfilter/buffersink.h}
> +or the options system.
>  
> -It requires a pointer to an AVABufferSinkContext structure, which
> +It accepts a pointer to an AVABufferSinkContext structure, which
>  defines the incoming buffers' formats, to be passed as the opaque
>  parameter to @code{avfilter_init_filter} for initialization.
>  
> @@ -1780,13 +1781,6 @@ Null audio sink, do absolutely nothing with the input audio. It is
>  mainly useful as a template and to be employed in analysis / debugging
>  tools.
>  
> - at section abuffersink
> -This sink is intended for programmatic use. Frames that arrive on this sink can
> -be retrieved by the calling program using the interface defined in
> - at file{libavfilter/buffersink.h}.
> -
> -This filter accepts no parameters.
> -
>  @c man end AUDIO SINKS
>  
>  @chapter Video Filters
> @@ -6298,12 +6292,12 @@ Buffer video frames, and make them available to the end of the filter
>  graph.
>  
>  This sink is mainly intended for a programmatic use, in particular
> -through the interface defined in @file{libavfilter/buffersink.h}.
> +through the interface defined in @file{libavfilter/buffersink.h}
> +or the options system.
>  
> -It does not require a string parameter in input, but you need to
> -specify a pointer to a list of supported pixel formats terminated by
> --1 in the opaque parameter provided to @code{avfilter_init_filter}
> -when initializing this sink.
> +It accepts a pointer to an AVBufferSinkContext structure, which
> +defines the incoming buffers' formats, to be passed as the opaque
> +parameter to @code{avfilter_init_filter} for initialization.
>  
>  @section nullsink
>  
> diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
> index 03702dc..801f327 100644
> --- a/libavfilter/buffersink.c
> +++ b/libavfilter/buffersink.c
> @@ -28,6 +28,7 @@
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/common.h"
>  #include "libavutil/mathematics.h"
> +#include "libavutil/opt.h"
>  
>  #include "audio.h"
>  #include "avfilter.h"
> @@ -35,23 +36,32 @@
>  #include "internal.h"
>  
>  typedef struct {
> +    const AVClass *class;
>      AVFifoBuffer *fifo;                      ///< FIFO buffer of video frame references
>      unsigned warning_limit;
>  
>      /* only used for video */
>      enum AVPixelFormat *pixel_fmts;           ///< list of accepted pixel formats, must be terminated with -1
> +    int pixel_fmts_size;
>  
>      /* only used for audio */
>      enum AVSampleFormat *sample_fmts;       ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
> +    int sample_fmts_size;
>      int64_t *channel_layouts;               ///< list of accepted channel layouts, terminated by -1
> +    int channel_layouts_size;
> +    int *channel_counts;                    ///< list of accepted channel counts, terminated by -1
> +    int channel_counts_size;
>      int all_channel_counts;
>      int *sample_rates;                      ///< list of accepted sample rates, terminated by -1
> +    int sample_rates_size;
>  
>      /* only used for compat API */
>      AVAudioFifo  *audio_fifo;    ///< FIFO for audio samples
>      int64_t next_pts;            ///< interpolating audio pts
>  } BufferSinkContext;
>  
> +#define NB_ITEMS(list) (list ## _size / sizeof(*list))
> +
>  static av_cold void uninit(AVFilterContext *ctx)
>  {
>      BufferSinkContext *sink = ctx->priv;
> @@ -68,10 +78,6 @@ static av_cold void uninit(AVFilterContext *ctx)
>          av_fifo_free(sink->fifo);
>          sink->fifo = NULL;
>      }
> -    av_freep(&sink->pixel_fmts);
> -    av_freep(&sink->sample_fmts);
> -    av_freep(&sink->sample_rates);
> -    av_freep(&sink->channel_layouts);
>  }
>  
>  static int add_buffer_ref(AVFilterContext *ctx, AVFrame *ref)
> @@ -286,6 +292,7 @@ static int attribute_align_arg compat_read(AVFilterContext *ctx, AVFilterBufferR
>      if (ret < 0)
>          goto fail;
>  
> +    AV_NOWARN_DEPRECATED(
>      if (ctx->inputs[0]->type == AVMEDIA_TYPE_VIDEO) {
>          buf = avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize,
>                                                          AV_PERM_READ,
> @@ -304,6 +311,7 @@ static int attribute_align_arg compat_read(AVFilterContext *ctx, AVFilterBufferR
>      }
>  
>      avfilter_copy_frame_props(buf, frame);
> +    )
>  
>      buf->buf->priv = frame;
>      buf->buf->free = compat_free_buffer;
> @@ -366,13 +374,11 @@ static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
>  {
>      BufferSinkContext *buf = ctx->priv;
>      AVBufferSinkParams *params = opaque;
> +    int ret;
>  
> -    if (params && params->pixel_fmts) {
> -        const int *pixel_fmts = params->pixel_fmts;
> -
> -        buf->pixel_fmts = ff_copy_int_list(pixel_fmts);
> -        if (!buf->pixel_fmts)
> -            return AVERROR(ENOMEM);
> +    if (params) {
> +        if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, AV_PIX_FMT_NONE, 0)) < 0)
> +            return ret;
>      }
>  
>      return common_init(ctx);
> @@ -381,64 +387,41 @@ static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
>  static int vsink_query_formats(AVFilterContext *ctx)
>  {
>      BufferSinkContext *buf = ctx->priv;
> +    AVFilterFormats *formats = NULL;
> +    unsigned i;
> +    int ret;
>  
> -    if (buf->pixel_fmts)
> -        ff_set_common_formats(ctx, ff_make_format_list(buf->pixel_fmts));
> -    else
> +    if (buf->pixel_fmts_size % sizeof(*buf->pixel_fmts)) {
> +        av_log(ctx, AV_LOG_ERROR, "Invalid size for format list\n");
> +        return AVERROR(EINVAL);
> +    }
> +
> +    if (buf->pixel_fmts_size) {
> +        for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
> +            if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
> +                return ret;

coverity says formats leaks here (1005315)

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-cvslog/attachments/20130421/18ea17db/attachment.asc>


More information about the ffmpeg-cvslog mailing list