vc1.c

来自「linux下的MPEG1」· C语言 代码 · 共 1,909 行 · 第 1/5 页

C
1,909
字号
        {            v->ttmbf = get_bits(gb, 1);            if (v->ttmbf)            {                v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];            }        } else {            v->ttmbf = 1;            v->ttfrm = TT_8X8;        }        break;    case B_TYPE:        if (v->pq < 5) v->tt_index = 0;        else if(v->pq < 13) v->tt_index = 1;        else v->tt_index = 2;        lowquant = (v->pq > 12) ? 0 : 1;        v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);        v->s.mspel = v->s.quarter_sample;        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);        if (status < 0) return -1;        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "               "Imode: %i, Invert: %i\n", status>>1, status&1);        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);        if (status < 0) return -1;        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "               "Imode: %i, Invert: %i\n", status>>1, status&1);        v->s.mv_table_index = get_bits(gb, 2);        v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];        if (v->dquant)        {            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");            vop_dquant_decoding(v);        }        v->ttfrm = 0;        if (v->vstransform)        {            v->ttmbf = get_bits(gb, 1);            if (v->ttmbf)            {                v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];            }        } else {            v->ttmbf = 1;            v->ttfrm = TT_8X8;        }        break;    }    /* AC Syntax */    v->c_ac_table_index = decode012(gb);    if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)    {        v->y_ac_table_index = decode012(gb);    }    /* DC Syntax */    v->s.dc_table_index = get_bits(gb, 1);    if(v->s.pict_type == BI_TYPE) {        v->s.pict_type = B_TYPE;        v->bi_type = 1;    }    return 0;}static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb){    int fcm;    int pqindex, lowquant;    int status;    v->p_frame_skipped = 0;    if(v->interlace)        fcm = decode012(gb);    switch(get_prefix(gb, 0, 4)) {    case 0:        v->s.pict_type = P_TYPE;        break;    case 1:        v->s.pict_type = B_TYPE;        break;    case 2:        v->s.pict_type = I_TYPE;        break;    case 3:        v->s.pict_type = BI_TYPE;        break;    case 4:        v->s.pict_type = P_TYPE; // skipped pic        v->p_frame_skipped = 1;        return 0;    }    if(v->tfcntrflag)        get_bits(gb, 8);    if(v->broadcast) {        if(!v->interlace || v->panscanflag) {            get_bits(gb, 2);        } else {            get_bits1(gb);            get_bits1(gb);        }    }    if(v->panscanflag) {        //...    }    v->rnd = get_bits1(gb);    if(v->interlace)        v->uvsamp = get_bits1(gb);    if(v->finterpflag) v->interpfrm = get_bits(gb, 1);    if(v->s.pict_type == B_TYPE) {        v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);        v->bfraction = vc1_bfraction_lut[v->bfraction];        if(v->bfraction == 0) {            v->s.pict_type = BI_TYPE; /* XXX: should not happen here */        }    }    pqindex = get_bits(gb, 5);    v->pqindex = pqindex;    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)        v->pq = pquant_table[0][pqindex];    else        v->pq = pquant_table[1][pqindex];    v->pquantizer = 1;    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)        v->pquantizer = pqindex < 9;    if (v->quantizer_mode == QUANT_NON_UNIFORM)        v->pquantizer = 0;    v->pqindex = pqindex;    if (pqindex < 9) v->halfpq = get_bits(gb, 1);    else v->halfpq = 0;    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)        v->pquantizer = get_bits(gb, 1);    switch(v->s.pict_type) {    case I_TYPE:    case BI_TYPE:        status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);        if (status < 0) return -1;        av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "                "Imode: %i, Invert: %i\n", status>>1, status&1);        v->condover = CONDOVER_NONE;        if(v->overlap && v->pq <= 8) {            v->condover = decode012(gb);            if(v->condover == CONDOVER_SELECT) {                status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);                if (status < 0) return -1;                av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "                        "Imode: %i, Invert: %i\n", status>>1, status&1);            }        }        break;    case P_TYPE:        if(v->postprocflag)            v->postproc = get_bits1(gb);        if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);        else v->mvrange = 0;        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11        v->range_x = 1 << (v->k_x - 1);        v->range_y = 1 << (v->k_y - 1);        if (v->pq < 5) v->tt_index = 0;        else if(v->pq < 13) v->tt_index = 1;        else v->tt_index = 2;        lowquant = (v->pq > 12) ? 0 : 1;        v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];        if (v->mv_mode == MV_PMODE_INTENSITY_COMP)        {            int scale, shift, i;            v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];            v->lumscale = get_bits(gb, 6);            v->lumshift = get_bits(gb, 6);            /* fill lookup tables for intensity compensation */            if(!v->lumscale) {                scale = -64;                shift = (255 - v->lumshift * 2) << 6;                if(v->lumshift > 31)                    shift += 128 << 6;            } else {                scale = v->lumscale + 32;                if(v->lumshift > 31)                    shift = (v->lumshift - 64) << 6;                else                    shift = v->lumshift << 6;            }            for(i = 0; i < 256; i++) {                v->luty[i] = clip_uint8((scale * i + shift + 32) >> 6);                v->lutuv[i] = clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);            }        }        if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)            v->s.quarter_sample = 0;        else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {            if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)                v->s.quarter_sample = 0;            else                v->s.quarter_sample = 1;        } else            v->s.quarter_sample = 1;        v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));        if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&                 v->mv_mode2 == MV_PMODE_MIXED_MV)                || v->mv_mode == MV_PMODE_MIXED_MV)        {            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);            if (status < 0) return -1;            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "                   "Imode: %i, Invert: %i\n", status>>1, status&1);        } else {            v->mv_type_is_raw = 0;            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);        }        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);        if (status < 0) return -1;        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "               "Imode: %i, Invert: %i\n", status>>1, status&1);        /* Hopefully this is correct for P frames */        v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables        v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];        if (v->dquant)        {            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");            vop_dquant_decoding(v);        }        v->ttfrm = 0; //FIXME Is that so ?        if (v->vstransform)        {            v->ttmbf = get_bits(gb, 1);            if (v->ttmbf)            {                v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];            }        } else {            v->ttmbf = 1;            v->ttfrm = TT_8X8;        }        break;    case B_TYPE:        if(v->postprocflag)            v->postproc = get_bits1(gb);        if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);        else v->mvrange = 0;        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11        v->range_x = 1 << (v->k_x - 1);        v->range_y = 1 << (v->k_y - 1);        if (v->pq < 5) v->tt_index = 0;        else if(v->pq < 13) v->tt_index = 1;        else v->tt_index = 2;        lowquant = (v->pq > 12) ? 0 : 1;        v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);        v->s.mspel = v->s.quarter_sample;        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);        if (status < 0) return -1;        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "               "Imode: %i, Invert: %i\n", status>>1, status&1);        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);        if (status < 0) return -1;        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "               "Imode: %i, Invert: %i\n", status>>1, status&1);        v->s.mv_table_index = get_bits(gb, 2);        v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];        if (v->dquant)        {            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");            vop_dquant_decoding(v);        }        v->ttfrm = 0;        if (v->vstransform)        {            v->ttmbf = get_bits(gb, 1);            if (v->ttmbf)            {                v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];            }        } else {            v->ttmbf = 1;            v->ttfrm = TT_8X8;        }        break;    }    /* AC Syntax */    v->c_ac_table_index = decode012(gb);    if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)    {        v->y_ac_table_index = decode012(gb);    }    /* DC Syntax */    v->s.dc_table_index = get_bits(gb, 1);    if (v->s.pict_type == I_TYPE && v->dquant) {        av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");        vop_dquant_decoding(v);    }    v->bi_type = 0;    if(v->s.pict_type == BI_TYPE) {        v->s.pict_type = B_TYPE;        v->bi_type = 1;    }    return 0;}/***********************************************************************//** * @defgroup block VC-1 Block-level functions * @see 7.1.4, p91 and 8.1.1.7, p(1)04 * @{ *//** * @def GET_MQUANT * @brief Get macroblock-level quantizer scale */#define GET_MQUANT()                                           \  if (v->dquantfrm)                                            \  {                                                            \    int edges = 0;                                             \    if (v->dqprofile == DQPROFILE_ALL_MBS)                     \    {                                                          \      if (v->dqbilevel)                                        \      {                                                        \        mquant = (get_bits(gb, 1)) ? v->altpq : v->pq;         \      }                                                        \      else                                                     \      {                                                        \        mqdiff = get_bits(gb, 3);                              \        if (mqdiff != 7) mquant = v->pq + mqdiff;              \        else mquant = get_bits(gb, 5);                         \      }                                                        \    }                                                          \    if(v->dqprofile == DQPROFILE_SINGLE_EDGE)                  \        edges = 1 << v->dqsbedge;                              \    else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES)            \        edges = (3 << v->dqsbedge) % 15;                       \    else if(v->dqprofile == DQPROFILE_FOUR_EDGES)              \        edges = 15;                                            \    if((edges&1) && !s->mb_x)                                  \        mquant = v->altpq;                                     \    if((edges&2) && s->first_slice_line)                       \        mquant = v->altpq;                                     \    if((edges&4) && s->mb_x == (s->mb_width - 1))              \        mquant = v->altpq;                                     \    if((edges&8) && s->mb_y == (s->mb_height - 1))             \        mquant = v->altpq;                                     \  }/** * @def GET_MVDATA(_dmv_x, _dmv_y) * @brief Get MV differentials * @see MVDATA decoding from 8.3.5.2, p(1)20 * @param _dmv_x Horizontal differential for decoded MV * @param _dmv_y Vertical differential for decoded MV */#define GET_MVDATA(_dmv_x, _dmv_y)                                  \  index = 1 + get_vlc2(gb, vc1_mv_diff_vlc[s->mv_table_index].table,\                       VC1_MV_DIFF_VLC_BITS, 2);                    \  if (index > 36)                                                   \  {                                                                 \    mb_has_coeffs = 1;                                              \    index -= 37;                                                    \  }                                                                 \  else 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?