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

📄 inter_b.c

📁 T264是中国的视频编码自由组织合力开发的264编解码程序
💻 C
📖 第 1 页 / 共 3 页
字号:
            }
            if (sad_l1 < sad_min)
            {
                sad_min = sad_l1;
                part[i] = B_L1_8x16;
                t->memcpy_stride_u(pred_l1, 8, 16, 16, pred_l0, 16);

                vec_best[i][0].refno = -1;
                vec_best[i][0].x = 0;
                vec_best[i][0].y = 0;
            }
            if (part[i] == B_L0_8x16)
            {
                vec_best[i][1].refno = -1;
                vec_best[i][1].x = 0;
                vec_best[i][1].y = 0;
            }
        }

        pred_l0 += 8;
        pred_l1 += 8;
        pred_bi += 8;
        t->mb.vec_ref[VEC_LUMA + 1].vec[0] = vec_best[i][0];
        t->mb.vec_ref[VEC_LUMA + 1].vec[1] = vec_best[i][1];
        context.offset += 8;
        src += 8;
        sad_all += sad_min;
    }
    t->mb.mb_part = old_part;

    return sad_all;
}

uint32_t
T264_mode_decision_inter_8x8b(_RW T264_t * t, int32_t i, T264_vector_t vec_best[2], uint8_t* pred, uint8_t* part)
{
    DECLARE_ALIGNED_MATRIX(pred_l1, 16, 16, uint8_t, CACHE_SIZE);
    DECLARE_ALIGNED_MATRIX(pred_bi, 16, 16, uint8_t, CACHE_SIZE);

    T264_vector_t vec[5 + 10];  // NOTE: max 10 refs
    T264_search_context_t context;
    int32_t num;
    uint32_t sad_min;
    T264_vector_t vec_median;
    uint8_t* pred_l0 = pred;
    uint8_t* src = t->mb.src_y + (i / 2 * 8) * t->stride + i % 2 * 8;
    uint8_t* dst = pred + i / 2 * 16 * 8 + i % 2 * 8;

    context.height = 8;
    context.width  = 8;
    context.limit_x= t->param.search_x;
    context.limit_y= t->param.search_y;
    context.vec    = vec;
    context.mb_part= MB_8x8;
    context.offset = ((t->mb.mb_y << 4) + i / 2 * 8) * t->edged_stride + (t->mb.mb_x << 4) + i % 2 * 8;

    vec[0].refno = vec_best[0].refno;
    get_pmv(t, 0, vec, MB_8x8, luma_index[4 * i], 2, &num);
    context.vec_num= num;
    context.list_index = 0;

    sad_min = t->search(t, &context);
    sad_min+= eg_size_ue(t->bs, B_L0_8x8) + REFCOST(context.vec_best.refno);
    sad_min = T264_quarter_pixel_search(t, 0, src, t->ref[0][context.vec_best.refno], context.offset, 
        &context.vec_best, &vec[0], sad_min, 8, 8, dst, MB_8x8);
    vec_best[0] = context.vec_best;
    vec_median = vec[0];
    *part = B_L0_8x8;

    // list 1
    vec_best[1].refno = -1;
    vec_best[1].x = 0;
    vec_best[1].y = 0;
    if (t->refl1_num > 0)
    {
        uint32_t sad_l1, sad_bi;

        vec[0].refno = 0;
        get_pmv(t, 1, vec, MB_8x8, luma_index[4 * i], 2, &num);
        context.vec_num= num;
        context.list_index = 1;

        sad_l1 = t->search(t, &context);
        sad_l1+= eg_size_ue(t->bs, B_L1_8x8) + REFCOST1(context.vec_best.refno);
        sad_l1 = T264_quarter_pixel_search(t, 1, src, t->ref[1][context.vec_best.refno], context.offset, 
            &context.vec_best, &vec[0], sad_l1, 8, 8, pred_l1, MB_8x8);
        vec_best[1] = context.vec_best;

        t->pia[MB_8x8](dst, pred_l1, 16, 16, pred_bi, 16);
        sad_bi = t->cmp[MB_8x8](src, t->stride, pred_bi, 16) + t->mb.lambda *
           (eg_size_se(t->bs, vec_best[0].x - vec_median.x) +
            eg_size_se(t->bs, vec_best[0].y - vec_median.y) +
            eg_size_se(t->bs, vec_best[1].x - vec[0].x) +
            eg_size_se(t->bs, vec_best[1].y - vec[0].y) + 
            2 * T264_MIN(context.vec_best.refno, 1)) +
            eg_size_ue(t->bs, B_Bi_8x8) +
            REFCOST(vec_best[0].refno);
        if (sad_bi < sad_min)
        {
            sad_min = sad_bi;
            *part = B_Bi_8x8;
            t->memcpy_stride_u(pred_bi, 8, 8, 16, dst, 16);
        }
        if (sad_l1 < sad_min)
        {
            sad_min = sad_l1;
            *part = B_L1_8x8;
            t->memcpy_stride_u(pred_l1, 8, 8, 16, dst, 16);
            
            vec_best[0].refno = -1;
            vec_best[0].x = 0;
            vec_best[0].y = 0;
        }
        if (*part == B_L0_8x8)
        {
            vec_best[1].refno = -1;
            vec_best[1].x = 0;
            vec_best[1].y = 0;
        }
    }

    return sad_min;
}

void
T264_encode_interb_uv(_RW T264_t* t)
{
    DECLARE_ALIGNED_MATRIX(pred_u, 8, 8, uint8_t, CACHE_SIZE);
    DECLARE_ALIGNED_MATRIX(pred_v, 8, 8, uint8_t, CACHE_SIZE);
    DECLARE_ALIGNED_MATRIX(pred_u_l0, 8, 8, uint8_t, CACHE_SIZE);
    DECLARE_ALIGNED_MATRIX(pred_v_l0, 8, 8, uint8_t, CACHE_SIZE);
    DECLARE_ALIGNED_MATRIX(pred_u_l1, 8, 8, uint8_t, CACHE_SIZE);
    DECLARE_ALIGNED_MATRIX(pred_v_l1, 8, 8, uint8_t, CACHE_SIZE);

    T264_vector_t vec;
    uint8_t* src, *dst;
    int32_t i;

	if(t->mb.is_copy)
	{			
		T264_mb4x4_interb_uv_mc(t,t->mb.vec,pred_u,pred_v);
	}else
    switch (t->mb.mb_part)
    {
    case MB_16x16:
        {
            switch (t->mb.mb_part2[0])
            {
            case B_L0_16x16:
                vec = t->mb.vec[0][0];
                src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_u;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);
                src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_v;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);
                break;
            case B_L1_16x16:
                vec = t->mb.vec[1][0];
                src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_u;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);
                src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_v;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);
                break;
            case B_Bi_16x16:
                vec = t->mb.vec[0][0];
                src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_u_l0;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);
                src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_v_l0;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);

                vec = t->mb.vec[1][0];
                src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_u_l1;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);
                src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                dst = pred_v_l1;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 8);

                t->pia[MB_8x8](pred_u_l0, pred_u_l1, 8, 8, pred_u, 8);
                t->pia[MB_8x8](pred_v_l0, pred_v_l1, 8, 8, pred_v, 8);
                break;
            }
        }
        break;
    case MB_16x8:
        {
            for (i = 0 ; i < 2 ; i ++)
            {
                switch (t->mb.mb_part2[i])
                {
                case B_L0_16x8:
                    vec = t->mb.vec[0][i * 8];
                    src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_u + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);
                    src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_v + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);
                    break;
                case B_L1_16x8:
                    vec = t->mb.vec[1][i * 8];
                    src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_u + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);
                    src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_v + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);
                    break;
                case B_Bi_16x8:
                    vec = t->mb.vec[0][i * 8];
                    src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_u_l0 + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);
                    src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_v_l0 + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);

                    vec = t->mb.vec[1][i * 8];
                    src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_u_l1 + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);
                    src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3);
                    dst = pred_v_l1 + i * 8 * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 8, 4);

                    t->pia[MB_8x4](pred_u_l0 + i * 8 * 4, pred_u_l1 + i * 8 * 4, 8, 8, pred_u + i * 8 * 4, 8);
                    t->pia[MB_8x4](pred_v_l0 + i * 8 * 4, pred_v_l1 + i * 8 * 4, 8, 8, pred_v + i * 8 * 4, 8);
                    break;
                }
            }
        }
        break;
    case MB_8x16:
        {
            for (i = 0 ; i < 2 ; i ++)
            {
                switch (t->mb.mb_part2[i])
                {
                case B_L0_8x16:
                    vec = t->mb.vec[0][i * 2];
                    src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_u + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);
                    src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_v + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);
                    break;
                case B_L1_8x16:
                    vec = t->mb.vec[1][i * 2];
                    src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_u + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);
                    src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_v + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);
                    break;
                case B_Bi_8x16:
                    vec = t->mb.vec[0][i * 2];
                    src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_u_l0 + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);
                    src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_v_l0 + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);

                    vec = t->mb.vec[1][i * 2];
                    src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_u_l1 + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);
                    src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3)) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + i * 4;
                    dst = pred_v_l1 + i * 4;
                    t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 8);

                    t->pia[MB_4x8](pred_u_l0 + i * 4, pred_u_l1 + i * 4, 8, 8, pred_u + i * 4, 8);
                    t->pia[MB_4x8](pred_v_l0 + i * 4, pred_v_l1 + i * 4, 8, 8, pred_v + i * 4, 8);
                    break;
                }
            }
        }
        break;
    case MB_8x8:
        for(i = 0 ; i < 4 ; i ++)
        {
            int32_t offset = i / 2 * 32 + i % 2 * 4;
            switch(t->mb.submb_part[luma_index[4 * i]])
            {
            case B_L0_8x8:
                vec = t->mb.vec[0][luma_index[4 * i]];
                src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_u + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);
                src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_v + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);
                break;
            case B_L1_8x8:
                vec = t->mb.vec[1][luma_index[4 * i]];
                src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_u + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);
                src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_v + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);
                break;
            case B_Bi_8x8:
                vec = t->mb.vec[0][luma_index[4 * i]];
                src = t->ref[0][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_u_l0 + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);
                src = t->ref[0][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_v_l0 + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);

                vec = t->mb.vec[1][luma_index[4 * i]];
                src = t->ref[1][vec.refno]->U + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_u_l1 + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);
                src = t->ref[1][vec.refno]->V + ((t->mb.mb_y << 3) + (vec.y >> 3) + i / 2 * 4) * t->edged_stride_uv + (t->mb.mb_x << 3) + (vec.x >> 3) + (i % 2 * 4);
                dst = pred_v_l1 + offset;
                t->eighth_pixel_mc_u(src, t->edged_stride_uv, dst, vec.x, vec.y, 4, 4);

                t->pia[MB_4x4](pred_u_l0 + offset, pred_u_l1 + offset, 8, 8, pred_u + offset, 8);
                t->pia[MB_4x4](pred_v_l0 + offset, pred_v_l1 + offset, 8, 8, pred_v + offset, 8);
                break;
            default:
                break;
            }
        }
        break;
    default:
        break;
    }

    T264_transform_inter_uv(t, pred_u, pred_v);
}

⌨️ 快捷键说明

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