From f079a64aea0d19dd7adfc045747cd4b4dfb6225c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5ns=20Rullg=C3=A5rd?= Date: Tue, 3 Aug 2010 20:59:00 +0000 Subject: [PATCH] Move cavs dsp functions to their own struct Originally committed as revision 24685 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/cavs.c | 37 ++++++++++++++++---------------- libavcodec/cavs.h | 2 ++ libavcodec/cavsdec.c | 2 +- libavcodec/cavsdsp.c | 5 ++++- libavcodec/cavsdsp.h | 41 ++++++++++++++++++++++++++++++++++++ libavcodec/dsputil.c | 4 ---- libavcodec/dsputil.h | 10 --------- libavcodec/x86/cavsdsp_mmx.c | 13 ++++++++++-- libavcodec/x86/dsputil_mmx.c | 6 ------ libavcodec/x86/dsputil_mmx.h | 2 -- 10 files changed, 78 insertions(+), 44 deletions(-) create mode 100644 libavcodec/cavsdsp.h diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index ff6c86964a..3958cf8093 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -113,22 +113,22 @@ void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) { if(h->flags & A_AVAIL) { qp_avg = (h->qp + h->left_qp + 1) >> 1; SET_PARAMS; - h->s.dsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]); - h->s.dsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]); - h->s.dsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]); + h->cdsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]); + h->cdsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]); + h->cdsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]); } qp_avg = h->qp; SET_PARAMS; - h->s.dsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]); - h->s.dsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc, + h->cdsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]); + h->cdsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc, bs[6],bs[7]); if(h->flags & B_AVAIL) { qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1; SET_PARAMS; - h->s.dsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]); - h->s.dsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]); - h->s.dsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]); + h->cdsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]); + h->cdsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]); + h->cdsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]); } } } @@ -414,30 +414,30 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) { if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16 mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0, - h->s.dsp.put_cavs_qpel_pixels_tab[0], + h->cdsp.put_cavs_qpel_pixels_tab[0], h->s.dsp.put_h264_chroma_pixels_tab[0], - h->s.dsp.avg_cavs_qpel_pixels_tab[0], + h->cdsp.avg_cavs_qpel_pixels_tab[0], h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]); }else{ mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0, - h->s.dsp.put_cavs_qpel_pixels_tab[1], + h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], - h->s.dsp.avg_cavs_qpel_pixels_tab[1], + h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]); mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0, - h->s.dsp.put_cavs_qpel_pixels_tab[1], + h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], - h->s.dsp.avg_cavs_qpel_pixels_tab[1], + h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]); mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4, - h->s.dsp.put_cavs_qpel_pixels_tab[1], + h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], - h->s.dsp.avg_cavs_qpel_pixels_tab[1], + h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]); mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4, - h->s.dsp.put_cavs_qpel_pixels_tab[1], + h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], - h->s.dsp.avg_cavs_qpel_pixels_tab[1], + h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]); } } @@ -672,6 +672,7 @@ av_cold int ff_cavs_init(AVCodecContext *avctx) { MpegEncContext * const s = &h->s; MPV_decode_defaults(s); + ff_cavsdsp_init(&h->cdsp, avctx); s->avctx = avctx; avctx->pix_fmt= PIX_FMT_YUV420P; diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h index 729c83ea7b..dfa320fa84 100644 --- a/libavcodec/cavs.h +++ b/libavcodec/cavs.h @@ -24,6 +24,7 @@ #include "dsputil.h" #include "mpegvideo.h" +#include "cavsdsp.h" #define SLICE_MAX_START_CODE 0x000001af #define EXT_START_CODE 0x000001b5 @@ -153,6 +154,7 @@ struct dec_2dvlc { typedef struct { MpegEncContext s; + CAVSDSPContext cdsp; Picture picture; ///< currently decoded frame Picture DPB[2]; ///< reference frames int dist[2]; ///< temporal distances from current frame to ref frames diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 9d6307c217..9845fb47fc 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -143,7 +143,7 @@ static int decode_residual_block(AVSContext *h, GetBitContext *gb, if(dequant(h,level_buf, run_buf, block, ff_cavs_dequant_mul[qp], ff_cavs_dequant_shift[qp], i)) return -1; - h->s.dsp.cavs_idct8_add(dst,block,stride); + h->cdsp.cavs_idct8_add(dst,block,stride); h->s.dsp.clear_block(block); return 0; } diff --git a/libavcodec/cavsdsp.c b/libavcodec/cavsdsp.c index 808f62b69f..3593cfa05a 100644 --- a/libavcodec/cavsdsp.c +++ b/libavcodec/cavsdsp.c @@ -24,6 +24,7 @@ #include #include "dsputil.h" +#include "cavsdsp.h" /***************************************************************************** * @@ -510,7 +511,7 @@ CAVS_MC(put_, 16) CAVS_MC(avg_, 8) CAVS_MC(avg_, 16) -av_cold void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx) { +av_cold void ff_cavsdsp_init(CAVSDSPContext* c, AVCodecContext *avctx) { #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_c; \ c->PFX ## _pixels_tab[IDX][ 1] = ff_ ## PFX ## NUM ## _mc10_c; \ @@ -537,4 +538,6 @@ av_cold void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx) { c->cavs_filter_cv = cavs_filter_cv_c; c->cavs_filter_ch = cavs_filter_ch_c; c->cavs_idct8_add = cavs_idct8_add_c; + + if (HAVE_MMX) ff_cavsdsp_init_mmx(c, avctx); } diff --git a/libavcodec/cavsdsp.h b/libavcodec/cavsdsp.h new file mode 100644 index 0000000000..d3fae69e84 --- /dev/null +++ b/libavcodec/cavsdsp.h @@ -0,0 +1,41 @@ +/* + * Chinese AVS video (AVS1-P2, JiZhun profile) decoder. + * Copyright (c) 2006 Stefan Gehrer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_CAVSDSP_H +#define AVCODEC_CAVSDSP_H + +#include +#include "dsputil.h" + +typedef struct CAVSDSPContext { + qpel_mc_func put_cavs_qpel_pixels_tab[2][16]; + qpel_mc_func avg_cavs_qpel_pixels_tab[2][16]; + void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride); +} CAVSDSPContext; + +void ff_cavsdsp_init(CAVSDSPContext* c, AVCodecContext *avctx); +void ff_cavsdsp_init_mmx(CAVSDSPContext* c, AVCodecContext *avctx); + +#endif diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index a6424bb512..534f03f885 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -4343,10 +4343,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->draw_edges = draw_edges_c; -#if CONFIG_CAVS_DECODER - ff_cavsdsp_init(c,avctx); -#endif - #if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER ff_mlp_init(c, avctx); #endif diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index d67483679c..9ef0270ade 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -339,15 +339,6 @@ typedef struct DSPContext { qpel_mc_func put_2tap_qpel_pixels_tab[4][16]; qpel_mc_func avg_2tap_qpel_pixels_tab[4][16]; - /* AVS specific */ - qpel_mc_func put_cavs_qpel_pixels_tab[2][16]; - qpel_mc_func avg_cavs_qpel_pixels_tab[2][16]; - void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); - void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); - void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); - void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); - void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride); - me_cmp_func pix_abs[2][4]; /* huffyuv specific */ @@ -640,7 +631,6 @@ void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); void ff_dsputil_init_dwt(DSPContext *c); -void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx); void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx); void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx); void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx); diff --git a/libavcodec/x86/cavsdsp_mmx.c b/libavcodec/x86/cavsdsp_mmx.c index e8c7065fd7..7872b3cced 100644 --- a/libavcodec/x86/cavsdsp_mmx.c +++ b/libavcodec/x86/cavsdsp_mmx.c @@ -25,6 +25,7 @@ #include "libavutil/common.h" #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" +#include "libavcodec/cavsdsp.h" #include "dsputil_mmx.h" /***************************************************************************** @@ -437,7 +438,7 @@ CAVS_MC(put_, 16,mmx2) CAVS_MC(avg_, 8, mmx2) CAVS_MC(avg_, 16,mmx2) -void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx) { +static void ff_cavsdsp_init_mmx2(CAVSDSPContext* c, AVCodecContext *avctx) { #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmx2; \ c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_mmx2; \ @@ -453,7 +454,7 @@ void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx) { c->cavs_idct8_add = cavs_idct8_add_mmx; } -void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx) { +static void ff_cavsdsp_init_3dnow(CAVSDSPContext* c, AVCodecContext *avctx) { #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmx2; \ c->PFX ## _pixels_tab[IDX][ 2] = ff_ ## PFX ## NUM ## _mc20_3dnow; \ @@ -468,3 +469,11 @@ void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx) { #undef dspfunc c->cavs_idct8_add = cavs_idct8_add_mmx; } + +void ff_cavsdsp_init_mmx(CAVSDSPContext *c, AVCodecContext *avctx) +{ + int mm_flags = mm_support(); + + if (mm_flags & FF_MM_MMX2) ff_cavsdsp_init_mmx2 (c, avctx); + if (mm_flags & FF_MM_3DNOW) ff_cavsdsp_init_3dnow(c, avctx); +} diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index 79d4bfce29..f06d4e5a5a 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -2727,9 +2727,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov; #endif - if (CONFIG_CAVS_DECODER) - ff_cavsdsp_init_mmx2(c, avctx); - if (CONFIG_VC1_DECODER) ff_vc1dsp_init_mmx(c, avctx); @@ -2790,9 +2787,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_3dnow; c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_3dnow; - - if (CONFIG_CAVS_DECODER) - ff_cavsdsp_init_3dnow(c, avctx); } diff --git a/libavcodec/x86/dsputil_mmx.h b/libavcodec/x86/dsputil_mmx.h index 5de1c908f1..116a9c68a5 100644 --- a/libavcodec/x86/dsputil_mmx.h +++ b/libavcodec/x86/dsputil_mmx.h @@ -162,8 +162,6 @@ void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); -void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx); -void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx); void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);