[FFmpeg-devel] [PATCH] Command passing interface for libavfilter

Michael Niedermayer michaelni at gmx.at
Mon Aug 29 20:14:50 CEST 2011


On Mon, Aug 29, 2011 at 06:23:33PM +0200, Stefano Sabatini wrote:
> On date Monday 2011-08-29 17:49:47 +0200, Michael Niedermayer encoded:
> > On Mon, Aug 29, 2011 at 04:57:10PM +0200, Stefano Sabatini wrote:
> > > On date Monday 2011-08-29 00:45:13 +0200, Michael Niedermayer encoded:
> [...]
> > Will apply attached patches soon if i hear no more comments
> > 
> > 
> > [...]
> > -- 
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> > 
> > Opposition brings concord. Out of discord comes the fairest harmony.
> > -- Heraclitus
> 
> > From 074cda2ba4c10e39b7230a9030475c230a8336f8 Mon Sep 17 00:00:00 2001
> > From: Michael Niedermayer <michaelni at gmx.at>
> > Date: Sun, 28 Aug 2011 20:46:31 +0200
> > Subject: [PATCH 1/5] avfilter: Add command passing support
> > 
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavfilter/avfilter.c      |   12 ++++++++++++
> >  libavfilter/avfilter.h      |   22 +++++++++++++++++++++-
> >  libavfilter/avfiltergraph.c |   30 ++++++++++++++++++++++++++++++
> >  libavfilter/avfiltergraph.h |   20 ++++++++++++++++++++
> >  4 files changed, 83 insertions(+), 1 deletions(-)
> > 
> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > index 23bb26c..5c293dd 100644
> > --- a/libavfilter/avfilter.c
> > +++ b/libavfilter/avfilter.c
> > @@ -26,6 +26,7 @@
> >  #include "libavutil/audioconvert.h"
> >  #include "libavutil/imgutils.h"
> >  #include "libavutil/avassert.h"
> > +#include "libavutil/avstring.h"
> >  #include "avfilter.h"
> >  #include "internal.h"
> >  
> > @@ -616,6 +617,17 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
> >      draw_slice(link, y, h, slice_dir);
> >  }
> >  
> > +int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
> > +{
> > +    if(!strcmp(cmd, "ping")){
> > +        av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
> > +        return 0;
> > +    }else if(filter->filter->process_command) {
> > +        return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
> > +    }
> > +    return AVERROR(ENOSYS);
> > +}
> > +
> >  void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
> >  {
> >      void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
> > diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> > index db6ff6d..4a8c436 100644
> > --- a/libavfilter/avfilter.h
> > +++ b/libavfilter/avfilter.h
> > @@ -29,7 +29,7 @@
> >  #include "libavutil/rational.h"
> >  
> >  #define LIBAVFILTER_VERSION_MAJOR  2
> > -#define LIBAVFILTER_VERSION_MINOR 35
> > +#define LIBAVFILTER_VERSION_MINOR 36
> >  #define LIBAVFILTER_VERSION_MICRO  0
> >  
> >  #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
> > @@ -552,6 +552,20 @@ typedef struct AVFilter {
> >       * NULL_IF_CONFIG_SMALL() macro to define it.
> >       */
> >      const char *description;
> > +
> > +    /**
> > +     * Make the filter instance process a command.
> > +     *
> > +     * @param cmd    the command to process, for handling simplicity all commands must be alphanumeric only
> > +     * @param arg    the argument for the command
> > +     * @param res    a buffer with size res_size where the filter(s) can write a response message / return a response. This must not change when the command is not supported.
> 
> > +     * @param flags  if AVFILTER_CMD_FLAG_FAST is set and the command would be
> > +     *               timeconsuming then a filter should treat it like an unsupported command
> 
> maybe AVFILTER_CMD_FLAG_* should be defined in avfilter.h, so they can
> be used without including avfiltergraph.h.

good idea


> 
> > +     *
> > +     * @returns >=0 on success otherwise an error code.
> > +     *          AVERROR(ENOSYS) on unsupported commands
> > +     */
> > +    int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
> >  } AVFilter;
> >  
> >  /** An instance of a filter */
> > @@ -792,6 +806,12 @@ void avfilter_end_frame(AVFilterLink *link);
> >  void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
> >  
> >  /**
> > + * Make the filter instance process a command.
> > + * It is recommanded to use avfilter_graph_send_command()
> 
> Nit++: missing ending point.

ok


> 
> [...]
> > diff --git a/libavfilter/avfiltergraph.h b/libavfilter/avfiltergraph.h
> > index f4c88bc..e668104 100644
> > --- a/libavfilter/avfiltergraph.h
> > +++ b/libavfilter/avfiltergraph.h
> > @@ -136,4 +136,24 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
> >                           AVFilterInOut **inputs, AVFilterInOut **outputs,
> >                           void *log_ctx);
> >  
> 
> > +#define AVFILTER_CMD_FLAG_ONE   1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
> > +#define AVFILTER_CMD_FLAG_FAST  2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
> 
> as said, should be moved to avfilter.h
> 
> > +
> > +/**
> > + * Send a command to one or more filter instances.
> > + *
> > + * @param graph  the filter graph
> > + * @param target the filter(s) to which the command should be sent
> > + *               "all" sends to all filters
> > + *               otherwise it can be a filter or filter instance name
> > + *               which will send the command to all matching filters.
> > + * @param cmd    the command to sent, for handling simplicity all commands must be alphanumeric only
> > + * @param arg    the argument for the command
> 
> > + * @param res    a buffer with size res_size where the filter(s) can write a response message / return a response.
> 
> Nit+: please choose between "write a response message" or "return a
> response", remove the other variant (the first one is more explicit ->
> better IMO)

ok


> 
> [...]
> 
> No more comments from me, thanks.

will push after it passes fate

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

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- 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-devel/attachments/20110829/61381f2a/attachment.asc>


More information about the ffmpeg-devel mailing list