⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analyse.c.svn-base

📁 现在关于h.264的源码很多
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
        i_part_cost_bi += h->pixf.mbcmp[PIXEL_16x8]( a->l0.me16x8[i].p_fenc[0], h->mb.pic.i_stride[0], pix[0], 16 );        i_part_cost = a->l0.me16x8[i].cost;        a->i_mb_partition16x8[i] = D_L0_8x8; /* not actually 8x8, only the L0 matters */        if( a->l1.me16x8[i].cost < i_part_cost )        {            i_part_cost = a->l1.me16x8[i].cost;            a->i_mb_partition16x8[i] = D_L1_8x8;        }        if( i_part_cost_bi + a->i_lambda * 1 < i_part_cost )        {            i_part_cost = i_part_cost_bi;            a->i_mb_partition16x8[i] = D_BI_8x8;        }        a->i_cost16x8bi += i_part_cost;        x264_mb_cache_mv_b16x8( h, a, i, 0 );    }    /* mb type cost */    a->i_mb_type16x8 = B_L0_L0        + (a->i_mb_partition16x8[0]>>2) * 3        + (a->i_mb_partition16x8[1]>>2);    a->i_cost16x8bi += a->i_lambda * i_mb_b16x8_cost_table[a->i_mb_type16x8];    if( a->b_mbrd )    {        if( a->i_cost16x8bi < a->i_best_satd )            a->i_best_satd = a->i_cost16x8bi;        if( a->i_cost16x8bi < a->i_best_satd * 3/2 )        {            h->mb.i_type = a->i_mb_type16x8;            h->mb.i_partition = D_16x8;            a->i_cost16x8bi = x264_rd_cost_mb( h, a->i_lambda2 );        }        else            a->i_cost16x8bi = COST_MAX;    }}static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a ){    uint8_t **p_fref[2] =        { h->mb.pic.p_fref[0][a->l0.i_ref],          h->mb.pic.p_fref[1][a->l1.i_ref] };    uint8_t pix[2][8*16];    int mvc[2][2];    int i, l;    h->mb.i_partition = D_8x16;    a->i_cost8x16bi = 0;    for( i = 0; i < 2; i++ )    {        int i_part_cost;        int i_part_cost_bi = 0;        for( l = 0; l < 2; l++ )        {            x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;            x264_me_t *m = &lX->me8x16[i];            m->i_pixel = PIXEL_8x16;            m->p_cost_mv = a->p_cost_mv;            LOAD_FENC( m, h->mb.pic.p_fenc, 8*i, 0 );            LOAD_HPELS( m, p_fref[l], 8*i, 0 );            mvc[0][0] = lX->me8x8[i].mv[0];            mvc[0][1] = lX->me8x8[i].mv[1];            mvc[1][0] = lX->me8x8[i+2].mv[0];            mvc[1][1] = lX->me8x8[i+2].mv[1];            x264_mb_predict_mv( h, 0, 4*i, 2, m->mvp );            x264_me_search( h, m, mvc, 2 );            /* BI mode */            h->mc.mc_luma( m->p_fref, m->i_stride[0], pix[l], 8,                            m->mv[0], m->mv[1], 8, 16 );            /* FIXME: ref cost */            i_part_cost_bi += m->cost_mv;        }        WEIGHTED_AVG( PIXEL_8x16, pix[0], 8, pix[1], 8 );        i_part_cost_bi += h->pixf.mbcmp[PIXEL_8x16]( a->l0.me8x16[i].p_fenc[0], h->mb.pic.i_stride[0], pix[0], 8 );        i_part_cost = a->l0.me8x16[i].cost;        a->i_mb_partition8x16[i] = D_L0_8x8;        if( a->l1.me8x16[i].cost < i_part_cost )        {            i_part_cost = a->l1.me8x16[i].cost;            a->i_mb_partition8x16[i] = D_L1_8x8;        }        if( i_part_cost_bi + a->i_lambda * 1 < i_part_cost )        {            i_part_cost = i_part_cost_bi;            a->i_mb_partition8x16[i] = D_BI_8x8;        }        a->i_cost8x16bi += i_part_cost;        x264_mb_cache_mv_b8x16( h, a, i, 0 );    }    /* mb type cost */    a->i_mb_type8x16 = B_L0_L0        + (a->i_mb_partition8x16[0]>>2) * 3        + (a->i_mb_partition8x16[1]>>2);    a->i_cost8x16bi += a->i_lambda * i_mb_b16x8_cost_table[a->i_mb_type8x16];    if( a->b_mbrd )    {        if( a->i_cost8x16bi < a->i_best_satd )            a->i_best_satd = a->i_cost8x16bi;        if( a->i_cost8x16bi < a->i_best_satd * 3/2 )        {            h->mb.i_type = a->i_mb_type8x16;            h->mb.i_partition = D_8x16;            a->i_cost8x16bi = x264_rd_cost_mb( h, a->i_lambda2 );        }        else            a->i_cost8x16bi = COST_MAX;    }}static inline void x264_mb_analyse_transform( x264_t *h ){    h->mb.cache.b_transform_8x8_allowed =        h->param.analyse.b_transform_8x8        && !IS_INTRA( h->mb.i_type ) && x264_mb_transform_8x8_allowed( h );    if( h->mb.cache.b_transform_8x8_allowed )    {        int i_cost4, i_cost8;        /* FIXME only luma mc is needed */        x264_mb_mc( h );        i_cost8 = h->pixf.sa8d[PIXEL_16x16]( h->mb.pic.p_fenc[0], h->mb.pic.i_stride[0],                                             h->mb.pic.p_fdec[0], h->mb.pic.i_stride[0] );        i_cost4 = h->pixf.satd[PIXEL_16x16]( h->mb.pic.p_fenc[0], h->mb.pic.i_stride[0],                                             h->mb.pic.p_fdec[0], h->mb.pic.i_stride[0] );        h->mb.b_transform_8x8 = i_cost8 < i_cost4;    }}static inline void x264_mb_analyse_transform_rd( x264_t *h, x264_mb_analysis_t *a, int *i_cost ){    h->mb.cache.b_transform_8x8_allowed =        h->param.analyse.b_transform_8x8 && x264_mb_transform_8x8_allowed( h );    if( h->mb.cache.b_transform_8x8_allowed )    {        int i_cost8;        x264_analyse_update_cache( h, a );        h->mb.b_transform_8x8 = !h->mb.b_transform_8x8;        /* FIXME only luma is needed, but the score for comparison already includes chroma */        i_cost8 = x264_rd_cost_mb( h, a->i_lambda2 );        if( *i_cost >= i_cost8 )        {            if( *i_cost > 0 )                a->i_best_satd = (int64_t)a->i_best_satd * i_cost8 / *i_cost;            /* prevent a rare division by zero in x264_mb_analyse_intra */            if( a->i_best_satd == 0 )                a->i_best_satd = 1;            *i_cost = i_cost8;        }        else            h->mb.b_transform_8x8 = !h->mb.b_transform_8x8;    }}/***************************************************************************** * x264_macroblock_analyse: *****************************************************************************/void x264_macroblock_analyse( x264_t *h ){    x264_mb_analysis_t analysis;    int i_cost = COST_MAX;    int i;    /* init analysis */    x264_mb_analyse_init( h, &analysis, x264_ratecontrol_qp( h ) );    /*--------------------------- Do the analysis ---------------------------*/    if( h->sh.i_type == SLICE_TYPE_I )    {        x264_mb_analyse_intra( h, &analysis, COST_MAX );        i_cost = analysis.i_sad_i16x16;        h->mb.i_type = I_16x16;        if( analysis.i_sad_i4x4 < i_cost )        {            i_cost = analysis.i_sad_i4x4;            h->mb.i_type = I_4x4;        }        if( analysis.i_sad_i8x8 < i_cost )            h->mb.i_type = I_8x8;    }    else if( h->sh.i_type == SLICE_TYPE_P )    {        int b_skip = 0;        int i_intra_cost, i_intra_type;        /* Fast P_SKIP detection */        if( h->param.analyse.b_fast_pskip &&           (( h->mb.i_mb_type_left == P_SKIP ) ||            ( h->mb.i_mb_type_top == P_SKIP ) ||            ( h->mb.i_mb_type_topleft == P_SKIP ) ||            ( h->mb.i_mb_type_topright == P_SKIP )))        {            b_skip = x264_macroblock_probe_pskip( h );        }        if( b_skip )        {            h->mb.i_type = P_SKIP;            h->mb.i_partition = D_16x16;        }        else        {            const unsigned int flags = h->param.analyse.inter;            int i_type;            int i_partition;            int i_thresh16x8;            x264_mb_analyse_load_costs( h, &analysis );            x264_mb_analyse_inter_p16x16( h, &analysis );            if( analysis.b_mbrd && h->mb.i_type == P_SKIP )                return;            if( flags & X264_ANALYSE_PSUB16x16 )            {                if( h->param.analyse.b_mixed_references )                    x264_mb_analyse_inter_p8x8_mixed_ref( h, &analysis );                else                    x264_mb_analyse_inter_p8x8( h, &analysis );            }            /* Select best inter mode */            i_type = P_L0;            i_partition = D_16x16;            i_cost = analysis.l0.me16x16.cost;            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost )            {                int i;                i_type = P_8x8;                i_partition = D_8x8;                h->mb.i_sub_partition[0] = h->mb.i_sub_partition[1] =                h->mb.i_sub_partition[2] = h->mb.i_sub_partition[3] = D_L0_8x8;                i_cost = analysis.l0.i_cost8x8;                /* Do sub 8x8 */                if( flags & X264_ANALYSE_PSUB8x8 )                {                    int i_cost_bak = i_cost;                    int b_sub8x8 = 0;                    for( i = 0; i < 4; i++ )                    {                        x264_mb_analyse_inter_p4x4( h, &analysis, i );                        if( analysis.l0.i_cost4x4[i] < analysis.l0.me8x8[i].cost )                        {                            int i_cost8x8 = analysis.l0.i_cost4x4[i];                            h->mb.i_sub_partition[i] = D_L0_4x4;                            x264_mb_analyse_inter_p8x4( h, &analysis, i );                            if( analysis.l0.i_cost8x4[i] < i_cost8x8 )                            {                                h->mb.i_sub_partition[i] = D_L0_8x4;                                i_cost8x8 = analysis.l0.i_cost8x4[i];                            }                            x264_mb_analyse_inter_p4x8( h, &analysis, i );                            if( analysis.l0.i_cost4x8[i] < i_cost8x8 )                            {                                h->mb.i_sub_partition[i] = D_L0_4x8;                                i_cost8x8 = analysis.l0.i_cost4x8[i];                            }                            i_cost += i_cost8x8 - analysis.l0.me8x8[i].cost;                            b_sub8x8 = 1;                        }                        x264_mb_cache_mv_p8x8( h, &analysis, i );                    }                    /* TODO: RD per subpartition */                    if( b_sub8x8 && analysis.b_mbrd )                    {                        i_cost = x264_rd_cost_mb( h, analysis.i_lambda2 );                        if( i_cost > i_cost_bak )                        {                            i_cost = i_cost_bak;                            h->mb.i_sub_partition[0] = h->mb.i_sub_partition[1] =                            h->mb.i_sub_partition[2] = h->mb.i_sub_partition[3] = D_L0_8x8;                        }                    }                }            }            /* Now do 16x8/8x16 */            i_thresh16x8 = analysis.l0.me8x8[1].cost_mv + analysis.l0.me8x8[2].cost_mv;            if( analysis.b_mbrd )                i_thresh16x8 = i_thresh16x8 * analysis.i_lambda2 / analysis.i_lambda;            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8 )            {                x264_mb_analyse_inter_p16x8( h, &analysis );                if( analysis.l0.i_cost16x8 < i_cost )                {                    i_type = P_L0;                    i_partition = D_16x8;                    i_cost = analysis.l0.i_cost16x8;                }                x264_mb_analyse_inter_p8x16( h, &analysis );                if( analysis.l0.i_cost8x16 < i_cost )                {                    i_type = P_L0;                    i_partition = D_8x16;                    i_cost = analysis.l0.i_cost8x16;                }            }            h->mb.i_partition = i_partition;            /* refine qpel */            //FIXME mb_type costs?            if( analysis.b_mbrd )            {                h->mb.i_type = i_type;                x264_mb_analyse_transform_rd( h, &analysis, &i_cost );            }            else if( i_partition == D_16x16 )            {                x264_me_refine_qpel( h, &analysis.l0.me16x16 );                i_cost = analysis.l0.me16x16.cost;            }            else if( i_partition == D_16x8 )            {                x264_me_refine_qpel( h, &analysis.l0.me16x8[0] );                x264_me_refine_qpel( h, &analysis.l0.me16x8[1] );                i_cost = analysis.l0.me16x8[0].cost + analysis.l0.me16x8[1].cost;            }            else if( i_partition == D_8x16 )            {                x264_me_refine_qpel( h, &analysis.l0.me8x16[0] );                x264_me_refine_qpel( h, &analysis.l0.me8x16[1] );                i_cost = analysis.l0.me8x16[0].cost + analysis.l0.me8x16[1].cost;            }            else if( i_partition == D_8x8 )            {                int i8x8;                i_cost = 0;                for( i8x8 = 0; i8x8 < 4; i8x8++ )                {                    switch( h->mb.i_sub_partition[i8x8] )                    {                        case D_L0_8x8:                            x264_me_refine_qpel( h, &analysis.l0.me8x8[i8x8] );                            i_cost += analysis.l0.me8x8[i8x8].cost;                            break;                        case D_L0_8x4:                            x264_me_refine_qpel( h, &analysis.l0.me8x4[i8x8][0] );                            x264_me_refine_qpel( h, &analysis.l0.me8x4[i8x8][1] );                            i_cost += analysis.l0.me8x4[i8x8][0].cost +                                      analysis.l0.me8x4[i8x8][1].cost;                            break;                        case D_L0_4x8:                            x264_me_refine_qpel( h, &analysis.l0.me4x8[i8x8][0] );                            x264_me_refine_qpel( h, &analysis.l0.me4x8[i8x8][1] );                            i_cost += analysis.l0.me4x8[i8x8][0].cost +                                      analysis.l0.me4x8[i8x8][1].cost;                            break;                        case D_L0_4x4:                            x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][0] );                            x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][1] );                            x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][2] );                            x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][3] );           

⌨️ 快捷键说明

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