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

📄 analyse.c

📁 H.264改进解码软件
💻 C
📖 第 1 页 / 共 5 页
字号:
/*    uint8_t **p_fref[2];
    uint8_t pix[2][8*8];
    int i, l;
    p_fref[0]=h->mb.pic.p_fref[0][a->l0.i_ref];
    p_fref[1]=h->mb.pic.p_fref[1][a->l1.i_ref];
    
    

    /* XXX Needed for x264_mb_predict_mv */
   /* h->mb.i_partition = D_8x8;

    a->i_cost8x8bi = 0;

    for( i = 0; i < 4; i++ )
    {
        const int x8 = i%2;
        const int y8 = i/2;
        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->me8x8[i];

            m->i_pixel = PIXEL_8x8;
            m->p_cost_mv = a->p_cost_mv;

            LOAD_FENC( m, h->mb.pic.p_fenc, 8*x8, 8*y8 );
            LOAD_HPELS( m, p_fref[l], l, lX->i_ref, 8*x8, 8*y8 );

            x264_mb_predict_mv( h, l, 4*i, 2, m->mvp );
            x264_me_search( h, m, &lX->me16x16.mv, 1 );

            x264_macroblock_cache_mv( h, 2*x8, 2*y8, 2, 2, l, m->mv[0], m->mv[1] );

            /* BI mode */
   /*         h->mc.mc_luma( m->p_fref, m->i_stride[0], pix[l], 8,
                            m->mv[0], m->mv[1], 8, 8 );
            i_part_cost_bi += m->cost_mv;
            /* FIXME: ref cost */
   /*     }

        WEIGHTED_AVG( PIXEL_8x8, pix[0], 8, pix[1], 8 );
        i_part_cost_bi += h->pixf.mbcmp[PIXEL_8x8]( a->l0.me8x8[i].p_fenc[0], FENC_STRIDE, pix[0], 8 )
                        + a->i_lambda * i_sub_mb_b_cost_table[D_BI_8x8];
        a->l0.me8x8[i].cost += a->i_lambda * i_sub_mb_b_cost_table[D_L0_8x8];
        a->l1.me8x8[i].cost += a->i_lambda * i_sub_mb_b_cost_table[D_L1_8x8];

        i_part_cost = a->l0.me8x8[i].cost;
        h->mb.i_sub_partition[i] = D_L0_8x8;
        if( a->l1.me8x8[i].cost < i_part_cost )
        {
            i_part_cost = a->l1.me8x8[i].cost;
            h->mb.i_sub_partition[i] = D_L1_8x8;
        }
        if( i_part_cost_bi < i_part_cost )
        {
            i_part_cost = i_part_cost_bi;
            h->mb.i_sub_partition[i] = D_BI_8x8;
        }
        if( a->i_cost8x8direct[i] < i_part_cost )
        {
            i_part_cost = a->i_cost8x8direct[i];
            h->mb.i_sub_partition[i] = D_DIRECT_8x8;
        }
        a->i_cost8x8bi += i_part_cost;

        /* XXX Needed for x264_mb_predict_mv */
   /*     x264_mb_cache_mv_b8x8( h, a, i, 0 );
    }

    /* mb type cost */
 /*   a->i_cost8x8bi += a->i_lambda * i_mb_b_cost_table[B_8x8];

    if( a->b_mbrd )
    {
        if( a->i_cost8x8bi < a->i_best_satd )
            a->i_best_satd = a->i_cost8x8bi;

        if( a->i_cost8x8bi < a->i_best_satd * 3/2 )
        {
            h->mb.i_type = B_8x8;
            h->mb.i_partition = D_8x8;
//            a->i_cost8x8bi = x264_rd_cost_mb( h, a->i_lambda2 );
        }
        else
            a->i_cost8x8bi = COST_MAX;
    }
}*/

/*static void x264_mb_analyse_inter_b16x8( 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 **p_fref[2] ;     
    DECLARE_ALIGNED( uint8_t,  pix[2][16*8], 16 );
    int mvc[2][2];
    int i, l;
    p_fref[0]=h->mb.pic.p_fref[0][a->l0.i_ref];
    p_fref[1]=h->mb.pic.p_fref[1][a->l1.i_ref]; 

    h->mb.i_partition = D_16x8;
    a->i_cost16x8bi = 0;

    for( i = 0; i < 2; i++ )
    {
        int i_part_cost;
        int i_part_cost_bi = 0;

        /* TODO: check only the list(s) that were used in b8x8? */
    /*    for( l = 0; l < 2; l++ )
        {
            x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
            x264_me_t *m = &lX->me16x8[i];

            m->i_pixel = PIXEL_16x8;
            m->p_cost_mv = a->p_cost_mv;

            LOAD_FENC( m, h->mb.pic.p_fenc, 0, 8*i );
            LOAD_HPELS( m, p_fref[l], l, lX->i_ref, 0, 8*i );

            mvc[0][0] = lX->me8x8[2*i].mv[0];
            mvc[0][1] = lX->me8x8[2*i].mv[1];
            mvc[1][0] = lX->me8x8[2*i+1].mv[0];
            mvc[1][1] = lX->me8x8[2*i+1].mv[1];

            x264_mb_predict_mv( h, 0, 8*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], 16,
                            m->mv[0], m->mv[1], 16, 8 );
            /* FIXME: ref cost */
   /*         i_part_cost_bi += m->cost_mv;
        }

        WEIGHTED_AVG( PIXEL_16x8, pix[0], 16, pix[1], 16 );
        i_part_cost_bi += h->pixf.mbcmp[PIXEL_16x8]( a->l0.me16x8[i].p_fenc[0], FENC_STRIDE, 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];
    uint8_t pix[2][8*16];
    int mvc[2][2];
    int i, l;
    p_fref[0]=h->mb.pic.p_fref[0][a->l0.i_ref];
    p_fref[1]=h->mb.pic.p_fref[1][a->l1.i_ref];

    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], l, lX->i_ref, 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], FENC_STRIDE, 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 void refine_bidir( x264_t *h, x264_mb_analysis_t *a )
{
    const int i_biweight = h->mb.bipred_weight[a->l0.i_ref][a->l1.i_ref];
    int i;

    switch( h->mb.i_partition )
    {
    case D_16x16:
        if( h->mb.i_type == B_BI_BI )
            x264_me_refine_bidir( h, &a->l0.me16x16, &a->l1.me16x16, i_biweight );
        break;
    case D_16x8:
        for( i=0; i<2; i++ )
            if( a->i_mb_partition16x8[i] == D_BI_8x8 )
                x264_me_refine_bidir( h, &a->l0.me16x8[i], &a->l1.me16x8[i], i_biweight );
        break;
    case D_8x16:
        for( i=0; i<2; i++ )
            if( a->i_mb_partition8x16[i] == D_BI_8x8 )
                x264_me_refine_bidir( h, &a->l0.me8x16[i], &a->l1.me8x16[i], i_biweight );
        break;
    case D_8x8:
        for( i=0; i<4; i++ )
            if( h->mb.i_sub_partition[i] == D_BI_8x8 )
                x264_me_refine_bidir( h, &a->l0.me8x8[i], &a->l1.me8x8[i], i_biweight );
        break;
    }
}*/

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], FENC_STRIDE,
                                             h->mb.pic.p_fdec[0], FDEC_STRIDE );
        i_cost4 = h->pixf.satd[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
                                             h->mb.pic.p_fdec[0], FDEC_STRIDE );

        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 );

		//确定宏块的最

⌨️ 快捷键说明

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