コード例 #1
0
ファイル: hevc_cabac.c プロジェクト: JSinglan/libav
void ff_hevc_cabac_init(HEVCContext *s)
{
    int i;
    int init_type;
    GetBitContext *gb = &s->gb;

    align_get_bits(gb);
    ff_init_cabac_states(&s->cc);
    ff_init_cabac_decoder(&s->cc,
                          gb->buffer + get_bits_count(gb) / 8,
                          (get_bits_left(&s->gb) + 7) / 8);

    init_type = 2 - s->sh.slice_type;
    if (s->sh.cabac_init_flag && s->sh.slice_type != I_SLICE)
        init_type ^= 3;

    elem_offset[0] = 0;
    for (i = 1; i < sizeof(num_bins_in_se); i++) {
        elem_offset[i] = elem_offset[i-1] + num_bins_in_se[i-1];
    }

    for (i = 0; i < HEVC_CONTEXTS; i++) {
        int init_value = init_values[init_type][i];
        int m = (init_value >> 4)*5 - 45;
        int n = ((init_value & 15) << 3) - 16;
        int pre_ctx_state = av_clip_c(((m * av_clip_c(s->sh.slice_qp, 0, 51)) >> 4) + n,
                                      1, 126);
        int mps = (pre_ctx_state <= 63) ? 0 : 1;
        int state_idx = mps ? (pre_ctx_state - 64) : (63 - pre_ctx_state);
        s->cabac_state[i] = (state_idx << 1) + mps;
    }
}
コード例 #2
0
ファイル: hevc_cabac.c プロジェクト: AVLeo/libav
static void cabac_init_decoder(HEVCContext *s)
{
    GetBitContext *gb = &s->HEVClc.gb;
    skip_bits(gb, 1);
    align_get_bits(gb);
    ff_init_cabac_decoder(&s->HEVClc.cc,
                          gb->buffer + get_bits_count(gb) / 8,
                          (get_bits_left(gb) + 7) / 8);
}
コード例 #3
0
ファイル: hevc_cabac.c プロジェクト: JSinglan/libav
void ff_hevc_cabac_reinit(HEVCContext *s)
{
     int n;
     GetBitContext *gb = &s->gb;
     
     n = -get_bits_count(gb) & 7;
     if (n) skip_bits(gb, n);
     ff_init_cabac_decoder(&s->cc,
                          gb->buffer + get_bits_count(gb) / 8,
                          (get_bits_left(&s->gb) + 7) / 8);
}
コード例 #4
0
ファイル: cabac.c プロジェクト: gromaudio/dashtest
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;
}
コード例 #5
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;
}