[FFmpeg-devel] [PATCH 4/5] avfilter/mp_decimate: remove avcodec dependency

2014-08-02 Thread Clément Bœsch
---
 configure   |  4 ++--
 libavfilter/vf_mpdecimate.c | 44 
 2 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/configure b/configure
index bc187a5..210cafb 100755
--- a/configure
+++ b/configure
@@ -2549,8 +2549,8 @@ ladspa_filter_extralibs='$ldl'
 mcdeint_filter_deps=avcodec gpl
 movie_filter_deps=avcodec avformat
 mp_filter_deps=gpl avcodec swscale inline_asm
-mpdecimate_filter_deps=gpl avcodec
-mpdecimate_filter_select=me_cmp pixblockdsp
+mpdecimate_filter_deps=gpl
+mpdecimate_filter_select=pixelutils
 mptestsrc_filter_deps=gpl
 negate_filter_deps=lut_filter
 perspective_filter_deps=gpl
diff --git a/libavfilter/vf_mpdecimate.c b/libavfilter/vf_mpdecimate.c
index c667a9f..76af175 100644
--- a/libavfilter/vf_mpdecimate.c
+++ b/libavfilter/vf_mpdecimate.c
@@ -26,9 +26,8 @@
 
 #include libavutil/opt.h
 #include libavutil/pixdesc.h
+#include libavutil/pixelutils.h
 #include libavutil/timestamp.h
-#include libavcodec/dsputil.h
-#include libavcodec/pixblockdsp.h
 #include avfilter.h
 #include internal.h
 #include formats.h
@@ -49,9 +48,7 @@ typedef struct {
 
 int hsub, vsub;/// chroma subsampling values
 AVFrame *ref;  /// reference picture
-DSPContext dspctx; /// context providing optimized diff 
routines
-PixblockDSPContext pdsp;
-AVCodecContext *avctx; /// codec context required for the 
DSPContext
+av_pixelutils_sad_fn sad;  /// sum of absolute difference function
 } DecimateContext;
 
 #define OFFSET(x) offsetof(DecimateContext, x)
@@ -72,25 +69,21 @@ AVFILTER_DEFINE_CLASS(mpdecimate);
  * Return 1 if the two planes are different, 0 otherwise.
  */
 static int diff_planes(AVFilterContext *ctx,
-   uint8_t *cur, uint8_t *ref, int linesize,
+   uint8_t *cur, int cur_linesize,
+   uint8_t *ref, int ref_linesize,
int w, int h)
 {
 DecimateContext *decimate = ctx-priv;
-DSPContext *dspctx = decimate-dspctx;
-PixblockDSPContext *pdsp = decimate-pdsp;
 
 int x, y;
 int d, c = 0;
 int t = (w/16)*(h/16)*decimate-frac;
-int16_t block[8*8];
 
 /* compute difference for blocks of 8x8 bytes */
 for (y = 0; y  h-7; y += 4) {
 for (x = 8; x  w-7; x += 4) {
-pdsp-diff_pixels(block,
-cur+x+y*linesize,
-ref+x+y*linesize, linesize);
-d = dspctx-sum_abs_dctelem(block);
+d = decimate-sad(cur + y*cur_linesize + x, cur_linesize,
+  ref + y*ref_linesize + x, ref_linesize);
 if (d  decimate-hi)
 return 1;
 if (d  decimate-lo) {
@@ -124,7 +117,8 @@ static int decimate_frame(AVFilterContext *ctx,
 int vsub = plane == 1 || plane == 2 ? decimate-vsub : 0;
 int hsub = plane == 1 || plane == 2 ? decimate-hsub : 0;
 if (diff_planes(ctx,
-cur-data[plane], ref-data[plane], 
ref-linesize[plane],
+cur-data[plane], cur-linesize[plane],
+ref-data[plane], ref-linesize[plane],
 FF_CEIL_RSHIFT(ref-width,  hsub),
 FF_CEIL_RSHIFT(ref-height, vsub)))
 return 0;
@@ -135,17 +129,23 @@ static int decimate_frame(AVFilterContext *ctx,
 
 static av_cold int init(AVFilterContext *ctx)
 {
+int ret;
 DecimateContext *decimate = ctx-priv;
 
+AVPixelUtils *pixels = av_pixelutils_alloc();
+if (!pixels)
+return AVERROR(ENOMEM);
+ret = av_pixelutils_init(pixels, decimate);
+if (ret  0) {
+av_free(pixels);
+return ret;
+}
+decimate-sad = pixels-sad_u[AV_PIXEL_BLOCKSZ_8x8];
+av_free(pixels);
+
 av_log(ctx, AV_LOG_VERBOSE, max_drop_count:%d hi:%d lo:%d frac:%f\n,
decimate-max_drop_count, decimate-hi, decimate-lo, 
decimate-frac);
 
-decimate-avctx = avcodec_alloc_context3(NULL);
-if (!decimate-avctx)
-return AVERROR(ENOMEM);
-avpriv_dsputil_init(decimate-dspctx, decimate-avctx);
-ff_pixblockdsp_init(decimate-pdsp, decimate-avctx);
-
 return 0;
 }
 
@@ -153,10 +153,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
 DecimateContext *decimate = ctx-priv;
 av_frame_free(decimate-ref);
-if (decimate-avctx) {
-avcodec_close(decimate-avctx);
-av_freep(decimate-avctx);
-}
 }
 
 static int query_formats(AVFilterContext *ctx)
-- 
2.0.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/5] avfilter/mp_decimate: remove avcodec dependency

2014-08-02 Thread Clément Bœsch
---
 configure   |  4 ++--
 libavfilter/vf_mpdecimate.c | 36 
 2 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/configure b/configure
index bc187a5..210cafb 100755
--- a/configure
+++ b/configure
@@ -2549,8 +2549,8 @@ ladspa_filter_extralibs='$ldl'
 mcdeint_filter_deps=avcodec gpl
 movie_filter_deps=avcodec avformat
 mp_filter_deps=gpl avcodec swscale inline_asm
-mpdecimate_filter_deps=gpl avcodec
-mpdecimate_filter_select=me_cmp pixblockdsp
+mpdecimate_filter_deps=gpl
+mpdecimate_filter_select=pixelutils
 mptestsrc_filter_deps=gpl
 negate_filter_deps=lut_filter
 perspective_filter_deps=gpl
diff --git a/libavfilter/vf_mpdecimate.c b/libavfilter/vf_mpdecimate.c
index c667a9f..3ed9602 100644
--- a/libavfilter/vf_mpdecimate.c
+++ b/libavfilter/vf_mpdecimate.c
@@ -26,9 +26,8 @@
 
 #include libavutil/opt.h
 #include libavutil/pixdesc.h
+#include libavutil/pixelutils.h
 #include libavutil/timestamp.h
-#include libavcodec/dsputil.h
-#include libavcodec/pixblockdsp.h
 #include avfilter.h
 #include internal.h
 #include formats.h
@@ -49,9 +48,7 @@ typedef struct {
 
 int hsub, vsub;/// chroma subsampling values
 AVFrame *ref;  /// reference picture
-DSPContext dspctx; /// context providing optimized diff 
routines
-PixblockDSPContext pdsp;
-AVCodecContext *avctx; /// codec context required for the 
DSPContext
+av_pixelutils_sad_fn sad;  /// sum of absolute difference function
 } DecimateContext;
 
 #define OFFSET(x) offsetof(DecimateContext, x)
@@ -72,25 +69,21 @@ AVFILTER_DEFINE_CLASS(mpdecimate);
  * Return 1 if the two planes are different, 0 otherwise.
  */
 static int diff_planes(AVFilterContext *ctx,
-   uint8_t *cur, uint8_t *ref, int linesize,
+   uint8_t *cur, int cur_linesize,
+   uint8_t *ref, int ref_linesize,
int w, int h)
 {
 DecimateContext *decimate = ctx-priv;
-DSPContext *dspctx = decimate-dspctx;
-PixblockDSPContext *pdsp = decimate-pdsp;
 
 int x, y;
 int d, c = 0;
 int t = (w/16)*(h/16)*decimate-frac;
-int16_t block[8*8];
 
 /* compute difference for blocks of 8x8 bytes */
 for (y = 0; y  h-7; y += 4) {
 for (x = 8; x  w-7; x += 4) {
-pdsp-diff_pixels(block,
-cur+x+y*linesize,
-ref+x+y*linesize, linesize);
-d = dspctx-sum_abs_dctelem(block);
+d = decimate-sad(cur + y*cur_linesize + x, cur_linesize,
+  ref + y*ref_linesize + x, ref_linesize);
 if (d  decimate-hi)
 return 1;
 if (d  decimate-lo) {
@@ -124,7 +117,8 @@ static int decimate_frame(AVFilterContext *ctx,
 int vsub = plane == 1 || plane == 2 ? decimate-vsub : 0;
 int hsub = plane == 1 || plane == 2 ? decimate-hsub : 0;
 if (diff_planes(ctx,
-cur-data[plane], ref-data[plane], 
ref-linesize[plane],
+cur-data[plane], cur-linesize[plane],
+ref-data[plane], ref-linesize[plane],
 FF_CEIL_RSHIFT(ref-width,  hsub),
 FF_CEIL_RSHIFT(ref-height, vsub)))
 return 0;
@@ -137,15 +131,13 @@ static av_cold int init(AVFilterContext *ctx)
 {
 DecimateContext *decimate = ctx-priv;
 
+decimate-sad = av_pixelutils_get_sad_fn(3, 3, 0, decimate); // 8x8, not 
aligned on blocksize
+if (!decimate-sad)
+return AVERROR(EINVAL);
+
 av_log(ctx, AV_LOG_VERBOSE, max_drop_count:%d hi:%d lo:%d frac:%f\n,
decimate-max_drop_count, decimate-hi, decimate-lo, 
decimate-frac);
 
-decimate-avctx = avcodec_alloc_context3(NULL);
-if (!decimate-avctx)
-return AVERROR(ENOMEM);
-avpriv_dsputil_init(decimate-dspctx, decimate-avctx);
-ff_pixblockdsp_init(decimate-pdsp, decimate-avctx);
-
 return 0;
 }
 
@@ -153,10 +145,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
 DecimateContext *decimate = ctx-priv;
 av_frame_free(decimate-ref);
-if (decimate-avctx) {
-avcodec_close(decimate-avctx);
-av_freep(decimate-avctx);
-}
 }
 
 static int query_formats(AVFilterContext *ctx)
-- 
2.0.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel