Mercurial > libavcodec.hg
changeset 1132:61c89e8ffa88 libavcodec
rvlc decoding support
author | michaelni |
---|---|
date | Wed, 12 Mar 2003 23:09:18 +0000 |
parents | 2575d16b62d7 |
children | 47558360835e |
files | h263.c mpeg4data.h |
diffstat | 2 files changed, 276 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/h263.c Wed Mar 12 21:57:24 2003 +0000 +++ b/h263.c Wed Mar 12 23:09:18 2003 +0000 @@ -70,7 +70,7 @@ int n, int coded); static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded, int intra); + int n, int coded, int intra, int rvlc); static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr); #ifdef CONFIG_ENCODERS static void mpeg4_inv_pred_ac(MpegEncContext * s, DCTELEM *block, int n, @@ -2308,9 +2308,13 @@ &mvtab[0][0], 2, 1); init_rl(&rl_inter); init_rl(&rl_intra); + init_rl(&rvlc_rl_inter); + init_rl(&rvlc_rl_intra); init_rl(&rl_intra_aic); init_vlc_rl(&rl_inter); init_vlc_rl(&rl_intra); + init_vlc_rl(&rvlc_rl_inter); + init_vlc_rl(&rvlc_rl_intra); init_vlc_rl(&rl_intra_aic); init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */, &DCtab_lum[0][1], 2, 1, @@ -3040,15 +3044,6 @@ } }else if(s->mb_intra){ s->ac_pred = s->pred_dir_table[xy]>>7; - - /* decode each block */ - for (i = 0; i < 6; i++) { - if(mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0){ - fprintf(stderr, "texture corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - cbp+=cbp; - } }else if(!s->mb_intra){ // s->mcsel= 0; //FIXME do we need to init that @@ -3058,24 +3053,18 @@ } else { s->mv_type = MV_TYPE_16X16; } - /* decode each block */ - for (i = 0; i < 6; i++) { - if(mpeg4_decode_block(s, block[i], i, cbp&32, 0) < 0){ - fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); - return -1; - } - cbp+=cbp; - } } } else { /* I-Frame */ - int i; s->mb_intra = 1; s->ac_pred = s->pred_dir_table[xy]>>7; - + } + + if (!(mb_type&MB_TYPE_SKIPED)) { + int i; /* decode each block */ for (i = 0; i < 6; i++) { - if(mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0){ - fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y); + if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){ + fprintf(stderr, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra); return -1; } cbp+=cbp; @@ -3410,7 +3399,7 @@ /* decode each block */ if (s->h263_pred) { for (i = 0; i < 6; i++) { - if (mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0) + if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0) return -1; cbp+=cbp; } @@ -3427,7 +3416,7 @@ /* decode each block */ if (s->h263_pred) { for (i = 0; i < 6; i++) { - if (mpeg4_decode_block(s, block[i], i, cbp&32, 0) < 0) + if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0) return -1; cbp+=cbp; } @@ -3695,7 +3684,7 @@ * @return <0 if an error occured */ static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded, int intra) + int n, int coded, int intra, int rvlc) { int level, i, last, run; int dc_pred_dir; @@ -3704,6 +3693,8 @@ const uint8_t * scan_table; int qmul, qadd; + //Note intra & rvlc should be optimized away if this is inlined + if(intra) { /* DC coef */ if(s->partitioned_frame){ @@ -3720,8 +3711,14 @@ i = 0; if (!coded) goto not_coded; - rl = &rl_intra; - rl_vlc = rl_intra.rl_vlc[0]; + + if(rvlc){ + rl = &rvlc_rl_intra; + rl_vlc = rvlc_rl_intra.rl_vlc[0]; + }else{ + rl = &rl_intra; + rl_vlc = rl_intra.rl_vlc[0]; + } if (s->ac_pred) { if (dc_pred_dir == 0) scan_table = s->intra_v_scantable.permutated; /* left */ @@ -3738,18 +3735,27 @@ s->block_last_index[n] = i; return 0; } - rl = &rl_inter; + if(rvlc) rl = &rvlc_rl_inter; + else rl = &rl_inter; scan_table = s->intra_scantable.permutated; if(s->mpeg_quant){ qmul=1; qadd=0; - rl_vlc = rl_inter.rl_vlc[0]; + if(rvlc){ + rl_vlc = rvlc_rl_inter.rl_vlc[0]; + }else{ + rl_vlc = rl_inter.rl_vlc[0]; + } }else{ qmul = s->qscale << 1; qadd = (s->qscale - 1) | 1; - rl_vlc = rl_inter.rl_vlc[s->qscale]; + if(rvlc){ + rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale]; + }else{ + rl_vlc = rl_inter.rl_vlc[s->qscale]; + } } } { @@ -3758,9 +3764,39 @@ UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); if (level==0) { + /* escape */ + if(rvlc){ + if(SHOW_UBITS(re, &s->gb, 1)==0){ + fprintf(stderr, "1. marker bit missing in rvlc esc\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 1); + + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); + run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); + SKIP_COUNTER(re, &s->gb, 1+1+6); + UPDATE_CACHE(re, &s->gb); + + if(SHOW_UBITS(re, &s->gb, 1)==0){ + fprintf(stderr, "2. marker bit missing in rvlc esc\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 1); + + level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11); + + if(SHOW_UBITS(re, &s->gb, 5)!=0x10){ + fprintf(stderr, "reverse esc missing\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 5); + + level= level * qmul + qadd; + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1); + SKIP_COUNTER(re, &s->gb, 1+11+5+1); + + i+= run + 1; + if(last) i+=192; + }else{ int cache; cache= GET_CACHE(re, &s->gb); - /* escape */ if (cache&0x80000000) { if (cache&0x40000000) { /* third escape */ @@ -3842,6 +3878,7 @@ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); } + } } else { i+= run; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
--- a/mpeg4data.h Wed Mar 12 21:57:24 2003 +0000 +++ b/mpeg4data.h Wed Mar 12 23:09:18 2003 +0000 @@ -121,6 +121,214 @@ intra_level, }; +static const uint16_t inter_rvlc[170][2]={ //note this is identical to the intra rvlc except that its reordered +{0x0006, 3},{0x0001, 4},{0x0004, 5},{0x001C, 7}, +{0x003C, 8},{0x003D, 8},{0x007C, 9},{0x00FC, 10}, +{0x00FD, 10},{0x01FC, 11},{0x01FD, 11},{0x03FC, 12}, +{0x07FC, 13},{0x07FD, 13},{0x0BFC, 13},{0x0BFD, 13}, +{0x0FFC, 14},{0x0FFD, 14},{0x1FFC, 15},{0x0007, 3}, +{0x000C, 6},{0x005C, 8},{0x007D, 9},{0x017C, 10}, +{0x02FC, 11},{0x03FD, 12},{0x0DFC, 13},{0x17FC, 14}, +{0x17FD, 14},{0x000A, 4},{0x001D, 7},{0x00BC, 9}, +{0x02FD, 11},{0x05FC, 12},{0x1BFC, 14},{0x1BFD, 14}, +{0x0005, 5},{0x005D, 8},{0x017D, 10},{0x05FD, 12}, +{0x0DFD, 13},{0x1DFC, 14},{0x1FFD, 15},{0x0008, 5}, +{0x006C, 8},{0x037C, 11},{0x0EFC, 13},{0x2FFC, 15}, +{0x0009, 5},{0x00BD, 9},{0x037D, 11},{0x0EFD, 13}, +{0x000D, 6},{0x01BC, 10},{0x06FC, 12},{0x1DFD, 14}, +{0x0014, 6},{0x01BD, 10},{0x06FD, 12},{0x2FFD, 15}, +{0x0015, 6},{0x01DC, 10},{0x0F7C, 13},{0x002C, 7}, +{0x01DD, 10},{0x1EFC, 14},{0x002D, 7},{0x03BC, 11}, +{0x0034, 7},{0x077C, 12},{0x006D, 8},{0x0F7D, 13}, +{0x0074, 8},{0x1EFD, 14},{0x0075, 8},{0x1F7C, 14}, +{0x00DC, 9},{0x1F7D, 14},{0x00DD, 9},{0x1FBC, 14}, +{0x00EC, 9},{0x37FC, 15},{0x01EC, 10},{0x01ED, 10}, +{0x01F4, 10},{0x03BD, 11},{0x03DC, 11},{0x03DD, 11}, +{0x03EC, 11},{0x03ED, 11},{0x03F4, 11},{0x077D, 12}, +{0x07BC, 12},{0x07BD, 12},{0x0FBC, 13},{0x0FBD, 13}, +{0x0FDC, 13},{0x0FDD, 13},{0x1FBD, 14},{0x1FDC, 14}, +{0x1FDD, 14},{0x37FD, 15},{0x3BFC, 15}, +{0x000B, 4},{0x0078, 8},{0x03F5, 11},{0x0FEC, 13}, +{0x1FEC, 14},{0x0012, 5},{0x00ED, 9},{0x07DC, 12}, +{0x1FED, 14},{0x3BFD, 15},{0x0013, 5},{0x03F8, 11}, +{0x3DFC, 15},{0x0018, 6},{0x07DD, 12},{0x0019, 6}, +{0x07EC, 12},{0x0022, 6},{0x0FED, 13},{0x0023, 6}, +{0x0FF4, 13},{0x0035, 7},{0x0FF5, 13},{0x0038, 7}, +{0x0FF8, 13},{0x0039, 7},{0x0FF9, 13},{0x0042, 7}, +{0x1FF4, 14},{0x0043, 7},{0x1FF5, 14},{0x0079, 8}, +{0x1FF8, 14},{0x0082, 8},{0x3DFD, 15},{0x0083, 8}, +{0x00F4, 9},{0x00F5, 9},{0x00F8, 9},{0x00F9, 9}, +{0x0102, 9},{0x0103, 9},{0x01F5, 10},{0x01F8, 10}, +{0x01F9, 10},{0x0202, 10},{0x0203, 10},{0x03F9, 11}, +{0x0402, 11},{0x0403, 11},{0x07ED, 12},{0x07F4, 12}, +{0x07F5, 12},{0x07F8, 12},{0x07F9, 12},{0x0802, 12}, +{0x0803, 12},{0x1002, 13},{0x1003, 13},{0x1FF9, 14}, +{0x2002, 14},{0x2003, 14},{0x3EFC, 15},{0x3EFD, 15}, +{0x3F7C, 15},{0x3F7D, 15},{0x0000, 4} +}; + +static const uint8_t inter_rvlc_run[169]={ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 2, 2, 3, 3, 3, 3, + 3, 3, 3, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 6, 6, 6, 6, + 7, 7, 7, 7, 8, 8, 8, 9, + 9, 9, 10, 10, 11, 11, 12, 12, +13, 13, 14, 14, 15, 15, 16, 16, +17, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, + 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 2, 2, 2, 3, 3, 4, + 4, 5, 5, 6, 6, 7, 7, 8, + 8, 9, 9, 10, 10, 11, 11, 12, +12, 13, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, +27, 28, 29, 30, 31, 32, 33, 34, +35, 36, 37, 38, 39, 40, 41, 42, +43, 44, +}; + +static const uint8_t inter_rvlc_level[169]={ + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 1, 2, 3, + 4, 5, 6, 7, 1, 2, 3, 4, + 5, 6, 7, 1, 2, 3, 4, 5, + 1, 2, 3, 4, 1, 2, 3, 4, + 1, 2, 3, 4, 1, 2, 3, 1, + 2, 3, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, + 1, 2, 3, 4, 5, 1, 2, 3, + 4, 5, 1, 2, 3, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, +}; + +static RLTable rvlc_rl_inter = { + 169, + 103, + inter_rvlc, + inter_rvlc_run, + inter_rvlc_level, +}; + +static const uint16_t intra_rvlc[170][2]={ +{0x0006, 3},{0x0007, 3},{0x000A, 4},{0x0009, 5}, +{0x0014, 6},{0x0015, 6},{0x0034, 7},{0x0074, 8}, +{0x0075, 8},{0x00DD, 9},{0x00EC, 9},{0x01EC, 10}, +{0x01ED, 10},{0x01F4, 10},{0x03EC, 11},{0x03ED, 11}, +{0x03F4, 11},{0x077D, 12},{0x07BC, 12},{0x0FBD, 13}, +{0x0FDC, 13},{0x07BD, 12},{0x0FDD, 13},{0x1FBD, 14}, +{0x1FDC, 14},{0x1FDD, 14},{0x1FFC, 15},{0x0001, 4}, +{0x0008, 5},{0x002D, 7},{0x006C, 8},{0x006D, 8}, +{0x00DC, 9},{0x01DD, 10},{0x03DC, 11},{0x03DD, 11}, +{0x077C, 12},{0x0FBC, 13},{0x1F7D, 14},{0x1FBC, 14}, +{0x0004, 5},{0x002C, 7},{0x00BC, 9},{0x01DC, 10}, +{0x03BC, 11},{0x03BD, 11},{0x0EFD, 13},{0x0F7C, 13}, +{0x0F7D, 13},{0x1EFD, 14},{0x1F7C, 14},{0x0005, 5}, +{0x005C, 8},{0x00BD, 9},{0x037D, 11},{0x06FC, 12}, +{0x0EFC, 13},{0x1DFD, 14},{0x1EFC, 14},{0x1FFD, 15}, +{0x000C, 6},{0x005D, 8},{0x01BD, 10},{0x03FD, 12}, +{0x06FD, 12},{0x1BFD, 14},{0x000D, 6},{0x007D, 9}, +{0x02FC, 11},{0x05FC, 12},{0x1BFC, 14},{0x1DFC, 14}, +{0x001C, 7},{0x017C, 10},{0x02FD, 11},{0x05FD, 12}, +{0x2FFC, 15},{0x001D, 7},{0x017D, 10},{0x037C, 11}, +{0x0DFD, 13},{0x2FFD, 15},{0x003C, 8},{0x01BC, 10}, +{0x0BFD, 13},{0x17FD, 14},{0x003D, 8},{0x01FD, 11}, +{0x0DFC, 13},{0x37FC, 15},{0x007C, 9},{0x03FC, 12}, +{0x00FC, 10},{0x0BFC, 13},{0x00FD, 10},{0x37FD, 15}, +{0x01FC, 11},{0x07FC, 13},{0x07FD, 13},{0x0FFC, 14}, +{0x0FFD, 14},{0x17FC, 14},{0x3BFC, 15}, +{0x000B, 4},{0x0078, 8},{0x03F5, 11},{0x0FEC, 13}, +{0x1FEC, 14},{0x0012, 5},{0x00ED, 9},{0x07DC, 12}, +{0x1FED, 14},{0x3BFD, 15},{0x0013, 5},{0x03F8, 11}, +{0x3DFC, 15},{0x0018, 6},{0x07DD, 12},{0x0019, 6}, +{0x07EC, 12},{0x0022, 6},{0x0FED, 13},{0x0023, 6}, +{0x0FF4, 13},{0x0035, 7},{0x0FF5, 13},{0x0038, 7}, +{0x0FF8, 13},{0x0039, 7},{0x0FF9, 13},{0x0042, 7}, +{0x1FF4, 14},{0x0043, 7},{0x1FF5, 14},{0x0079, 8}, +{0x1FF8, 14},{0x0082, 8},{0x3DFD, 15},{0x0083, 8}, +{0x00F4, 9},{0x00F5, 9},{0x00F8, 9},{0x00F9, 9}, +{0x0102, 9},{0x0103, 9},{0x01F5, 10},{0x01F8, 10}, +{0x01F9, 10},{0x0202, 10},{0x0203, 10},{0x03F9, 11}, +{0x0402, 11},{0x0403, 11},{0x07ED, 12},{0x07F4, 12}, +{0x07F5, 12},{0x07F8, 12},{0x07F9, 12},{0x0802, 12}, +{0x0803, 12},{0x1002, 13},{0x1003, 13},{0x1FF9, 14}, +{0x2002, 14},{0x2003, 14},{0x3EFC, 15},{0x3EFD, 15}, +{0x3F7C, 15},{0x3F7D, 15},{0x0000, 4} +}; + +static const uint8_t intra_rvlc_run[169]={ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 4, 4, 4, 4, + 4, 4, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 7, 7, 7, + 7, 7, 8, 8, 8, 8, 9, 9, + 9, 9, 10, 10, 11, 11, 12, 12, +13, 14, 15, 16, 17, 18, 19, + 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 2, 2, 2, 3, 3, 4, + 4, 5, 5, 6, 6, 7, 7, 8, + 8, 9, 9, 10, 10, 11, 11, 12, +12, 13, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, +27, 28, 29, 30, 31, 32, 33, 34, +35, 36, 37, 38, 39, 40, 41, 42, +43, 44, +}; + +static const uint8_t intra_rvlc_level[169]={ + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, + 5, 6, 1, 2, 3, 4, 5, 6, + 1, 2, 3, 4, 5, 1, 2, 3, + 4, 5, 1, 2, 3, 4, 1, 2, + 3, 4, 1, 2, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 1, + 1, 2, 3, 4, 5, 1, 2, 3, + 4, 5, 1, 2, 3, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, +}; + +static RLTable rvlc_rl_intra = { + 169, + 103, + intra_rvlc, + intra_rvlc_run, + intra_rvlc_level, +}; + static const uint16_t sprite_trajectory_tab[15][2] = { {0x00, 2}, {0x02, 3}, {0x03, 3}, {0x04, 3}, {0x05, 3}, {0x06, 3}, {0x0E, 4}, {0x1E, 5}, {0x3E, 6}, {0x7E, 7}, {0xFE, 8},