Ejemplo n.º 1
0
int ff_hevc_intra_chroma_pred_mode_decode(HEVCContext *s)
{
    if (!GET_CABAC(elem_offset[INTRA_CHROMA_PRED_MODE]))
        return 4;

    return (get_cabac_bypass(&s->cc) << 1) |
        get_cabac_bypass(&s->cc);
}
Ejemplo n.º 2
0
int ff_hevc_sao_band_position_decode(HEVCContext *s)
{
    int i;
    int value = get_cabac_bypass(&s->HEVClc.cc);

    for (i = 0; i < 4; i++)
        value = (value << 1) | get_cabac_bypass(&s->HEVClc.cc);
    return value;
}
Ejemplo n.º 3
0
int ff_hevc_rem_intra_luma_pred_mode_decode(HEVCContext *s)
{
    int i;
    int value = get_cabac_bypass(&s->HEVClc.cc);

    for (i = 0; i < 4; i++)
        value = (value << 1) | get_cabac_bypass(&s->HEVClc.cc);
    return value;
}
Ejemplo n.º 4
0
int ff_hevc_intra_chroma_pred_mode_decode(HEVCContext *s)
{
    int ret;
    if (!GET_CABAC(elem_offset[INTRA_CHROMA_PRED_MODE]))
        return 4;

    ret  = get_cabac_bypass(&s->HEVClc.cc) << 1;
    ret |= get_cabac_bypass(&s->HEVClc.cc);
    return ret;
}
Ejemplo n.º 5
0
int ff_hevc_last_significant_coeff_suffix_decode(HEVCContext *s,
                                                 int last_significant_coeff_prefix)
{
    int i;
    int length = (last_significant_coeff_prefix >> 1) - 1;
    int value = get_cabac_bypass(&s->HEVClc.cc);

    for (i = 1; i < length; i++)
        value = (value << 1) | get_cabac_bypass(&s->HEVClc.cc);
    return value;
}
Ejemplo n.º 6
0
int ff_hevc_abs_mvd_minus2_decode(HEVCContext *s)
{
    int ret = 0;
    int k = 1;

    while (get_cabac_bypass(&s->cc)) {
        ret += 1 << k;
        k++;
    }
    while (k--)
        ret += get_cabac_bypass(&s->cc) << k;

    return ret;
}
Ejemplo n.º 7
0
int ff_hevc_mvd_decode(HEVCContext *s)
{
    int ret = 2;
    int k = 1;

    while (k < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc.cc)) {
        ret += 1 << k;
        k++;
    }
    if (k == CABAC_MAX_BIN)
        av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);
    while (k--)
        ret += get_cabac_bypass(&s->HEVClc.cc) << k;
    return get_cabac_bypass_sign(&s->HEVClc.cc, -ret);
}
Ejemplo n.º 8
0
int ff_hevc_mpm_idx_decode(HEVCContext *s)
{
    int i = 0;
    while (i < 2 && get_cabac_bypass(&s->HEVClc.cc))
        i++;
    return i;
}
Ejemplo n.º 9
0
int ff_hevc_coeff_abs_level_remaining(HEVCContext *s, int first_elem, int base_level)
{
    int i;
    static int c_rice_param, last_coeff_abs_level_remaining;
    int prefix = 0;
    int suffix = 0;

    if (first_elem) {
        c_rice_param = 0;
        last_coeff_abs_level_remaining = 0;
        av_dlog(s->avctx,
               "c_rice_param reset to 0\n");
    }

    while (get_cabac_bypass(&s->cc))
        prefix++;

    if (prefix < 3) {
        for (i = 0; i < c_rice_param; i++)
            suffix = (suffix << 1) | get_cabac_bypass(&s->cc);
        last_coeff_abs_level_remaining = (prefix << c_rice_param) + suffix;
    } else {
        for (i = 0; i < prefix - 3 + c_rice_param; i++)
            suffix = (suffix << 1) | get_cabac_bypass(&s->cc);
        last_coeff_abs_level_remaining = (((1 << (prefix - 3)) + 3 - 1)
                                          << c_rice_param) + suffix;
    }

    av_dlog(s->avctx,
           "coeff_abs_level_remaining c_rice_param: %d\n", c_rice_param);
    av_dlog(s->avctx,
           "coeff_abs_level_remaining base_level: %d, prefix: %d, suffix: %d\n",
           base_level, prefix, suffix);
    av_dlog(s->avctx,
           "coeff_abs_level_remaining: %d\n",
           last_coeff_abs_level_remaining);

    av_dlog(s->avctx, "last_coeff_(%d) > %d\n", base_level + last_coeff_abs_level_remaining, 3*(1<<(c_rice_param)));

    c_rice_param = FFMIN(c_rice_param +
                         ((base_level + last_coeff_abs_level_remaining) >
                          (3 * (1 << c_rice_param))), 4);
    av_dlog(s->avctx,
           "new c_rice_param: %d\n", c_rice_param);

    return last_coeff_abs_level_remaining;
}
Ejemplo n.º 10
0
int ff_hevc_coeff_sign_flag(HEVCContext *s, uint8_t nb)
{
    int i;
    int ret = 0;

    for (i = 0; i < nb; i++)
        ret = (ret << 1) | get_cabac_bypass(&s->HEVClc.cc);
    return ret;
}
Ejemplo n.º 11
0
int ff_hevc_sao_offset_abs_decode(HEVCContext *s)
{
    int i = 0;
    int length = (1 << (FFMIN(s->ps.sps->bit_depth, 10) - 5)) - 1;

    while (i < length && get_cabac_bypass(&s->HEVClc.cc))
        i++;
    return i;
}
Ejemplo n.º 12
0
int ff_hevc_sao_type_idx_decode(HEVCContext *s)
{
    if (!GET_CABAC(elem_offset[SAO_TYPE_IDX]))
        return 0;

    if (!get_cabac_bypass(&s->HEVClc.cc))
        return SAO_BAND;
    return SAO_EDGE;
}
Ejemplo n.º 13
0
int ff_hevc_merge_idx_decode(HEVCContext *s)
{
    int i = GET_CABAC(elem_offset[MERGE_IDX]);

    if (i != 0) {
        while (i < s->sh.max_num_merge_cand-1 && get_cabac_bypass(&s->HEVClc.cc))
            i++;
    }
    return i;
}
Ejemplo n.º 14
0
int ff_hevc_ref_idx_lx_decode(HEVCContext *s, int num_ref_idx_lx)
{
    int i = 0;
    int max = num_ref_idx_lx - 1;
    int max_ctx = FFMIN(max, 2);
    
    while (i < max_ctx && GET_CABAC(elem_offset[REF_IDX_L0] + i))
        i++;
    if (i==2) {
        while (i < max && get_cabac_bypass(&s->cc))
            i++;
    }
    return i;
}
Ejemplo n.º 15
0
int ff_hevc_part_mode_decode(HEVCContext *s, int log2_cb_size)
{
    if (GET_CABAC(elem_offset[PART_MODE])) // 1
        return PART_2Nx2N;
    if (log2_cb_size == s->ps.sps->log2_min_cb_size) {
        if (s->HEVClc.cu.pred_mode == MODE_INTRA) // 0
            return PART_NxN;
        if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01
            return PART_2NxN;
        if (log2_cb_size == 3) // 00
            return PART_Nx2N;
        if (GET_CABAC(elem_offset[PART_MODE] + 2)) // 001
            return PART_Nx2N;
        return PART_NxN; // 000
    }

    if (!s->ps.sps->amp_enabled_flag) {
        if (GET_CABAC(elem_offset[PART_MODE] + 1)) // 01
            return PART_2NxN;
        return PART_Nx2N;
    }

    if (GET_CABAC(elem_offset[PART_MODE] + 1)) { // 01X, 01XX
        if (GET_CABAC(elem_offset[PART_MODE] + 3)) // 011
            return PART_2NxN;
        if (get_cabac_bypass(&s->HEVClc.cc)) // 0101
            return PART_2NxnD;
        return PART_2NxnU; // 0100
    }

    if (GET_CABAC(elem_offset[PART_MODE] + 3)) // 001
        return PART_Nx2N;
    if (get_cabac_bypass(&s->HEVClc.cc)) // 0001
        return PART_nRx2N;
    return PART_nLx2N;  // 0000
}
Ejemplo n.º 16
0
int ff_hevc_coeff_abs_level_remaining(HEVCContext *s, int base_level, int rc_rice_param)
{
    int prefix = 0;
    int suffix = 0;
    int last_coeff_abs_level_remaining;
    int i;

    while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc.cc))
        prefix++;
    if (prefix == CABAC_MAX_BIN)
        av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
    if (prefix < 3) {
        for (i = 0; i < rc_rice_param; i++)
            suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc.cc);
        last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
    } else {
        int prefix_minus3 = prefix - 3;
        for (i = 0; i < prefix_minus3 + rc_rice_param; i++)
            suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc.cc);
        last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
                                              << rc_rice_param) + suffix;
    }
    return last_coeff_abs_level_remaining;
}
Ejemplo n.º 17
0
int ff_hevc_cu_qp_delta_abs(HEVCContext *s)
{
    int prefix_val = 0;
    int suffix_val = 0;
    int inc = 0;

    while (prefix_val < 5 && GET_CABAC(elem_offset[CU_QP_DELTA] + inc)) {
        prefix_val++;
        inc = 1;
    }
    if (prefix_val >= 5) {
        int k = 0;
        while (k < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc.cc)) {
            suffix_val += 1 << k;
            k++;
        }
        if (k == CABAC_MAX_BIN)
            av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k);

        while (k--)
            suffix_val += get_cabac_bypass(&s->HEVClc.cc) << k;
    }
    return prefix_val + suffix_val;
}
Ejemplo n.º 18
0
int ff_hevc_sao_eo_class_decode(HEVCContext *s)
{
    int ret = get_cabac_bypass(&s->HEVClc.cc) << 1;
    ret    |= get_cabac_bypass(&s->HEVClc.cc);
    return ret;
}
Ejemplo n.º 19
0
int ff_hevc_mvd_sign_flag_decode(HEVCContext *s)
{
    return get_cabac_bypass(&s->cc);
}
Ejemplo n.º 20
0
int ff_hevc_sao_eo_class_decode(HEVCContext *s)
{
    return (get_cabac_bypass(&s->cc) << 1) |
        get_cabac_bypass(&s->cc);
}
Ejemplo n.º 21
0
int ff_hevc_sao_offset_sign_decode(HEVCContext *s)
{
    return get_cabac_bypass(&s->HEVClc.cc);
}
Ejemplo n.º 22
0
int ff_hevc_cu_qp_delta_sign_flag(HEVCContext *s)
{
    return get_cabac_bypass(&s->HEVClc.cc);
}
Ejemplo n.º 23
0
int main(){
    CABACContext c;
    uint8_t b[9*SIZE];
    uint8_t r[9*SIZE];
    int i;
    uint8_t state[10]= {0};
    
    ff_init_cabac_encoder(&c, b, SIZE);
    ff_init_cabac_states(&c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
    
    for(i=0; i<SIZE; i++){
        r[i]= random()%7;
    }
    
    for(i=0; i<SIZE; i++){
START_TIMER
        put_cabac_bypass(&c, r[i]&1);
STOP_TIMER("put_cabac_bypass")
    }
    
    for(i=0; i<SIZE; i++){
START_TIMER
        put_cabac(&c, state, r[i]&1);
STOP_TIMER("put_cabac")
    }

    for(i=0; i<SIZE; i++){
START_TIMER
        put_cabac_u(&c, state, r[i], 6, 3, i&1);
STOP_TIMER("put_cabac_u")
    }    

    for(i=0; i<SIZE; i++){
START_TIMER
        put_cabac_ueg(&c, state, r[i], 3, 0, 1, 2);
STOP_TIMER("put_cabac_ueg")
    }    
   
    put_cabac_terminate(&c, 1);
    
    ff_init_cabac_decoder(&c, b, SIZE);
    
    memset(state, 0, sizeof(state));
    
    for(i=0; i<SIZE; i++){
START_TIMER
        if( (r[i]&1) != get_cabac_bypass(&c) )
            printf("CABAC bypass failure at %d\n", i);
STOP_TIMER("get_cabac_bypass")
    }
    
    for(i=0; i<SIZE; i++){
START_TIMER
        if( (r[i]&1) != get_cabac(&c, state) )
            printf("CABAC failure at %d\n", i);
STOP_TIMER("get_cabac")
    }

    for(i=0; i<SIZE; i++){
START_TIMER
        if( r[i] != get_cabac_u(&c, state, (i&1) ? 6 : 7, 3, i&1) )
            printf("CABAC unary (truncated) binarization failure at %d\n", i);
STOP_TIMER("get_cabac_u")
    }

    for(i=0; i<SIZE; i++){
START_TIMER
        if( r[i] != get_cabac_ueg(&c, state, 3, 0, 1, 2))
            printf("CABAC unary (truncated) binarization failure at %d\n", i);
STOP_TIMER("get_cabac_ueg")
    }

    if(!get_cabac_terminate(&c))
        printf("where's the Terminator?\n");
    
    return 0;
}
Ejemplo n.º 24
0
int main(void) {
    CABACContext c;
    uint8_t b[9*SIZE];
    uint8_t r[9*SIZE];
    int i;
    uint8_t state[10]= {0};
    AVLFG prng;

    av_lfg_init(&prng, 1);
    ff_init_cabac_encoder(&c, b, SIZE);
    ff_init_cabac_states(&c);

    for(i=0; i<SIZE; i++) {
        r[i] = av_lfg_get(&prng) % 7;
    }

    for(i=0; i<SIZE; i++) {
        START_TIMER
        put_cabac_bypass(&c, r[i]&1);
        STOP_TIMER("put_cabac_bypass")
    }

    for(i=0; i<SIZE; i++) {
        START_TIMER
        put_cabac(&c, state, r[i]&1);
        STOP_TIMER("put_cabac")
    }

    for(i=0; i<SIZE; i++) {
        START_TIMER
        put_cabac_u(&c, state, r[i], 6, 3, i&1);
        STOP_TIMER("put_cabac_u")
    }

    for(i=0; i<SIZE; i++) {
        START_TIMER
        put_cabac_ueg(&c, state, r[i], 3, 0, 1, 2);
        STOP_TIMER("put_cabac_ueg")
    }

    put_cabac_terminate(&c, 1);

    ff_init_cabac_decoder(&c, b, SIZE);

    memset(state, 0, sizeof(state));

    for(i=0; i<SIZE; i++) {
        START_TIMER
        if( (r[i]&1) != get_cabac_bypass(&c) )
            av_log(NULL, AV_LOG_ERROR, "CABAC bypass failure at %d\n", i);
        STOP_TIMER("get_cabac_bypass")
    }

    for(i=0; i<SIZE; i++) {
        START_TIMER
        if( (r[i]&1) != get_cabac(&c, state) )
            av_log(NULL, AV_LOG_ERROR, "CABAC failure at %d\n", i);
        STOP_TIMER("get_cabac")
    }
#if 0
    for(i=0; i<SIZE; i++) {
        START_TIMER
        if( r[i] != get_cabac_u(&c, state, (i&1) ? 6 : 7, 3, i&1) )
            av_log(NULL, AV_LOG_ERROR, "CABAC unary (truncated) binarization failure at %d\n", i);
        STOP_TIMER("get_cabac_u")
    }

    for(i=0; i<SIZE; i++) {
        START_TIMER
        if( r[i] != get_cabac_ueg(&c, state, 3, 0, 1, 2))
            av_log(NULL, AV_LOG_ERROR, "CABAC unary (truncated) binarization failure at %d\n", i);
        STOP_TIMER("get_cabac_ueg")
    }
#endif
    if(!get_cabac_terminate(&c))
        av_log(NULL, AV_LOG_ERROR, "where's the Terminator?\n");

    return 0;
}