[FFmpeg-devel] [PATCH 2/3] avfilter: use AVDSP

Michael Niedermayer michaelni at gmx.at
Sat Jul 26 15:34:07 CEST 2014


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavfilter/deshake.h       |    5 ++---
 libavfilter/f_select.c      |   20 ++++++++------------
 libavfilter/vf_deshake.c    |   16 +++++++---------
 libavfilter/vf_mpdecimate.c |   26 +++++++++-----------------
 libavfilter/vf_spp.c        |   21 ++++++++-------------
 libavfilter/vf_spp.h        |    9 ++-------
 6 files changed, 36 insertions(+), 61 deletions(-)

diff --git a/libavfilter/deshake.h b/libavfilter/deshake.h
index 615953c..0d74db9 100644
--- a/libavfilter/deshake.h
+++ b/libavfilter/deshake.h
@@ -24,7 +24,7 @@
 
 #include "config.h"
 #include "avfilter.h"
-#include "libavcodec/dsputil.h"
+#include "libavcodec/avdsp.h"
 #include "transform.h"
 #if CONFIG_OPENCL
 #include "libavutil/opencl.h"
@@ -80,8 +80,7 @@ typedef struct {
     int blocksize;             ///< Size of blocks to compare
     int contrast;              ///< Contrast threshold
     int search;                ///< Motion search method
-    AVCodecContext *avctx;
-    DSPContext c;              ///< Context providing optimized SAD methods
+    AVDSP *dsp;                ///< Context providing optimized SAD methods
     Transform last;            ///< Transform from last frame
     int refcount;              ///< Number of reference frames (defines averaging window)
     FILE *fp;
diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index c7c53b4..374ffe1 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -35,7 +35,7 @@
 #include "video.h"
 
 #if CONFIG_AVCODEC
-#include "libavcodec/dsputil.h"
+#include "libavcodec/avdsp.h"
 #endif
 
 static const char *const var_names[] = {
@@ -145,8 +145,7 @@ typedef struct SelectContext {
     double var_values[VAR_VARS_NB];
     int do_scene_detect;            ///< 1 if the expression requires scene detection variables, 0 otherwise
 #if CONFIG_AVCODEC
-    AVCodecContext *avctx;          ///< codec context required for the DSPContext (scene detect only)
-    DSPContext c;                   ///< context providing optimized SAD methods   (scene detect only)
+    AVDSP *dsp;                     ///< context providing optimized SAD methods   (scene detect only)
     double prev_mafd;               ///< previous MAFD                             (scene detect only)
 #endif
     AVFrame *prev_picref; ///< previous frame                            (scene detect only)
@@ -242,10 +241,10 @@ static int config_input(AVFilterLink *inlink)
 
 #if CONFIG_AVCODEC
     if (select->do_scene_detect) {
-        select->avctx = avcodec_alloc_context3(NULL);
-        if (!select->avctx)
+        select->dsp = avcodec_dsp_alloc();
+        if (!select->dsp)
             return AVERROR(ENOMEM);
-        avpriv_dsputil_init(&select->c, select->avctx);
+        avcodec_dsp_init(select->dsp);
     }
 #endif
     return 0;
@@ -271,8 +270,8 @@ static double get_scene_score(AVFilterContext *ctx, AVFrame *frame)
 
         for (y = 0; y < frame->height - 8; y += 8) {
             for (x = 0; x < frame->width*3 - 8; x += 8) {
-                sad += select->c.sad[1](NULL, p1 + x, p2 + x,
-                                        linesize, 8);
+                sad += select->dsp->sad[1](NULL, p1 + x, p2 + x,
+                                           linesize, 8);
                 nb_sad += 8 * 8;
             }
             p1 += 8 * linesize;
@@ -421,10 +420,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 #if CONFIG_AVCODEC
     if (select->do_scene_detect) {
         av_frame_free(&select->prev_picref);
-        if (select->avctx) {
-            avcodec_close(select->avctx);
-            av_freep(&select->avctx);
-        }
+        av_freep(&select->dsp);
     }
 #endif
 }
diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
index 50aa451..565ea3a 100644
--- a/libavfilter/vf_deshake.c
+++ b/libavfilter/vf_deshake.c
@@ -57,7 +57,7 @@
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "libavcodec/dsputil.h"
+#include "libavcodec/avdsp.h"
 
 #include "deshake.h"
 #include "deshake_opencl.h"
@@ -132,9 +132,9 @@ static void find_block_motion(DeshakeContext *deshake, uint8_t *src1,
     int smallest = INT_MAX;
     int tmp, tmp2;
 
-    #define CMP(i, j) deshake->c.sad[0](NULL, src1 + cy * stride + cx, \
-                                        src2 + (j) * stride + (i), stride, \
-                                        deshake->blocksize)
+    #define CMP(i, j) deshake->dsp->sad[0](NULL, src1 + cy * stride + cx, \
+                                            src2 + (j) * stride + (i), stride, \
+                                            deshake->blocksize)
 
     if (deshake->search == EXHAUSTIVE) {
         // Compare every possible position - this is sloooow!
@@ -413,8 +413,8 @@ static int config_props(AVFilterLink *link)
     deshake->last.angle = 0;
     deshake->last.zoom = 0;
 
-    deshake->avctx = avcodec_alloc_context3(NULL);
-    avpriv_dsputil_init(&deshake->c, deshake->avctx);
+    deshake->dsp = avcodec_dsp_alloc();
+    avcodec_dsp_init(deshake->dsp);
 
     return 0;
 }
@@ -428,9 +428,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_frame_free(&deshake->ref);
     if (deshake->fp)
         fclose(deshake->fp);
-    if (deshake->avctx)
-        avcodec_close(deshake->avctx);
-    av_freep(&deshake->avctx);
+    av_freep(&deshake->dsp);
 }
 
 static int filter_frame(AVFilterLink *link, AVFrame *in)
diff --git a/libavfilter/vf_mpdecimate.c b/libavfilter/vf_mpdecimate.c
index c667a9f..e24f7dd 100644
--- a/libavfilter/vf_mpdecimate.c
+++ b/libavfilter/vf_mpdecimate.c
@@ -27,8 +27,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/timestamp.h"
-#include "libavcodec/dsputil.h"
-#include "libavcodec/pixblockdsp.h"
+#include "libavcodec/avdsp.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
+    AVDSP *dsp;             ///< context providing optimized diff routines
 } DecimateContext;
 
 #define OFFSET(x) offsetof(DecimateContext, x)
@@ -76,8 +73,7 @@ static int diff_planes(AVFilterContext *ctx,
                        int w, int h)
 {
     DecimateContext *decimate = ctx->priv;
-    DSPContext *dspctx = &decimate->dspctx;
-    PixblockDSPContext *pdsp = &decimate->pdsp;
+    AVDSP *dsp = decimate->dsp;
 
     int x, y;
     int d, c = 0;
@@ -87,10 +83,10 @@ static int diff_planes(AVFilterContext *ctx,
     /* 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,
+            dsp->diff_pixels(block,
                                 cur+x+y*linesize,
                                 ref+x+y*linesize, linesize);
-            d = dspctx->sum_abs_dctelem(block);
+            d = dsp->sum_abs_dctelem(block);
             if (d > decimate->hi)
                 return 1;
             if (d > decimate->lo) {
@@ -140,11 +136,10 @@ static av_cold int init(AVFilterContext *ctx)
     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)
+    decimate->dsp = avcodec_dsp_alloc();
+    if (!decimate->dsp)
         return AVERROR(ENOMEM);
-    avpriv_dsputil_init(&decimate->dspctx, decimate->avctx);
-    ff_pixblockdsp_init(&decimate->pdsp, decimate->avctx);
+    avcodec_dsp_init(decimate->dsp);
 
     return 0;
 }
@@ -153,10 +148,7 @@ 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);
-    }
+    av_freep(&decimate->dsp);
 }
 
 static int query_formats(AVFilterContext *ctx)
diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c
index bb85778..0327f1e 100644
--- a/libavfilter/vf_spp.c
+++ b/libavfilter/vf_spp.c
@@ -231,10 +231,10 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src,
                 const int x1 = x + offset[i + count - 1][0];
                 const int y1 = y + offset[i + count - 1][1];
                 const int index = x1 + y1*linesize;
-                p->pdsp.get_pixels(block, p->src + index, linesize);
-                p->fdsp.fdct(block);
-                p->requantize(block2, block, qp, p->idsp.idct_permutation);
-                p->idsp.idct(block2);
+                p->dsp->get_pixels(block, p->src + index, linesize);
+                p->dsp->fdct(block);
+                p->requantize(block2, block, qp, p->dsp->idct_permutation);
+                p->dsp->idct(block2);
                 add_block(p->temp + index, linesize, block2);
             }
         }
@@ -376,12 +376,10 @@ static av_cold int init(AVFilterContext *ctx)
 {
     SPPContext *spp = ctx->priv;
 
-    spp->avctx = avcodec_alloc_context3(NULL);
-    if (!spp->avctx)
+    spp->dsp = avcodec_dsp_alloc();
+    if (!spp->dsp)
         return AVERROR(ENOMEM);
-    ff_idctdsp_init(&spp->idsp, spp->avctx);
-    ff_fdctdsp_init(&spp->fdsp, spp->avctx);
-    ff_pixblockdsp_init(&spp->pdsp, spp->avctx);
+    avcodec_dsp_init(spp->dsp);
     spp->store_slice = store_slice_c;
     switch (spp->mode) {
     case MODE_HARD: spp->requantize = hardthresh_c; break;
@@ -398,10 +396,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     av_freep(&spp->temp);
     av_freep(&spp->src);
-    if (spp->avctx) {
-        avcodec_close(spp->avctx);
-        av_freep(&spp->avctx);
-    }
+    av_freep(&spp->dsp);
     av_freep(&spp->non_b_qp_table);
 }
 
diff --git a/libavfilter/vf_spp.h b/libavfilter/vf_spp.h
index c8eac3c..f6c54c9 100644
--- a/libavfilter/vf_spp.h
+++ b/libavfilter/vf_spp.h
@@ -23,9 +23,7 @@
 #define AVFILTER_SPP_H
 
 #include "libavcodec/avcodec.h"
-#include "libavcodec/pixblockdsp.h"
-#include "libavcodec/idctdsp.h"
-#include "libavcodec/fdctdsp.h"
+#include "libavcodec/avdsp.h"
 #include "avfilter.h"
 
 #define MAX_LEVEL 6 /* quality levels */
@@ -40,10 +38,7 @@ typedef struct {
     int temp_linesize;
     uint8_t *src;
     int16_t *temp;
-    AVCodecContext *avctx;
-    IDCTDSPContext idsp;
-    FDCTDSPContext fdsp;
-    PixblockDSPContext pdsp;
+    AVDSP *dsp;
     int8_t *non_b_qp_table;
     int non_b_qp_alloc_size;
     int use_bframe_qp;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list