comparison vc9.c @ 2475:db05cb59c6fc libavcodec

- add another way to decode norm6 VLC; modify VLC_NORM6_METH0D define in vc9data.h to select the behaviour - modified decode_b_picture_primary_header so that decode_bi_picture_header is no more required Fixes: - modifications for some more using of MpegEncContext - fixed a bit frame type decoding - switch from pointers to index for AC tables - corrected P CBPCY decoding (p_cbpcy += 4) patch by anonymous
author michael
date Sun, 30 Jan 2005 21:54:20 +0000
parents 81a9f883a17a
children 38dbec9a148d
comparison
equal deleted inserted replaced
2474:81a9f883a17a 2475:db05cb59c6fc
131 static VLC vc9_bfraction_vlc; 131 static VLC vc9_bfraction_vlc;
132 #define VC9_IMODE_VLC_BITS 4 132 #define VC9_IMODE_VLC_BITS 4
133 static VLC vc9_imode_vlc; 133 static VLC vc9_imode_vlc;
134 #define VC9_NORM2_VLC_BITS 3 134 #define VC9_NORM2_VLC_BITS 3
135 static VLC vc9_norm2_vlc; 135 static VLC vc9_norm2_vlc;
136 #if TILE_VLC_METHOD == 1
136 #define VC9_NORM6_VLC_BITS 9 137 #define VC9_NORM6_VLC_BITS 9
137 static VLC vc9_norm6_vlc; 138 static VLC vc9_norm6_vlc;
139 #endif
140 #if TILE_VLC_METHOD == 2
141 #define VC9_NORM6_FIRST_BITS 8
142 #define VC9_NORM6_SECOND 8
143 static VLC vc9_norm6_first, vc9_norm6_second;
144 #endif
138 /* Could be optimized, one table only needs 8 bits */ 145 /* Could be optimized, one table only needs 8 bits */
139 #define VC9_TTMB_VLC_BITS 9 //12 146 #define VC9_TTMB_VLC_BITS 9 //12
140 static VLC vc9_ttmb_vlc[3]; 147 static VLC vc9_ttmb_vlc[3];
141 #define VC9_MV_DIFF_VLC_BITS 9 //15 148 #define VC9_MV_DIFF_VLC_BITS 9 //15
142 static VLC vc9_mv_diff_vlc[4]; 149 static VLC vc9_mv_diff_vlc[4];
210 /* All profiles */ 217 /* All profiles */
211 uint8_t mv_mode, mv_mode2; /* MV coding mode */ 218 uint8_t mv_mode, mv_mode2; /* MV coding mode */
212 uint8_t pq, altpq; /* Quantizers */ 219 uint8_t pq, altpq; /* Quantizers */
213 uint8_t dquantfrm, dqprofile, dqsbedge, dqbilevel; /* pquant parameters */ 220 uint8_t dquantfrm, dqprofile, dqsbedge, dqbilevel; /* pquant parameters */
214 int tile; /* 3x2 if (width_mb%3) else 2x3 */ 221 int tile; /* 3x2 if (width_mb%3) else 2x3 */
215 VLC *luma_ac_vlc, *chroma_ac_vlc, 222 int ac_table_level;
216 *luma_dc_vlc, *chroma_dc_vlc; /* transac/dcfrm bits are indexes */ 223 VLC *luma_dc_vlc, *chroma_dc_vlc; /* transac/dcfrm bits are indexes */
217 uint8_t ttmbf, ttfrm; /* Transform type */ 224 uint8_t ttmbf, ttfrm; /* Transform type */
218 uint8_t lumscale, lumshift; /* Luma compensation parameters */ 225 uint8_t lumscale, lumshift; /* Luma compensation parameters */
219 int16_t bfraction; /* Relative position % anchors=> how to scale MVs */ 226 int16_t bfraction; /* Relative position % anchors=> how to scale MVs */
220 uint8_t halfpq; /* Uniform quant over image and qp+.5 */ 227 uint8_t halfpq; /* Uniform quant over image and qp+.5 */
221 uint8_t respic; 228 uint8_t respic;
229 int buffer_fullness; /* For HRD ? */
222 /* Ranges: 230 /* Ranges:
223 * 0 -> [-64n 63.f] x [-32, 31.f] 231 * 0 -> [-64n 63.f] x [-32, 31.f]
224 * 1 -> [-128, 127.f] x [-64, 63.f] 232 * 1 -> [-128, 127.f] x [-64, 63.f]
225 * 2 -> [-512, 511.f] x [-128, 127.f] 233 * 2 -> [-512, 511.f] x [-128, 127.f]
226 * 3 -> [-1024, 1023.f] x [-256, 255.f] 234 * 3 -> [-1024, 1023.f] x [-256, 255.f]
227 */ 235 */
228 uint8_t mvrange; 236 uint8_t mvrange;
229 uint8_t pquantizer; 237 uint8_t pquantizer;
230 uint8_t *previous_line_cbpcy; /* To use for predicted CBPCY */ 238 uint8_t *previous_line_cbpcy; /* To use for predicted CBPCY */
231 VLC *cbpcy_vlc /* Current CBPCY VLC table */, 239 VLC *cbpcy_vlc /* Current CBPCY VLC table */,
232 *mv_diff_vlc /* Current MV Diff VLC table */,
233 *ttmb_vlc /* Current MB Transform Type VLC table */; 240 *ttmb_vlc /* Current MB Transform Type VLC table */;
234 BitPlane mv_type_mb_plane; /* bitplane for mv_type == (4MV) */ 241 BitPlane mv_type_mb_plane; /* bitplane for mv_type == (4MV) */
235 BitPlane skip_mb_plane, /* bitplane for skipped MBs */ 242 BitPlane skip_mb_plane, /* bitplane for skipped MBs */
236 direct_mb_plane; /* bitplane for "direct" MBs */ 243 direct_mb_plane; /* bitplane for "direct" MBs */
237 244
310 v->ac_pred_plane = v->over_flags_plane = (struct BitPlane) { NULL, 0, 0, 0 }; 317 v->ac_pred_plane = v->over_flags_plane = (struct BitPlane) { NULL, 0, 0, 0 };
311 v->hrd_rate = v->hrd_buffer = NULL; 318 v->hrd_rate = v->hrd_buffer = NULL;
312 #endif 319 #endif
313 320
314 /* VLC tables */ 321 /* VLC tables */
315 #if 0 // spec -> actual tables converter 322 #if TILE_VLC_METHOD == 1
323 # if 0 // spec -> actual tables converter
316 for(i=0; i<64; i++){ 324 for(i=0; i<64; i++){
317 int code= (vc9_norm6_spec[i][1] << vc9_norm6_spec[i][4]) + vc9_norm6_spec[i][3]; 325 int code= (vc9_norm6_spec[i][1] << vc9_norm6_spec[i][4]) + vc9_norm6_spec[i][3];
318 av_log(NULL, AV_LOG_DEBUG, "0x%03X, ", code); 326 av_log(NULL, AV_LOG_DEBUG, "0x%03X, ", code);
319 if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n"); 327 if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n");
320 } 328 }
321 for(i=0; i<64; i++){ 329 for(i=0; i<64; i++){
322 int code= vc9_norm6_spec[i][2] + vc9_norm6_spec[i][4]; 330 int code= vc9_norm6_spec[i][2] + vc9_norm6_spec[i][4];
323 av_log(NULL, AV_LOG_DEBUG, "%2d, ", code); 331 av_log(NULL, AV_LOG_DEBUG, "%2d, ", code);
324 if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n"); 332 if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n");
325 } 333 }
334 # endif
326 #endif 335 #endif
327 if(!done) 336 if(!done)
328 { 337 {
329 done = 1; 338 done = 1;
330 INIT_VLC(&vc9_bfraction_vlc, VC9_BFRACTION_VLC_BITS, 23, 339 INIT_VLC(&vc9_bfraction_vlc, VC9_BFRACTION_VLC_BITS, 23,
331 vc9_bfraction_bits, 1, 1, 340 vc9_bfraction_bits, 1, 1,
332 vc9_bfraction_codes, 1, 1, 1); 341 vc9_bfraction_codes, 1, 1, 1);
333 INIT_VLC(&vc9_norm2_vlc, VC9_NORM2_VLC_BITS, 4, 342 INIT_VLC(&vc9_norm2_vlc, VC9_NORM2_VLC_BITS, 4,
334 vc9_norm2_bits, 1, 1, 343 vc9_norm2_bits, 1, 1,
335 vc9_norm2_codes, 1, 1, 1); 344 vc9_norm2_codes, 1, 1, 1);
345 #if TILE_VLC_METHOD == 1
336 INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64, 346 INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64,
337 vc9_norm6_bits, 1, 1, 347 vc9_norm6_bits, 1, 1,
338 vc9_norm6_codes, 2, 2, 1); 348 vc9_norm6_codes, 2, 2, 1);
349 #endif
350 #if TILE_VLC_METHOD == 2
351 INIT_VLC(&vc9_norm6_first, VC9_NORM6_FIRST_BITS, 64,
352 &vc9_norm6_first[0][1], 1, 1,
353 &vc9_norm6_first[0][0], 1, 1, 1);
354 INIT_VLC(&vc9_norm6_second, VC9_NORM6_SECOND_BITS, 64,
355 vc9_norm6_second[0][1], 1, 1,
356 vc9_norm6_second[0][1], 1, 1, 1);
357 #endif
339 INIT_VLC(&vc9_imode_vlc, VC9_IMODE_VLC_BITS, 7, 358 INIT_VLC(&vc9_imode_vlc, VC9_IMODE_VLC_BITS, 7,
340 vc9_imode_bits, 1, 1, 359 vc9_imode_bits, 1, 1,
341 vc9_imode_codes, 1, 1, 1); 360 vc9_imode_codes, 1, 1, 1);
342 for (i=0; i<3; i++) 361 for (i=0; i<3; i++)
343 { 362 {
399 { 418 {
400 //mantissae, ordered (if not, use a function ? 419 //mantissae, ordered (if not, use a function ?
401 v->hrd_rate[i] = get_bits(gb, 16); 420 v->hrd_rate[i] = get_bits(gb, 16);
402 if (i && v->hrd_rate[i-1]>=v->hrd_rate[i]) 421 if (i && v->hrd_rate[i-1]>=v->hrd_rate[i])
403 { 422 {
404 av_log(v, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:" 423 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:"
405 "%i vs %i\n", v->hrd_rate[i-1], v->hrd_rate[i]); 424 "%i vs %i\n", v->hrd_rate[i-1], v->hrd_rate[i]);
406 return -1; 425 return -1;
407 } 426 }
408 v->hrd_buffer[i] = get_bits(gb, 16); 427 v->hrd_buffer[i] = get_bits(gb, 16);
409 if (i && v->hrd_buffer[i-1]<v->hrd_buffer[i]) 428 if (i && v->hrd_buffer[i-1]<v->hrd_buffer[i])
410 { 429 {
411 av_log(v, AV_LOG_ERROR, "HDR Buffers aren't decreasing:" 430 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Buffers aren't decreasing:"
412 "%i vs %i\n", v->hrd_buffer[i-1], v->hrd_buffer[i]); 431 "%i vs %i\n", v->hrd_buffer[i-1], v->hrd_buffer[i]);
413 return -1; 432 return -1;
414 } 433 }
415 } 434 }
416 return 0; 435 return 0;
474 avctx->coded_width = avctx->width; 493 avctx->coded_width = avctx->width;
475 avctx->coded_height = avctx->height; 494 avctx->coded_height = avctx->height;
476 } 495 }
477 496
478 /* 6.1.8, p23 */ 497 /* 6.1.8, p23 */
479 if ( get_bits(gb, 1) /* framerateflag */) 498 if ( !get_bits(gb, 1) /* framerateflag */)
480 { 499 {
481 if ( get_bits(gb, 1) /* framerateind */) 500 if ( get_bits(gb, 1) /* framerateind */)
482 { 501 {
483 nr = get_bits(gb, 8); 502 nr = get_bits(gb, 8);
484 dr = get_bits(gb, 4); 503 dr = get_bits(gb, 4);
597 616
598 // (fps-2)/4 (->30) 617 // (fps-2)/4 (->30)
599 v->frmrtq_postproc = get_bits(gb, 3); //common 618 v->frmrtq_postproc = get_bits(gb, 3); //common
600 // (bitrate-32kbps)/64kbps 619 // (bitrate-32kbps)/64kbps
601 v->bitrtq_postproc = get_bits(gb, 5); //common 620 v->bitrtq_postproc = get_bits(gb, 5); //common
602 v->loopfilter = get_bits(gb, 1); //common 621 v->s.loop_filter = get_bits(gb, 1); //common
603 622
604 #if HAS_ADVANCED_PROFILE 623 #if HAS_ADVANCED_PROFILE
605 if (v->profile <= PROFILE_MAIN) 624 if (v->profile <= PROFILE_MAIN)
606 #endif 625 #endif
607 { 626 {
608 v->res_x8 = get_bits(gb, 1); //reserved 627 v->res_x8 = get_bits(gb, 1); //reserved
609 if (v->res_x8) 628 if (v->res_x8)
610 { 629 {
611 av_log(avctx, AV_LOG_ERROR, 630 av_log(avctx, AV_LOG_ERROR,
612 "1 for reserved RES_X8 is forbidden\n"); 631 "1 for reserved RES_X8 is forbidden\n");
613 return -1; 632 //return -1;
614 } 633 }
615 v->multires = get_bits(gb, 1); 634 v->multires = get_bits(gb, 1);
616 v->res_fasttx = get_bits(gb, 1); 635 v->res_fasttx = get_bits(gb, 1);
617 if (!v->res_fasttx) 636 if (!v->res_fasttx)
618 { 637 {
795 plane ++; 814 plane ++;
796 } 815 }
797 } 816 }
798 817
799 //FIXME optimize 818 //FIXME optimize
800 //FIXME is this supposed to set elements to 0/FF or 0/1? 0/x!=0, not used for
801 // prediction
802 //FIXME Use BitPlane struct or return if table is raw (no bits read here but 819 //FIXME Use BitPlane struct or return if table is raw (no bits read here but
803 // later on) 820 // later on)
821 //Elements must be either 0 or 1
804 static int bitplane_decoding(BitPlane *bp, VC9Context *v) 822 static int bitplane_decoding(BitPlane *bp, VC9Context *v)
805 { 823 {
806 GetBitContext *gb = &v->s.gb; 824 GetBitContext *gb = &v->s.gb;
807 825
808 int imode, x, y, code, use_vertical_tile, tile_w, tile_h; 826 int imode, x, y, code, use_vertical_tile, tile_w, tile_h;
822 case IMODE_NORM2: 840 case IMODE_NORM2:
823 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1); 841 if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1);
824 for(x=0; x<(bp->height*bp->width)>>1; x++){ 842 for(x=0; x<(bp->height*bp->width)>>1; x++){
825 code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); 843 code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2);
826 *(++planep) = code&1; //lsb => left 844 *(++planep) = code&1; //lsb => left
827 *(++planep) = code&2; //msb => right - bitplane => only !0 matters 845 *(++planep) = (code>>1)&1; //msb => right
828 //FIXME width->stride 846 //FIXME width->stride
829 } 847 }
830 break; 848 break;
831 case IMODE_DIFF6: 849 case IMODE_DIFF6:
832 case IMODE_NORM6: 850 case IMODE_NORM6:
834 tile_w= use_vertical_tile ? 2 : 3; 852 tile_w= use_vertical_tile ? 2 : 3;
835 tile_h= use_vertical_tile ? 3 : 2; 853 tile_h= use_vertical_tile ? 3 : 2;
836 854
837 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){ 855 for(y= bp->height%tile_h; y< bp->height; y+=tile_h){
838 for(x= bp->width%tile_w; x< bp->width; x+=tile_w){ 856 for(x= bp->width%tile_w; x< bp->width; x+=tile_w){
857 #if TILE_VLC_METHOD == 1 //FIXME Too much optimized ?
839 code = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2); 858 code = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2);
840 if(code<0){ 859 if(code<0){
841 av_log(v->s.avctx, AV_LOG_DEBUG, "inavlid NORM-6 VLC\n"); 860 av_log(v->s.avctx, AV_LOG_DEBUG, "inavlid NORM-6 VLC\n");
842 return -1; 861 return -1;
843 } 862 }
863 #endif
864 #if TILE_VLC_METHOD == 2 //TODO Optimize VLC decoding
865 code = get_vlc2(gb, vc9_norm6_first.table, VC9_NORM6_FIRST_BITS, 2);
866 if (vc9_norm6_mode[code] == 1)
867 {
868 # if TRACE
869 code = get_bits(gb, 5);
870 assert(code>-1 && code<20);
871 code = vc9_norm6_flc_val[code];
872 # else
873 code = vc9_norm6_flc_val[get_bits(gb, 5)];
874 # endif
875 }
876 else if (vc9_norm6_mode[code] == 2)
877 {
878 # if TRACE
879 code = get_vlc2(gb, vc9_norm6_second.table, VC9_NORM6_SECOND_BITS, 2);
880 assert(code>-1 && code<22);
881 code = vc9_norm6_second_val[code];
882 # else
883 code = vc9_norm6_second_val[get_vlc2(gb, vc9_norm6_second.table, VC9_NORM6_SECOND_BITS, 2)];
884 # endif
885 #endif //TILE_VLC_METHOD == 2
844 //FIXME following is a pure guess and probably wrong 886 //FIXME following is a pure guess and probably wrong
845 //FIXME A bitplane (0 | !0), so could the shifts be avoided ? 887 //FIXME A bitplane (0 | !0), so could the shifts be avoided ?
846 planep[x + 0*bp->stride]= (code>>0)&1; 888 planep[x + 0*bp->stride]= (code>>0)&1;
847 planep[x + 1 + 0*bp->stride]= (code>>1)&1; 889 planep[x + 1 + 0*bp->stride]= (code>>1)&1;
890 //FIXME Does branch prediction help here?
848 if(use_vertical_tile){ 891 if(use_vertical_tile){
849 planep[x + 0 + 1*bp->stride]= (code>>2)&1; 892 planep[x + 0 + 1*bp->stride]= (code>>2)&1;
850 planep[x + 1 + 1*bp->stride]= (code>>3)&1; 893 planep[x + 1 + 1*bp->stride]= (code>>3)&1;
851 planep[x + 0 + 2*bp->stride]= (code>>4)&1; 894 planep[x + 0 + 2*bp->stride]= (code>>4)&1;
852 planep[x + 1 + 2*bp->stride]= (code>>5)&1; 895 planep[x + 1 + 2*bp->stride]= (code>>5)&1;
943 986
944 /*****************************************************************************/ 987 /*****************************************************************************/
945 /* All Profiles picture header decoding specific functions */ 988 /* All Profiles picture header decoding specific functions */
946 /* Only pro/epilog differs between Simple/Main and Advanced => check caller */ 989 /* Only pro/epilog differs between Simple/Main and Advanced => check caller */
947 /*****************************************************************************/ 990 /*****************************************************************************/
948 static int decode_bi_picture_header(VC9Context *v) 991
949 { 992 /* Tables 11+12, p62-65 */
950 /* Very particular case: 993 static int decode_b_picture_primary_header(VC9Context *v)
951 - for S/M Profiles, decode_b_picture_header reads BF, 994 {
952 bfraction then determine if this is a BI frame, calling
953 this function afterwards
954 - for A Profile, PTYPE already tells so and we can go
955 directly there
956 */
957 GetBitContext *gb = &v->s.gb; 995 GetBitContext *gb = &v->s.gb;
958 int pqindex; 996 int pqindex, status;
997
998 /* Prolog common to all frametypes should be done in caller */
999 if (v->profile == PROFILE_SIMPLE)
1000 {
1001 av_log(v->s.avctx, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n");
1002 return FRAME_SKIPED;
1003 }
1004
1005 v->bfraction = vc9_bfraction_lut[get_vlc2(gb, vc9_bfraction_vlc.table,
1006 VC9_BFRACTION_VLC_BITS, 2)];
1007 if (v->bfraction < -1)
1008 {
1009 av_log(v->s.avctx, AV_LOG_ERROR, "Invalid BFRaction\n");
1010 return FRAME_SKIPED;
1011 }
1012 else if (!v->bfraction)
1013 {
1014 /* We actually have a BI frame */
1015 v->s.pict_type = BI_TYPE;
1016 v->buffer_fullness = get_bits(gb, 7);
1017 }
959 1018
960 /* Read the quantization stuff */ 1019 /* Read the quantization stuff */
961 pqindex = get_bits(gb, 5); 1020 pqindex = get_bits(gb, 5);
962 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) 1021 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
963 v->pq = pquant_table[0][pqindex]; 1022 v->pq = pquant_table[0][pqindex];
970 v->pquantizer = get_bits(gb, 1); 1029 v->pquantizer = get_bits(gb, 1);
971 1030
972 /* Read the MV type/mode */ 1031 /* Read the MV type/mode */
973 if (v->extended_mv == 1) 1032 if (v->extended_mv == 1)
974 v->mvrange = get_prefix(gb, 0, 3); 1033 v->mvrange = get_prefix(gb, 0, 3);
975 1034 if (v->s.pict_type != BI_TYPE)
976 /* FIXME: what table are used in that case ? */ 1035 {
977 v->mv_diff_vlc = &vc9_mv_diff_vlc[0]; 1036 v->mv_mode = get_bits(gb, 1);
978 v->cbpcy_vlc = &ff_msmp4_mb_i_vlc; 1037 if (v->pq < 13)
979 1038 {
980 av_log(v->s.avctx, AV_LOG_DEBUG, "B frame, QP=%i\n", v->pq); 1039 if (!v->mv_mode)
981 av_log(v->s.avctx, AV_LOG_ERROR, "BI_TYPE not supported yet\n"); 1040 {
982 /* Epilog should be done in caller */ 1041 v->mv_mode = get_bits(gb, 2);
983 return -1; 1042 if (v->mv_mode)
984 } 1043 av_log(v->s.avctx, AV_LOG_ERROR,
985
986 /* Tables 11+12, p62-65 */
987 static int decode_b_picture_primary_header(VC9Context *v)
988 {
989 GetBitContext *gb = &v->s.gb;
990 int pqindex, status;
991
992 /* Prolog common to all frametypes should be done in caller */
993 if (v->profile == PROFILE_SIMPLE)
994 {
995 av_log(v, AV_LOG_ERROR, "Found a B frame while in Simple Profile!\n");
996 return FRAME_SKIPED;
997 }
998
999 v->bfraction = vc9_bfraction_lut[get_vlc2(gb, vc9_bfraction_vlc.table,
1000 VC9_BFRACTION_VLC_BITS, 2)];
1001 if (v->bfraction < -1)
1002 {
1003 av_log(v, AV_LOG_ERROR, "Invalid BFRaction\n");
1004 return FRAME_SKIPED;
1005 }
1006 else if (!v->bfraction)
1007 {
1008 /* We actually have a BI frame */
1009 return decode_bi_picture_header(v);
1010 }
1011
1012 /* Read the quantization stuff */
1013 pqindex = get_bits(gb, 5);
1014 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
1015 v->pq = pquant_table[0][pqindex];
1016 else
1017 {
1018 v->pq = pquant_table[v->quantizer_mode-1][pqindex];
1019 }
1020 if (pqindex < 9) v->halfpq = get_bits(gb, 1);
1021 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
1022 v->pquantizer = get_bits(gb, 1);
1023
1024 /* Read the MV type/mode */
1025 if (v->extended_mv == 1)
1026 v->mvrange = get_prefix(gb, 0, 3);
1027 v->mv_mode = get_bits(gb, 1);
1028 if (v->pq < 13)
1029 {
1030 if (!v->mv_mode)
1031 {
1032 v->mv_mode = get_bits(gb, 2);
1033 if (v->mv_mode)
1034 av_log(v, AV_LOG_ERROR,
1035 "mv_mode for lowquant B frame was %i\n", v->mv_mode); 1044 "mv_mode for lowquant B frame was %i\n", v->mv_mode);
1036 } 1045 }
1037 } 1046 }
1038 else 1047 else
1039 { 1048 {
1040 if (!v->mv_mode) 1049 if (!v->mv_mode)
1041 { 1050 {
1042 if (get_bits(gb, 1)) 1051 if (get_bits(gb, 1))
1043 av_log(v, AV_LOG_ERROR, 1052 av_log(v->s.avctx, AV_LOG_ERROR,
1044 "mv_mode for highquant B frame was %i\n", v->mv_mode); 1053 "mv_mode for highquant B frame was %i\n", v->mv_mode);
1045 } 1054 }
1046 v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping 1055 v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping
1056 }
1047 } 1057 }
1048 1058
1049 return 0; 1059 return 0;
1050 } 1060 }
1051 1061
1079 av_log(v->s.avctx, AV_LOG_DEBUG, "Skip MB plane encoding: " 1089 av_log(v->s.avctx, AV_LOG_DEBUG, "Skip MB plane encoding: "
1080 "Imode: %i, Invert: %i\n", status>>1, status&1); 1090 "Imode: %i, Invert: %i\n", status>>1, status&1);
1081 #endif 1091 #endif
1082 1092
1083 /* FIXME: what is actually chosen for B frames ? */ 1093 /* FIXME: what is actually chosen for B frames ? */
1084 v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(gb, 2)]; 1094 v->s.mv_table_index = get_bits(gb, 2); //but using vc9_ tables
1085 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)]; 1095 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)];
1096
1086 if (v->dquant) 1097 if (v->dquant)
1087 { 1098 {
1088 vop_dquant_decoding(v); 1099 vop_dquant_decoding(v);
1089 } 1100 }
1090 1101
1092 { 1103 {
1093 v->ttmbf = get_bits(gb, 1); 1104 v->ttmbf = get_bits(gb, 1);
1094 if (v->ttmbf) 1105 if (v->ttmbf)
1095 { 1106 {
1096 v->ttfrm = get_bits(gb, 2); 1107 v->ttfrm = get_bits(gb, 2);
1097 av_log(v, AV_LOG_INFO, "Transform used: %ix%i\n", 1108 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
1098 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8); 1109 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8);
1099 } 1110 }
1100 } 1111 }
1101 /* Epilog should be done in caller */ 1112 /* Epilog (AC/DC syntax) should be done in caller */
1102 return 0; 1113 return 0;
1103 } 1114 }
1104 1115
1105 /* Tables 5+7, p53-54 and 55-57 */ 1116 /* Tables 5+7, p53-54 and 55-57 */
1106 static int decode_i_picture_header(VC9Context *v) 1117 static int decode_i_picture_header(VC9Context *v)
1110 1121
1111 /* Prolog common to all frametypes should be done in caller */ 1122 /* Prolog common to all frametypes should be done in caller */
1112 //BF = Buffer Fullness 1123 //BF = Buffer Fullness
1113 if (v->profile <= PROFILE_MAIN && get_bits(gb, 7)) 1124 if (v->profile <= PROFILE_MAIN && get_bits(gb, 7))
1114 { 1125 {
1115 av_log(v, AV_LOG_DEBUG, "I BufferFullness not 0\n"); 1126 av_log(v->s.avctx, AV_LOG_DEBUG, "I BufferFullness not 0\n");
1116 } 1127 }
1117 1128
1118 /* Quantizer stuff */ 1129 /* Quantizer stuff */
1119 pqindex = get_bits(gb, 5); 1130 pqindex = get_bits(gb, 5);
1120 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) 1131 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
1159 } 1170 }
1160 } 1171 }
1161 } 1172 }
1162 #endif 1173 #endif
1163 1174
1164 /* Epilog should be done in caller */ 1175 /* Epilog (AC/DC syntax) should be done in caller */
1165 return status; 1176 return status;
1166 } 1177 }
1167 1178
1168 /* Table 9, p58-60 */ 1179 /* Table 9, p58-60 */
1169 static int decode_p_picture_primary_header(VC9Context *v) 1180 static int decode_p_picture_primary_header(VC9Context *v)
1226 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " 1237 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1227 "Imode: %i, Invert: %i\n", status>>1, status&1); 1238 "Imode: %i, Invert: %i\n", status>>1, status&1);
1228 #endif 1239 #endif
1229 1240
1230 /* Hopefully this is correct for P frames */ 1241 /* Hopefully this is correct for P frames */
1231 v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(gb, 2)]; 1242 v->s.mv_table_index =get_bits(gb, 2); //but using vc9_ tables
1232 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)]; 1243 v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)];
1233 1244
1234 if (v->dquant) 1245 if (v->dquant)
1235 { 1246 {
1236 av_log(v->s.avctx, AV_LOG_INFO, "VOP DQuant info\n"); 1247 av_log(v->s.avctx, AV_LOG_INFO, "VOP DQuant info\n");
1237 vop_dquant_decoding(v); 1248 vop_dquant_decoding(v);
1238 } 1249 }
1239 1250
1251 v->ttfrm = 0; //FIXME Is that so ?
1240 if (v->vstransform) 1252 if (v->vstransform)
1241 { 1253 {
1242 v->ttmbf = get_bits(gb, 1); 1254 v->ttmbf = get_bits(gb, 1);
1243 if (v->ttmbf) 1255 if (v->ttmbf)
1244 { 1256 {
1245 v->ttfrm = get_bits(gb, 2); 1257 v->ttfrm = get_bits(gb, 2);
1246 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n", 1258 av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n",
1247 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8); 1259 (v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8);
1248 } 1260 }
1249 } 1261 }
1250 /* Epilog should be done in caller */ 1262 /* Epilog (AC/DC syntax) should be done in caller */
1251 return 0; 1263 return 0;
1252 } 1264 }
1253 1265
1254 1266
1255 static int standard_decode_picture_primary_header(VC9Context *v) 1267 static int standard_decode_picture_primary_header(VC9Context *v)
1259 1271
1260 if (v->finterpflag) v->interpfrm = get_bits(gb, 1); 1272 if (v->finterpflag) v->interpfrm = get_bits(gb, 1);
1261 skip_bits(gb, 2); //framecnt unused 1273 skip_bits(gb, 2); //framecnt unused
1262 if (v->rangered) v->rangeredfrm = get_bits(gb, 1); 1274 if (v->rangered) v->rangeredfrm = get_bits(gb, 1);
1263 v->s.pict_type = get_bits(gb, 1); 1275 v->s.pict_type = get_bits(gb, 1);
1264 if (v->s.avctx->max_b_frames && !v->s.pict_type) 1276 if (v->s.avctx->max_b_frames)
1265 { 1277 {
1266 if (get_bits(gb, 1)) v->s.pict_type = I_TYPE; 1278 if (!v->s.pict_type)
1279 {
1280 if (get_bits(gb, 1)) v->s.pict_type = I_TYPE;
1281 else v->s.pict_type = B_TYPE;
1282 }
1267 else v->s.pict_type = P_TYPE; 1283 else v->s.pict_type = P_TYPE;
1268 } 1284 }
1269 else v->s.pict_type++; //P_TYPE 1285 else v->s.pict_type++;
1270 1286
1271 switch (v->s.pict_type) 1287 switch (v->s.pict_type)
1272 { 1288 {
1273 case I_TYPE: status = decode_i_picture_header(v); break; 1289 case I_TYPE: status = decode_i_picture_header(v); break;
1274 case BI_TYPE: status = decode_bi_picture_header(v); break;
1275 case P_TYPE: status = decode_p_picture_primary_header(v); break; 1290 case P_TYPE: status = decode_p_picture_primary_header(v); break;
1291 case BI_TYPE:
1276 case B_TYPE: status = decode_b_picture_primary_header(v); break; 1292 case B_TYPE: status = decode_b_picture_primary_header(v); break;
1277 } 1293 }
1278 1294
1279 if (status == FRAME_SKIPED) 1295 if (status == FRAME_SKIPED)
1280 { 1296 {
1281 av_log(v, AV_LOG_INFO, "Skipping frame...\n"); 1297 av_log(v->s.avctx, AV_LOG_INFO, "Skipping frame...\n");
1282 return status; 1298 return status;
1283 } 1299 }
1284 return 0; 1300 return 0;
1285 } 1301 }
1286 1302
1294 case P_TYPE: status = decode_p_picture_secondary_header(v); break; 1310 case P_TYPE: status = decode_p_picture_secondary_header(v); break;
1295 case B_TYPE: status = decode_b_picture_secondary_header(v); break; 1311 case B_TYPE: status = decode_b_picture_secondary_header(v); break;
1296 } 1312 }
1297 1313
1298 /* AC Syntax */ 1314 /* AC Syntax */
1299 index = decode012(gb); 1315 v->ac_table_level = decode012(gb);
1300 v->luma_ac_vlc = NULL + index; //FIXME Add AC table
1301 v->chroma_ac_vlc = NULL + index;
1302 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) 1316 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
1303 { 1317 {
1304 index = decode012(gb); 1318 index = decode012(gb);
1305 v->luma_ac2_vlc = NULL + index; //FIXME Add AC2 table 1319 v->luma_ac2_vlc = NULL + index; //FIXME Add AC2 table
1306 v->chroma_ac2_vlc = NULL + index; 1320 v->chroma_ac2_vlc = NULL + index;
1386 case B_TYPE: if (decode_b_picture_secondary_header(v) < 0) return FRAME_SKIPED; 1400 case B_TYPE: if (decode_b_picture_secondary_header(v) < 0) return FRAME_SKIPED;
1387 default: break; 1401 default: break;
1388 } 1402 }
1389 1403
1390 /* AC Syntax */ 1404 /* AC Syntax */
1391 index = decode012(gb); 1405 v->ac_table_level = decode012(gb);
1392 v->luma_ac_vlc = NULL + index; //FIXME
1393 v->chroma_ac_vlc = NULL + index; //FIXME
1394 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) 1406 if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
1395 { 1407 {
1396 index = decode012(gb); //FIXME 1408 index = decode012(gb); //FIXME
1397 v->luma_ac2_vlc = NULL + index; 1409 v->luma_ac2_vlc = NULL + index;
1398 v->chroma_ac2_vlc = NULL + index; 1410 v->chroma_ac2_vlc = NULL + index;
1492 s->ac_pred = get_bits(gb, 1); 1504 s->ac_pred = get_bits(gb, 1);
1493 1505
1494 /* TODO: Decode blocks from that mb wrt cbpcy */ 1506 /* TODO: Decode blocks from that mb wrt cbpcy */
1495 1507
1496 /* Update for next block */ 1508 /* Update for next block */
1509 #if TRACE > 2
1510 av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i,"
1511 " cbpcy=%i%i%i%i\n", current_mb,
1512 p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3],
1513 previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3],
1514 cbpcy[0], cbpcy[1], cbpcy[2], cbpcy[3]);
1515 #endif
1497 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy); 1516 *((uint32_t*)p_cbpcy) = *((uint32_t*)previous_cbpcy);
1498 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy); 1517 *((uint32_t*)previous_cbpcy) = *((uint32_t*)cbpcy);
1499 current_mb++; 1518 current_mb++;
1500 } 1519 }
1501 } 1520 }
1520 } \ 1539 } \
1521 } 1540 }
1522 1541
1523 /* MVDATA decoding from 8.3.5.2, p(1)20 */ 1542 /* MVDATA decoding from 8.3.5.2, p(1)20 */
1524 #define GET_MVDATA(_dmv_x, _dmv_y) \ 1543 #define GET_MVDATA(_dmv_x, _dmv_y) \
1525 index = 1 + get_vlc2(gb, v->mv_diff_vlc->table, \ 1544 index = 1 + get_vlc2(gb, vc9_mv_diff_vlc[s->mv_table_index].table,\
1526 VC9_MV_DIFF_VLC_BITS, 2); \ 1545 VC9_MV_DIFF_VLC_BITS, 2); \
1527 if (index > 36) \ 1546 if (index > 36) \
1528 { \ 1547 { \
1529 mb_has_coeffs = 1; \ 1548 mb_has_coeffs = 1; \
1530 index -= 37; \ 1549 index -= 37; \
1531 } \ 1550 } \
1532 else mb_has_coeffs = 0; \ 1551 else mb_has_coeffs = 0; \
1533 mb_is_intra = 0; \ 1552 s->mb_intra = 0; \
1534 if (!index) { _dmv_x = _dmv_y = 0; } \ 1553 if (!index) { _dmv_x = _dmv_y = 0; } \
1535 else if (index == 35) \ 1554 else if (index == 35) \
1536 { \ 1555 { \
1537 _dmv_x = get_bits(gb, k_x); \ 1556 _dmv_x = get_bits(gb, k_x); \
1538 _dmv_y = get_bits(gb, k_y); \ 1557 _dmv_y = get_bits(gb, k_y); \
1539 mb_is_intra = 1; \ 1558 s->mb_intra = 1; \
1540 } \ 1559 } \
1541 else \ 1560 else \
1542 { \ 1561 { \
1543 index1 = index%6; \ 1562 index1 = index%6; \
1544 if (hpel_flag && index1 == 5) val = 1; \ 1563 if (hpel_flag && index1 == 5) val = 1; \
1568 int mqdiff, mquant; /* MB quantization */ 1587 int mqdiff, mquant; /* MB quantization */
1569 int ttmb; /* MB Transform type */ 1588 int ttmb; /* MB Transform type */
1570 1589
1571 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 }, 1590 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
1572 offset_table[6] = { 0, 1, 3, 7, 15, 31 }; 1591 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
1573 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra; 1592 int mb_has_coeffs = 1; /* last_flag */
1574 int dmv_x, dmv_y; /* Differential MV components */ 1593 int dmv_x, dmv_y; /* Differential MV components */
1575 int k_x, k_y; /* Long MV fixed bitlength */ 1594 int k_x, k_y; /* Long MV fixed bitlength */
1576 int hpel_flag; /* Some MB properties */ 1595 int hpel_flag; /* Some MB properties */
1577 int index, index1; /* LUT indices */ 1596 int index, index1; /* LUT indices */
1578 int val, sign; /* MVDATA temp values */ 1597 int val, sign; /* MVDATA temp values */
1602 { 1621 {
1603 /* Init CBPCY for line */ 1622 /* Init CBPCY for line */
1604 *((uint32_t*)previous_cbpcy) = 0x00000000; 1623 *((uint32_t*)previous_cbpcy) = 0x00000000;
1605 p_cbpcy = v->previous_line_cbpcy+4; 1624 p_cbpcy = v->previous_line_cbpcy+4;
1606 1625
1607 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++) 1626 for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++, p_cbpcy += 4)
1608 { 1627 {
1609 if (v->mv_type_mb_plane.is_raw) 1628 if (v->mv_type_mb_plane.is_raw)
1610 v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1); 1629 v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1);
1611 if (v->skip_mb_plane.is_raw) 1630 if (v->skip_mb_plane.is_raw)
1612 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1); 1631 v->skip_mb_plane.data[current_mb] = get_bits(gb, 1);
1618 1637
1619 /* hybrid mv pred, 8.3.5.3.4 */ 1638 /* hybrid mv pred, 8.3.5.3.4 */
1620 if (v->mv_mode == MV_PMODE_1MV || 1639 if (v->mv_mode == MV_PMODE_1MV ||
1621 v->mv_mode == MV_PMODE_MIXED_MV) 1640 v->mv_mode == MV_PMODE_MIXED_MV)
1622 hybrid_pred = get_bits(gb, 1); 1641 hybrid_pred = get_bits(gb, 1);
1623 if (mb_is_intra && !mb_has_coeffs) 1642 if (s->mb_intra && !mb_has_coeffs)
1624 { 1643 {
1625 GET_MQUANT(); 1644 GET_MQUANT();
1626 s->ac_pred = get_bits(gb, 1); 1645 s->ac_pred = get_bits(gb, 1);
1627 } 1646 }
1628 else if (mb_has_coeffs) 1647 else if (mb_has_coeffs)
1629 { 1648 {
1630 if (mb_is_intra) s->ac_pred = get_bits(gb, 1); 1649 if (s->mb_intra) s->ac_pred = get_bits(gb, 1);
1631 GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS); 1650 predicted_cbpcy = get_vlc2(gb, v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS, 2);
1651 cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) ? previous_cbpcy[1] : p_cbpcy[2];
1652 cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01);
1653 cbpcy[1] = (p_cbpcy[2] == p_cbpcy[3]) ? cbpcy[0] : p_cbpcy[3];
1654 cbpcy[1] ^= ((predicted_cbpcy>>4)&0x01);
1655 cbpcy[2] = (previous_cbpcy[1] == cbpcy[0]) ? previous_cbpcy[3] : cbpcy[0];
1656 cbpcy[2] ^= ((predicted_cbpcy>>3)&0x01);
1657 cbpcy[3] = (cbpcy[1] == cbpcy[0]) ? cbpcy[2] : cbpcy[1];
1658 cbpcy[3] ^= ((predicted_cbpcy>>2)&0x01);
1659 //GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS);
1660
1632 GET_MQUANT(); 1661 GET_MQUANT();
1633 } 1662 }
1634 if (!v->ttmbf) 1663 if (!v->ttmbf)
1635 ttmb = get_vlc2(gb, v->ttmb_vlc->table, 1664 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
1636 VC9_TTMB_VLC_BITS, 12); 1665 VC9_TTMB_VLC_BITS, 12);
1657 GET_MVDATA(dmv_x, dmv_y); 1686 GET_MVDATA(dmv_x, dmv_y);
1658 } 1687 }
1659 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */) 1688 if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */)
1660 hybrid_pred = get_bits(gb, 1); 1689 hybrid_pred = get_bits(gb, 1);
1661 GET_MQUANT(); 1690 GET_MQUANT();
1662 if (mb_is_intra /* One of the 4 blocks is intra */ && 1691 if (s->mb_intra /* One of the 4 blocks is intra */ &&
1663 index /* non-zero pred for that block */) 1692 index /* non-zero pred for that block */)
1664 s->ac_pred = get_bits(gb, 1); 1693 s->ac_pred = get_bits(gb, 1);
1665 if (!v->ttmbf) 1694 if (!v->ttmbf)
1666 ttmb = get_vlc2(gb, v->ttmb_vlc->table, 1695 ttmb = get_vlc2(gb, v->ttmb_vlc->table,
1667 VC9_TTMB_VLC_BITS, 12); 1696 VC9_TTMB_VLC_BITS, 12);
1707 int mquant, mqdiff; /* MB quant stuff */ 1736 int mquant, mqdiff; /* MB quant stuff */
1708 int ttmb; /* MacroBlock transform type */ 1737 int ttmb; /* MacroBlock transform type */
1709 1738
1710 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 }, 1739 static const int size_table[6] = { 0, 2, 3, 4, 5, 8 },
1711 offset_table[6] = { 0, 1, 3, 7, 15, 31 }; 1740 offset_table[6] = { 0, 1, 3, 7, 15, 31 };
1712 int mb_has_coeffs = 1 /* last_flag */, mb_is_intra = 1; 1741 int mb_has_coeffs = 1; /* last_flag */
1713 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */ 1742 int dmv1_x, dmv1_y, dmv2_x, dmv2_y; /* Differential MV components */
1714 int k_x, k_y; /* Long MV fixed bitlength */ 1743 int k_x, k_y; /* Long MV fixed bitlength */
1715 int hpel_flag; /* Some MB properties */ 1744 int hpel_flag; /* Some MB properties */
1716 int index, index1; /* LUT indices */ 1745 int index, index1; /* LUT indices */
1717 int val, sign; /* MVDATA temp values */ 1746 int val, sign; /* MVDATA temp values */
1752 } 1781 }
1753 else 1782 else
1754 { 1783 {
1755 /* FIXME getting tired commenting */ 1784 /* FIXME getting tired commenting */
1756 GET_MVDATA(dmv1_x, dmv1_y); 1785 GET_MVDATA(dmv1_x, dmv1_y);
1757 if (!mb_is_intra /* b_mv1 tells not intra */) 1786 if (!s->mb_intra /* b_mv1 tells not intra */)
1758 { 1787 {
1759 /* FIXME: actually read it */ 1788 /* FIXME: actually read it */
1760 b_mv_type = decode012(gb); 1789 b_mv_type = decode012(gb);
1761 if (v->bfraction > 420 /*1/2*/ && 1790 if (v->bfraction > 420 /*1/2*/ &&
1762 b_mv_type < 3) b_mv_type = 1-b_mv_type; 1791 b_mv_type < 3) b_mv_type = 1-b_mv_type;
1766 if (!v->skip_mb_plane.data[current_mb]) 1795 if (!v->skip_mb_plane.data[current_mb])
1767 { 1796 {
1768 if (mb_has_coeffs /* BMV1 == "last" */) 1797 if (mb_has_coeffs /* BMV1 == "last" */)
1769 { 1798 {
1770 GET_MQUANT(); 1799 GET_MQUANT();
1771 if (mb_is_intra /* intra mb */) 1800 if (s->mb_intra /* intra mb */)
1772 s->ac_pred = get_bits(gb, 1); 1801 s->ac_pred = get_bits(gb, 1);
1773 } 1802 }
1774 else 1803 else
1775 { 1804 {
1776 /* if bmv1 tells MVs are interpolated */ 1805 /* if bmv1 tells MVs are interpolated */
1779 GET_MVDATA(dmv2_x, dmv2_y); 1808 GET_MVDATA(dmv2_x, dmv2_y);
1780 } 1809 }
1781 /* GET_MVDATA has reset some stuff */ 1810 /* GET_MVDATA has reset some stuff */
1782 if (mb_has_coeffs /* b_mv2 == "last" */) 1811 if (mb_has_coeffs /* b_mv2 == "last" */)
1783 { 1812 {
1784 if (mb_is_intra /* intra_mb */) 1813 if (s->mb_intra /* intra_mb */)
1785 s->ac_pred = get_bits(gb, 1); 1814 s->ac_pred = get_bits(gb, 1);
1786 GET_MQUANT(); 1815 GET_MQUANT();
1787 } 1816 }
1788 } 1817 }
1789 } 1818 }