-static int decode_residual_block(AVSContext *h, GetBitContext *gb,
- const dec_2dvlc_t *r, int esc_golomb_order,
- int qp, uint8_t *dst, int stride) {
- int i, level_code, esc_code, level, run, mask;
- DCTELEM level_buf[64];
- uint8_t run_buf[64];
- DCTELEM *block = h->block;
-
- for(i=0;i<65;i++) {
- level_code = get_ue_code(gb,r->golomb_order);
- if(level_code >= ESCAPE_CODE) {
- run = ((level_code - ESCAPE_CODE) >> 1) + 1;
- esc_code = get_ue_code(gb,esc_golomb_order);
- level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
- while(level > r->inc_limit)
- r++;
- mask = -(level_code & 1);
- level = (level^mask) - mask;
- } else {
- level = r->rltab[level_code][0];
- if(!level) //end of block signal
- break;
- run = r->rltab[level_code][1];
- r += r->rltab[level_code][2];
- }
- level_buf[i] = level;
- run_buf[i] = run;
- }
- 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);
- return 0;
-}
-
-
-static inline void decode_residual_chroma(AVSContext *h) {
- if(h->cbp & (1<<4))
- decode_residual_block(h,&h->s.gb,ff_cavs_chroma_dec,0,
- ff_cavs_chroma_qp[h->qp],h->cu,h->c_stride);
- if(h->cbp & (1<<5))
- decode_residual_block(h,&h->s.gb,ff_cavs_chroma_dec,0,
- ff_cavs_chroma_qp[h->qp],h->cv,h->c_stride);
-}
-
-static inline int decode_residual_inter(AVSContext *h) {
- int block;
-
- /* get coded block pattern */
- int cbp= get_ue_golomb(&h->s.gb);
- if(cbp > 63){
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n");
- return -1;
- }
- h->cbp = cbp_tab[cbp][1];
-
- /* get quantizer */
- if(h->cbp && !h->qp_fixed)
- h->qp = (h->qp + get_se_golomb(&h->s.gb)) & 63;
- for(block=0;block<4;block++)
- if(h->cbp & (1<<block))
- decode_residual_block(h,&h->s.gb,ff_cavs_inter_dec,0,h->qp,
- h->cy + h->luma_scan[block], h->l_stride);
- decode_residual_chroma(h);
-
- return 0;
-}
-
-/*****************************************************************************
- *
- * macroblock level
- *
- ****************************************************************************/
-
-static int decode_mb_i(AVSContext *h, int cbp_code) {
- GetBitContext *gb = &h->s.gb;
- int block, pred_mode_uv;
- uint8_t top[18];
- uint8_t *left = NULL;
- uint8_t *d;
-
- init_mb(h);
-
- /* get intra prediction modes from stream */
- for(block=0;block<4;block++) {
- int nA,nB,predpred;
- int pos = ff_cavs_scan3x3[block];
-
- nA = h->pred_mode_Y[pos-1];
- nB = h->pred_mode_Y[pos-3];
- predpred = FFMIN(nA,nB);
- if(predpred == NOT_AVAIL) // if either is not available
- predpred = INTRA_L_LP;
- if(!get_bits1(gb)){
- int rem_mode= get_bits(gb, 2);
- predpred = rem_mode + (rem_mode >= predpred);
- }
- h->pred_mode_Y[pos] = predpred;
- }
- pred_mode_uv = get_ue_golomb(gb);
- if(pred_mode_uv > 6) {
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
- return -1;
- }
- modify_mb_i(h, &pred_mode_uv);
-
- /* get coded block pattern */
- if(h->pic_type == FF_I_TYPE)
- cbp_code = get_ue_golomb(gb);
- if(cbp_code > 63){
- av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n");
- return -1;
- }
- h->cbp = cbp_tab[cbp_code][0];
- if(h->cbp && !h->qp_fixed)
- h->qp = (h->qp + get_se_golomb(gb)) & 63; //qp_delta
-
- /* luma intra prediction interleaved with residual decode/transform/add */
- for(block=0;block<4;block++) {
- d = h->cy + h->luma_scan[block];
- load_intra_pred_luma(h, top, &left, block);
- h->intra_pred_l[h->pred_mode_Y[ff_cavs_scan3x3[block]]]
- (d, top, left, h->l_stride);
- if(h->cbp & (1<<block))
- decode_residual_block(h,gb,ff_cavs_intra_dec,1,h->qp,d,h->l_stride);
- }
-
- /* chroma intra prediction */
- load_intra_pred_chroma(h);
- h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10],
- h->left_border_u, h->c_stride);
- h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10],
- h->left_border_v, h->c_stride);
-
- decode_residual_chroma(h);
- ff_cavs_filter(h,I_8X8);
- set_mv_intra(h);
- return 0;
-}
-
-static void decode_mb_p(AVSContext *h, enum mb_t mb_type) {
- GetBitContext *gb = &h->s.gb;
- int ref[4];
-
- init_mb(h);
- switch(mb_type) {
- case P_SKIP:
- ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0);
- break;
- case P_16X16:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]);
- break;
- case P_16X8:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ref[2] = h->ref_flag ? 0 : get_bits1(gb);
- ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]);
- ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]);
- break;
- case P_8X16:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ref[1] = h->ref_flag ? 0 : get_bits1(gb);
- ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]);
- ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, ref[1]);
- break;
- case P_8X8:
- ref[0] = h->ref_flag ? 0 : get_bits1(gb);
- ref[1] = h->ref_flag ? 0 : get_bits1(gb);
- ref[2] = h->ref_flag ? 0 : get_bits1(gb);
- ref[3] = h->ref_flag ? 0 : get_bits1(gb);
- ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]);
- ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]);
- ff_cavs_mv(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]);
- ff_cavs_mv(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]);
- }
- ff_cavs_inter(h, mb_type);
- set_intra_mode_default(h);
- store_mvs(h);
- if(mb_type != P_SKIP)
- decode_residual_inter(h);
- ff_cavs_filter(h,mb_type);
- *h->col_type = mb_type;
-}
-
-static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
- int block;
- enum sub_mb_t sub_type[4];
- int flags;
-
- init_mb(h);