Revision 61ccfcc0 libavcodec/cabac.c

View differences:

libavcodec/cabac.c
127 127
int main(){
128 128
    CABACContext c;
129 129
    uint8_t b[9*SIZE];
130
    uint8_t bit[9*SIZE];
130
    uint8_t r[9*SIZE];
131 131
    int i;
132
    uint8_t state= 0;
132
    uint8_t state[10]= {0};
133 133
    
134 134
    ff_init_cabac_encoder(&c, b, SIZE);
135 135
    ff_init_cabac_states(&c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
136 136
    
137 137
    for(i=0; i<SIZE; i++){
138
        bit[i]= (random()%7)&1;
138
        r[i]= random()%7;
139 139
    }
140 140
    
141 141
    for(i=0; i<SIZE; i++){
142 142
START_TIMER
143
        put_cabac_bypass(&c, bit[i]);
143
        put_cabac_bypass(&c, r[i]&1);
144 144
STOP_TIMER("put_cabac_bypass")
145 145
    }
146 146
    
147 147
    for(i=0; i<SIZE; i++){
148 148
START_TIMER
149
        put_cabac(&c, &state, bit[i]);
149
        put_cabac(&c, state, r[i]&1);
150 150
STOP_TIMER("put_cabac")
151 151
    }
152 152

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

  
159
    for(i=0; i<SIZE; i++){
160
START_TIMER
161
        put_cabac_ueg(&c, state, r[i], 0, 3, 0, 1, 2);
162
STOP_TIMER("put_cabac_ueg")
163
    }    
164
   
153 165
    put_cabac_terminate(&c, 1);
154 166
    
155 167
    ff_init_cabac_decoder(&c, b, SIZE);
156 168
    
157
    state=0;
169
    memset(state, 0, sizeof(state));
158 170
    
159 171
    for(i=0; i<SIZE; i++){
160 172
START_TIMER
161
        if( bit[i] != get_cabac_bypass(&c) )
173
        if( (r[i]&1) != get_cabac_bypass(&c) )
162 174
            printf("CABAC bypass failure at %d\n", i);
163 175
STOP_TIMER("get_cabac_bypass")
164 176
    }
165 177
    
166 178
    for(i=0; i<SIZE; i++){
167 179
START_TIMER
168
        if( bit[i] != get_cabac(&c, &state) )
180
        if( (r[i]&1) != get_cabac(&c, state) )
169 181
            printf("CABAC failure at %d\n", i);
170 182
STOP_TIMER("get_cabac")
171 183
    }
172
    
184

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

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

  
173 199
    if(!get_cabac_terminate(&c))
174 200
        printf("where's the Terminator?\n");
175 201
    

Also available in: Unified diff