Mercurial > libavcodec.hg
comparison h263.c @ 1482:b372ecde32a8 libavcodec
h263 stuffing decode fix
author | michaelni |
---|---|
date | Fri, 26 Sep 2003 22:18:25 +0000 |
parents | 460e5ead6722 |
children | 8e7d8112de29 |
comparison
equal
deleted
inserted
replaced
1481:0cfed95c7707 | 1482:b372ecde32a8 |
---|---|
38 | 38 |
39 //#undef NDEBUG | 39 //#undef NDEBUG |
40 //#include <assert.h> | 40 //#include <assert.h> |
41 | 41 |
42 #define INTRA_MCBPC_VLC_BITS 6 | 42 #define INTRA_MCBPC_VLC_BITS 6 |
43 #define INTER_MCBPC_VLC_BITS 6 | 43 #define INTER_MCBPC_VLC_BITS 7 |
44 #define CBPY_VLC_BITS 6 | 44 #define CBPY_VLC_BITS 6 |
45 #define MV_VLC_BITS 9 | 45 #define MV_VLC_BITS 9 |
46 #define DC_VLC_BITS 9 | 46 #define DC_VLC_BITS 9 |
47 #define SPRITE_TRAJ_VLC_BITS 6 | 47 #define SPRITE_TRAJ_VLC_BITS 6 |
48 #define MB_TYPE_B_VLC_BITS 4 | 48 #define MB_TYPE_B_VLC_BITS 4 |
2426 static int done = 0; | 2426 static int done = 0; |
2427 | 2427 |
2428 if (!done) { | 2428 if (!done) { |
2429 done = 1; | 2429 done = 1; |
2430 | 2430 |
2431 init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 8, | 2431 init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, |
2432 intra_MCBPC_bits, 1, 1, | 2432 intra_MCBPC_bits, 1, 1, |
2433 intra_MCBPC_code, 1, 1); | 2433 intra_MCBPC_code, 1, 1); |
2434 init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 25, | 2434 init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, |
2435 inter_MCBPC_bits, 1, 1, | 2435 inter_MCBPC_bits, 1, 1, |
2436 inter_MCBPC_code, 1, 1); | 2436 inter_MCBPC_code, 1, 1); |
2437 init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16, | 2437 init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16, |
2438 &cbpy_tab[0][1], 2, 1, | 2438 &cbpy_tab[0][1], 2, 1, |
2439 &cbpy_tab[0][0], 2, 1); | 2439 &cbpy_tab[0][0], 2, 1); |
2869 | 2869 |
2870 if(show_bits_long(&s->gb, 19)==DC_MARKER){ | 2870 if(show_bits_long(&s->gb, 19)==DC_MARKER){ |
2871 return mb_num-1; | 2871 return mb_num-1; |
2872 } | 2872 } |
2873 | 2873 |
2874 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); | 2874 do{ |
2875 if (cbpc < 0){ | 2875 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); |
2876 | 2876 if (cbpc < 0){ |
2877 fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | 2877 fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); |
2878 return -1; | 2878 return -1; |
2879 } | 2879 } |
2880 }while(cbpc == 8); | |
2881 | |
2880 s->cbp_table[xy]= cbpc & 3; | 2882 s->cbp_table[xy]= cbpc & 3; |
2881 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; | 2883 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
2882 s->mb_intra = 1; | 2884 s->mb_intra = 1; |
2883 | 2885 |
2884 if(cbpc & 4) { | 2886 if(cbpc & 4) { |
2901 }else{ /* P/S_TYPE */ | 2903 }else{ /* P/S_TYPE */ |
2902 int mx, my, pred_x, pred_y, bits; | 2904 int mx, my, pred_x, pred_y, bits; |
2903 int16_t * const mot_val= s->motion_val[s->block_index[0]]; | 2905 int16_t * const mot_val= s->motion_val[s->block_index[0]]; |
2904 const int stride= s->block_wrap[0]*2; | 2906 const int stride= s->block_wrap[0]*2; |
2905 | 2907 |
2908 do{ | |
2906 bits= show_bits(&s->gb, 17); | 2909 bits= show_bits(&s->gb, 17); |
2907 if(bits==MOTION_MARKER){ | 2910 if(bits==MOTION_MARKER){ |
2908 return mb_num-1; | 2911 return mb_num-1; |
2909 } | 2912 } |
2910 skip_bits1(&s->gb); | 2913 skip_bits1(&s->gb); |
2925 | 2928 |
2926 if(s->mbintra_table[xy]) | 2929 if(s->mbintra_table[xy]) |
2927 ff_clean_intra_table_entries(s); | 2930 ff_clean_intra_table_entries(s); |
2928 continue; | 2931 continue; |
2929 } | 2932 } |
2933 | |
2930 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); | 2934 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
2931 if (cbpc < 0){ | 2935 if (cbpc < 0){ |
2932 fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | 2936 fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); |
2933 return -1; | 2937 return -1; |
2934 } | 2938 } |
2935 if (cbpc > 20) | 2939 }while(cbpc == 20); |
2936 cbpc+=3; | 2940 |
2937 else if (cbpc == 20) | |
2938 fprintf(stderr, "Stuffing !"); | |
2939 s->cbp_table[xy]= cbpc&(8+3); //8 is dquant | 2941 s->cbp_table[xy]= cbpc&(8+3); //8 is dquant |
2940 | 2942 |
2941 s->mb_intra = ((cbpc & 4) != 0); | 2943 s->mb_intra = ((cbpc & 4) != 0); |
2942 | 2944 |
2943 if(s->mb_intra){ | 2945 if(s->mb_intra){ |
3232 int16_t *mot_val; | 3234 int16_t *mot_val; |
3233 static int8_t quant_tab[4] = { -1, -2, 1, 2 }; | 3235 static int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
3234 const int xy= s->mb_x + s->mb_y * s->mb_stride; | 3236 const int xy= s->mb_x + s->mb_y * s->mb_stride; |
3235 | 3237 |
3236 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { | 3238 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { |
3239 do{ | |
3237 if (get_bits1(&s->gb)) { | 3240 if (get_bits1(&s->gb)) { |
3238 /* skip mb */ | 3241 /* skip mb */ |
3239 s->mb_intra = 0; | 3242 s->mb_intra = 0; |
3240 for(i=0;i<6;i++) | 3243 for(i=0;i<6;i++) |
3241 s->block_last_index[i] = -1; | 3244 s->block_last_index[i] = -1; |
3257 } | 3260 } |
3258 goto end; | 3261 goto end; |
3259 } | 3262 } |
3260 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); | 3263 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
3261 //fprintf(stderr, "\tCBPC: %d", cbpc); | 3264 //fprintf(stderr, "\tCBPC: %d", cbpc); |
3262 if (cbpc < 0) | 3265 if (cbpc < 0){ |
3266 fprintf(stderr, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); | |
3263 return -1; | 3267 return -1; |
3264 if (cbpc > 20) | 3268 } |
3265 cbpc+=3; | 3269 }while(cbpc == 20); |
3266 else if (cbpc == 20) | |
3267 fprintf(stderr, "Stuffing !"); | |
3268 | 3270 |
3269 dquant = cbpc & 8; | 3271 dquant = cbpc & 8; |
3270 s->mb_intra = ((cbpc & 4) != 0); | 3272 s->mb_intra = ((cbpc & 4) != 0); |
3271 if (s->mb_intra) goto intra; | 3273 if (s->mb_intra) goto intra; |
3272 | 3274 |
3499 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | 3501 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
3500 mb_type |= ff_mpeg4_set_direct_mv(s, mx, my); | 3502 mb_type |= ff_mpeg4_set_direct_mv(s, mx, my); |
3501 } | 3503 } |
3502 s->current_picture.mb_type[xy]= mb_type; | 3504 s->current_picture.mb_type[xy]= mb_type; |
3503 } else { /* I-Frame */ | 3505 } else { /* I-Frame */ |
3504 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); | 3506 do{ |
3505 if (cbpc < 0) | 3507 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); |
3506 return -1; | 3508 if (cbpc < 0){ |
3509 fprintf(stderr, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); | |
3510 return -1; | |
3511 } | |
3512 }while(cbpc == 8); | |
3513 | |
3507 dquant = cbpc & 4; | 3514 dquant = cbpc & 4; |
3508 s->mb_intra = 1; | 3515 s->mb_intra = 1; |
3509 intra: | 3516 intra: |
3510 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; | 3517 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
3511 if (s->h263_pred || s->h263_aic) { | 3518 if (s->h263_pred || s->h263_aic) { |
3518 } | 3525 } |
3519 }else | 3526 }else |
3520 s->ac_pred = 0; | 3527 s->ac_pred = 0; |
3521 | 3528 |
3522 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); | 3529 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
3523 if(cbpy<0) return -1; | 3530 if(cbpy<0){ |
3531 fprintf(stderr, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | |
3532 return -1; | |
3533 } | |
3524 cbp = (cbpc & 3) | (cbpy << 2); | 3534 cbp = (cbpc & 3) | (cbpy << 2); |
3525 if (dquant) { | 3535 if (dquant) { |
3526 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); | 3536 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); |
3527 } | 3537 } |
3528 | 3538 |