comparison vp8.c @ 12343:a18ab740d2db libavcodec

VP8: eliminate a dereference in coefficient decoding
author darkshikari
date Mon, 02 Aug 2010 22:48:38 +0000
parents b4c63ffd959b
children db60aff8eeef
comparison
equal deleted inserted replaced
12342:b4c63ffd959b 12343:a18ab740d2db
193 uint8_t intra; 193 uint8_t intra;
194 uint8_t last; 194 uint8_t last;
195 uint8_t golden; 195 uint8_t golden;
196 uint8_t pred16x16[4]; 196 uint8_t pred16x16[4];
197 uint8_t pred8x8c[3]; 197 uint8_t pred8x8c[3];
198 uint8_t token[4][8][3][NUM_DCT_TOKENS-1]; 198 /* Padded to allow overreads */
199 uint8_t token[4][17][3][NUM_DCT_TOKENS-1];
199 uint8_t mvc[2][19]; 200 uint8_t mvc[2][19];
200 } prob[2]; 201 } prob[2];
201 } VP8Context; 202 } VP8Context;
202 203
203 static void vp8_decode_flush(AVCodecContext *avctx) 204 static void vp8_decode_flush(AVCodecContext *avctx)
386 } 387 }
387 388
388 static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size) 389 static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
389 { 390 {
390 VP56RangeCoder *c = &s->c; 391 VP56RangeCoder *c = &s->c;
391 int header_size, hscale, vscale, i, j, k, l, ret; 392 int header_size, hscale, vscale, i, j, k, l, m, ret;
392 int width = s->avctx->width; 393 int width = s->avctx->width;
393 int height = s->avctx->height; 394 int height = s->avctx->height;
394 395
395 s->keyframe = !(buf[0] & 1); 396 s->keyframe = !(buf[0] & 1);
396 s->profile = (buf[0]>>1) & 7; 397 s->profile = (buf[0]>>1) & 7;
426 427
427 if (hscale || vscale) 428 if (hscale || vscale)
428 av_log_missing_feature(s->avctx, "Upscaling", 1); 429 av_log_missing_feature(s->avctx, "Upscaling", 1);
429 430
430 s->update_golden = s->update_altref = VP56_FRAME_CURRENT; 431 s->update_golden = s->update_altref = VP56_FRAME_CURRENT;
431 memcpy(s->prob->token , vp8_token_default_probs , sizeof(s->prob->token)); 432 for (i = 0; i < 4; i++)
433 for (j = 0; j < 16; j++)
434 memcpy(s->prob->token[i][j], vp8_token_default_probs[i][vp8_coeff_band[j]],
435 sizeof(s->prob->token[i][j]));
432 memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter, sizeof(s->prob->pred16x16)); 436 memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter, sizeof(s->prob->pred16x16));
433 memcpy(s->prob->pred8x8c , vp8_pred8x8c_prob_inter , sizeof(s->prob->pred8x8c)); 437 memcpy(s->prob->pred8x8c , vp8_pred8x8c_prob_inter , sizeof(s->prob->pred8x8c));
434 memcpy(s->prob->mvc , vp8_mv_default_prob , sizeof(s->prob->mvc)); 438 memcpy(s->prob->mvc , vp8_mv_default_prob , sizeof(s->prob->mvc));
435 memset(&s->segmentation, 0, sizeof(s->segmentation)); 439 memset(&s->segmentation, 0, sizeof(s->segmentation));
436 } 440 }
486 490
487 for (i = 0; i < 4; i++) 491 for (i = 0; i < 4; i++)
488 for (j = 0; j < 8; j++) 492 for (j = 0; j < 8; j++)
489 for (k = 0; k < 3; k++) 493 for (k = 0; k < 3; k++)
490 for (l = 0; l < NUM_DCT_TOKENS-1; l++) 494 for (l = 0; l < NUM_DCT_TOKENS-1; l++)
491 if (vp56_rac_get_prob_branchy(c, vp8_token_update_probs[i][j][k][l])) 495 if (vp56_rac_get_prob_branchy(c, vp8_token_update_probs[i][j][k][l])) {
492 s->prob->token[i][j][k][l] = vp8_rac_get_uint(c, 8); 496 int prob = vp8_rac_get_uint(c, 8);
497 for (m = 0; m < 16; m++)
498 if (vp8_coeff_band[m] == j)
499 s->prob->token[i][m][k][l] = prob;
500 }
493 501
494 if ((s->mbskip_enabled = vp8_rac_get(c))) 502 if ((s->mbskip_enabled = vp8_rac_get(c)))
495 s->prob->mbskip = vp8_rac_get_uint(c, 8); 503 s->prob->mbskip = vp8_rac_get_uint(c, 8);
496 504
497 if (!s->keyframe) { 505 if (!s->keyframe) {
805 */ 813 */
806 static int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16], 814 static int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16],
807 uint8_t probs[8][3][NUM_DCT_TOKENS-1], 815 uint8_t probs[8][3][NUM_DCT_TOKENS-1],
808 int i, int zero_nhood, int16_t qmul[2]) 816 int i, int zero_nhood, int16_t qmul[2])
809 { 817 {
810 uint8_t *token_prob = probs[vp8_coeff_band[i]][zero_nhood]; 818 uint8_t *token_prob = probs[i][zero_nhood];
811 int nonzero = 0; 819 int nonzero = 0;
812 int coeff; 820 int coeff;
813 821
814 do { 822 do {
815 if (!vp56_rac_get_prob_branchy(c, token_prob[0])) // DCT_EOB 823 if (!vp56_rac_get_prob_branchy(c, token_prob[0])) // DCT_EOB
817 825
818 skip_eob: 826 skip_eob:
819 if (!vp56_rac_get_prob_branchy(c, token_prob[1])) { // DCT_0 827 if (!vp56_rac_get_prob_branchy(c, token_prob[1])) { // DCT_0
820 if (++i == 16) 828 if (++i == 16)
821 return nonzero; // invalid input; blocks should end with EOB 829 return nonzero; // invalid input; blocks should end with EOB
822 token_prob = probs[vp8_coeff_band[i]][0]; 830 token_prob = probs[i][0];
823 goto skip_eob; 831 goto skip_eob;
824 } 832 }
825 833
826 if (!vp56_rac_get_prob_branchy(c, token_prob[2])) { // DCT_1 834 if (!vp56_rac_get_prob_branchy(c, token_prob[2])) { // DCT_1
827 coeff = 1; 835 coeff = 1;
828 token_prob = probs[vp8_coeff_band[i+1]][1]; 836 token_prob = probs[i+1][1];
829 } else { 837 } else {
830 if (!vp56_rac_get_prob_branchy(c, token_prob[3])) { // DCT 2,3,4 838 if (!vp56_rac_get_prob_branchy(c, token_prob[3])) { // DCT 2,3,4
831 coeff = vp56_rac_get_prob(c, token_prob[4]); 839 coeff = vp56_rac_get_prob(c, token_prob[4]);
832 if (coeff) 840 if (coeff)
833 coeff += vp56_rac_get_prob(c, token_prob[5]); 841 coeff += vp56_rac_get_prob(c, token_prob[5]);
848 int cat = (a<<1) + b; 856 int cat = (a<<1) + b;
849 coeff = 3 + (8<<cat); 857 coeff = 3 + (8<<cat);
850 coeff += vp8_rac_get_coeff(c, vp8_dct_cat_prob[cat]); 858 coeff += vp8_rac_get_coeff(c, vp8_dct_cat_prob[cat]);
851 } 859 }
852 } 860 }
853 token_prob = probs[vp8_coeff_band[i+1]][2]; 861 token_prob = probs[i+1][2];
854 } 862 }
855 863
856 // todo: full [16] qmat? load into register? 864 // todo: full [16] qmat? load into register?
857 block[zigzag_scan[i]] = (vp8_rac_get(c) ? -coeff : coeff) * qmul[!!i]; 865 block[zigzag_scan[i]] = (vp8_rac_get(c) ? -coeff : coeff) * qmul[!!i];
858 nonzero = ++i; 866 nonzero = ++i;