00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030 #include "internal.h"
00031 #include "dsputil.h"
00032 #include "avcodec.h"
00033 #include "mpegvideo.h"
00034 #include "vc1.h"
00035 #include "vc1data.h"
00036 #include "msmpeg4data.h"
00037 #include "unary.h"
00038 #include "simple_idct.h"
00039
00040 #undef NDEBUG
00041 #include <assert.h>
00042
00043
00054 enum Imode {
00055 IMODE_RAW,
00056 IMODE_NORM2,
00057 IMODE_DIFF2,
00058 IMODE_NORM6,
00059 IMODE_DIFF6,
00060 IMODE_ROWSKIP,
00061 IMODE_COLSKIP
00062 };
00064
00071 static void decode_rowskip(uint8_t* plane, int width, int height, int stride,
00072 GetBitContext *gb)
00073 {
00074 int x, y;
00075
00076 for (y = 0; y < height; y++) {
00077 if (!get_bits1(gb))
00078 memset(plane, 0, width);
00079 else
00080 for (x = 0; x < width; x++)
00081 plane[x] = get_bits1(gb);
00082 plane += stride;
00083 }
00084 }
00085
00093 static void decode_colskip(uint8_t* plane, int width, int height, int stride,
00094 GetBitContext *gb)
00095 {
00096 int x, y;
00097
00098 for (x = 0; x < width; x++) {
00099 if (!get_bits1(gb))
00100 for (y = 0; y < height; y++)
00101 plane[y*stride] = 0;
00102 else
00103 for (y = 0; y < height; y++)
00104 plane[y*stride] = get_bits1(gb);
00105 plane ++;
00106 }
00107 }
00108
00116 static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
00117 {
00118 GetBitContext *gb = &v->s.gb;
00119
00120 int imode, x, y, code, offset;
00121 uint8_t invert, *planep = data;
00122 int width, height, stride;
00123
00124 width = v->s.mb_width;
00125 height = v->s.mb_height >> v->field_mode;
00126 stride = v->s.mb_stride;
00127 invert = get_bits1(gb);
00128 imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
00129
00130 *raw_flag = 0;
00131 switch (imode) {
00132 case IMODE_RAW:
00133
00134 *raw_flag = 1;
00135 return invert;
00136 case IMODE_DIFF2:
00137 case IMODE_NORM2:
00138 if ((height * width) & 1) {
00139 *planep++ = get_bits1(gb);
00140 offset = 1;
00141 }
00142 else
00143 offset = 0;
00144
00145 for (y = offset; y < height * width; y += 2) {
00146 code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
00147 *planep++ = code & 1;
00148 offset++;
00149 if (offset == width) {
00150 offset = 0;
00151 planep += stride - width;
00152 }
00153 *planep++ = code >> 1;
00154 offset++;
00155 if (offset == width) {
00156 offset = 0;
00157 planep += stride - width;
00158 }
00159 }
00160 break;
00161 case IMODE_DIFF6:
00162 case IMODE_NORM6:
00163 if (!(height % 3) && (width % 3)) {
00164 for (y = 0; y < height; y += 3) {
00165 for (x = width & 1; x < width; x += 2) {
00166 code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
00167 if (code < 0) {
00168 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
00169 return -1;
00170 }
00171 planep[x + 0] = (code >> 0) & 1;
00172 planep[x + 1] = (code >> 1) & 1;
00173 planep[x + 0 + stride] = (code >> 2) & 1;
00174 planep[x + 1 + stride] = (code >> 3) & 1;
00175 planep[x + 0 + stride * 2] = (code >> 4) & 1;
00176 planep[x + 1 + stride * 2] = (code >> 5) & 1;
00177 }
00178 planep += stride * 3;
00179 }
00180 if (width & 1)
00181 decode_colskip(data, 1, height, stride, &v->s.gb);
00182 } else {
00183 planep += (height & 1) * stride;
00184 for (y = height & 1; y < height; y += 2) {
00185 for (x = width % 3; x < width; x += 3) {
00186 code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
00187 if (code < 0) {
00188 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
00189 return -1;
00190 }
00191 planep[x + 0] = (code >> 0) & 1;
00192 planep[x + 1] = (code >> 1) & 1;
00193 planep[x + 2] = (code >> 2) & 1;
00194 planep[x + 0 + stride] = (code >> 3) & 1;
00195 planep[x + 1 + stride] = (code >> 4) & 1;
00196 planep[x + 2 + stride] = (code >> 5) & 1;
00197 }
00198 planep += stride * 2;
00199 }
00200 x = width % 3;
00201 if (x)
00202 decode_colskip(data, x, height, stride, &v->s.gb);
00203 if (height & 1)
00204 decode_rowskip(data + x, width - x, 1, stride, &v->s.gb);
00205 }
00206 break;
00207 case IMODE_ROWSKIP:
00208 decode_rowskip(data, width, height, stride, &v->s.gb);
00209 break;
00210 case IMODE_COLSKIP:
00211 decode_colskip(data, width, height, stride, &v->s.gb);
00212 break;
00213 default:
00214 break;
00215 }
00216
00217
00218 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {
00219 planep = data;
00220 planep[0] ^= invert;
00221 for (x = 1; x < width; x++)
00222 planep[x] ^= planep[x-1];
00223 for (y = 1; y < height; y++) {
00224 planep += stride;
00225 planep[0] ^= planep[-stride];
00226 for (x = 1; x < width; x++) {
00227 if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
00228 else planep[x] ^= planep[x-1];
00229 }
00230 }
00231 } else if (invert) {
00232 planep = data;
00233 for (x = 0; x < stride * height; x++)
00234 planep[x] = !planep[x];
00235 }
00236 return (imode << 1) + invert;
00237 }
00238
00240
00241
00245 static int vop_dquant_decoding(VC1Context *v)
00246 {
00247 GetBitContext *gb = &v->s.gb;
00248 int pqdiff;
00249
00250
00251 if (v->dquant == 2) {
00252 pqdiff = get_bits(gb, 3);
00253 if (pqdiff == 7)
00254 v->altpq = get_bits(gb, 5);
00255 else
00256 v->altpq = v->pq + pqdiff + 1;
00257 } else {
00258 v->dquantfrm = get_bits1(gb);
00259 if (v->dquantfrm) {
00260 v->dqprofile = get_bits(gb, 2);
00261 switch (v->dqprofile) {
00262 case DQPROFILE_SINGLE_EDGE:
00263 case DQPROFILE_DOUBLE_EDGES:
00264 v->dqsbedge = get_bits(gb, 2);
00265 break;
00266 case DQPROFILE_ALL_MBS:
00267 v->dqbilevel = get_bits1(gb);
00268 if (!v->dqbilevel)
00269 v->halfpq = 0;
00270 default:
00271 break;
00272 }
00273 if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) {
00274 pqdiff = get_bits(gb, 3);
00275 if (pqdiff == 7)
00276 v->altpq = get_bits(gb, 5);
00277 else
00278 v->altpq = v->pq + pqdiff + 1;
00279 }
00280 }
00281 }
00282 return 0;
00283 }
00284
00285 static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
00286
00294 int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
00295 {
00296 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
00297 v->profile = get_bits(gb, 2);
00298 if (v->profile == PROFILE_COMPLEX) {
00299 av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
00300 }
00301
00302 if (v->profile == PROFILE_ADVANCED) {
00303 v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
00304 v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
00305 return decode_sequence_header_adv(v, gb);
00306 } else {
00307 v->zz_8x4 = wmv2_scantableA;
00308 v->zz_4x8 = wmv2_scantableB;
00309 v->res_y411 = get_bits1(gb);
00310 v->res_sprite = get_bits1(gb);
00311 if (v->res_y411) {
00312 av_log(avctx, AV_LOG_ERROR,
00313 "Old interlaced mode is not supported\n");
00314 return -1;
00315 }
00316 }
00317
00318
00319 v->frmrtq_postproc = get_bits(gb, 3);
00320
00321 v->bitrtq_postproc = get_bits(gb, 5);
00322 v->s.loop_filter = get_bits1(gb);
00323 if (v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
00324 av_log(avctx, AV_LOG_ERROR,
00325 "LOOPFILTER shall not be enabled in Simple Profile\n");
00326 }
00327 if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
00328 v->s.loop_filter = 0;
00329
00330 v->res_x8 = get_bits1(gb);
00331 v->multires = get_bits1(gb);
00332 v->res_fasttx = get_bits1(gb);
00333 if (!v->res_fasttx) {
00334 v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct_8;
00335 v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
00336 v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
00337 v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
00338 v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add_8;
00339 v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;
00340 v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;
00341 v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;
00342 }
00343
00344 v->fastuvmc = get_bits1(gb);
00345 if (!v->profile && !v->fastuvmc) {
00346 av_log(avctx, AV_LOG_ERROR,
00347 "FASTUVMC unavailable in Simple Profile\n");
00348 return -1;
00349 }
00350 v->extended_mv = get_bits1(gb);
00351 if (!v->profile && v->extended_mv)
00352 {
00353 av_log(avctx, AV_LOG_ERROR,
00354 "Extended MVs unavailable in Simple Profile\n");
00355 return -1;
00356 }
00357 v->dquant = get_bits(gb, 2);
00358 v->vstransform = get_bits1(gb);
00359
00360 v->res_transtab = get_bits1(gb);
00361 if (v->res_transtab)
00362 {
00363 av_log(avctx, AV_LOG_ERROR,
00364 "1 for reserved RES_TRANSTAB is forbidden\n");
00365 return -1;
00366 }
00367
00368 v->overlap = get_bits1(gb);
00369
00370 v->s.resync_marker = get_bits1(gb);
00371 v->rangered = get_bits1(gb);
00372 if (v->rangered && v->profile == PROFILE_SIMPLE) {
00373 av_log(avctx, AV_LOG_INFO,
00374 "RANGERED should be set to 0 in Simple Profile\n");
00375 }
00376
00377 v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3);
00378 v->quantizer_mode = get_bits(gb, 2);
00379
00380 v->finterpflag = get_bits1(gb);
00381
00382 if (v->res_sprite) {
00383 int w = get_bits(gb, 11);
00384 int h = get_bits(gb, 11);
00385 avcodec_set_dimensions(v->s.avctx, w, h);
00386 skip_bits(gb, 5);
00387 v->res_x8 = get_bits1(gb);
00388 if (get_bits1(gb)) {
00389 av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");
00390 return -1;
00391 }
00392 skip_bits(gb, 3);
00393 v->res_rtm_flag = 0;
00394 } else {
00395 v->res_rtm_flag = get_bits1(gb);
00396 }
00397 if (!v->res_rtm_flag) {
00398
00399
00400 av_log(avctx, AV_LOG_ERROR,
00401 "Old WMV3 version detected, some frames may be decoded incorrectly\n");
00402
00403 }
00404
00405 if (!v->res_fasttx)
00406 skip_bits(gb, 16);
00407 av_log(avctx, AV_LOG_DEBUG,
00408 "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
00409 "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
00410 "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
00411 "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
00412 v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
00413 v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
00414 v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
00415 v->dquant, v->quantizer_mode, avctx->max_b_frames);
00416 return 0;
00417 }
00418
00419 static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
00420 {
00421 int w, h;
00422 v->res_rtm_flag = 1;
00423 v->level = get_bits(gb, 3);
00424 if (v->level >= 5) {
00425 av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
00426 }
00427 v->chromaformat = get_bits(gb, 2);
00428 if (v->chromaformat != 1) {
00429 av_log(v->s.avctx, AV_LOG_ERROR,
00430 "Only 4:2:0 chroma format supported\n");
00431 return -1;
00432 }
00433
00434
00435 v->frmrtq_postproc = get_bits(gb, 3);
00436
00437 v->bitrtq_postproc = get_bits(gb, 5);
00438 v->postprocflag = get_bits1(gb);
00439
00440 w = (get_bits(gb, 12) + 1) << 1;
00441 h = (get_bits(gb, 12) + 1) << 1;
00442 avcodec_set_dimensions(v->s.avctx, w, h);
00443 v->broadcast = get_bits1(gb);
00444 v->interlace = get_bits1(gb);
00445 v->tfcntrflag = get_bits1(gb);
00446 v->finterpflag = get_bits1(gb);
00447 skip_bits1(gb);
00448
00449 av_log(v->s.avctx, AV_LOG_DEBUG,
00450 "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
00451 "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
00452 "TFCTRflag=%i, FINTERPflag=%i\n",
00453 v->level, v->frmrtq_postproc, v->bitrtq_postproc,
00454 v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
00455 v->tfcntrflag, v->finterpflag);
00456
00457 v->psf = get_bits1(gb);
00458 if (v->psf) {
00459 av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
00460 return -1;
00461 }
00462 v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
00463 if (get_bits1(gb)) {
00464 int w, h, ar = 0;
00465 av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
00466 w = get_bits(gb, 14) + 1;
00467 h = get_bits(gb, 14) + 1;
00468 av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
00469 if (get_bits1(gb))
00470 ar = get_bits(gb, 4);
00471 if (ar && ar < 14) {
00472 v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
00473 } else if (ar == 15) {
00474 w = get_bits(gb, 8) + 1;
00475 h = get_bits(gb, 8) + 1;
00476 v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
00477 } else {
00478 av_reduce(&v->s.avctx->sample_aspect_ratio.num,
00479 &v->s.avctx->sample_aspect_ratio.den,
00480 v->s.avctx->height * w,
00481 v->s.avctx->width * h,
00482 1 << 30);
00483 }
00484 av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n",
00485 v->s.avctx->sample_aspect_ratio.num,
00486 v->s.avctx->sample_aspect_ratio.den);
00487
00488 if (get_bits1(gb)) {
00489 if (get_bits1(gb)) {
00490 v->s.avctx->time_base.num = 32;
00491 v->s.avctx->time_base.den = get_bits(gb, 16) + 1;
00492 } else {
00493 int nr, dr;
00494 nr = get_bits(gb, 8);
00495 dr = get_bits(gb, 4);
00496 if (nr && nr < 8 && dr && dr < 3) {
00497 v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1];
00498 v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000;
00499 }
00500 }
00501 if (v->broadcast) {
00502 v->s.avctx->time_base.den *= 2;
00503 v->s.avctx->ticks_per_frame = 2;
00504 }
00505 }
00506
00507 if (get_bits1(gb)) {
00508 v->color_prim = get_bits(gb, 8);
00509 v->transfer_char = get_bits(gb, 8);
00510 v->matrix_coef = get_bits(gb, 8);
00511 }
00512 }
00513
00514 v->hrd_param_flag = get_bits1(gb);
00515 if (v->hrd_param_flag) {
00516 int i;
00517 v->hrd_num_leaky_buckets = get_bits(gb, 5);
00518 skip_bits(gb, 4);
00519 skip_bits(gb, 4);
00520 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
00521 skip_bits(gb, 16);
00522 skip_bits(gb, 16);
00523 }
00524 }
00525 return 0;
00526 }
00527
00528 int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
00529 {
00530 int i;
00531
00532 av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
00533 v->broken_link = get_bits1(gb);
00534 v->closed_entry = get_bits1(gb);
00535 v->panscanflag = get_bits1(gb);
00536 v->refdist_flag = get_bits1(gb);
00537 v->s.loop_filter = get_bits1(gb);
00538 v->fastuvmc = get_bits1(gb);
00539 v->extended_mv = get_bits1(gb);
00540 v->dquant = get_bits(gb, 2);
00541 v->vstransform = get_bits1(gb);
00542 v->overlap = get_bits1(gb);
00543 v->quantizer_mode = get_bits(gb, 2);
00544
00545 if (v->hrd_param_flag) {
00546 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
00547 skip_bits(gb, 8);
00548 }
00549 }
00550
00551 if(get_bits1(gb)){
00552 int w = (get_bits(gb, 12)+1)<<1;
00553 int h = (get_bits(gb, 12)+1)<<1;
00554 avcodec_set_dimensions(avctx, w, h);
00555 }
00556 if (v->extended_mv)
00557 v->extended_dmv = get_bits1(gb);
00558 if ((v->range_mapy_flag = get_bits1(gb))) {
00559 av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
00560 v->range_mapy = get_bits(gb, 3);
00561 }
00562 if ((v->range_mapuv_flag = get_bits1(gb))) {
00563 av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
00564 v->range_mapuv = get_bits(gb, 3);
00565 }
00566
00567 av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
00568 "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
00569 "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
00570 "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
00571 v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
00572 v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
00573
00574 return 0;
00575 }
00576
00577 int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
00578 {
00579 int pqindex, lowquant, status;
00580
00581 if (v->finterpflag)
00582 v->interpfrm = get_bits1(gb);
00583 skip_bits(gb, 2);
00584 v->rangeredfrm = 0;
00585 if (v->rangered)
00586 v->rangeredfrm = get_bits1(gb);
00587 v->s.pict_type = get_bits1(gb);
00588 if (v->s.avctx->max_b_frames) {
00589 if (!v->s.pict_type) {
00590 if (get_bits1(gb))
00591 v->s.pict_type = AV_PICTURE_TYPE_I;
00592 else
00593 v->s.pict_type = AV_PICTURE_TYPE_B;
00594 } else
00595 v->s.pict_type = AV_PICTURE_TYPE_P;
00596 } else
00597 v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
00598
00599 v->bi_type = 0;
00600 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
00601 v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
00602 v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
00603 if (v->bfraction == 0) {
00604 v->s.pict_type = AV_PICTURE_TYPE_BI;
00605 }
00606 }
00607 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
00608 skip_bits(gb, 7);
00609
00610 if (v->parse_only)
00611 return 0;
00612
00613
00614 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
00615 v->rnd = 1;
00616 if (v->s.pict_type == AV_PICTURE_TYPE_P)
00617 v->rnd ^= 1;
00618
00619
00620 pqindex = get_bits(gb, 5);
00621 if (!pqindex)
00622 return -1;
00623 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
00624 v->pq = ff_vc1_pquant_table[0][pqindex];
00625 else
00626 v->pq = ff_vc1_pquant_table[1][pqindex];
00627
00628 v->pquantizer = 1;
00629 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
00630 v->pquantizer = pqindex < 9;
00631 if (v->quantizer_mode == QUANT_NON_UNIFORM)
00632 v->pquantizer = 0;
00633 v->pqindex = pqindex;
00634 if (pqindex < 9)
00635 v->halfpq = get_bits1(gb);
00636 else
00637 v->halfpq = 0;
00638 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
00639 v->pquantizer = get_bits1(gb);
00640 v->dquantfrm = 0;
00641 if (v->extended_mv == 1)
00642 v->mvrange = get_unary(gb, 0, 3);
00643 v->k_x = v->mvrange + 9 + (v->mvrange >> 1);
00644 v->k_y = v->mvrange + 8;
00645 v->range_x = 1 << (v->k_x - 1);
00646 v->range_y = 1 << (v->k_y - 1);
00647 if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)
00648 v->respic = get_bits(gb, 2);
00649
00650 if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) {
00651 v->x8_type = get_bits1(gb);
00652 } else
00653 v->x8_type = 0;
00654
00655
00656
00657 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P)
00658 v->use_ic = 0;
00659
00660 switch (v->s.pict_type) {
00661 case AV_PICTURE_TYPE_P:
00662 if (v->pq < 5) v->tt_index = 0;
00663 else if (v->pq < 13) v->tt_index = 1;
00664 else v->tt_index = 2;
00665
00666 lowquant = (v->pq > 12) ? 0 : 1;
00667 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
00668 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00669 int scale, shift, i;
00670 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
00671 v->lumscale = get_bits(gb, 6);
00672 v->lumshift = get_bits(gb, 6);
00673 v->use_ic = 1;
00674
00675 if (!v->lumscale) {
00676 scale = -64;
00677 shift = (255 - v->lumshift * 2) << 6;
00678 if (v->lumshift > 31)
00679 shift += 128 << 6;
00680 } else {
00681 scale = v->lumscale + 32;
00682 if (v->lumshift > 31)
00683 shift = (v->lumshift - 64) << 6;
00684 else
00685 shift = v->lumshift << 6;
00686 }
00687 for (i = 0; i < 256; i++) {
00688 v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
00689 v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
00690 }
00691 }
00692 v->qs_last = v->s.quarter_sample;
00693 if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
00694 v->s.quarter_sample = 0;
00695 else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00696 if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
00697 v->s.quarter_sample = 0;
00698 else
00699 v->s.quarter_sample = 1;
00700 } else
00701 v->s.quarter_sample = 1;
00702 v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
00703
00704 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
00705 v->mv_mode2 == MV_PMODE_MIXED_MV) ||
00706 v->mv_mode == MV_PMODE_MIXED_MV) {
00707 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
00708 if (status < 0)
00709 return -1;
00710 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
00711 "Imode: %i, Invert: %i\n", status>>1, status&1);
00712 } else {
00713 v->mv_type_is_raw = 0;
00714 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
00715 }
00716 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
00717 if (status < 0)
00718 return -1;
00719 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
00720 "Imode: %i, Invert: %i\n", status>>1, status&1);
00721
00722
00723 v->s.mv_table_index = get_bits(gb, 2);
00724 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
00725
00726 if (v->dquant) {
00727 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
00728 vop_dquant_decoding(v);
00729 }
00730
00731 v->ttfrm = 0;
00732 if (v->vstransform) {
00733 v->ttmbf = get_bits1(gb);
00734 if (v->ttmbf) {
00735 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
00736 }
00737 } else {
00738 v->ttmbf = 1;
00739 v->ttfrm = TT_8X8;
00740 }
00741 break;
00742 case AV_PICTURE_TYPE_B:
00743 if (v->pq < 5) v->tt_index = 0;
00744 else if (v->pq < 13) v->tt_index = 1;
00745 else v->tt_index = 2;
00746
00747 v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
00748 v->qs_last = v->s.quarter_sample;
00749 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
00750 v->s.mspel = v->s.quarter_sample;
00751
00752 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
00753 if (status < 0)
00754 return -1;
00755 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
00756 "Imode: %i, Invert: %i\n", status>>1, status&1);
00757 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
00758 if (status < 0)
00759 return -1;
00760 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
00761 "Imode: %i, Invert: %i\n", status>>1, status&1);
00762
00763 v->s.mv_table_index = get_bits(gb, 2);
00764 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
00765
00766 if (v->dquant) {
00767 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
00768 vop_dquant_decoding(v);
00769 }
00770
00771 v->ttfrm = 0;
00772 if (v->vstransform) {
00773 v->ttmbf = get_bits1(gb);
00774 if (v->ttmbf) {
00775 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
00776 }
00777 } else {
00778 v->ttmbf = 1;
00779 v->ttfrm = TT_8X8;
00780 }
00781 break;
00782 }
00783
00784 if (!v->x8_type) {
00785
00786 v->c_ac_table_index = decode012(gb);
00787 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
00788 v->y_ac_table_index = decode012(gb);
00789 }
00790
00791 v->s.dc_table_index = get_bits1(gb);
00792 }
00793
00794 if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
00795 v->s.pict_type = AV_PICTURE_TYPE_B;
00796 v->bi_type = 1;
00797 }
00798 return 0;
00799 }
00800
00801
00802 #define INIT_LUT(lumscale, lumshift, luty, lutuv) \
00803 if (!lumscale) { \
00804 scale = -64; \
00805 shift = (255 - lumshift * 2) << 6; \
00806 if (lumshift > 31) \
00807 shift += 128 << 6; \
00808 } else { \
00809 scale = lumscale + 32; \
00810 if (lumshift > 31) \
00811 shift = (lumshift - 64) << 6; \
00812 else \
00813 shift = lumshift << 6; \
00814 } \
00815 for (i = 0; i < 256; i++) { \
00816 luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); \
00817 lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6); \
00818 }
00819
00820 int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
00821 {
00822 int pqindex, lowquant;
00823 int status;
00824 int mbmodetab, imvtab, icbptab, twomvbptab, fourmvbptab;
00825 int scale, shift, i;
00826
00827 v->numref=0;
00828 v->p_frame_skipped = 0;
00829 if (v->second_field) {
00830 if(v->fcm!=2 || v->field_mode!=1)
00831 return -1;
00832 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
00833 if (v->fptype & 4)
00834 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
00835 v->s.current_picture_ptr->f.pict_type = v->s.pict_type;
00836 if (!v->pic_header_flag)
00837 goto parse_common_info;
00838 }
00839
00840 v->field_mode = 0;
00841 if (v->interlace) {
00842 v->fcm = decode012(gb);
00843 if (v->fcm) {
00844 if (v->fcm == ILACE_FIELD)
00845 v->field_mode = 1;
00846 if (!v->warn_interlaced++)
00847 av_log(v->s.avctx, AV_LOG_ERROR,
00848 "Interlaced frames/fields support is incomplete\n");
00849 }
00850 } else {
00851 v->fcm = PROGRESSIVE;
00852 }
00853
00854 if (v->field_mode) {
00855 v->fptype = get_bits(gb, 3);
00856 v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
00857 if (v->fptype & 4)
00858 v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
00859 } else {
00860 switch (get_unary(gb, 0, 4)) {
00861 case 0:
00862 v->s.pict_type = AV_PICTURE_TYPE_P;
00863 break;
00864 case 1:
00865 v->s.pict_type = AV_PICTURE_TYPE_B;
00866 break;
00867 case 2:
00868 v->s.pict_type = AV_PICTURE_TYPE_I;
00869 break;
00870 case 3:
00871 v->s.pict_type = AV_PICTURE_TYPE_BI;
00872 break;
00873 case 4:
00874 v->s.pict_type = AV_PICTURE_TYPE_P;
00875 v->p_frame_skipped = 1;
00876 break;
00877 }
00878 }
00879 if (v->tfcntrflag)
00880 skip_bits(gb, 8);
00881 if (v->broadcast) {
00882 if (!v->interlace || v->psf) {
00883 v->rptfrm = get_bits(gb, 2);
00884 } else {
00885 v->tff = get_bits1(gb);
00886 v->rff = get_bits1(gb);
00887 }
00888 }
00889 if (v->panscanflag) {
00890 av_log_missing_feature(v->s.avctx, "Pan-scan", 0);
00891
00892 }
00893 if (v->p_frame_skipped) {
00894 return 0;
00895 }
00896 v->rnd = get_bits1(gb);
00897 if (v->interlace)
00898 v->uvsamp = get_bits1(gb);
00899 if(!ff_vc1_bfraction_vlc.table)
00900 return 0;
00901 if (v->field_mode) {
00902 if (!v->refdist_flag)
00903 v->refdist = 0;
00904 else {
00905 if ((v->s.pict_type != AV_PICTURE_TYPE_B)
00906 && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
00907 v->refdist = get_bits(gb, 2);
00908 if (v->refdist == 3)
00909 v->refdist += get_unary(gb, 0, 16);
00910 } else {
00911 v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
00912 v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
00913 v->frfd = (v->bfraction * v->refdist) >> 8;
00914 v->brfd = v->refdist - v->frfd - 1;
00915 if (v->brfd < 0)
00916 v->brfd = 0;
00917 }
00918 }
00919 goto parse_common_info;
00920 }
00921 if (v->finterpflag)
00922 v->interpfrm = get_bits1(gb);
00923 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
00924 v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
00925 v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
00926 if (v->bfraction == 0) {
00927 v->s.pict_type = AV_PICTURE_TYPE_BI;
00928 }
00929 }
00930
00931 parse_common_info:
00932 if (v->field_mode)
00933 v->cur_field_type = !(v->tff ^ v->second_field);
00934 pqindex = get_bits(gb, 5);
00935 if (!pqindex)
00936 return -1;
00937 v->pqindex = pqindex;
00938 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
00939 v->pq = ff_vc1_pquant_table[0][pqindex];
00940 else
00941 v->pq = ff_vc1_pquant_table[1][pqindex];
00942
00943 v->pquantizer = 1;
00944 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
00945 v->pquantizer = pqindex < 9;
00946 if (v->quantizer_mode == QUANT_NON_UNIFORM)
00947 v->pquantizer = 0;
00948 v->pqindex = pqindex;
00949 if (pqindex < 9)
00950 v->halfpq = get_bits1(gb);
00951 else
00952 v->halfpq = 0;
00953 if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
00954 v->pquantizer = get_bits1(gb);
00955 if (v->postprocflag)
00956 v->postproc = get_bits(gb, 2);
00957
00958 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P)
00959 v->use_ic = 0;
00960
00961 if (v->parse_only)
00962 return 0;
00963
00964 switch (v->s.pict_type) {
00965 case AV_PICTURE_TYPE_I:
00966 case AV_PICTURE_TYPE_BI:
00967 if (v->fcm == ILACE_FRAME) {
00968 status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v);
00969 if (status < 0)
00970 return -1;
00971 av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
00972 "Imode: %i, Invert: %i\n", status>>1, status&1);
00973 }
00974 status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
00975 if (status < 0)
00976 return -1;
00977 av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
00978 "Imode: %i, Invert: %i\n", status>>1, status&1);
00979 v->condover = CONDOVER_NONE;
00980 if (v->overlap && v->pq <= 8) {
00981 v->condover = decode012(gb);
00982 if (v->condover == CONDOVER_SELECT) {
00983 status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
00984 if (status < 0)
00985 return -1;
00986 av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
00987 "Imode: %i, Invert: %i\n", status>>1, status&1);
00988 }
00989 }
00990 break;
00991 case AV_PICTURE_TYPE_P:
00992 if (v->field_mode) {
00993 v->numref = get_bits1(gb);
00994 if (!v->numref) {
00995 v->reffield = get_bits1(gb);
00996 v->ref_field_type[0] = v->reffield ^ !v->cur_field_type;
00997 }
00998 }
00999 if (v->extended_mv)
01000 v->mvrange = get_unary(gb, 0, 3);
01001 else
01002 v->mvrange = 0;
01003 if (v->interlace) {
01004 if (v->extended_dmv)
01005 v->dmvrange = get_unary(gb, 0, 3);
01006 else
01007 v->dmvrange = 0;
01008 if (v->fcm == ILACE_FRAME) {
01009 v->fourmvswitch = get_bits1(gb);
01010 v->intcomp = get_bits1(gb);
01011 if (v->intcomp) {
01012 v->lumscale = get_bits(gb, 6);
01013 v->lumshift = get_bits(gb, 6);
01014 INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv);
01015 }
01016 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
01017 av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
01018 "Imode: %i, Invert: %i\n", status>>1, status&1);
01019 mbmodetab = get_bits(gb, 2);
01020 if (v->fourmvswitch)
01021 v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[mbmodetab];
01022 else
01023 v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab];
01024 imvtab = get_bits(gb, 2);
01025 v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
01026
01027 icbptab = get_bits(gb, 3);
01028 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
01029 twomvbptab = get_bits(gb, 2);
01030 v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab];
01031 if (v->fourmvswitch) {
01032 fourmvbptab = get_bits(gb, 2);
01033 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
01034 }
01035 }
01036 }
01037 v->k_x = v->mvrange + 9 + (v->mvrange >> 1);
01038 v->k_y = v->mvrange + 8;
01039 v->range_x = 1 << (v->k_x - 1);
01040 v->range_y = 1 << (v->k_y - 1);
01041
01042 if (v->pq < 5)
01043 v->tt_index = 0;
01044 else if (v->pq < 13)
01045 v->tt_index = 1;
01046 else
01047 v->tt_index = 2;
01048 if (v->fcm != ILACE_FRAME) {
01049 int mvmode;
01050 mvmode = get_unary(gb, 1, 4);
01051 lowquant = (v->pq > 12) ? 0 : 1;
01052 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode];
01053 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
01054 int mvmode2;
01055 mvmode2 = get_unary(gb, 1, 3);
01056 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2];
01057 if (v->field_mode)
01058 v->intcompfield = decode210(gb);
01059 v->lumscale = get_bits(gb, 6);
01060 v->lumshift = get_bits(gb, 6);
01061 INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv);
01062 if ((v->field_mode) && !v->intcompfield) {
01063 v->lumscale2 = get_bits(gb, 6);
01064 v->lumshift2 = get_bits(gb, 6);
01065 INIT_LUT(v->lumscale2, v->lumshift2, v->luty2, v->lutuv2);
01066 }
01067 v->use_ic = 1;
01068 }
01069 v->qs_last = v->s.quarter_sample;
01070 if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
01071 v->s.quarter_sample = 0;
01072 else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
01073 if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
01074 v->s.quarter_sample = 0;
01075 else
01076 v->s.quarter_sample = 1;
01077 } else
01078 v->s.quarter_sample = 1;
01079 v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN
01080 || (v->mv_mode == MV_PMODE_INTENSITY_COMP
01081 && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
01082 }
01083 if (v->fcm == PROGRESSIVE) {
01084 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
01085 v->mv_mode2 == MV_PMODE_MIXED_MV)
01086 || v->mv_mode == MV_PMODE_MIXED_MV) {
01087 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
01088 if (status < 0)
01089 return -1;
01090 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
01091 "Imode: %i, Invert: %i\n", status>>1, status&1);
01092 } else {
01093 v->mv_type_is_raw = 0;
01094 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
01095 }
01096 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
01097 if (status < 0)
01098 return -1;
01099 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
01100 "Imode: %i, Invert: %i\n", status>>1, status&1);
01101
01102
01103 v->s.mv_table_index = get_bits(gb, 2);
01104 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
01105 } else if (v->fcm == ILACE_FRAME) {
01106 v->qs_last = v->s.quarter_sample;
01107 v->s.quarter_sample = 1;
01108 v->s.mspel = 1;
01109 } else {
01110 mbmodetab = get_bits(gb, 3);
01111 imvtab = get_bits(gb, 2 + v->numref);
01112 if (!v->numref)
01113 v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
01114 else
01115 v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab];
01116 icbptab = get_bits(gb, 3);
01117 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
01118 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
01119 v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
01120 fourmvbptab = get_bits(gb, 2);
01121 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
01122 v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab];
01123 } else {
01124 v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab];
01125 }
01126 }
01127 if (v->dquant) {
01128 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
01129 vop_dquant_decoding(v);
01130 }
01131
01132 v->ttfrm = 0;
01133 if (v->vstransform) {
01134 v->ttmbf = get_bits1(gb);
01135 if (v->ttmbf) {
01136 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
01137 }
01138 } else {
01139 v->ttmbf = 1;
01140 v->ttfrm = TT_8X8;
01141 }
01142 break;
01143 case AV_PICTURE_TYPE_B:
01144
01145 if (v->fcm == ILACE_FRAME)
01146 return -1;
01147 if (v->extended_mv)
01148 v->mvrange = get_unary(gb, 0, 3);
01149 else
01150 v->mvrange = 0;
01151 v->k_x = v->mvrange + 9 + (v->mvrange >> 1);
01152 v->k_y = v->mvrange + 8;
01153 v->range_x = 1 << (v->k_x - 1);
01154 v->range_y = 1 << (v->k_y - 1);
01155
01156 if (v->pq < 5)
01157 v->tt_index = 0;
01158 else if (v->pq < 13)
01159 v->tt_index = 1;
01160 else
01161 v->tt_index = 2;
01162
01163 if (v->field_mode) {
01164 int mvmode;
01165 av_log(v->s.avctx, AV_LOG_ERROR, "B Fields do not work currently\n");
01166 return -1;
01167 if (v->extended_dmv)
01168 v->dmvrange = get_unary(gb, 0, 3);
01169 mvmode = get_unary(gb, 1, 3);
01170 lowquant = (v->pq > 12) ? 0 : 1;
01171 v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode];
01172 v->qs_last = v->s.quarter_sample;
01173 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV);
01174 v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || v->mv_mode == MV_PMODE_1MV_HPEL);
01175 status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
01176 if (status < 0)
01177 return -1;
01178 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
01179 "Imode: %i, Invert: %i\n", status>>1, status&1);
01180 mbmodetab = get_bits(gb, 3);
01181 if (v->mv_mode == MV_PMODE_MIXED_MV)
01182 v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab];
01183 else
01184 v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab];
01185 imvtab = get_bits(gb, 3);
01186 v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab];
01187 icbptab = get_bits(gb, 3);
01188 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
01189 if (v->mv_mode == MV_PMODE_MIXED_MV) {
01190 fourmvbptab = get_bits(gb, 2);
01191 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
01192 }
01193 v->numref = 1;
01194 } else {
01195 v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
01196 v->qs_last = v->s.quarter_sample;
01197 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
01198 v->s.mspel = v->s.quarter_sample;
01199 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
01200 if (status < 0)
01201 return -1;
01202 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
01203 "Imode: %i, Invert: %i\n", status>>1, status&1);
01204 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
01205 if (status < 0)
01206 return -1;
01207 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
01208 "Imode: %i, Invert: %i\n", status>>1, status&1);
01209 v->s.mv_table_index = get_bits(gb, 2);
01210 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
01211 }
01212
01213 if (v->dquant) {
01214 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
01215 vop_dquant_decoding(v);
01216 }
01217
01218 v->ttfrm = 0;
01219 if (v->vstransform) {
01220 v->ttmbf = get_bits1(gb);
01221 if (v->ttmbf) {
01222 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
01223 }
01224 } else {
01225 v->ttmbf = 1;
01226 v->ttfrm = TT_8X8;
01227 }
01228 break;
01229 }
01230
01231
01232 v->c_ac_table_index = decode012(gb);
01233 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
01234 v->y_ac_table_index = decode012(gb);
01235 }
01236
01237 v->s.dc_table_index = get_bits1(gb);
01238 if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
01239 && v->dquant) {
01240 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
01241 vop_dquant_decoding(v);
01242 }
01243
01244 v->bi_type = 0;
01245 if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
01246 v->s.pict_type = AV_PICTURE_TYPE_B;
01247 v->bi_type = 1;
01248 }
01249 return 0;
01250 }