[FFmpeg-devel] [PATCH 2/2] libavutil/libavfilter: deshake opencl filter based on comments on 20130328

Michael Niedermayer michaelni at gmx.at
Fri Mar 29 13:16:11 CET 2013


On Thu, Mar 28, 2013 at 09:00:59PM +0800, Wei Gao wrote:
> 

>  configure                      |    1 
>  libavfilter/Makefile           |    2 
>  libavfilter/allfilters.c       |   22 ++++
>  libavfilter/deshake_kernel.h   |  211 +++++++++++++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.c |  155 ++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.h |   67 +++++++++++++
>  libavfilter/vf_deshake.c       |  184 +++++++++++++++++++++++++++++++++++
>  7 files changed, 641 insertions(+), 1 deletion(-)
> 95c3962107f34417d1af350dedf3711bf4d4dce5  0002-deshake-opencl-filter-based-on-comments-on-20130328.ogyLfS.patch
> From 313ce83f866c4f1414d6bdca2ac677173f38814b Mon Sep 17 00:00:00 2001
> From: highgod0401 <highgod0401 at gmail.com>
> Date: Thu, 28 Mar 2013 20:55:42 +0800
> Subject: [PATCH 2/2] deshake opencl filter based on comments on 20130328
> 
> ---
>  configure                      |   1 +
>  libavfilter/Makefile           |   2 +
>  libavfilter/allfilters.c       |  22 ++++-
>  libavfilter/deshake_kernel.h   | 211 +++++++++++++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.c | 155 ++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.h |  67 +++++++++++++
>  libavfilter/vf_deshake.c       | 184 +++++++++++++++++++++++++++++++++++
>  7 files changed, 641 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/deshake_kernel.h
>  create mode 100644 libavfilter/transform_opencl.c
>  create mode 100644 libavfilter/transform_opencl.h
> 
> diff --git a/configure b/configure
> index 9c42a85..531e753 100755
> --- a/configure
> +++ b/configure
> @@ -2088,6 +2088,7 @@ cropdetect_filter_deps="gpl"
>  decimate_filter_deps="gpl avcodec"
>  delogo_filter_deps="gpl"
>  deshake_filter_deps="avcodec"
> +deshake_opencl_filter_deps="opencl deshake_filter"
>  drawtext_filter_deps="libfreetype"
>  ebur128_filter_deps="gpl"
>  flite_filter_deps="libflite"
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 0040a33..b91b802 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -9,6 +9,7 @@ FFLIBS-$(CONFIG_ASYNCTS_FILTER)              += avresample
>  FFLIBS-$(CONFIG_ATEMPO_FILTER)               += avcodec
>  FFLIBS-$(CONFIG_DECIMATE_FILTER)             += avcodec
>  FFLIBS-$(CONFIG_DESHAKE_FILTER)              += avcodec
> +FFLIBS-$(CONFIG_DESHAKE_OPENCL_FILTER)       += avcodec
>  FFLIBS-$(CONFIG_MOVIE_FILTER)                += avformat avcodec
>  FFLIBS-$(CONFIG_MP_FILTER)                   += avcodec
>  FFLIBS-$(CONFIG_PAN_FILTER)                  += swresample
> @@ -109,6 +110,7 @@ OBJS-$(CONFIG_CURVES_FILTER)                 += vf_curves.o
>  OBJS-$(CONFIG_DECIMATE_FILTER)               += vf_decimate.o
>  OBJS-$(CONFIG_DELOGO_FILTER)                 += vf_delogo.o
>  OBJS-$(CONFIG_DESHAKE_FILTER)                += vf_deshake.o
> +OBJS-$(CONFIG_DESHAKE_OPENCL_FILTER)         += vf_deshake.o transform_opencl.o
>  OBJS-$(CONFIG_DRAWBOX_FILTER)                += vf_drawbox.o
>  OBJS-$(CONFIG_DRAWTEXT_FILTER)               += vf_drawtext.o
>  OBJS-$(CONFIG_EDGEDETECT_FILTER)             += vf_edgedetect.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 086e6c9..53af870 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -21,7 +21,10 @@
>  
>  #include "avfilter.h"
>  #include "config.h"
> -
> +#if CONFIG_OPENCL
> +#include "libavutil/opencl.h"
> +#include "deshake_kernel.h"
> +#endif
>  
>  #define REGISTER_FILTER(X, x, y)                                        \
>      {                                                                   \

> @@ -35,7 +38,21 @@
>          extern AVFilter avfilter_##x;                                   \
>          avfilter_register(&avfilter_##x);                               \
>      }
> +#if CONFIG_OPENCL
> +#define OPENCL_REGISTER_FILTER(X, x, y)                                          \
> +    {                                                                            \
> +        extern AVFilter avfilter_##y##_##x;                                      \
> +        if (CONFIG_##X##_FILTER) {                                               \
> +            avfilter_register(&avfilter_##y##_##x);                              \
> +            av_opencl_register_kernel((avfilter_##y##_##x).name,ff_kernel_##x);  \
> +        }                                                                        \
> +    }
>  
> +static void opencl_filters_register_all(void)
> +{
> +    OPENCL_REGISTER_FILTER(DESHAKE_OPENCL,     deshake_opencl,       vf);
> +}
> +#endif
>  void avfilter_register_all(void)
>  {
>      static int initialized;
> @@ -198,4 +215,7 @@ void avfilter_register_all(void)
>      REGISTER_FILTER_UNCONDITIONAL(vsink_buffer);
>      REGISTER_FILTER_UNCONDITIONAL(af_afifo);
>      REGISTER_FILTER_UNCONDITIONAL(vf_fifo);
> +#if CONFIG_OPENCL
> +    opencl_filters_register_all();
> +#endif
>  }

can be simplified to:

         extern AVFilter avfilter_##x;                                   \
         avfilter_register(&avfilter_##x);                               \
     }
+#define OPENCL_REGISTER_FILTER(X, x, y)                                          \
+    {                                                                            \
+        extern AVFilter avfilter_##y##_##x;                                      \
+        if (CONFIG_##X##_FILTER) {                                               \
+            avfilter_register(&avfilter_##y##_##x);                              \
+            av_opencl_register_kernel((avfilter_##y##_##x).name,ff_kernel_##x);  \
+        }                                                                        \
+    }

+static void opencl_filters_register_all(void)
+{
+#if CONFIG_OPENCL
+    OPENCL_REGISTER_FILTER(DESHAKE_OPENCL,     deshake_opencl,       vf);
+#endif
+}
 void avfilter_register_all(void)
 {
     static int initialized;
...
     REGISTER_FILTER_UNCONDITIONAL(vsink_buffer);
     REGISTER_FILTER_UNCONDITIONAL(af_afifo);
     REGISTER_FILTER_UNCONDITIONAL(vf_fifo);
+    opencl_filters_register_all();
 }



[...]
> +#define TRANSFORM_OPENCL_CHECK(method, ...)\
> +    status = method(__VA_ARGS__); if(status != CL_SUCCESS) {\
> +        av_log(&transformopencl, AV_LOG_ERROR, "error %s %d\n", # method, status);  return AVERROR_EXTERNAL; }

putting only 1 statement per line should make this more readable



> +
> +#define TRANSFORM_OPENCL_SET_KERNEL_ARG(arg_ptr)\
> +    status = clSetKernelArg((kernel),(arg_no++),(sizeof(arg_ptr)),(void*)(&(arg_ptr)));if(status != CL_SUCCESS) {\
> +        av_log(&transformopencl, AV_LOG_ERROR, "error %s %d\n", "clSetKernelArg", status );  return AVERROR_EXTERNAL; }

same here


> +
> +typedef struct TransformOpencl {
> +    const AVClass *class;
> +    int   log_offset;
> +    void *log_ctx;
> +} TransformOpencl;
> +
> +static const AVClass transformopencl_class = {"TRANSFORMOPENCL", av_default_item_name,
> +                                                   NULL, LIBAVUTIL_VERSION_INT,
> +                                                   offsetof(TransformOpencl, log_offset),
> +                                                   offsetof(TransformOpencl, log_ctx)};
> +

> +static TransformOpencl transformopencl = {&transformopencl_class};

the class should be part of the context not a global variable.
If its part of the context then the instance can also be distinguished


[...]
> @@ -553,6 +661,49 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>  
>      return ff_filter_frame(outlink, out);
>  }
> +#if CONFIG_DESHAKE_OPENCL_FILTER
> +static av_cold int init_opencl(AVFilterContext *ctx, const char *args)
> +{
> +    DeshakeContext *deshake = ctx->priv;
> +    AVDictionary *options = NULL;
> +    int ret = init(ctx, args);
> +    if (ret < 0)
> +        return ret;
> +    av_dict_set(&options, "build_option", "-I.", 0);
> +    ret = av_opencl_init(options, NULL);
> +    av_dict_free(&options);
> +    if (ret < 0)
> +        return ret;

> +    memset(&(deshake->opencl_env), 0, sizeof(DeshakeOpenclEnv));

> +    deshake->opencl_env.cl_inbuf.cl_buf  = NULL;
> +    deshake->opencl_env.cl_outbuf.cl_buf = NULL;

arent these 2 redundant with the memset above ?

also the opencl deshake code should be split into a seperate file
avoiding the interleaving with #ifs ...

[...]

Thanks

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.
-------------- 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/20130329/02628763/attachment.asc>


More information about the ffmpeg-devel mailing list