From ef07ac1e126b95ad7e1b56504c19b59901265c3e Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 26 Aug 2012 09:19:33 +0200 Subject: cavs: Move data tables used in only one place to that file --- libavcodec/cavs.c | 68 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 19 deletions(-) (limited to 'libavcodec/cavs.c') diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index 42922e08dd..c3eebfabbb 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -32,6 +32,36 @@ #include "cavs.h" #include "cavsdata.h" +static const uint8_t alpha_tab[64] = { + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, + 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 18, 20, + 22, 24, 26, 28, 30, 33, 33, 35, 35, 36, 37, 37, 39, 39, 42, 44, + 46, 48, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64 +}; + +static const uint8_t beta_tab[64] = { + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, + 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27 +}; + +static const uint8_t tc_tab[64] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, + 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9 +}; + +/** mark block as unavailable, i.e. out of picture + or not yet decoded */ +static const cavs_vector un_mv = { 0, 0, 1, NOT_AVAIL }; + +static const int8_t left_modifier_l[8] = { 0, -1, 6, -1, -1, 7, 6, 7 }; +static const int8_t top_modifier_l[8] = { -1, 1, 5, -1, -1, 5, 7, 7 }; +static const int8_t left_modifier_c[7] = { 5, -1, 2, -1, 6, 5, 6 }; +static const int8_t top_modifier_c[7] = { 4, 1, -1, -1, 4, 6, 6 }; + /***************************************************************************** * * in-loop deblocking filter @@ -307,14 +337,14 @@ void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) { /* modify pred modes according to availability of neighbour samples */ if(!(h->flags & A_AVAIL)) { - modify_pred(ff_left_modifier_l, &h->pred_mode_Y[4] ); - modify_pred(ff_left_modifier_l, &h->pred_mode_Y[7] ); - modify_pred(ff_left_modifier_c, pred_mode_uv ); + modify_pred(left_modifier_l, &h->pred_mode_Y[4]); + modify_pred(left_modifier_l, &h->pred_mode_Y[7]); + modify_pred(left_modifier_c, pred_mode_uv); } if(!(h->flags & B_AVAIL)) { - modify_pred(ff_top_modifier_l, &h->pred_mode_Y[4] ); - modify_pred(ff_top_modifier_l, &h->pred_mode_Y[5] ); - modify_pred(ff_top_modifier_c, pred_mode_uv ); + modify_pred(top_modifier_l, &h->pred_mode_Y[4]); + modify_pred(top_modifier_l, &h->pred_mode_Y[5]); + modify_pred(top_modifier_c, pred_mode_uv); } } @@ -496,7 +526,7 @@ void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC, ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) || ((mvA->x | mvA->y | mvA->ref) == 0) || ((mvB->x | mvB->y | mvB->ref) == 0) )) { - mvP2 = &ff_cavs_un_mv; + mvP2 = &un_mv; /* if there is only one suitable candidate, take it */ } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) { mvP2= mvA; @@ -545,10 +575,10 @@ void ff_cavs_init_mb(AVSContext *h) { h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1]; /* clear top predictors if MB B is not available */ if(!(h->flags & B_AVAIL)) { - h->mv[MV_FWD_B2] = ff_cavs_un_mv; - h->mv[MV_FWD_B3] = ff_cavs_un_mv; - h->mv[MV_BWD_B2] = ff_cavs_un_mv; - h->mv[MV_BWD_B3] = ff_cavs_un_mv; + h->mv[MV_FWD_B2] = un_mv; + h->mv[MV_FWD_B3] = un_mv; + h->mv[MV_BWD_B2] = un_mv; + h->mv[MV_BWD_B3] = un_mv; h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL; h->flags &= ~(C_AVAIL|D_AVAIL); } else if(h->mbx) { @@ -558,13 +588,13 @@ void ff_cavs_init_mb(AVSContext *h) { h->flags &= ~C_AVAIL; /* clear top-right predictors if MB C is not available */ if(!(h->flags & C_AVAIL)) { - h->mv[MV_FWD_C2] = ff_cavs_un_mv; - h->mv[MV_BWD_C2] = ff_cavs_un_mv; + h->mv[MV_FWD_C2] = un_mv; + h->mv[MV_BWD_C2] = un_mv; } /* clear top-left predictors if MB D is not available */ if(!(h->flags & D_AVAIL)) { - h->mv[MV_FWD_D3] = ff_cavs_un_mv; - h->mv[MV_BWD_D3] = ff_cavs_un_mv; + h->mv[MV_FWD_D3] = un_mv; + h->mv[MV_BWD_D3] = un_mv; } } @@ -597,7 +627,7 @@ int ff_cavs_next_mb(AVSContext *h) { h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; /* clear left mv predictors */ for(i=0;i<=20;i+=4) - h->mv[i] = ff_cavs_un_mv; + h->mv[i] = un_mv; h->mbx = 0; h->mby++; /* re-calculate sample pointers */ @@ -622,7 +652,7 @@ void ff_cavs_init_pic(AVSContext *h) { /* clear some predictors */ for(i=0;i<=20;i+=4) - h->mv[i] = ff_cavs_un_mv; + h->mv[i] = un_mv; h->mv[MV_BWD_X0] = ff_cavs_dir_mv; set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); h->mv[MV_FWD_X0] = ff_cavs_dir_mv; @@ -693,8 +723,8 @@ av_cold int ff_cavs_init(AVCodecContext *avctx) { h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left; h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top; h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128; - h->mv[ 7] = ff_cavs_un_mv; - h->mv[19] = ff_cavs_un_mv; + h->mv[ 7] = un_mv; + h->mv[19] = un_mv; return 0; } -- cgit v1.2.3 From a6d9f9e60e090d3ef1be6c8497d3f5eaa7bd4e2e Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 26 Aug 2012 09:57:19 +0200 Subject: cavs: Move inline functions only used in one file out of the header --- libavcodec/cavs.c | 9 +++++++++ libavcodec/cavs.h | 48 ------------------------------------------------ libavcodec/cavsdec.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 48 deletions(-) (limited to 'libavcodec/cavs.c') diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index c3eebfabbb..1188974dc9 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -328,6 +328,15 @@ static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) #undef LOWPASS +static inline void modify_pred(const int8_t *mod_table, int *mode) +{ + *mode = mod_table[*mode]; + if(*mode < 0) { + av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); + *mode = 0; + } +} + void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) { /* save pred modes before they get modified */ h->pred_mode_Y[3] = h->pred_mode_Y[5]; diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h index e18503ba4b..8f5da54b3a 100644 --- a/libavcodec/cavs.h +++ b/libavcodec/cavs.h @@ -229,25 +229,6 @@ extern const uint8_t ff_cavs_partition_flags[30]; extern const cavs_vector ff_cavs_intra_mv; extern const cavs_vector ff_cavs_dir_mv; -static inline void modify_pred(const int8_t *mod_table, int *mode) -{ - *mode = mod_table[*mode]; - if(*mode < 0) { - av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); - *mode = 0; - } -} - -static inline void set_intra_mode_default(AVSContext *h) { - if(h->stream_revision > 0) { - h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; - h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = NOT_AVAIL; - } else { - h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP; - h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP; - } -} - static inline void set_mvs(cavs_vector *mv, enum cavs_block size) { switch(size) { case BLK_16X16: @@ -262,35 +243,6 @@ static inline void set_mvs(cavs_vector *mv, enum cavs_block size) { } } -static inline void set_mv_intra(AVSContext *h) { - h->mv[MV_FWD_X0] = ff_cavs_intra_mv; - set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); - h->mv[MV_BWD_X0] = ff_cavs_intra_mv; - set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); - if(h->pic_type != AV_PICTURE_TYPE_B) - h->col_type_base[h->mbidx] = I_8X8; -} - -static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf, - DCTELEM *dst, int mul, int shift, int coeff_num) { - int round = 1 << (shift - 1); - int pos = -1; - const uint8_t *scantab = h->scantable.permutated; - - /* inverse scan and dequantization */ - while(--coeff_num >= 0){ - pos += run_buf[coeff_num]; - if(pos > 63) { - av_log(h->s.avctx, AV_LOG_ERROR, - "position out of block bounds at pic %d MB(%d,%d)\n", - h->picture.poc, h->mbx, h->mby); - return -1; - } - dst[scantab[pos]] = (level_buf[coeff_num]*mul + round) >> shift; - } - return 0; -} - void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type); void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, int block); diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 8dae8911eb..e70dad038a 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -511,6 +511,26 @@ static inline int get_ue_code(GetBitContext *gb, int order) { return get_ue_golomb(gb); } +static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf, + DCTELEM *dst, int mul, int shift, int coeff_num) { + int round = 1 << (shift - 1); + int pos = -1; + const uint8_t *scantab = h->scantable.permutated; + + /* inverse scan and dequantization */ + while(--coeff_num >= 0){ + pos += run_buf[coeff_num]; + if(pos > 63) { + av_log(h->s.avctx, AV_LOG_ERROR, + "position out of block bounds at pic %d MB(%d,%d)\n", + h->picture.poc, h->mbx, h->mby); + return -1; + } + dst[scantab[pos]] = (level_buf[coeff_num]*mul + round) >> shift; + } + return 0; +} + /** * decode coefficients from one 8x8 block, dequantize, inverse transform * and add them to sample block @@ -597,6 +617,15 @@ static inline int decode_residual_inter(AVSContext *h) { * ****************************************************************************/ +static inline void set_mv_intra(AVSContext *h) { + h->mv[MV_FWD_X0] = ff_cavs_intra_mv; + set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); + h->mv[MV_BWD_X0] = ff_cavs_intra_mv; + set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); + if(h->pic_type != AV_PICTURE_TYPE_B) + h->col_type_base[h->mbidx] = I_8X8; +} + static int decode_mb_i(AVSContext *h, int cbp_code) { GetBitContext *gb = &h->s.gb; unsigned pred_mode_uv; @@ -664,6 +693,16 @@ static int decode_mb_i(AVSContext *h, int cbp_code) { return 0; } +static inline void set_intra_mode_default(AVSContext *h) { + if(h->stream_revision > 0) { + h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; + h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = NOT_AVAIL; + } else { + h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP; + h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP; + } +} + static void decode_mb_p(AVSContext *h, enum cavs_mb mb_type) { GetBitContext *gb = &h->s.gb; int ref[4]; -- cgit v1.2.3 From 88386feefd52f3d4292b9be26d299e1bb74ef703 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 26 Aug 2012 09:59:41 +0200 Subject: cavs: convert cavsdata.h to a .c file Defining tables in header files is ugly and prone to duplication. Signed-off-by: Diego Biurrun --- libavcodec/Makefile | 2 +- libavcodec/cavs.c | 1 - libavcodec/cavsdata.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 libavcodec/cavsdata.c (limited to 'libavcodec/cavs.c') diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 5219a00290..394966e2fd 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -117,7 +117,7 @@ OBJS-$(CONFIG_BMV_VIDEO_DECODER) += bmv.o OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmv.o OBJS-$(CONFIG_C93_DECODER) += c93.o OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \ - mpeg12data.o + cavsdata.o mpeg12data.o OBJS-$(CONFIG_CDGRAPHICS_DECODER) += cdgraphics.o OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index 1188974dc9..02d572ee11 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -30,7 +30,6 @@ #include "golomb.h" #include "mathops.h" #include "cavs.h" -#include "cavsdata.h" static const uint8_t alpha_tab[64] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, diff --git a/libavcodec/cavsdata.c b/libavcodec/cavsdata.c new file mode 100644 index 0000000000..4e4a131987 --- /dev/null +++ b/libavcodec/cavsdata.c @@ -0,0 +1,62 @@ +/* + * Chinese AVS video (AVS1-P2, JiZhun profile) decoder. + * Copyright (c) 2006 Stefan Gehrer + * + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "cavs.h" + +const uint8_t ff_cavs_partition_flags[30] = { + 0, //I_8X8 + 0, //P_SKIP + 0, //P_16X16 + SPLITH, //P_16X8 + SPLITV, //P_8X16 + SPLITH|SPLITV, //P_8X8 + SPLITH|SPLITV, //B_SKIP + SPLITH|SPLITV, //B_DIRECT + 0, //B_FWD_16X16 + 0, //B_BWD_16X16 + 0, //B_SYM_16X16 + FWD0|FWD1 |SPLITH, + FWD0|FWD1 |SPLITV, + BWD0|BWD1 |SPLITH, + BWD0|BWD1 |SPLITV, + FWD0|BWD1 |SPLITH, + FWD0|BWD1 |SPLITV, + BWD0|FWD1 |SPLITH, + BWD0|FWD1 |SPLITV, + FWD0|FWD1 |SYM1|SPLITH, + FWD0|FWD1 |SYM1 |SPLITV, + BWD0|FWD1 |SYM1|SPLITH, + BWD0|FWD1 |SYM1 |SPLITV, + FWD0|FWD1|SYM0 |SPLITH, + FWD0|FWD1|SYM0 |SPLITV, + FWD0|BWD1|SYM0 |SPLITH, + FWD0|BWD1|SYM0 |SPLITV, + FWD0|FWD1|SYM0|SYM1|SPLITH, + FWD0|FWD1|SYM0|SYM1 |SPLITV, + SPLITH|SPLITV, //B_8X8 = 29 +}; + +/** mark block as "no prediction from this direction" + e.g. forward motion vector in BWD partition */ +const cavs_vector ff_cavs_dir_mv = {0,0,1,REF_DIR}; + +/** mark block as using intra prediction */ +const cavs_vector ff_cavs_intra_mv = {0,0,1,REF_INTRA}; -- cgit v1.2.3