static void init_fdec(davs2_t *h, int64_t pts, int64_t dts)
{
    int num_in_spu = h->i_width_in_spu * h->i_height_in_spu;
    int i;

    h->fdec->i_type              = h->i_frame_type;
    h->fdec->i_qp                = h->i_qp;
    h->fdec->i_poc               = h->i_poc;
    h->fdec->i_coi               = h->i_coi;
    h->fdec->b_refered_by_others = h->rps.refered_by_others;
    h->fdec->i_decoded_line      = -1;
    h->fdec->i_pts               = pts;
    h->fdec->i_dts               = dts;

    for (i = 0; i < AVS2_MAX_REFS; i++) {
        h->fdec->dist_refs[i] = -1;
        h->fdec->dist_scale_refs[i] = -1;
    }

    if (h->i_frame_type != AVS2_B_SLICE) {
        for (i = 0; i < h->num_of_references; i++) {
            h->fdec->dist_refs[i] = AVS2_DISTANCE_INDEX(2 * (h->fdec->i_poc - h->fref[i]->i_poc));
            if (h->fdec->dist_refs[i] <= 0) {
                davs2_log(h, DAVS2_LOG_ERROR, "invalid reference frame distance.");
                h->fdec->dist_refs[i] = 1;
            }
            h->fdec->dist_scale_refs[i] = (MULTI / h->fdec->dist_refs[i]);
        }
    } else {
        h->fdec->dist_refs[B_FWD] = AVS2_DISTANCE_INDEX(2 * (h->fdec->i_poc - h->fref[B_FWD]->i_poc));
        h->fdec->dist_refs[B_BWD] = AVS2_DISTANCE_INDEX(2 * (h->fref[B_BWD]->i_poc - h->fdec->i_poc));
        if (h->fdec->dist_refs[B_FWD] <= 0) {
            davs2_log(h, DAVS2_LOG_ERROR, "invalid reference frame distance. B_FWD");
            h->fdec->dist_refs[B_FWD] = 1;
        }
        if (h->fdec->dist_refs[B_BWD] <= 0) {
            davs2_log(h, DAVS2_LOG_ERROR, "invalid reference frame distance. B_BWD");
            h->fdec->dist_refs[B_BWD] = 1;
        }
        h->fdec->dist_scale_refs[B_FWD] = (MULTI / h->fdec->dist_refs[B_FWD]);
        h->fdec->dist_scale_refs[B_BWD] = (MULTI / h->fdec->dist_refs[B_BWD]);
    }

    /* clear mvbuf and refbuf */
    memset(h->fdec->mvbuf, 0, num_in_spu * sizeof(mv_t));
    memset(h->fdec->refbuf, INVALID_REF, num_in_spu * sizeof(int8_t));
}
static void init_fdec(davs2_t *h, int64_t pts, int64_t dts)
{
    int num_in_spu = h->i_width_in_spu * h->i_height_in_spu;
    int i;

    h->fdec->i_type              = h->i_frame_type;
    h->fdec->i_qp                = h->i_qp;
    h->fdec->i_poc               = h->i_poc;
    h->fdec->i_coi               = h->i_coi;
    h->fdec->b_refered_by_others = h->rps.refered_by_others;
    h->fdec->i_decoded_line      = -1;
    h->fdec->i_pts               = pts;
    h->fdec->i_dts               = dts;

    for (i = 0; i < AVS2_MAX_REFS; i++) {
        h->fdec->dist_refs[i] = -1;
        h->fdec->dist_scale_refs[i] = -1;
    }

    if (h->i_frame_type != AVS2_B_SLICE) {
        for (i = 0; i < h->num_of_references; i++) {
            h->fdec->dist_refs[i] = AVS2_DISTANCE_INDEX(2 * (h->fdec->i_poc - h->fref[i]->i_poc));
            if (h->fdec->dist_refs[i] <= 0) {
                davs2_log(h, DAVS2_LOG_ERROR, "invalid reference frame distance.");
                h->fdec->dist_refs[i] = 1;
            }
            h->fdec->dist_scale_refs[i] = (MULTI / h->fdec->dist_refs[i]);
        }
    } else {
        h->fdec->dist_refs[B_FWD] = AVS2_DISTANCE_INDEX(2 * (h->fdec->i_poc - h->fref[B_FWD]->i_poc));
        h->fdec->dist_refs[B_BWD] = AVS2_DISTANCE_INDEX(2 * (h->fref[B_BWD]->i_poc - h->fdec->i_poc));
        if (h->fdec->dist_refs[B_FWD] <= 0) {
            davs2_log(h, DAVS2_LOG_ERROR, "invalid reference frame distance. B_FWD");
            h->fdec->dist_refs[B_FWD] = 1;
        }
        if (h->fdec->dist_refs[B_BWD] <= 0) {
            davs2_log(h, DAVS2_LOG_ERROR, "invalid reference frame distance. B_BWD");
            h->fdec->dist_refs[B_BWD] = 1;
        }
        h->fdec->dist_scale_refs[B_FWD] = (MULTI / h->fdec->dist_refs[B_FWD]);
        h->fdec->dist_scale_refs[B_BWD] = (MULTI / h->fdec->dist_refs[B_BWD]);
    }

     
    memset(h->fdec->mvbuf, 0, num_in_spu * sizeof(mv_t));
    memset(h->fdec->refbuf, INVALID_REF, num_in_spu * sizeof(int8_t));
}