FFmpeg
vc1_block.c
Go to the documentation of this file.
1 /*
2  * VC-1 and WMV3 decoder
3  * Copyright (c) 2011 Mashiat Sarker Shakkhar
4  * Copyright (c) 2006-2007 Konstantin Shishkov
5  * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * VC-1 and WMV3 block decoding routines
27  */
28 
29 #include "avcodec.h"
30 #include "mpegutils.h"
31 #include "mpegvideo.h"
32 #include "msmpeg4data.h"
33 #include "unary.h"
34 #include "vc1.h"
35 #include "vc1_pred.h"
36 #include "vc1acdata.h"
37 #include "vc1data.h"
38 
39 #define MB_INTRA_VLC_BITS 9
40 #define DC_VLC_BITS 9
41 
42 // offset tables for interlaced picture MVDATA decoding
43 static const uint8_t offset_table[2][9] = {
44  { 0, 1, 2, 4, 8, 16, 32, 64, 128 },
45  { 0, 1, 3, 7, 15, 31, 63, 127, 255 },
46 };
47 
48 // mapping table for internal block representation
49 static const int block_map[6] = {0, 2, 1, 3, 4, 5};
50 
51 /***********************************************************************/
52 /**
53  * @name VC-1 Bitplane decoding
54  * @see 8.7, p56
55  * @{
56  */
57 
58 
59 static inline void init_block_index(VC1Context *v)
60 {
61  MpegEncContext *s = &v->s;
63  if (v->field_mode && !(v->second_field ^ v->tff)) {
64  s->dest[0] += s->current_picture_ptr->f->linesize[0];
65  s->dest[1] += s->current_picture_ptr->f->linesize[1];
66  s->dest[2] += s->current_picture_ptr->f->linesize[2];
67  }
68 }
69 
70 /** @} */ //Bitplane group
71 
72 static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
73 {
74  MpegEncContext *s = &v->s;
75  uint8_t *dest;
76  int block_count = CONFIG_GRAY && (s->avctx->flags & AV_CODEC_FLAG_GRAY) ? 4 : 6;
77  int fieldtx = 0;
78  int i;
79 
80  /* The put pixels loop is one MB row and one MB column behind the decoding
81  * loop because we can only put pixels when overlap filtering is done. For
82  * interlaced frame pictures, however, the put pixels loop is only one
83  * column behind the decoding loop as interlaced frame pictures only need
84  * horizontal overlap filtering. */
85  if (!s->first_slice_line && v->fcm != ILACE_FRAME) {
86  if (s->mb_x) {
87  for (i = 0; i < block_count; i++) {
88  if (i > 3 ? v->mb_type[0][s->block_index[i] - s->block_wrap[i] - 1] :
89  v->mb_type[0][s->block_index[i] - 2 * s->block_wrap[i] - 2]) {
90  dest = s->dest[0] + ((i & 2) - 4) * 4 * s->linesize + ((i & 1) - 2) * 8;
91  if (put_signed)
93  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize - 8 : dest,
94  i > 3 ? s->uvlinesize : s->linesize);
95  else
97  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize - 8 : dest,
98  i > 3 ? s->uvlinesize : s->linesize);
99  }
100  }
101  }
102  if (s->mb_x == v->end_mb_x - 1) {
103  for (i = 0; i < block_count; i++) {
104  if (i > 3 ? v->mb_type[0][s->block_index[i] - s->block_wrap[i]] :
105  v->mb_type[0][s->block_index[i] - 2 * s->block_wrap[i]]) {
106  dest = s->dest[0] + ((i & 2) - 4) * 4 * s->linesize + (i & 1) * 8;
107  if (put_signed)
109  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize : dest,
110  i > 3 ? s->uvlinesize : s->linesize);
111  else
113  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize : dest,
114  i > 3 ? s->uvlinesize : s->linesize);
115  }
116  }
117  }
118  }
119  if (s->mb_y == s->end_mb_y - 1 || v->fcm == ILACE_FRAME) {
120  if (s->mb_x) {
121  if (v->fcm == ILACE_FRAME)
122  fieldtx = v->fieldtx_plane[s->mb_y * s->mb_stride + s->mb_x - 1];
123  for (i = 0; i < block_count; i++) {
124  if (i > 3 ? v->mb_type[0][s->block_index[i] - 1] :
125  v->mb_type[0][s->block_index[i] - 2]) {
126  if (fieldtx)
127  dest = s->dest[0] + ((i & 2) >> 1) * s->linesize + ((i & 1) - 2) * 8;
128  else
129  dest = s->dest[0] + (i & 2) * 4 * s->linesize + ((i & 1) - 2) * 8;
130  if (put_signed)
132  i > 3 ? s->dest[i - 3] - 8 : dest,
133  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
134  else
136  i > 3 ? s->dest[i - 3] - 8 : dest,
137  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
138  }
139  }
140  }
141  if (s->mb_x == v->end_mb_x - 1) {
142  if (v->fcm == ILACE_FRAME)
143  fieldtx = v->fieldtx_plane[s->mb_y * s->mb_stride + s->mb_x];
144  for (i = 0; i < block_count; i++) {
145  if (v->mb_type[0][s->block_index[i]]) {
146  if (fieldtx)
147  dest = s->dest[0] + ((i & 2) >> 1) * s->linesize + (i & 1) * 8;
148  else
149  dest = s->dest[0] + (i & 2) * 4 * s->linesize + (i & 1) * 8;
150  if (put_signed)
152  i > 3 ? s->dest[i - 3] : dest,
153  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
154  else
156  i > 3 ? s->dest[i - 3] : dest,
157  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
158  }
159  }
160  }
161  }
162 }
163 
164 #define inc_blk_idx(idx) do { \
165  idx++; \
166  if (idx >= v->n_allocated_blks) \
167  idx = 0; \
168  } while (0)
169 
170 /***********************************************************************/
171 /**
172  * @name VC-1 Block-level functions
173  * @see 7.1.4, p91 and 8.1.1.7, p(1)04
174  * @{
175  */
176 
177 /**
178  * @def GET_MQUANT
179  * @brief Get macroblock-level quantizer scale
180  */
181 #define GET_MQUANT() \
182  if (v->dquantfrm) { \
183  int edges = 0; \
184  if (v->dqprofile == DQPROFILE_ALL_MBS) { \
185  if (v->dqbilevel) { \
186  mquant = (get_bits1(gb)) ? -v->altpq : v->pq; \
187  } else { \
188  mqdiff = get_bits(gb, 3); \
189  if (mqdiff != 7) \
190  mquant = -v->pq - mqdiff; \
191  else \
192  mquant = -get_bits(gb, 5); \
193  } \
194  } \
195  if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
196  edges = 1 << v->dqsbedge; \
197  else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
198  edges = (3 << v->dqsbedge) % 15; \
199  else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
200  edges = 15; \
201  if ((edges&1) && !s->mb_x) \
202  mquant = -v->altpq; \
203  if ((edges&2) && !s->mb_y) \
204  mquant = -v->altpq; \
205  if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
206  mquant = -v->altpq; \
207  if ((edges&8) && \
208  s->mb_y == ((s->mb_height >> v->field_mode) - 1)) \
209  mquant = -v->altpq; \
210  if (!mquant || mquant > 31 || mquant < -31) { \
211  av_log(v->s.avctx, AV_LOG_ERROR, \
212  "Overriding invalid mquant %d\n", mquant); \
213  mquant = 1; \
214  } \
215  }
216 
217 /**
218  * @def GET_MVDATA(_dmv_x, _dmv_y)
219  * @brief Get MV differentials
220  * @see MVDATA decoding from 8.3.5.2, p(1)20
221  * @param _dmv_x Horizontal differential for decoded MV
222  * @param _dmv_y Vertical differential for decoded MV
223  */
224 #define GET_MVDATA(_dmv_x, _dmv_y) \
225  index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
226  VC1_MV_DIFF_VLC_BITS, 2); \
227  if (index > 36) { \
228  mb_has_coeffs = 1; \
229  index -= 37; \
230  } else \
231  mb_has_coeffs = 0; \
232  s->mb_intra = 0; \
233  if (!index) { \
234  _dmv_x = _dmv_y = 0; \
235  } else if (index == 35) { \
236  _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
237  _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
238  } else if (index == 36) { \
239  _dmv_x = 0; \
240  _dmv_y = 0; \
241  s->mb_intra = 1; \
242  } else { \
243  index1 = index % 6; \
244  _dmv_x = offset_table[1][index1]; \
245  val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
246  if (val > 0) { \
247  val = get_bits(gb, val); \
248  sign = 0 - (val & 1); \
249  _dmv_x = (sign ^ ((val >> 1) + _dmv_x)) - sign; \
250  } \
251  \
252  index1 = index / 6; \
253  _dmv_y = offset_table[1][index1]; \
254  val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
255  if (val > 0) { \
256  val = get_bits(gb, val); \
257  sign = 0 - (val & 1); \
258  _dmv_y = (sign ^ ((val >> 1) + _dmv_y)) - sign; \
259  } \
260  }
261 
263  int *dmv_y, int *pred_flag)
264 {
265  int index, index1;
266  int extend_x, extend_y;
267  GetBitContext *gb = &v->s.gb;
268  int bits, esc;
269  int val, sign;
270 
271  if (v->numref) {
273  esc = 125;
274  } else {
276  esc = 71;
277  }
278  extend_x = v->dmvrange & 1;
279  extend_y = (v->dmvrange >> 1) & 1;
280  index = get_vlc2(gb, v->imv_vlc->table, bits, 3);
281  if (index == esc) {
282  *dmv_x = get_bits(gb, v->k_x);
283  *dmv_y = get_bits(gb, v->k_y);
284  if (v->numref) {
285  if (pred_flag)
286  *pred_flag = *dmv_y & 1;
287  *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
288  }
289  }
290  else {
291  av_assert0(index < esc);
292  index1 = (index + 1) % 9;
293  if (index1 != 0) {
294  val = get_bits(gb, index1 + extend_x);
295  sign = 0 - (val & 1);
296  *dmv_x = (sign ^ ((val >> 1) + offset_table[extend_x][index1])) - sign;
297  } else
298  *dmv_x = 0;
299  index1 = (index + 1) / 9;
300  if (index1 > v->numref) {
301  val = get_bits(gb, (index1 >> v->numref) + extend_y);
302  sign = 0 - (val & 1);
303  *dmv_y = (sign ^ ((val >> 1) + offset_table[extend_y][index1 >> v->numref])) - sign;
304  } else
305  *dmv_y = 0;
306  if (v->numref && pred_flag)
307  *pred_flag = index1 & 1;
308  }
309 }
310 
311 /** Reconstruct motion vector for B-frame and do motion compensation
312  */
313 static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2],
314  int direct, int mode)
315 {
316  if (direct) {
317  ff_vc1_mc_1mv(v, 0);
318  ff_vc1_interp_mc(v);
319  return;
320  }
321  if (mode == BMV_TYPE_INTERPOLATED) {
322  ff_vc1_mc_1mv(v, 0);
323  ff_vc1_interp_mc(v);
324  return;
325  }
326 
327  ff_vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
328 }
329 
330 /** Get predicted DC value for I-frames only
331  * prediction dir: left=0, top=1
332  * @param s MpegEncContext
333  * @param overlap flag indicating that overlap filtering is used
334  * @param pq integer part of picture quantizer
335  * @param[in] n block index in the current MB
336  * @param dc_val_ptr Pointer to DC predictor
337  * @param dir_ptr Prediction direction for use in AC prediction
338  */
339 static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
340  int16_t **dc_val_ptr, int *dir_ptr)
341 {
342  int a, b, c, wrap, pred, scale;
343  int16_t *dc_val;
344  static const uint16_t dcpred[32] = {
345  -1, 1024, 512, 341, 256, 205, 171, 146, 128,
346  114, 102, 93, 85, 79, 73, 68, 64,
347  60, 57, 54, 51, 49, 47, 45, 43,
348  41, 39, 38, 37, 35, 34, 33
349  };
350 
351  /* find prediction - wmv3_dc_scale always used here in fact */
352  if (n < 4) scale = s->y_dc_scale;
353  else scale = s->c_dc_scale;
354 
355  wrap = s->block_wrap[n];
356  dc_val = s->dc_val[0] + s->block_index[n];
357 
358  /* B A
359  * C X
360  */
361  c = dc_val[ - 1];
362  b = dc_val[ - 1 - wrap];
363  a = dc_val[ - wrap];
364 
365  if (pq < 9 || !overlap) {
366  /* Set outer values */
367  if (s->first_slice_line && (n != 2 && n != 3))
368  b = a = dcpred[scale];
369  if (s->mb_x == 0 && (n != 1 && n != 3))
370  b = c = dcpred[scale];
371  } else {
372  /* Set outer values */
373  if (s->first_slice_line && (n != 2 && n != 3))
374  b = a = 0;
375  if (s->mb_x == 0 && (n != 1 && n != 3))
376  b = c = 0;
377  }
378 
379  if (abs(a - b) <= abs(b - c)) {
380  pred = c;
381  *dir_ptr = 1; // left
382  } else {
383  pred = a;
384  *dir_ptr = 0; // top
385  }
386 
387  /* update predictor */
388  *dc_val_ptr = &dc_val[0];
389  return pred;
390 }
391 
392 
393 /** Get predicted DC value
394  * prediction dir: left=0, top=1
395  * @param s MpegEncContext
396  * @param overlap flag indicating that overlap filtering is used
397  * @param pq integer part of picture quantizer
398  * @param[in] n block index in the current MB
399  * @param a_avail flag indicating top block availability
400  * @param c_avail flag indicating left block availability
401  * @param dc_val_ptr Pointer to DC predictor
402  * @param dir_ptr Prediction direction for use in AC prediction
403  */
404 static inline int ff_vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
405  int a_avail, int c_avail,
406  int16_t **dc_val_ptr, int *dir_ptr)
407 {
408  int a, b, c, wrap, pred;
409  int16_t *dc_val;
410  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
411  int q1, q2 = 0;
412  int dqscale_index;
413 
414  /* scale predictors if needed */
415  q1 = FFABS(s->current_picture.qscale_table[mb_pos]);
416  dqscale_index = s->y_dc_scale_table[q1] - 1;
417  if (dqscale_index < 0)
418  return 0;
419 
420  wrap = s->block_wrap[n];
421  dc_val = s->dc_val[0] + s->block_index[n];
422 
423  /* B A
424  * C X
425  */
426  c = dc_val[ - 1];
427  b = dc_val[ - 1 - wrap];
428  a = dc_val[ - wrap];
429 
430  if (c_avail && (n != 1 && n != 3)) {
431  q2 = FFABS(s->current_picture.qscale_table[mb_pos - 1]);
432  if (q2 && q2 != q1)
433  c = (int)((unsigned)c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
434  }
435  if (a_avail && (n != 2 && n != 3)) {
436  q2 = FFABS(s->current_picture.qscale_table[mb_pos - s->mb_stride]);
437  if (q2 && q2 != q1)
438  a = (int)((unsigned)a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
439  }
440  if (a_avail && c_avail && (n != 3)) {
441  int off = mb_pos;
442  if (n != 1)
443  off--;
444  if (n != 2)
445  off -= s->mb_stride;
446  q2 = FFABS(s->current_picture.qscale_table[off]);
447  if (q2 && q2 != q1)
448  b = (int)((unsigned)b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
449  }
450 
451  if (c_avail && (!a_avail || abs(a - b) <= abs(b - c))) {
452  pred = c;
453  *dir_ptr = 1; // left
454  } else if (a_avail) {
455  pred = a;
456  *dir_ptr = 0; // top
457  } else {
458  pred = 0;
459  *dir_ptr = 1; // left
460  }
461 
462  /* update predictor */
463  *dc_val_ptr = &dc_val[0];
464  return pred;
465 }
466 
467 /** @} */ // Block group
468 
469 /**
470  * @name VC1 Macroblock-level functions in Simple/Main Profiles
471  * @see 7.1.4, p91 and 8.1.1.7, p(1)04
472  * @{
473  */
474 
475 static inline int vc1_coded_block_pred(MpegEncContext * s, int n,
476  uint8_t **coded_block_ptr)
477 {
478  int xy, wrap, pred, a, b, c;
479 
480  xy = s->block_index[n];
481  wrap = s->b8_stride;
482 
483  /* B C
484  * A X
485  */
486  a = s->coded_block[xy - 1 ];
487  b = s->coded_block[xy - 1 - wrap];
488  c = s->coded_block[xy - wrap];
489 
490  if (b == c) {
491  pred = a;
492  } else {
493  pred = c;
494  }
495 
496  /* store value */
497  *coded_block_ptr = &s->coded_block[xy];
498 
499  return pred;
500 }
501 
502 /**
503  * Decode one AC coefficient
504  * @param v The VC1 context
505  * @param last Last coefficient
506  * @param skip How much zero coefficients to skip
507  * @param value Decoded AC coefficient value
508  * @param codingset set of VLC to decode data
509  * @see 8.1.3.4
510  */
511 static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
512  int *value, int codingset)
513 {
514  GetBitContext *gb = &v->s.gb;
515  int index, run, level, lst, sign;
516 
517  index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
518  if (index < 0)
519  return index;
520  if (index != ff_vc1_ac_sizes[codingset] - 1) {
521  run = vc1_index_decode_table[codingset][index][0];
522  level = vc1_index_decode_table[codingset][index][1];
523  lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;
524  sign = get_bits1(gb);
525  } else {
526  int escape = decode210(gb);
527  if (escape != 2) {
528  index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
529  if (index < 0)
530  return AVERROR_INVALIDDATA;
531  run = vc1_index_decode_table[codingset][index][0];
532  level = vc1_index_decode_table[codingset][index][1];
533  lst = index >= vc1_last_decode_table[codingset];
534  if (escape == 0) {
535  if (lst)
536  level += vc1_last_delta_level_table[codingset][run];
537  else
538  level += vc1_delta_level_table[codingset][run];
539  } else {
540  if (lst)
541  run += vc1_last_delta_run_table[codingset][level] + 1;
542  else
543  run += vc1_delta_run_table[codingset][level] + 1;
544  }
545  sign = get_bits1(gb);
546  } else {
547  lst = get_bits1(gb);
548  if (v->s.esc3_level_length == 0) {
549  if (v->pq < 8 || v->dquantfrm) { // table 59
550  v->s.esc3_level_length = get_bits(gb, 3);
551  if (!v->s.esc3_level_length)
552  v->s.esc3_level_length = get_bits(gb, 2) + 8;
553  } else { // table 60
554  v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
555  }
556  v->s.esc3_run_length = 3 + get_bits(gb, 2);
557  }
558  run = get_bits(gb, v->s.esc3_run_length);
559  sign = get_bits1(gb);
560  level = get_bits(gb, v->s.esc3_level_length);
561  }
562  }
563 
564  *last = lst;
565  *skip = run;
566  *value = (level ^ -sign) + sign;
567 
568  return 0;
569 }
570 
571 /** Decode intra block in intra frames - should be faster than decode_intra_block
572  * @param v VC1Context
573  * @param block block to decode
574  * @param[in] n subblock index
575  * @param coded are AC coeffs present or not
576  * @param codingset set of VLC to decode data
577  */
578 static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
579  int coded, int codingset)
580 {
581  GetBitContext *gb = &v->s.gb;
582  MpegEncContext *s = &v->s;
583  int dc_pred_dir = 0; /* Direction of the DC prediction used */
584  int i;
585  int16_t *dc_val;
586  int16_t *ac_val, *ac_val2;
587  int dcdiff, scale;
588 
589  /* Get DC differential */
590  if (n < 4) {
592  } else {
594  }
595  if (dcdiff < 0) {
596  av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
597  return -1;
598  }
599  if (dcdiff) {
600  const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0;
601  if (dcdiff == 119 /* ESC index value */) {
602  dcdiff = get_bits(gb, 8 + m);
603  } else {
604  if (m)
605  dcdiff = (dcdiff << m) + get_bits(gb, m) - ((1 << m) - 1);
606  }
607  if (get_bits1(gb))
608  dcdiff = -dcdiff;
609  }
610 
611  /* Prediction */
612  dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
613  *dc_val = dcdiff;
614 
615  /* Store the quantized DC coeff, used for prediction */
616  if (n < 4)
617  scale = s->y_dc_scale;
618  else
619  scale = s->c_dc_scale;
620  block[0] = dcdiff * scale;
621 
622  ac_val = s->ac_val[0][s->block_index[n]];
623  ac_val2 = ac_val;
624  if (dc_pred_dir) // left
625  ac_val -= 16;
626  else // top
627  ac_val -= 16 * s->block_wrap[n];
628 
629  scale = v->pq * 2 + v->halfpq;
630 
631  //AC Decoding
632  i = !!coded;
633 
634  if (coded) {
635  int last = 0, skip, value;
636  const uint8_t *zz_table;
637  int k;
638 
639  if (v->s.ac_pred) {
640  if (!dc_pred_dir)
641  zz_table = v->zz_8x8[2];
642  else
643  zz_table = v->zz_8x8[3];
644  } else
645  zz_table = v->zz_8x8[1];
646 
647  while (!last) {
648  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
649  if (ret < 0)
650  return ret;
651  i += skip;
652  if (i > 63)
653  break;
654  block[zz_table[i++]] = value;
655  }
656 
657  /* apply AC prediction if needed */
658  if (s->ac_pred) {
659  int sh;
660  if (dc_pred_dir) { // left
661  sh = v->left_blk_sh;
662  } else { // top
663  sh = v->top_blk_sh;
664  ac_val += 8;
665  }
666  for (k = 1; k < 8; k++)
667  block[k << sh] += ac_val[k];
668  }
669  /* save AC coeffs for further prediction */
670  for (k = 1; k < 8; k++) {
671  ac_val2[k] = block[k << v->left_blk_sh];
672  ac_val2[k + 8] = block[k << v->top_blk_sh];
673  }
674 
675  /* scale AC coeffs */
676  for (k = 1; k < 64; k++)
677  if (block[k]) {
678  block[k] *= scale;
679  if (!v->pquantizer)
680  block[k] += (block[k] < 0) ? -v->pq : v->pq;
681  }
682 
683  } else {
684  int k;
685 
686  memset(ac_val2, 0, 16 * 2);
687 
688  /* apply AC prediction if needed */
689  if (s->ac_pred) {
690  int sh;
691  if (dc_pred_dir) { //left
692  sh = v->left_blk_sh;
693  } else { // top
694  sh = v->top_blk_sh;
695  ac_val += 8;
696  ac_val2 += 8;
697  }
698  memcpy(ac_val2, ac_val, 8 * 2);
699  for (k = 1; k < 8; k++) {
700  block[k << sh] = ac_val[k] * scale;
701  if (!v->pquantizer && block[k << sh])
702  block[k << sh] += (block[k << sh] < 0) ? -v->pq : v->pq;
703  }
704  }
705  }
706  if (s->ac_pred) i = 63;
707  s->block_last_index[n] = i;
708 
709  return 0;
710 }
711 
712 /** Decode intra block in intra frames - should be faster than decode_intra_block
713  * @param v VC1Context
714  * @param block block to decode
715  * @param[in] n subblock number
716  * @param coded are AC coeffs present or not
717  * @param codingset set of VLC to decode data
718  * @param mquant quantizer value for this macroblock
719  */
720 static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
721  int coded, int codingset, int mquant)
722 {
723  GetBitContext *gb = &v->s.gb;
724  MpegEncContext *s = &v->s;
725  int dc_pred_dir = 0; /* Direction of the DC prediction used */
726  int i;
727  int16_t *dc_val = NULL;
728  int16_t *ac_val, *ac_val2;
729  int dcdiff;
730  int a_avail = v->a_avail, c_avail = v->c_avail;
731  int use_pred = s->ac_pred;
732  int scale;
733  int q1, q2 = 0;
734  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
735  int quant = FFABS(mquant);
736 
737  /* Get DC differential */
738  if (n < 4) {
740  } else {
742  }
743  if (dcdiff < 0) {
744  av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
745  return -1;
746  }
747  if (dcdiff) {
748  const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
749  if (dcdiff == 119 /* ESC index value */) {
750  dcdiff = get_bits(gb, 8 + m);
751  } else {
752  if (m)
753  dcdiff = (dcdiff << m) + get_bits(gb, m) - ((1 << m) - 1);
754  }
755  if (get_bits1(gb))
756  dcdiff = -dcdiff;
757  }
758 
759  /* Prediction */
760  dcdiff += ff_vc1_pred_dc(&v->s, v->overlap, quant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
761  *dc_val = dcdiff;
762 
763  /* Store the quantized DC coeff, used for prediction */
764  if (n < 4)
765  scale = s->y_dc_scale;
766  else
767  scale = s->c_dc_scale;
768  block[0] = dcdiff * scale;
769 
770  /* check if AC is needed at all */
771  if (!a_avail && !c_avail)
772  use_pred = 0;
773 
774  scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
775 
776  ac_val = s->ac_val[0][s->block_index[n]];
777  ac_val2 = ac_val;
778  if (dc_pred_dir) // left
779  ac_val -= 16;
780  else // top
781  ac_val -= 16 * s->block_wrap[n];
782 
783  q1 = s->current_picture.qscale_table[mb_pos];
784  if (n == 3)
785  q2 = q1;
786  else if (dc_pred_dir) {
787  if (n == 1)
788  q2 = q1;
789  else if (c_avail && mb_pos)
790  q2 = s->current_picture.qscale_table[mb_pos - 1];
791  } else {
792  if (n == 2)
793  q2 = q1;
794  else if (a_avail && mb_pos >= s->mb_stride)
795  q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
796  }
797 
798  //AC Decoding
799  i = 1;
800 
801  if (coded) {
802  int last = 0, skip, value;
803  const uint8_t *zz_table;
804  int k;
805 
806  if (v->s.ac_pred) {
807  if (!use_pred && v->fcm == ILACE_FRAME) {
808  zz_table = v->zzi_8x8;
809  } else {
810  if (!dc_pred_dir) // top
811  zz_table = v->zz_8x8[2];
812  else // left
813  zz_table = v->zz_8x8[3];
814  }
815  } else {
816  if (v->fcm != ILACE_FRAME)
817  zz_table = v->zz_8x8[1];
818  else
819  zz_table = v->zzi_8x8;
820  }
821 
822  while (!last) {
823  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
824  if (ret < 0)
825  return ret;
826  i += skip;
827  if (i > 63)
828  break;
829  block[zz_table[i++]] = value;
830  }
831 
832  /* apply AC prediction if needed */
833  if (use_pred) {
834  int sh;
835  if (dc_pred_dir) { // left
836  sh = v->left_blk_sh;
837  } else { // top
838  sh = v->top_blk_sh;
839  ac_val += 8;
840  }
841  /* scale predictors if needed*/
842  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
843  if (q1 < 1)
844  return AVERROR_INVALIDDATA;
845  if (q2)
846  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
847  if (q2 && q1 != q2) {
848  for (k = 1; k < 8; k++)
849  block[k << sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
850  } else {
851  for (k = 1; k < 8; k++)
852  block[k << sh] += ac_val[k];
853  }
854  }
855  /* save AC coeffs for further prediction */
856  for (k = 1; k < 8; k++) {
857  ac_val2[k ] = block[k << v->left_blk_sh];
858  ac_val2[k + 8] = block[k << v->top_blk_sh];
859  }
860 
861  /* scale AC coeffs */
862  for (k = 1; k < 64; k++)
863  if (block[k]) {
864  block[k] *= scale;
865  if (!v->pquantizer)
866  block[k] += (block[k] < 0) ? -quant : quant;
867  }
868 
869  } else { // no AC coeffs
870  int k;
871 
872  memset(ac_val2, 0, 16 * 2);
873 
874  /* apply AC prediction if needed */
875  if (use_pred) {
876  int sh;
877  if (dc_pred_dir) { // left
878  sh = v->left_blk_sh;
879  } else { // top
880  sh = v->top_blk_sh;
881  ac_val += 8;
882  ac_val2 += 8;
883  }
884  memcpy(ac_val2, ac_val, 8 * 2);
885  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
886  if (q1 < 1)
887  return AVERROR_INVALIDDATA;
888  if (q2)
889  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
890  if (q2 && q1 != q2) {
891  for (k = 1; k < 8; k++)
892  ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
893  }
894  for (k = 1; k < 8; k++) {
895  block[k << sh] = ac_val2[k] * scale;
896  if (!v->pquantizer && block[k << sh])
897  block[k << sh] += (block[k << sh] < 0) ? -quant : quant;
898  }
899  }
900  }
901  if (use_pred) i = 63;
902  s->block_last_index[n] = i;
903 
904  return 0;
905 }
906 
907 /** Decode intra block in inter frames - more generic version than vc1_decode_i_block
908  * @param v VC1Context
909  * @param block block to decode
910  * @param[in] n subblock index
911  * @param coded are AC coeffs present or not
912  * @param mquant block quantizer
913  * @param codingset set of VLC to decode data
914  */
915 static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
916  int coded, int mquant, int codingset)
917 {
918  GetBitContext *gb = &v->s.gb;
919  MpegEncContext *s = &v->s;
920  int dc_pred_dir = 0; /* Direction of the DC prediction used */
921  int i;
922  int16_t *dc_val = NULL;
923  int16_t *ac_val, *ac_val2;
924  int dcdiff;
925  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
926  int a_avail = v->a_avail, c_avail = v->c_avail;
927  int use_pred = s->ac_pred;
928  int scale;
929  int q1, q2 = 0;
930  int quant = FFABS(mquant);
931 
932  s->bdsp.clear_block(block);
933 
934  /* XXX: Guard against dumb values of mquant */
935  quant = av_clip_uintp2(quant, 5);
936 
937  /* Set DC scale - y and c use the same */
940 
941  /* Get DC differential */
942  if (n < 4) {
944  } else {
946  }
947  if (dcdiff < 0) {
948  av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
949  return -1;
950  }
951  if (dcdiff) {
952  const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
953  if (dcdiff == 119 /* ESC index value */) {
954  dcdiff = get_bits(gb, 8 + m);
955  } else {
956  if (m)
957  dcdiff = (dcdiff << m) + get_bits(gb, m) - ((1 << m) - 1);
958  }
959  if (get_bits1(gb))
960  dcdiff = -dcdiff;
961  }
962 
963  /* Prediction */
964  dcdiff += ff_vc1_pred_dc(&v->s, v->overlap, quant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
965  *dc_val = dcdiff;
966 
967  /* Store the quantized DC coeff, used for prediction */
968 
969  if (n < 4) {
970  block[0] = dcdiff * s->y_dc_scale;
971  } else {
972  block[0] = dcdiff * s->c_dc_scale;
973  }
974 
975  //AC Decoding
976  i = 1;
977 
978  /* check if AC is needed at all and adjust direction if needed */
979  if (!a_avail) dc_pred_dir = 1;
980  if (!c_avail) dc_pred_dir = 0;
981  if (!a_avail && !c_avail) use_pred = 0;
982  ac_val = s->ac_val[0][s->block_index[n]];
983  ac_val2 = ac_val;
984 
985  scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
986 
987  if (dc_pred_dir) //left
988  ac_val -= 16;
989  else //top
990  ac_val -= 16 * s->block_wrap[n];
991 
992  q1 = s->current_picture.qscale_table[mb_pos];
993  if (dc_pred_dir && c_avail && mb_pos)
994  q2 = s->current_picture.qscale_table[mb_pos - 1];
995  if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)
996  q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
997  if (dc_pred_dir && n == 1)
998  q2 = q1;
999  if (!dc_pred_dir && n == 2)
1000  q2 = q1;
1001  if (n == 3) q2 = q1;
1002 
1003  if (coded) {
1004  int last = 0, skip, value;
1005  int k;
1006 
1007  while (!last) {
1008  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
1009  if (ret < 0)
1010  return ret;
1011  i += skip;
1012  if (i > 63)
1013  break;
1014  if (v->fcm == PROGRESSIVE)
1015  block[v->zz_8x8[0][i++]] = value;
1016  else {
1017  if (use_pred && (v->fcm == ILACE_FRAME)) {
1018  if (!dc_pred_dir) // top
1019  block[v->zz_8x8[2][i++]] = value;
1020  else // left
1021  block[v->zz_8x8[3][i++]] = value;
1022  } else {
1023  block[v->zzi_8x8[i++]] = value;
1024  }
1025  }
1026  }
1027 
1028  /* apply AC prediction if needed */
1029  if (use_pred) {
1030  /* scale predictors if needed*/
1031  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
1032  if (q1 < 1)
1033  return AVERROR_INVALIDDATA;
1034  if (q2)
1035  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
1036  if (q2 && q1 != q2) {
1037  if (dc_pred_dir) { // left
1038  for (k = 1; k < 8; k++)
1039  block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1040  } else { //top
1041  for (k = 1; k < 8; k++)
1042  block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1043  }
1044  } else {
1045  if (dc_pred_dir) { // left
1046  for (k = 1; k < 8; k++)
1047  block[k << v->left_blk_sh] += ac_val[k];
1048  } else { // top
1049  for (k = 1; k < 8; k++)
1050  block[k << v->top_blk_sh] += ac_val[k + 8];
1051  }
1052  }
1053  }
1054  /* save AC coeffs for further prediction */
1055  for (k = 1; k < 8; k++) {
1056  ac_val2[k ] = block[k << v->left_blk_sh];
1057  ac_val2[k + 8] = block[k << v->top_blk_sh];
1058  }
1059 
1060  /* scale AC coeffs */
1061  for (k = 1; k < 64; k++)
1062  if (block[k]) {
1063  block[k] *= scale;
1064  if (!v->pquantizer)
1065  block[k] += (block[k] < 0) ? -quant : quant;
1066  }
1067 
1068  if (use_pred) i = 63;
1069  } else { // no AC coeffs
1070  int k;
1071 
1072  memset(ac_val2, 0, 16 * 2);
1073  if (dc_pred_dir) { // left
1074  if (use_pred) {
1075  memcpy(ac_val2, ac_val, 8 * 2);
1076  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
1077  if (q1 < 1)
1078  return AVERROR_INVALIDDATA;
1079  if (q2)
1080  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
1081  if (q2 && q1 != q2) {
1082  for (k = 1; k < 8; k++)
1083  ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1084  }
1085  }
1086  } else { // top
1087  if (use_pred) {
1088  memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1089  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
1090  if (q1 < 1)
1091  return AVERROR_INVALIDDATA;
1092  if (q2)
1093  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
1094  if (q2 && q1 != q2) {
1095  for (k = 1; k < 8; k++)
1096  ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1097  }
1098  }
1099  }
1100 
1101  /* apply AC prediction if needed */
1102  if (use_pred) {
1103  if (dc_pred_dir) { // left
1104  for (k = 1; k < 8; k++) {
1105  block[k << v->left_blk_sh] = ac_val2[k] * scale;
1106  if (!v->pquantizer && block[k << v->left_blk_sh])
1107  block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -quant : quant;
1108  }
1109  } else { // top
1110  for (k = 1; k < 8; k++) {
1111  block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
1112  if (!v->pquantizer && block[k << v->top_blk_sh])
1113  block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -quant : quant;
1114  }
1115  }
1116  i = 63;
1117  }
1118  }
1119  s->block_last_index[n] = i;
1120 
1121  return 0;
1122 }
1123 
1124 /** Decode P block
1125  */
1126 static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
1127  int mquant, int ttmb, int first_block,
1128  uint8_t *dst, int linesize, int skip_block,
1129  int *ttmb_out)
1130 {
1131  MpegEncContext *s = &v->s;
1132  GetBitContext *gb = &s->gb;
1133  int i, j;
1134  int subblkpat = 0;
1135  int scale, off, idx, last, skip, value;
1136  int ttblk = ttmb & 7;
1137  int pat = 0;
1138  int quant = FFABS(mquant);
1139 
1140  s->bdsp.clear_block(block);
1141 
1142  if (ttmb == -1) {
1144  }
1145  if (ttblk == TT_4X4) {
1146  subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
1147  }
1148  if ((ttblk != TT_8X8 && ttblk != TT_4X4)
1149  && ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
1150  || (!v->res_rtm_flag && !first_block))) {
1151  subblkpat = decode012(gb);
1152  if (subblkpat)
1153  subblkpat ^= 3; // swap decoded pattern bits
1154  if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM)
1155  ttblk = TT_8X4;
1156  if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT)
1157  ttblk = TT_4X8;
1158  }
1159  scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
1160 
1161  // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
1162  if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
1163  subblkpat = 2 - (ttblk == TT_8X4_TOP);
1164  ttblk = TT_8X4;
1165  }
1166  if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
1167  subblkpat = 2 - (ttblk == TT_4X8_LEFT);
1168  ttblk = TT_4X8;
1169  }
1170  switch (ttblk) {
1171  case TT_8X8:
1172  pat = 0xF;
1173  i = 0;
1174  last = 0;
1175  while (!last) {
1176  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1177  if (ret < 0)
1178  return ret;
1179  i += skip;
1180  if (i > 63)
1181  break;
1182  if (!v->fcm)
1183  idx = v->zz_8x8[0][i++];
1184  else
1185  idx = v->zzi_8x8[i++];
1186  block[idx] = value * scale;
1187  if (!v->pquantizer)
1188  block[idx] += (block[idx] < 0) ? -quant : quant;
1189  }
1190  if (!skip_block) {
1191  if (i == 1)
1192  v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block);
1193  else {
1194  v->vc1dsp.vc1_inv_trans_8x8(block);
1195  s->idsp.add_pixels_clamped(block, dst, linesize);
1196  }
1197  }
1198  break;
1199  case TT_4X4:
1200  pat = ~subblkpat & 0xF;
1201  for (j = 0; j < 4; j++) {
1202  last = subblkpat & (1 << (3 - j));
1203  i = 0;
1204  off = (j & 1) * 4 + (j & 2) * 16;
1205  while (!last) {
1206  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1207  if (ret < 0)
1208  return ret;
1209  i += skip;
1210  if (i > 15)
1211  break;
1212  if (!v->fcm)
1214  else
1215  idx = ff_vc1_adv_interlaced_4x4_zz[i++];
1216  block[idx + off] = value * scale;
1217  if (!v->pquantizer)
1218  block[idx + off] += (block[idx + off] < 0) ? -quant : quant;
1219  }
1220  if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
1221  if (i == 1)
1222  v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
1223  else
1224  v->vc1dsp.vc1_inv_trans_4x4(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
1225  }
1226  }
1227  break;
1228  case TT_8X4:
1229  pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
1230  for (j = 0; j < 2; j++) {
1231  last = subblkpat & (1 << (1 - j));
1232  i = 0;
1233  off = j * 32;
1234  while (!last) {
1235  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1236  if (ret < 0)
1237  return ret;
1238  i += skip;
1239  if (i > 31)
1240  break;
1241  if (!v->fcm)
1242  idx = v->zz_8x4[i++] + off;
1243  else
1244  idx = ff_vc1_adv_interlaced_8x4_zz[i++] + off;
1245  block[idx] = value * scale;
1246  if (!v->pquantizer)
1247  block[idx] += (block[idx] < 0) ? -quant : quant;
1248  }
1249  if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1250  if (i == 1)
1251  v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j * 4 * linesize, linesize, block + off);
1252  else
1253  v->vc1dsp.vc1_inv_trans_8x4(dst + j * 4 * linesize, linesize, block + off);
1254  }
1255  }
1256  break;
1257  case TT_4X8:
1258  pat = ~(subblkpat * 5) & 0xF;
1259  for (j = 0; j < 2; j++) {
1260  last = subblkpat & (1 << (1 - j));
1261  i = 0;
1262  off = j * 4;
1263  while (!last) {
1264  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1265  if (ret < 0)
1266  return ret;
1267  i += skip;
1268  if (i > 31)
1269  break;
1270  if (!v->fcm)
1271  idx = v->zz_4x8[i++] + off;
1272  else
1273  idx = ff_vc1_adv_interlaced_4x8_zz[i++] + off;
1274  block[idx] = value * scale;
1275  if (!v->pquantizer)
1276  block[idx] += (block[idx] < 0) ? -quant : quant;
1277  }
1278  if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1279  if (i == 1)
1280  v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j * 4, linesize, block + off);
1281  else
1282  v->vc1dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off);
1283  }
1284  }
1285  break;
1286  }
1287  if (ttmb_out)
1288  *ttmb_out |= ttblk << (n * 4);
1289  return pat;
1290 }
1291 
1292 /** @} */ // Macroblock group
1293 
1294 static const uint8_t size_table[6] = { 0, 2, 3, 4, 5, 8 };
1295 
1296 /** Decode one P-frame MB
1297  */
1299 {
1300  MpegEncContext *s = &v->s;
1301  GetBitContext *gb = &s->gb;
1302  int i, j;
1303  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1304  int cbp; /* cbp decoding stuff */
1305  int mqdiff, mquant; /* MB quantization */
1306  int ttmb = v->ttfrm; /* MB Transform type */
1307 
1308  int mb_has_coeffs = 1; /* last_flag */
1309  int dmv_x, dmv_y; /* Differential MV components */
1310  int index, index1; /* LUT indexes */
1311  int val, sign; /* temp values */
1312  int first_block = 1;
1313  int dst_idx, off;
1314  int skipped, fourmv;
1315  int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
1316 
1317  mquant = v->pq; /* lossy initialization */
1318 
1319  if (v->mv_type_is_raw)
1320  fourmv = get_bits1(gb);
1321  else
1322  fourmv = v->mv_type_mb_plane[mb_pos];
1323  if (v->skip_is_raw)
1324  skipped = get_bits1(gb);
1325  else
1326  skipped = v->s.mbskip_table[mb_pos];
1327 
1328  if (!fourmv) { /* 1MV mode */
1329  if (!skipped) {
1330  GET_MVDATA(dmv_x, dmv_y);
1331 
1332  if (s->mb_intra) {
1333  s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
1334  s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
1335  }
1337  ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1338 
1339  /* FIXME Set DC val for inter block ? */
1340  if (s->mb_intra && !mb_has_coeffs) {
1341  GET_MQUANT();
1342  s->ac_pred = get_bits1(gb);
1343  cbp = 0;
1344  } else if (mb_has_coeffs) {
1345  if (s->mb_intra)
1346  s->ac_pred = get_bits1(gb);
1347  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1348  GET_MQUANT();
1349  } else {
1350  mquant = v->pq;
1351  cbp = 0;
1352  }
1353  s->current_picture.qscale_table[mb_pos] = mquant;
1354 
1355  if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
1356  ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
1357  VC1_TTMB_VLC_BITS, 2);
1358  if (!s->mb_intra) ff_vc1_mc_1mv(v, 0);
1359  dst_idx = 0;
1360  for (i = 0; i < 6; i++) {
1361  s->dc_val[0][s->block_index[i]] = 0;
1362  dst_idx += i >> 2;
1363  val = ((cbp >> (5 - i)) & 1);
1364  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1365  v->mb_type[0][s->block_index[i]] = s->mb_intra;
1366  if (s->mb_intra) {
1367  /* check if prediction blocks A and C are available */
1368  v->a_avail = v->c_avail = 0;
1369  if (i == 2 || i == 3 || !s->first_slice_line)
1370  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1371  if (i == 1 || i == 3 || s->mb_x)
1372  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1373 
1374  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
1375  (i & 4) ? v->codingset2 : v->codingset);
1376  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1377  continue;
1379  if (v->rangeredfrm)
1380  for (j = 0; j < 64; j++)
1381  v->block[v->cur_blk_idx][block_map[i]][j] *= 2;
1382  block_cbp |= 0xF << (i << 2);
1383  block_intra |= 1 << i;
1384  } else if (val) {
1385  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb, first_block,
1386  s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,
1387  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
1388  block_cbp |= pat << (i << 2);
1389  if (!v->ttmbf && ttmb < 8)
1390  ttmb = -1;
1391  first_block = 0;
1392  }
1393  }
1394  } else { // skipped
1395  s->mb_intra = 0;
1396  for (i = 0; i < 6; i++) {
1397  v->mb_type[0][s->block_index[i]] = 0;
1398  s->dc_val[0][s->block_index[i]] = 0;
1399  }
1400  s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
1401  s->current_picture.qscale_table[mb_pos] = 0;
1402  ff_vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1403  ff_vc1_mc_1mv(v, 0);
1404  }
1405  } else { // 4MV mode
1406  if (!skipped /* unskipped MB */) {
1407  int intra_count = 0, coded_inter = 0;
1408  int is_intra[6], is_coded[6];
1409  /* Get CBPCY */
1410  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1411  for (i = 0; i < 6; i++) {
1412  val = ((cbp >> (5 - i)) & 1);
1413  s->dc_val[0][s->block_index[i]] = 0;
1414  s->mb_intra = 0;
1415  if (i < 4) {
1416  dmv_x = dmv_y = 0;
1417  s->mb_intra = 0;
1418  mb_has_coeffs = 0;
1419  if (val) {
1420  GET_MVDATA(dmv_x, dmv_y);
1421  }
1422  ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1423  if (!s->mb_intra)
1424  ff_vc1_mc_4mv_luma(v, i, 0, 0);
1425  intra_count += s->mb_intra;
1426  is_intra[i] = s->mb_intra;
1427  is_coded[i] = mb_has_coeffs;
1428  }
1429  if (i & 4) {
1430  is_intra[i] = (intra_count >= 3);
1431  is_coded[i] = val;
1432  }
1433  if (i == 4)
1434  ff_vc1_mc_4mv_chroma(v, 0);
1435  v->mb_type[0][s->block_index[i]] = is_intra[i];
1436  if (!coded_inter)
1437  coded_inter = !is_intra[i] & is_coded[i];
1438  }
1439  // if there are no coded blocks then don't do anything more
1440  dst_idx = 0;
1441  if (!intra_count && !coded_inter)
1442  goto end;
1443  GET_MQUANT();
1444  s->current_picture.qscale_table[mb_pos] = mquant;
1445  /* test if block is intra and has pred */
1446  {
1447  int intrapred = 0;
1448  for (i = 0; i < 6; i++)
1449  if (is_intra[i]) {
1450  if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
1451  || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {
1452  intrapred = 1;
1453  break;
1454  }
1455  }
1456  if (intrapred)
1457  s->ac_pred = get_bits1(gb);
1458  else
1459  s->ac_pred = 0;
1460  }
1461  if (!v->ttmbf && coded_inter)
1463  for (i = 0; i < 6; i++) {
1464  dst_idx += i >> 2;
1465  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1466  s->mb_intra = is_intra[i];
1467  if (is_intra[i]) {
1468  /* check if prediction blocks A and C are available */
1469  v->a_avail = v->c_avail = 0;
1470  if (i == 2 || i == 3 || !s->first_slice_line)
1471  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1472  if (i == 1 || i == 3 || s->mb_x)
1473  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1474 
1475  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, is_coded[i], mquant,
1476  (i & 4) ? v->codingset2 : v->codingset);
1477  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1478  continue;
1480  if (v->rangeredfrm)
1481  for (j = 0; j < 64; j++)
1482  v->block[v->cur_blk_idx][block_map[i]][j] <<= 1;
1483  block_cbp |= 0xF << (i << 2);
1484  block_intra |= 1 << i;
1485  } else if (is_coded[i]) {
1486  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb,
1487  first_block, s->dest[dst_idx] + off,
1488  (i & 4) ? s->uvlinesize : s->linesize,
1489  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY),
1490  &block_tt);
1491  block_cbp |= pat << (i << 2);
1492  if (!v->ttmbf && ttmb < 8)
1493  ttmb = -1;
1494  first_block = 0;
1495  }
1496  }
1497  } else { // skipped MB
1498  s->mb_intra = 0;
1499  s->current_picture.qscale_table[mb_pos] = 0;
1500  for (i = 0; i < 6; i++) {
1501  v->mb_type[0][s->block_index[i]] = 0;
1502  s->dc_val[0][s->block_index[i]] = 0;
1503  }
1504  for (i = 0; i < 4; i++) {
1505  ff_vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1506  ff_vc1_mc_4mv_luma(v, i, 0, 0);
1507  }
1508  ff_vc1_mc_4mv_chroma(v, 0);
1509  s->current_picture.qscale_table[mb_pos] = 0;
1510  }
1511  }
1512 end:
1513  if (v->overlap && v->pq >= 9)
1515  vc1_put_blocks_clamped(v, 1);
1516 
1517  v->cbp[s->mb_x] = block_cbp;
1518  v->ttblk[s->mb_x] = block_tt;
1519  v->is_intra[s->mb_x] = block_intra;
1520 
1521  return 0;
1522 }
1523 
1524 /* Decode one macroblock in an interlaced frame p picture */
1525 
1527 {
1528  MpegEncContext *s = &v->s;
1529  GetBitContext *gb = &s->gb;
1530  int i;
1531  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1532  int cbp = 0; /* cbp decoding stuff */
1533  int mqdiff, mquant; /* MB quantization */
1534  int ttmb = v->ttfrm; /* MB Transform type */
1535 
1536  int mb_has_coeffs = 1; /* last_flag */
1537  int dmv_x, dmv_y; /* Differential MV components */
1538  int val; /* temp value */
1539  int first_block = 1;
1540  int dst_idx, off;
1541  int skipped, fourmv = 0, twomv = 0;
1542  int block_cbp = 0, pat, block_tt = 0;
1543  int idx_mbmode = 0, mvbp;
1544  int fieldtx;
1545 
1546  mquant = v->pq; /* Lossy initialization */
1547 
1548  if (v->skip_is_raw)
1549  skipped = get_bits1(gb);
1550  else
1551  skipped = v->s.mbskip_table[mb_pos];
1552  if (!skipped) {
1553  if (v->fourmvswitch)
1554  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_4MV_MBMODE_VLC_BITS, 2); // try getting this done
1555  else
1556  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2); // in a single line
1557  switch (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0]) {
1558  /* store the motion vector type in a flag (useful later) */
1559  case MV_PMODE_INTFR_4MV:
1560  fourmv = 1;
1561  v->blk_mv_type[s->block_index[0]] = 0;
1562  v->blk_mv_type[s->block_index[1]] = 0;
1563  v->blk_mv_type[s->block_index[2]] = 0;
1564  v->blk_mv_type[s->block_index[3]] = 0;
1565  break;
1567  fourmv = 1;
1568  v->blk_mv_type[s->block_index[0]] = 1;
1569  v->blk_mv_type[s->block_index[1]] = 1;
1570  v->blk_mv_type[s->block_index[2]] = 1;
1571  v->blk_mv_type[s->block_index[3]] = 1;
1572  break;
1574  twomv = 1;
1575  v->blk_mv_type[s->block_index[0]] = 1;
1576  v->blk_mv_type[s->block_index[1]] = 1;
1577  v->blk_mv_type[s->block_index[2]] = 1;
1578  v->blk_mv_type[s->block_index[3]] = 1;
1579  break;
1580  case MV_PMODE_INTFR_1MV:
1581  v->blk_mv_type[s->block_index[0]] = 0;
1582  v->blk_mv_type[s->block_index[1]] = 0;
1583  v->blk_mv_type[s->block_index[2]] = 0;
1584  v->blk_mv_type[s->block_index[3]] = 0;
1585  break;
1586  }
1587  if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
1588  for (i = 0; i < 4; i++) {
1589  s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
1590  s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
1591  }
1592  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
1593  s->mb_intra = 1;
1594  s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
1595  fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
1596  mb_has_coeffs = get_bits1(gb);
1597  if (mb_has_coeffs)
1598  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1599  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
1600  GET_MQUANT();
1601  s->current_picture.qscale_table[mb_pos] = mquant;
1602  /* Set DC scale - y and c use the same (not sure if necessary here) */
1603  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
1604  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
1605  dst_idx = 0;
1606  for (i = 0; i < 6; i++) {
1607  v->a_avail = v->c_avail = 0;
1608  v->mb_type[0][s->block_index[i]] = 1;
1609  s->dc_val[0][s->block_index[i]] = 0;
1610  dst_idx += i >> 2;
1611  val = ((cbp >> (5 - i)) & 1);
1612  if (i == 2 || i == 3 || !s->first_slice_line)
1613  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1614  if (i == 1 || i == 3 || s->mb_x)
1615  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1616 
1617  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
1618  (i & 4) ? v->codingset2 : v->codingset);
1619  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1620  continue;
1622  if (i < 4)
1623  off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
1624  else
1625  off = 0;
1626  block_cbp |= 0xf << (i << 2);
1627  }
1628 
1629  } else { // inter MB
1630  mb_has_coeffs = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][3];
1631  if (mb_has_coeffs)
1632  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1633  if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
1635  } else {
1636  if ((ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV)
1637  || (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV_FIELD)) {
1639  }
1640  }
1641  s->mb_intra = v->is_intra[s->mb_x] = 0;
1642  for (i = 0; i < 6; i++)
1643  v->mb_type[0][s->block_index[i]] = 0;
1644  fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][1];
1645  /* for all motion vector read MVDATA and motion compensate each block */
1646  dst_idx = 0;
1647  if (fourmv) {
1648  mvbp = v->fourmvbp;
1649  for (i = 0; i < 4; i++) {
1650  dmv_x = dmv_y = 0;
1651  if (mvbp & (8 >> i))
1652  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
1653  ff_vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0);
1654  ff_vc1_mc_4mv_luma(v, i, 0, 0);
1655  }
1656  ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
1657  } else if (twomv) {
1658  mvbp = v->twomvbp;
1659  dmv_x = dmv_y = 0;
1660  if (mvbp & 2) {
1661  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
1662  }
1663  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], 0);
1664  ff_vc1_mc_4mv_luma(v, 0, 0, 0);
1665  ff_vc1_mc_4mv_luma(v, 1, 0, 0);
1666  dmv_x = dmv_y = 0;
1667  if (mvbp & 1) {
1668  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
1669  }
1670  ff_vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], 0);
1671  ff_vc1_mc_4mv_luma(v, 2, 0, 0);
1672  ff_vc1_mc_4mv_luma(v, 3, 0, 0);
1673  ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
1674  } else {
1675  mvbp = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][2];
1676  dmv_x = dmv_y = 0;
1677  if (mvbp) {
1678  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
1679  }
1680  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0);
1681  ff_vc1_mc_1mv(v, 0);
1682  }
1683  if (cbp)
1684  GET_MQUANT(); // p. 227
1685  s->current_picture.qscale_table[mb_pos] = mquant;
1686  if (!v->ttmbf && cbp)
1688  for (i = 0; i < 6; i++) {
1689  s->dc_val[0][s->block_index[i]] = 0;
1690  dst_idx += i >> 2;
1691  val = ((cbp >> (5 - i)) & 1);
1692  if (!fieldtx)
1693  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1694  else
1695  off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
1696  if (val) {
1697  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb,
1698  first_block, s->dest[dst_idx] + off,
1699  (i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
1700  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
1701  block_cbp |= pat << (i << 2);
1702  if (!v->ttmbf && ttmb < 8)
1703  ttmb = -1;
1704  first_block = 0;
1705  }
1706  }
1707  }
1708  } else { // skipped
1709  s->mb_intra = v->is_intra[s->mb_x] = 0;
1710  for (i = 0; i < 6; i++) {
1711  v->mb_type[0][s->block_index[i]] = 0;
1712  s->dc_val[0][s->block_index[i]] = 0;
1713  }
1714  s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
1715  s->current_picture.qscale_table[mb_pos] = 0;
1716  v->blk_mv_type[s->block_index[0]] = 0;
1717  v->blk_mv_type[s->block_index[1]] = 0;
1718  v->blk_mv_type[s->block_index[2]] = 0;
1719  v->blk_mv_type[s->block_index[3]] = 0;
1720  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0);
1721  ff_vc1_mc_1mv(v, 0);
1722  v->fieldtx_plane[mb_pos] = 0;
1723  }
1724  if (v->overlap && v->pq >= 9)
1726  vc1_put_blocks_clamped(v, 1);
1727 
1728  v->cbp[s->mb_x] = block_cbp;
1729  v->ttblk[s->mb_x] = block_tt;
1730 
1731  return 0;
1732 }
1733 
1735 {
1736  MpegEncContext *s = &v->s;
1737  GetBitContext *gb = &s->gb;
1738  int i;
1739  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1740  int cbp = 0; /* cbp decoding stuff */
1741  int mqdiff, mquant; /* MB quantization */
1742  int ttmb = v->ttfrm; /* MB Transform type */
1743 
1744  int mb_has_coeffs = 1; /* last_flag */
1745  int dmv_x, dmv_y; /* Differential MV components */
1746  int val; /* temp values */
1747  int first_block = 1;
1748  int dst_idx, off;
1749  int pred_flag = 0;
1750  int block_cbp = 0, pat, block_tt = 0;
1751  int idx_mbmode = 0;
1752 
1753  mquant = v->pq; /* Lossy initialization */
1754 
1755  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
1756  if (idx_mbmode <= 1) { // intra MB
1757  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
1758  s->mb_intra = 1;
1759  s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
1760  s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
1761  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
1762  GET_MQUANT();
1763  s->current_picture.qscale_table[mb_pos] = mquant;
1764  /* Set DC scale - y and c use the same (not sure if necessary here) */
1765  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
1766  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
1767  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
1768  mb_has_coeffs = idx_mbmode & 1;
1769  if (mb_has_coeffs)
1770  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
1771  dst_idx = 0;
1772  for (i = 0; i < 6; i++) {
1773  v->a_avail = v->c_avail = 0;
1774  v->mb_type[0][s->block_index[i]] = 1;
1775  s->dc_val[0][s->block_index[i]] = 0;
1776  dst_idx += i >> 2;
1777  val = ((cbp >> (5 - i)) & 1);
1778  if (i == 2 || i == 3 || !s->first_slice_line)
1779  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1780  if (i == 1 || i == 3 || s->mb_x)
1781  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1782 
1783  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
1784  (i & 4) ? v->codingset2 : v->codingset);
1785  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1786  continue;
1788  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1789  block_cbp |= 0xf << (i << 2);
1790  }
1791  } else {
1792  s->mb_intra = v->is_intra[s->mb_x] = 0;
1793  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
1794  for (i = 0; i < 6; i++)
1795  v->mb_type[0][s->block_index[i]] = 0;
1796  if (idx_mbmode <= 5) { // 1-MV
1797  dmv_x = dmv_y = pred_flag = 0;
1798  if (idx_mbmode & 1) {
1799  get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
1800  }
1801  ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
1802  ff_vc1_mc_1mv(v, 0);
1803  mb_has_coeffs = !(idx_mbmode & 2);
1804  } else { // 4-MV
1806  for (i = 0; i < 4; i++) {
1807  dmv_x = dmv_y = pred_flag = 0;
1808  if (v->fourmvbp & (8 >> i))
1809  get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
1810  ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
1811  ff_vc1_mc_4mv_luma(v, i, 0, 0);
1812  }
1813  ff_vc1_mc_4mv_chroma(v, 0);
1814  mb_has_coeffs = idx_mbmode & 1;
1815  }
1816  if (mb_has_coeffs)
1817  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1818  if (cbp) {
1819  GET_MQUANT();
1820  }
1821  s->current_picture.qscale_table[mb_pos] = mquant;
1822  if (!v->ttmbf && cbp) {
1824  }
1825  dst_idx = 0;
1826  for (i = 0; i < 6; i++) {
1827  s->dc_val[0][s->block_index[i]] = 0;
1828  dst_idx += i >> 2;
1829  val = ((cbp >> (5 - i)) & 1);
1830  off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
1831  if (val) {
1832  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb,
1833  first_block, s->dest[dst_idx] + off,
1834  (i & 4) ? s->uvlinesize : s->linesize,
1835  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY),
1836  &block_tt);
1837  block_cbp |= pat << (i << 2);
1838  if (!v->ttmbf && ttmb < 8)
1839  ttmb = -1;
1840  first_block = 0;
1841  }
1842  }
1843  }
1844  if (v->overlap && v->pq >= 9)
1846  vc1_put_blocks_clamped(v, 1);
1847 
1848  v->cbp[s->mb_x] = block_cbp;
1849  v->ttblk[s->mb_x] = block_tt;
1850 
1851  return 0;
1852 }
1853 
1854 /** Decode one B-frame MB (in Main profile)
1855  */
1857 {
1858  MpegEncContext *s = &v->s;
1859  GetBitContext *gb = &s->gb;
1860  int i, j;
1861  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1862  int cbp = 0; /* cbp decoding stuff */
1863  int mqdiff, mquant; /* MB quantization */
1864  int ttmb = v->ttfrm; /* MB Transform type */
1865  int mb_has_coeffs = 0; /* last_flag */
1866  int index, index1; /* LUT indexes */
1867  int val, sign; /* temp values */
1868  int first_block = 1;
1869  int dst_idx, off;
1870  int skipped, direct;
1871  int dmv_x[2], dmv_y[2];
1872  int bmvtype = BMV_TYPE_BACKWARD;
1873 
1874  mquant = v->pq; /* lossy initialization */
1875  s->mb_intra = 0;
1876 
1877  if (v->dmb_is_raw)
1878  direct = get_bits1(gb);
1879  else
1880  direct = v->direct_mb_plane[mb_pos];
1881  if (v->skip_is_raw)
1882  skipped = get_bits1(gb);
1883  else
1884  skipped = v->s.mbskip_table[mb_pos];
1885 
1886  dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
1887  for (i = 0; i < 6; i++) {
1888  v->mb_type[0][s->block_index[i]] = 0;
1889  s->dc_val[0][s->block_index[i]] = 0;
1890  }
1891  s->current_picture.qscale_table[mb_pos] = 0;
1892 
1893  if (!direct) {
1894  if (!skipped) {
1895  GET_MVDATA(dmv_x[0], dmv_y[0]);
1896  dmv_x[1] = dmv_x[0];
1897  dmv_y[1] = dmv_y[0];
1898  }
1899  if (skipped || !s->mb_intra) {
1900  bmvtype = decode012(gb);
1901  switch (bmvtype) {
1902  case 0:
1903  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
1904  break;
1905  case 1:
1906  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
1907  break;
1908  case 2:
1909  bmvtype = BMV_TYPE_INTERPOLATED;
1910  dmv_x[0] = dmv_y[0] = 0;
1911  }
1912  }
1913  }
1914  for (i = 0; i < 6; i++)
1915  v->mb_type[0][s->block_index[i]] = s->mb_intra;
1916 
1917  if (skipped) {
1918  if (direct)
1919  bmvtype = BMV_TYPE_INTERPOLATED;
1920  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1921  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1922  return;
1923  }
1924  if (direct) {
1925  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1926  GET_MQUANT();
1927  s->mb_intra = 0;
1928  s->current_picture.qscale_table[mb_pos] = mquant;
1929  if (!v->ttmbf)
1931  dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
1932  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1933  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1934  } else {
1935  if (!mb_has_coeffs && !s->mb_intra) {
1936  /* no coded blocks - effectively skipped */
1937  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1938  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1939  return;
1940  }
1941  if (s->mb_intra && !mb_has_coeffs) {
1942  GET_MQUANT();
1943  s->current_picture.qscale_table[mb_pos] = mquant;
1944  s->ac_pred = get_bits1(gb);
1945  cbp = 0;
1946  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1947  } else {
1948  if (bmvtype == BMV_TYPE_INTERPOLATED) {
1949  GET_MVDATA(dmv_x[0], dmv_y[0]);
1950  if (!mb_has_coeffs) {
1951  /* interpolated skipped block */
1952  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1953  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1954  return;
1955  }
1956  }
1957  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1958  if (!s->mb_intra) {
1959  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1960  }
1961  if (s->mb_intra)
1962  s->ac_pred = get_bits1(gb);
1963  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1964  GET_MQUANT();
1965  s->current_picture.qscale_table[mb_pos] = mquant;
1966  if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
1968  }
1969  }
1970  dst_idx = 0;
1971  for (i = 0; i < 6; i++) {
1972  s->dc_val[0][s->block_index[i]] = 0;
1973  dst_idx += i >> 2;
1974  val = ((cbp >> (5 - i)) & 1);
1975  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1976  v->mb_type[0][s->block_index[i]] = s->mb_intra;
1977  if (s->mb_intra) {
1978  /* check if prediction blocks A and C are available */
1979  v->a_avail = v->c_avail = 0;
1980  if (i == 2 || i == 3 || !s->first_slice_line)
1981  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1982  if (i == 1 || i == 3 || s->mb_x)
1983  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1984 
1985  vc1_decode_intra_block(v, s->block[i], i, val, mquant,
1986  (i & 4) ? v->codingset2 : v->codingset);
1987  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1988  continue;
1989  v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
1990  if (v->rangeredfrm)
1991  for (j = 0; j < 64; j++)
1992  s->block[i][j] <<= 1;
1994  s->dest[dst_idx] + off,
1995  i & 4 ? s->uvlinesize
1996  : s->linesize);
1997  } else if (val) {
1998  vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
1999  first_block, s->dest[dst_idx] + off,
2000  (i & 4) ? s->uvlinesize : s->linesize,
2001  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), NULL);
2002  if (!v->ttmbf && ttmb < 8)
2003  ttmb = -1;
2004  first_block = 0;
2005  }
2006  }
2007 }
2008 
2009 /** Decode one B-frame MB (in interlaced field B picture)
2010  */
2012 {
2013  MpegEncContext *s = &v->s;
2014  GetBitContext *gb = &s->gb;
2015  int i, j;
2016  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2017  int cbp = 0; /* cbp decoding stuff */
2018  int mqdiff, mquant; /* MB quantization */
2019  int ttmb = v->ttfrm; /* MB Transform type */
2020  int mb_has_coeffs = 0; /* last_flag */
2021  int val; /* temp value */
2022  int first_block = 1;
2023  int dst_idx, off;
2024  int fwd;
2025  int dmv_x[2], dmv_y[2], pred_flag[2];
2026  int bmvtype = BMV_TYPE_BACKWARD;
2027  int block_cbp = 0, pat, block_tt = 0;
2028  int idx_mbmode;
2029 
2030  mquant = v->pq; /* Lossy initialization */
2031  s->mb_intra = 0;
2032 
2033  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
2034  if (idx_mbmode <= 1) { // intra MB
2035  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
2036  s->mb_intra = 1;
2037  s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
2038  s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
2039  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
2040  GET_MQUANT();
2041  s->current_picture.qscale_table[mb_pos] = mquant;
2042  /* Set DC scale - y and c use the same (not sure if necessary here) */
2043  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
2044  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
2045  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
2046  mb_has_coeffs = idx_mbmode & 1;
2047  if (mb_has_coeffs)
2048  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
2049  dst_idx = 0;
2050  for (i = 0; i < 6; i++) {
2051  v->a_avail = v->c_avail = 0;
2052  v->mb_type[0][s->block_index[i]] = 1;
2053  s->dc_val[0][s->block_index[i]] = 0;
2054  dst_idx += i >> 2;
2055  val = ((cbp >> (5 - i)) & 1);
2056  if (i == 2 || i == 3 || !s->first_slice_line)
2057  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2058  if (i == 1 || i == 3 || s->mb_x)
2059  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2060 
2061  vc1_decode_intra_block(v, s->block[i], i, val, mquant,
2062  (i & 4) ? v->codingset2 : v->codingset);
2063  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2064  continue;
2065  v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
2066  if (v->rangeredfrm)
2067  for (j = 0; j < 64; j++)
2068  s->block[i][j] <<= 1;
2069  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2071  s->dest[dst_idx] + off,
2072  (i & 4) ? s->uvlinesize
2073  : s->linesize);
2074  }
2075  } else {
2076  s->mb_intra = v->is_intra[s->mb_x] = 0;
2077  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
2078  for (i = 0; i < 6; i++)
2079  v->mb_type[0][s->block_index[i]] = 0;
2080  if (v->fmb_is_raw)
2081  fwd = v->forward_mb_plane[mb_pos] = get_bits1(gb);
2082  else
2083  fwd = v->forward_mb_plane[mb_pos];
2084  if (idx_mbmode <= 5) { // 1-MV
2085  int interpmvp = 0;
2086  dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
2087  pred_flag[0] = pred_flag[1] = 0;
2088  if (fwd)
2089  bmvtype = BMV_TYPE_FORWARD;
2090  else {
2091  bmvtype = decode012(gb);
2092  switch (bmvtype) {
2093  case 0:
2094  bmvtype = BMV_TYPE_BACKWARD;
2095  break;
2096  case 1:
2097  bmvtype = BMV_TYPE_DIRECT;
2098  break;
2099  case 2:
2100  bmvtype = BMV_TYPE_INTERPOLATED;
2101  interpmvp = get_bits1(gb);
2102  }
2103  }
2104  v->bmvtype = bmvtype;
2105  if (bmvtype != BMV_TYPE_DIRECT && idx_mbmode & 1) {
2106  get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD], &dmv_y[bmvtype == BMV_TYPE_BACKWARD], &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
2107  }
2108  if (interpmvp) {
2109  get_mvdata_interlaced(v, &dmv_x[1], &dmv_y[1], &pred_flag[1]);
2110  }
2111  if (bmvtype == BMV_TYPE_DIRECT) {
2112  dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2113  dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
2114  if (!s->next_picture_ptr->field_picture) {
2115  av_log(s->avctx, AV_LOG_ERROR, "Mixed field/frame direct mode not supported\n");
2116  return;
2117  }
2118  }
2119  ff_vc1_pred_b_mv_intfi(v, 0, dmv_x, dmv_y, 1, pred_flag);
2120  vc1_b_mc(v, dmv_x, dmv_y, (bmvtype == BMV_TYPE_DIRECT), bmvtype);
2121  mb_has_coeffs = !(idx_mbmode & 2);
2122  } else { // 4-MV
2123  if (fwd)
2124  bmvtype = BMV_TYPE_FORWARD;
2125  v->bmvtype = bmvtype;
2127  for (i = 0; i < 4; i++) {
2128  dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2129  dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
2130  if (v->fourmvbp & (8 >> i)) {
2131  get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD],
2132  &dmv_y[bmvtype == BMV_TYPE_BACKWARD],
2133  &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
2134  }
2135  ff_vc1_pred_b_mv_intfi(v, i, dmv_x, dmv_y, 0, pred_flag);
2136  ff_vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD, 0);
2137  }
2138  ff_vc1_mc_4mv_chroma(v, bmvtype == BMV_TYPE_BACKWARD);
2139  mb_has_coeffs = idx_mbmode & 1;
2140  }
2141  if (mb_has_coeffs)
2142  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2143  if (cbp) {
2144  GET_MQUANT();
2145  }
2146  s->current_picture.qscale_table[mb_pos] = mquant;
2147  if (!v->ttmbf && cbp) {
2149  }
2150  dst_idx = 0;
2151  for (i = 0; i < 6; i++) {
2152  s->dc_val[0][s->block_index[i]] = 0;
2153  dst_idx += i >> 2;
2154  val = ((cbp >> (5 - i)) & 1);
2155  off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
2156  if (val) {
2157  pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
2158  first_block, s->dest[dst_idx] + off,
2159  (i & 4) ? s->uvlinesize : s->linesize,
2160  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
2161  block_cbp |= pat << (i << 2);
2162  if (!v->ttmbf && ttmb < 8)
2163  ttmb = -1;
2164  first_block = 0;
2165  }
2166  }
2167  }
2168  v->cbp[s->mb_x] = block_cbp;
2169  v->ttblk[s->mb_x] = block_tt;
2170 }
2171 
2172 /** Decode one B-frame MB (in interlaced frame B picture)
2173  */
2175 {
2176  MpegEncContext *s = &v->s;
2177  GetBitContext *gb = &s->gb;
2178  int i, j;
2179  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2180  int cbp = 0; /* cbp decoding stuff */
2181  int mqdiff, mquant; /* MB quantization */
2182  int ttmb = v->ttfrm; /* MB Transform type */
2183  int mvsw = 0; /* motion vector switch */
2184  int mb_has_coeffs = 1; /* last_flag */
2185  int dmv_x, dmv_y; /* Differential MV components */
2186  int val; /* temp value */
2187  int first_block = 1;
2188  int dst_idx, off;
2189  int skipped, direct, twomv = 0;
2190  int block_cbp = 0, pat, block_tt = 0;
2191  int idx_mbmode = 0, mvbp;
2192  int stride_y, fieldtx;
2193  int bmvtype = BMV_TYPE_BACKWARD;
2194  int dir, dir2;
2195 
2196  mquant = v->pq; /* Lossy initialization */
2197  s->mb_intra = 0;
2198  if (v->skip_is_raw)
2199  skipped = get_bits1(gb);
2200  else
2201  skipped = v->s.mbskip_table[mb_pos];
2202 
2203  if (!skipped) {
2204  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
2205  if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
2206  twomv = 1;
2207  v->blk_mv_type[s->block_index[0]] = 1;
2208  v->blk_mv_type[s->block_index[1]] = 1;
2209  v->blk_mv_type[s->block_index[2]] = 1;
2210  v->blk_mv_type[s->block_index[3]] = 1;
2211  } else {
2212  v->blk_mv_type[s->block_index[0]] = 0;
2213  v->blk_mv_type[s->block_index[1]] = 0;
2214  v->blk_mv_type[s->block_index[2]] = 0;
2215  v->blk_mv_type[s->block_index[3]] = 0;
2216  }
2217  }
2218 
2219  if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
2220  for (i = 0; i < 4; i++) {
2221  s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = 0;
2222  s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = 0;
2223  s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
2224  s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
2225  }
2226  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
2227  s->mb_intra = 1;
2228  s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
2229  fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
2230  mb_has_coeffs = get_bits1(gb);
2231  if (mb_has_coeffs)
2232  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2233  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
2234  GET_MQUANT();
2235  s->current_picture.qscale_table[mb_pos] = mquant;
2236  /* Set DC scale - y and c use the same (not sure if necessary here) */
2237  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
2238  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
2239  dst_idx = 0;
2240  for (i = 0; i < 6; i++) {
2241  v->a_avail = v->c_avail = 0;
2242  v->mb_type[0][s->block_index[i]] = 1;
2243  s->dc_val[0][s->block_index[i]] = 0;
2244  dst_idx += i >> 2;
2245  val = ((cbp >> (5 - i)) & 1);
2246  if (i == 2 || i == 3 || !s->first_slice_line)
2247  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2248  if (i == 1 || i == 3 || s->mb_x)
2249  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2250 
2251  vc1_decode_intra_block(v, s->block[i], i, val, mquant,
2252  (i & 4) ? v->codingset2 : v->codingset);
2253  if (CONFIG_GRAY && i > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2254  continue;
2255  v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
2256  if (i < 4) {
2257  stride_y = s->linesize << fieldtx;
2258  off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
2259  } else {
2260  stride_y = s->uvlinesize;
2261  off = 0;
2262  }
2264  s->dest[dst_idx] + off,
2265  stride_y);
2266  }
2267  } else {
2268  s->mb_intra = v->is_intra[s->mb_x] = 0;
2269 
2270  if (v->dmb_is_raw)
2271  direct = get_bits1(gb);
2272  else
2273  direct = v->direct_mb_plane[mb_pos];
2274 
2275  if (direct) {
2277  av_log(s->avctx, AV_LOG_WARNING, "Mixed frame/field direct mode not supported\n");
2278  s->mv[0][0][0] = s->current_picture.motion_val[0][s->block_index[0]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][0], v->bfraction, 0, s->quarter_sample);
2279  s->mv[0][0][1] = s->current_picture.motion_val[0][s->block_index[0]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][1], v->bfraction, 0, s->quarter_sample);
2280  s->mv[1][0][0] = s->current_picture.motion_val[1][s->block_index[0]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][0], v->bfraction, 1, s->quarter_sample);
2281  s->mv[1][0][1] = s->current_picture.motion_val[1][s->block_index[0]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][1], v->bfraction, 1, s->quarter_sample);
2282 
2283  if (twomv) {
2284  s->mv[0][2][0] = s->current_picture.motion_val[0][s->block_index[2]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][0], v->bfraction, 0, s->quarter_sample);
2285  s->mv[0][2][1] = s->current_picture.motion_val[0][s->block_index[2]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][1], v->bfraction, 0, s->quarter_sample);
2286  s->mv[1][2][0] = s->current_picture.motion_val[1][s->block_index[2]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][0], v->bfraction, 1, s->quarter_sample);
2287  s->mv[1][2][1] = s->current_picture.motion_val[1][s->block_index[2]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][1], v->bfraction, 1, s->quarter_sample);
2288 
2289  for (i = 1; i < 4; i += 2) {
2290  s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][i-1][0];
2291  s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][i-1][1];
2292  s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][i-1][0];
2293  s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][i-1][1];
2294  }
2295  } else {
2296  for (i = 1; i < 4; i++) {
2297  s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][0][0];
2298  s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][0][1];
2299  s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][0][0];
2300  s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][0][1];
2301  }
2302  }
2303  }
2304 
2305  if (!direct) {
2306  if (skipped || !s->mb_intra) {
2307  bmvtype = decode012(gb);
2308  switch (bmvtype) {
2309  case 0:
2310  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
2311  break;
2312  case 1:
2313  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
2314  break;
2315  case 2:
2316  bmvtype = BMV_TYPE_INTERPOLATED;
2317  }
2318  }
2319 
2320  if (twomv && bmvtype != BMV_TYPE_INTERPOLATED)
2321  mvsw = get_bits1(gb);
2322  }
2323 
2324  if (!skipped) { // inter MB
2325  mb_has_coeffs = ff_vc1_mbmode_intfrp[0][idx_mbmode][3];
2326  if (mb_has_coeffs)
2327  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2328  if (!direct) {
2329  if (bmvtype == BMV_TYPE_INTERPOLATED && twomv) {
2331  } else if (bmvtype == BMV_TYPE_INTERPOLATED || twomv) {
2333  }
2334  }
2335 
2336  for (i = 0; i < 6; i++)
2337  v->mb_type[0][s->block_index[i]] = 0;
2338  fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[0][idx_mbmode][1];
2339  /* for all motion vector read MVDATA and motion compensate each block */
2340  dst_idx = 0;
2341  if (direct) {
2342  if (twomv) {
2343  for (i = 0; i < 4; i++) {
2344  ff_vc1_mc_4mv_luma(v, i, 0, 0);
2345  ff_vc1_mc_4mv_luma(v, i, 1, 1);
2346  }
2347  ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
2348  ff_vc1_mc_4mv_chroma4(v, 1, 1, 1);
2349  } else {
2350  ff_vc1_mc_1mv(v, 0);
2351  ff_vc1_interp_mc(v);
2352  }
2353  } else if (twomv && bmvtype == BMV_TYPE_INTERPOLATED) {
2354  mvbp = v->fourmvbp;
2355  for (i = 0; i < 4; i++) {
2356  dir = i==1 || i==3;
2357  dmv_x = dmv_y = 0;
2358  val = ((mvbp >> (3 - i)) & 1);
2359  if (val)
2360  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2361  j = i > 1 ? 2 : 0;
2362  ff_vc1_pred_mv_intfr(v, j, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir);
2363  ff_vc1_mc_4mv_luma(v, j, dir, dir);
2364  ff_vc1_mc_4mv_luma(v, j+1, dir, dir);
2365  }
2366 
2367  ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
2368  ff_vc1_mc_4mv_chroma4(v, 1, 1, 1);
2369  } else if (bmvtype == BMV_TYPE_INTERPOLATED) {
2370  mvbp = v->twomvbp;
2371  dmv_x = dmv_y = 0;
2372  if (mvbp & 2)
2373  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2374 
2375  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0);
2376  ff_vc1_mc_1mv(v, 0);
2377 
2378  dmv_x = dmv_y = 0;
2379  if (mvbp & 1)
2380  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2381 
2382  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 1);
2383  ff_vc1_interp_mc(v);
2384  } else if (twomv) {
2385  dir = bmvtype == BMV_TYPE_BACKWARD;
2386  dir2 = dir;
2387  if (mvsw)
2388  dir2 = !dir;
2389  mvbp = v->twomvbp;
2390  dmv_x = dmv_y = 0;
2391  if (mvbp & 2)
2392  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2393  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir);
2394 
2395  dmv_x = dmv_y = 0;
2396  if (mvbp & 1)
2397  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2398  ff_vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir2);
2399 
2400  if (mvsw) {
2401  for (i = 0; i < 2; i++) {
2402  s->mv[dir][i+2][0] = s->mv[dir][i][0] = s->current_picture.motion_val[dir][s->block_index[i+2]][0] = s->current_picture.motion_val[dir][s->block_index[i]][0];
2403  s->mv[dir][i+2][1] = s->mv[dir][i][1] = s->current_picture.motion_val[dir][s->block_index[i+2]][1] = s->current_picture.motion_val[dir][s->block_index[i]][1];
2404  s->mv[dir2][i+2][0] = s->mv[dir2][i][0] = s->current_picture.motion_val[dir2][s->block_index[i]][0] = s->current_picture.motion_val[dir2][s->block_index[i+2]][0];
2405  s->mv[dir2][i+2][1] = s->mv[dir2][i][1] = s->current_picture.motion_val[dir2][s->block_index[i]][1] = s->current_picture.motion_val[dir2][s->block_index[i+2]][1];
2406  }
2407  } else {
2408  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, v->mb_type[0], !dir);
2409  ff_vc1_pred_mv_intfr(v, 2, 0, 0, 2, v->range_x, v->range_y, v->mb_type[0], !dir);
2410  }
2411 
2412  ff_vc1_mc_4mv_luma(v, 0, dir, 0);
2413  ff_vc1_mc_4mv_luma(v, 1, dir, 0);
2414  ff_vc1_mc_4mv_luma(v, 2, dir2, 0);
2415  ff_vc1_mc_4mv_luma(v, 3, dir2, 0);
2416  ff_vc1_mc_4mv_chroma4(v, dir, dir2, 0);
2417  } else {
2418  dir = bmvtype == BMV_TYPE_BACKWARD;
2419 
2420  mvbp = ff_vc1_mbmode_intfrp[0][idx_mbmode][2];
2421  dmv_x = dmv_y = 0;
2422  if (mvbp)
2423  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2424 
2425  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], dir);
2426  v->blk_mv_type[s->block_index[0]] = 1;
2427  v->blk_mv_type[s->block_index[1]] = 1;
2428  v->blk_mv_type[s->block_index[2]] = 1;
2429  v->blk_mv_type[s->block_index[3]] = 1;
2430  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, 0, !dir);
2431  for (i = 0; i < 2; i++) {
2432  s->mv[!dir][i+2][0] = s->mv[!dir][i][0] = s->current_picture.motion_val[!dir][s->block_index[i+2]][0] = s->current_picture.motion_val[!dir][s->block_index[i]][0];
2433  s->mv[!dir][i+2][1] = s->mv[!dir][i][1] = s->current_picture.motion_val[!dir][s->block_index[i+2]][1] = s->current_picture.motion_val[!dir][s->block_index[i]][1];
2434  }
2435  ff_vc1_mc_1mv(v, dir);
2436  }
2437 
2438  if (cbp)
2439  GET_MQUANT(); // p. 227
2440  s->current_picture.qscale_table[mb_pos] = mquant;
2441  if (!v->ttmbf && cbp)
2443  for (i = 0; i < 6; i++) {
2444  s->dc_val[0][s->block_index[i]] = 0;
2445  dst_idx += i >> 2;
2446  val = ((cbp >> (5 - i)) & 1);
2447  if (!fieldtx)
2448  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2449  else
2450  off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
2451  if (val) {
2452  pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
2453  first_block, s->dest[dst_idx] + off,
2454  (i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
2455  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
2456  block_cbp |= pat << (i << 2);
2457  if (!v->ttmbf && ttmb < 8)
2458  ttmb = -1;
2459  first_block = 0;
2460  }
2461  }
2462 
2463  } else { // skipped
2464  dir = 0;
2465  for (i = 0; i < 6; i++) {
2466  v->mb_type[0][s->block_index[i]] = 0;
2467  s->dc_val[0][s->block_index[i]] = 0;
2468  }
2469  s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
2470  s->current_picture.qscale_table[mb_pos] = 0;
2471  v->blk_mv_type[s->block_index[0]] = 0;
2472  v->blk_mv_type[s->block_index[1]] = 0;
2473  v->blk_mv_type[s->block_index[2]] = 0;
2474  v->blk_mv_type[s->block_index[3]] = 0;
2475 
2476  if (!direct) {
2477  if (bmvtype == BMV_TYPE_INTERPOLATED) {
2478  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0);
2479  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 1);
2480  } else {
2481  dir = bmvtype == BMV_TYPE_BACKWARD;
2482  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], dir);
2483  if (mvsw) {
2484  int dir2 = dir;
2485  if (mvsw)
2486  dir2 = !dir;
2487  for (i = 0; i < 2; i++) {
2488  s->mv[dir][i+2][0] = s->mv[dir][i][0] = s->current_picture.motion_val[dir][s->block_index[i+2]][0] = s->current_picture.motion_val[dir][s->block_index[i]][0];
2489  s->mv[dir][i+2][1] = s->mv[dir][i][1] = s->current_picture.motion_val[dir][s->block_index[i+2]][1] = s->current_picture.motion_val[dir][s->block_index[i]][1];
2490  s->mv[dir2][i+2][0] = s->mv[dir2][i][0] = s->current_picture.motion_val[dir2][s->block_index[i]][0] = s->current_picture.motion_val[dir2][s->block_index[i+2]][0];
2491  s->mv[dir2][i+2][1] = s->mv[dir2][i][1] = s->current_picture.motion_val[dir2][s->block_index[i]][1] = s->current_picture.motion_val[dir2][s->block_index[i+2]][1];
2492  }
2493  } else {
2494  v->blk_mv_type[s->block_index[0]] = 1;
2495  v->blk_mv_type[s->block_index[1]] = 1;
2496  v->blk_mv_type[s->block_index[2]] = 1;
2497  v->blk_mv_type[s->block_index[3]] = 1;
2498  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, 0, !dir);
2499  for (i = 0; i < 2; i++) {
2500  s->mv[!dir][i+2][0] = s->mv[!dir][i][0] = s->current_picture.motion_val[!dir][s->block_index[i+2]][0] = s->current_picture.motion_val[!dir][s->block_index[i]][0];
2501  s->mv[!dir][i+2][1] = s->mv[!dir][i][1] = s->current_picture.motion_val[!dir][s->block_index[i+2]][1] = s->current_picture.motion_val[!dir][s->block_index[i]][1];
2502  }
2503  }
2504  }
2505  }
2506 
2507  ff_vc1_mc_1mv(v, dir);
2508  if (direct || bmvtype == BMV_TYPE_INTERPOLATED) {
2509  ff_vc1_interp_mc(v);
2510  }
2511  v->fieldtx_plane[mb_pos] = 0;
2512  }
2513  }
2514  v->cbp[s->mb_x] = block_cbp;
2515  v->ttblk[s->mb_x] = block_tt;
2516 
2517  return 0;
2518 }
2519 
2520 /** Decode blocks of I-frame
2521  */
2523 {
2524  int k, j;
2525  MpegEncContext *s = &v->s;
2526  int cbp, val;
2527  uint8_t *coded_val;
2528  int mb_pos;
2529 
2530  /* select coding mode used for VLC tables selection */
2531  switch (v->y_ac_table_index) {
2532  case 0:
2534  break;
2535  case 1:
2537  break;
2538  case 2:
2540  break;
2541  }
2542 
2543  switch (v->c_ac_table_index) {
2544  case 0:
2546  break;
2547  case 1:
2549  break;
2550  case 2:
2552  break;
2553  }
2554 
2555  /* Set DC scale - y and c use the same */
2556  s->y_dc_scale = s->y_dc_scale_table[v->pq];
2557  s->c_dc_scale = s->c_dc_scale_table[v->pq];
2558 
2559  //do frame decode
2560  s->mb_x = s->mb_y = 0;
2561  s->mb_intra = 1;
2562  s->first_slice_line = 1;
2563  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2564  s->mb_x = 0;
2565  init_block_index(v);
2566  for (; s->mb_x < v->end_mb_x; s->mb_x++) {
2568  s->bdsp.clear_blocks(v->block[v->cur_blk_idx][0]);
2569  mb_pos = s->mb_x + s->mb_y * s->mb_width;
2570  s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
2571  s->current_picture.qscale_table[mb_pos] = v->pq;
2572  for (int i = 0; i < 4; i++) {
2573  s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
2574  s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
2575  }
2576 
2577  // do actual MB decoding and displaying
2579  v->s.ac_pred = get_bits1(&v->s.gb);
2580 
2581  for (k = 0; k < 6; k++) {
2582  v->mb_type[0][s->block_index[k]] = 1;
2583 
2584  val = ((cbp >> (5 - k)) & 1);
2585 
2586  if (k < 4) {
2587  int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
2588  val = val ^ pred;
2589  *coded_val = val;
2590  }
2591  cbp |= val << (5 - k);
2592 
2593  vc1_decode_i_block(v, v->block[v->cur_blk_idx][block_map[k]], k, val, (k < 4) ? v->codingset : v->codingset2);
2594 
2595  if (CONFIG_GRAY && k > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2596  continue;
2598  }
2599 
2600  if (v->overlap && v->pq >= 9) {
2602  if (v->rangeredfrm)
2603  for (k = 0; k < 6; k++)
2604  for (j = 0; j < 64; j++)
2605  v->block[v->cur_blk_idx][block_map[k]][j] *= 2;
2606  vc1_put_blocks_clamped(v, 1);
2607  } else {
2608  if (v->rangeredfrm)
2609  for (k = 0; k < 6; k++)
2610  for (j = 0; j < 64; j++)
2611  v->block[v->cur_blk_idx][block_map[k]][j] = (v->block[v->cur_blk_idx][block_map[k]][j] - 64) * 2;
2612  vc1_put_blocks_clamped(v, 0);
2613  }
2614 
2615  if (v->s.loop_filter)
2617 
2618  if (get_bits_count(&s->gb) > v->bits) {
2619  ff_er_add_slice(&s->er, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);
2620  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
2621  get_bits_count(&s->gb), v->bits);
2622  return;
2623  }
2624 
2625  v->topleft_blk_idx = (v->topleft_blk_idx + 1) % (v->end_mb_x + 2);
2626  v->top_blk_idx = (v->top_blk_idx + 1) % (v->end_mb_x + 2);
2627  v->left_blk_idx = (v->left_blk_idx + 1) % (v->end_mb_x + 2);
2628  v->cur_blk_idx = (v->cur_blk_idx + 1) % (v->end_mb_x + 2);
2629  }
2630  if (!v->s.loop_filter)
2631  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2632  else if (s->mb_y)
2633  ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
2634 
2635  s->first_slice_line = 0;
2636  }
2637  if (v->s.loop_filter)
2638  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2639 
2640  /* This is intentionally mb_height and not end_mb_y - unlike in advanced
2641  * profile, these only differ are when decoding MSS2 rectangles. */
2642  ff_er_add_slice(&s->er, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END);
2643 }
2644 
2645 /** Decode blocks of I-frame for advanced profile
2646  */
2648 {
2649  int k;
2650  MpegEncContext *s = &v->s;
2651  int cbp, val;
2652  uint8_t *coded_val;
2653  int mb_pos;
2654  int mquant;
2655  int mqdiff;
2656  GetBitContext *gb = &s->gb;
2657 
2658  /* select coding mode used for VLC tables selection */
2659  switch (v->y_ac_table_index) {
2660  case 0:
2662  break;
2663  case 1:
2665  break;
2666  case 2:
2668  break;
2669  }
2670 
2671  switch (v->c_ac_table_index) {
2672  case 0:
2674  break;
2675  case 1:
2677  break;
2678  case 2:
2680  break;
2681  }
2682 
2683  // do frame decode
2684  s->mb_x = s->mb_y = 0;
2685  s->mb_intra = 1;
2686  s->first_slice_line = 1;
2687  s->mb_y = s->start_mb_y;
2688  if (s->start_mb_y) {
2689  s->mb_x = 0;
2690  init_block_index(v);
2691  memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
2692  (1 + s->b8_stride) * sizeof(*s->coded_block));
2693  }
2694  for (; s->mb_y < s->end_mb_y; s->mb_y++) {
2695  s->mb_x = 0;
2696  init_block_index(v);
2697  for (;s->mb_x < s->mb_width; s->mb_x++) {
2698  mquant = v->pq;
2700  s->bdsp.clear_blocks(v->block[v->cur_blk_idx][0]);
2701  mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2702  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
2703  for (int i = 0; i < 4; i++) {
2704  s->current_picture.motion_val[1][s->block_index[i] + v->blocks_off][0] = 0;
2705  s->current_picture.motion_val[1][s->block_index[i] + v->blocks_off][1] = 0;
2706  }
2707 
2708  // do actual MB decoding and displaying
2709  if (v->fieldtx_is_raw)
2710  v->fieldtx_plane[mb_pos] = get_bits1(&v->s.gb);
2712  if (v->acpred_is_raw)
2713  v->s.ac_pred = get_bits1(&v->s.gb);
2714  else
2715  v->s.ac_pred = v->acpred_plane[mb_pos];
2716 
2717  if (v->condover == CONDOVER_SELECT && v->overflg_is_raw)
2718  v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb);
2719 
2720  GET_MQUANT();
2721 
2722  s->current_picture.qscale_table[mb_pos] = mquant;
2723  /* Set DC scale - y and c use the same */
2724  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
2725  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
2726 
2727  for (k = 0; k < 6; k++) {
2728  v->mb_type[0][s->block_index[k]] = 1;
2729 
2730  val = ((cbp >> (5 - k)) & 1);
2731 
2732  if (k < 4) {
2733  int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
2734  val = val ^ pred;
2735  *coded_val = val;
2736  }
2737  cbp |= val << (5 - k);
2738 
2739  v->a_avail = !s->first_slice_line || (k == 2 || k == 3);
2740  v->c_avail = !!s->mb_x || (k == 1 || k == 3);
2741 
2742  vc1_decode_i_block_adv(v, v->block[v->cur_blk_idx][block_map[k]], k, val,
2743  (k < 4) ? v->codingset : v->codingset2, mquant);
2744 
2745  if (CONFIG_GRAY && k > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2746  continue;
2748  }
2749 
2750  if (v->overlap && (v->pq >= 9 || v->condover != CONDOVER_NONE))
2752  vc1_put_blocks_clamped(v, 1);
2753  if (v->s.loop_filter)
2755 
2756  if (get_bits_count(&s->gb) > v->bits) {
2757  // TODO: may need modification to handle slice coding
2758  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2759  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
2760  get_bits_count(&s->gb), v->bits);
2761  return;
2762  }
2767  }
2768  if (!v->s.loop_filter)
2769  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2770  else if (s->mb_y)
2771  ff_mpeg_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
2772  s->first_slice_line = 0;
2773  }
2774 
2775  if (v->s.loop_filter)
2776  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2777  ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
2778  (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
2779 }
2780 
2782 {
2783  MpegEncContext *s = &v->s;
2784  int apply_loop_filter;
2785 
2786  /* select coding mode used for VLC tables selection */
2787  switch (v->c_ac_table_index) {
2788  case 0:
2790  break;
2791  case 1:
2793  break;
2794  case 2:
2796  break;
2797  }
2798 
2799  switch (v->c_ac_table_index) {
2800  case 0:
2802  break;
2803  case 1:
2805  break;
2806  case 2:
2808  break;
2809  }
2810 
2811  apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
2812  s->first_slice_line = 1;
2813  memset(v->cbp_base, 0, sizeof(v->cbp_base[0]) * 3 * s->mb_stride);
2814  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2815  s->mb_x = 0;
2816  init_block_index(v);
2817  for (; s->mb_x < s->mb_width; s->mb_x++) {
2819 
2820  if (v->fcm == ILACE_FIELD) {
2822  if (apply_loop_filter)
2824  } else if (v->fcm == ILACE_FRAME) {
2826  if (apply_loop_filter)
2828  } else {
2829  vc1_decode_p_mb(v);
2830  if (apply_loop_filter)
2832  }
2833  if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
2834  // TODO: may need modification to handle slice coding
2835  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2836  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
2837  get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
2838  return;
2839  }
2844  }
2845  memmove(v->cbp_base,
2846  v->cbp - s->mb_stride,
2847  sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
2848  memmove(v->ttblk_base,
2849  v->ttblk - s->mb_stride,
2850  sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
2851  memmove(v->is_intra_base,
2852  v->is_intra - s->mb_stride,
2853  sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
2854  memmove(v->luma_mv_base,
2855  v->luma_mv - s->mb_stride,
2856  sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
2857  if (s->mb_y != s->start_mb_y)
2858  ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
2859  s->first_slice_line = 0;
2860  }
2861  if (s->end_mb_y >= s->start_mb_y)
2862  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2863  ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
2864  (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
2865 }
2866 
2868 {
2869  MpegEncContext *s = &v->s;
2870 
2871  /* select coding mode used for VLC tables selection */
2872  switch (v->c_ac_table_index) {
2873  case 0:
2875  break;
2876  case 1:
2878  break;
2879  case 2:
2881  break;
2882  }
2883 
2884  switch (v->c_ac_table_index) {
2885  case 0:
2887  break;
2888  case 1:
2890  break;
2891  case 2:
2893  break;
2894  }
2895 
2896  s->first_slice_line = 1;
2897  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2898  s->mb_x = 0;
2899  init_block_index(v);
2900  for (; s->mb_x < s->mb_width; s->mb_x++) {
2902 
2903  if (v->fcm == ILACE_FIELD) {
2905  if (v->s.loop_filter)
2907  } else if (v->fcm == ILACE_FRAME) {
2909  if (v->s.loop_filter)
2911  } else {
2912  vc1_decode_b_mb(v);
2913  if (v->s.loop_filter)
2915  }
2916  if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
2917  // TODO: may need modification to handle slice coding
2918  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2919  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
2920  get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
2921  return;
2922  }
2923  }
2924  memmove(v->cbp_base,
2925  v->cbp - s->mb_stride,
2926  sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
2927  memmove(v->ttblk_base,
2928  v->ttblk - s->mb_stride,
2929  sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
2930  memmove(v->is_intra_base,
2931  v->is_intra - s->mb_stride,
2932  sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
2933  if (!v->s.loop_filter)
2934  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2935  else if (s->mb_y)
2936  ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
2937  s->first_slice_line = 0;
2938  }
2939  if (v->s.loop_filter)
2940  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2941  ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
2942  (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
2943 }
2944 
2946 {
2947  MpegEncContext *s = &v->s;
2948 
2949  if (!v->s.last_picture.f->data[0])
2950  return;
2951 
2952  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END);
2953  s->first_slice_line = 1;
2954  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2955  s->mb_x = 0;
2956  init_block_index(v);
2958  memcpy(s->dest[0], s->last_picture.f->data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
2959  memcpy(s->dest[1], s->last_picture.f->data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
2960  memcpy(s->dest[2], s->last_picture.f->data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
2961  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2962  s->first_slice_line = 0;
2963  }
2965 }
2966 
2968 {
2969 
2970  v->s.esc3_level_length = 0;
2971  if (v->x8_type) {
2973  &v->s.gb, &v->s.mb_x, &v->s.mb_y,
2974  2 * v->pq + v->halfpq, v->pq * !v->pquantizer,
2975  v->s.loop_filter, v->s.low_delay);
2976 
2977  ff_er_add_slice(&v->s.er, 0, 0,
2978  (v->s.mb_x >> 1) - 1, (v->s.mb_y >> 1) - 1,
2979  ER_MB_END);
2980  } else {
2981  v->cur_blk_idx = 0;
2982  v->left_blk_idx = -1;
2983  v->topleft_blk_idx = 1;
2984  v->top_blk_idx = 2;
2985  switch (v->s.pict_type) {
2986  case AV_PICTURE_TYPE_I:
2987  if (v->profile == PROFILE_ADVANCED)
2989  else
2991  break;
2992  case AV_PICTURE_TYPE_P:
2993  if (v->p_frame_skipped)
2995  else
2997  break;
2998  case AV_PICTURE_TYPE_B:
2999  if (v->bi_type) {
3000  if (v->profile == PROFILE_ADVANCED)
3002  else
3004  } else
3006  break;
3007  }
3008  }
3009 }
in the bitstream is reported as 00b
Definition: vc1.h:149
const int ff_vc1_ttblk_to_tt[3][8]
Table for conversion between TTBLK and TTMB.
Definition: vc1data.c:34
#define VC1_TTBLK_VLC_BITS
Definition: vc1data.c:126
IDCTDSPContext idsp
Definition: mpegvideo.h:230
#define NULL
Definition: coverity.c:32
void ff_vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t *is_intra, int pred_flag, int dir)
Predict and set motion vector.
Definition: vc1_pred.c:211
int topleft_blk_idx
Definition: vc1.h:391
const char const char void * val
Definition: avisynth_c.h:863
discard all frames except keyframes
Definition: avcodec.h:810
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:2274
#define VC1_IF_MBMODE_VLC_BITS
Definition: vc1data.c:145
int p_frame_skipped
Definition: vc1.h:386
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
The VC1 Context.
Definition: vc1.h:173
int esc3_level_length
Definition: mpegvideo.h:440
VLC ff_vc1_ttblk_vlc[3]
Definition: vc1data.c:127
#define VC1_ICBPCY_VLC_BITS
Definition: vc1data.c:120
int k_x
Number of bits for MVs (depends on MV range)
Definition: vc1.h:235
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
Definition: mpegvideo.h:153
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:188
int mv_type_is_raw
mv type mb plane is not coded
Definition: vc1.h:289
uint8_t dmvrange
Frame decoding info for interlaced picture.
Definition: vc1.h:336
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define ER_MB_END
#define AC_VLC_BITS
Definition: intrax8.c:38
void(* vc1_inv_trans_8x4)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:38
static const uint8_t vc1_index_decode_table[AC_MODES][185][2]
Definition: vc1acdata.h:34
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
Definition: mpegvideo.h:154
int16_t(*[3] ac_val)[16]
used for MPEG-4 AC prediction, all 3 arrays must be continuous
Definition: mpegvideo.h:194
void(* put_pixels_clamped)(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.h:55
static const int vc1_last_decode_table[AC_MODES]
Definition: vc1acdata.h:30
void(* clear_block)(int16_t *block)
Definition: blockdsp.h:36
int tt_index
Index for Transform Type tables (to decode TTMB)
Definition: vc1.h:285
#define VC1_2REF_MVDATA_VLC_BITS
Definition: vc1data.c:140
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition: vc1.h:303
int field_picture
whether or not the picture was encoded in separate fields
Definition: mpegpicture.h:79
#define MB_TYPE_INTRA
Definition: mpegutils.h:73
static int ff_vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n, int a_avail, int c_avail, int16_t **dc_val_ptr, int *dir_ptr)
Get predicted DC value prediction dir: left=0, top=1.
Definition: vc1_block.c:404
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:36
uint8_t zz_8x8[4][64]
Zigzag table for TT_8x8, permuted for IDCT.
Definition: vc1.h:239
mpegvideo header.
int top_blk_idx
Definition: vc1.h:391
IntraX8Context x8
Definition: vc1.h:175
VLC * imv_vlc
Definition: vc1.h:342
static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n, int mquant, int ttmb, int first_block, uint8_t *dst, int linesize, int skip_block, int *ttmb_out)
Decode P block.
Definition: vc1_block.c:1126
uint8_t run
Definition: svq3.c:206
static const uint8_t q1[256]
Definition: twofish.c:96
int end_mb_x
Horizontal macroblock limit (used only by mss2)
Definition: vc1.h:399
static int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n, int16_t **dc_val_ptr, int *dir_ptr)
Get predicted DC value for I-frames only prediction dir: left=0, top=1.
Definition: vc1_block.c:339
int block_wrap[6]
Definition: mpegvideo.h:294
static int vc1_decode_p_mb(VC1Context *v)
Decode one P-frame MB.
Definition: vc1_block.c:1298
const uint8_t ff_vc1_adv_interlaced_4x8_zz[32]
Definition: vc1data.c:1065
int bits
Definition: vc1.h:179
int range_x
Definition: vc1.h:237
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS
Definition: vc1data.c:122
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo.c:2267
int esc3_run_length
Definition: mpegvideo.h:441
uint8_t * acpred_plane
AC prediction flags bitplane.
Definition: vc1.h:322
VC-1 tables.
int bi_type
Definition: vc1.h:387
void ff_vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y, int mv1, int *pred_flag)
Definition: vc1_pred.c:890
#define DC_VLC_BITS
Definition: vc1_block.c:40
The exact code depends on how similar the blocks are and how related they are to the block
uint8_t
void(* vc1_inv_trans_4x8_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:43
int left_blk_idx
Definition: vc1.h:391
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
int y_ac_table_index
Luma index from AC2FRM element.
Definition: vc1.h:255
int second_field
Definition: vc1.h:355
#define ER_MB_ERROR
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:108
int c_ac_table_index
AC coding set indexes.
Definition: vc1.h:254
const int ff_vc1_ac_sizes[AC_MODES]
Definition: vc1data.c:1133
void(* vc1_inv_trans_8x8)(int16_t *b)
Definition: vc1dsp.h:37
int ttfrm
Transform type info present at frame level.
Definition: vc1.h:257
static void vc1_decode_b_mb_intfi(VC1Context *v)
Decode one B-frame MB (in interlaced field B picture)
Definition: vc1_block.c:2011
#define MB_TYPE_16x16
Definition: mpegutils.h:54
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:180
int codingset2
index of current table set from 11.8 to use for chroma block decoding
Definition: vc1.h:261
int16_t bfraction
Relative position % anchors=> how to scale MVs.
Definition: vc1.h:272
int16_t((* luma_mv)[2]
Definition: vc1.h:394
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags...
Definition: vc1.h:218
MSMPEG4 data tables.
static const uint8_t offset_table[2][9]
Definition: vc1_block.c:43
int ff_intrax8_decode_picture(IntraX8Context *w, Picture *pict, GetBitContext *gb, int *mb_x, int *mb_y, int dquant, int quant_offset, int loopfilter, int lowdelay)
Decode single IntraX8 frame.
Definition: intrax8.c:773
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
uint8_t * forward_mb_plane
bitplane for "forward" MBs
Definition: vc1.h:288
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:129
static void vc1_decode_skip_blocks(VC1Context *v)
Definition: vc1_block.c:2945
static const uint8_t size_table[6]
Definition: vc1_block.c:1294
int fieldtx_is_raw
Definition: vc1.h:348
uint8_t * over_flags_plane
Overflags bitplane.
Definition: vc1.h:324
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:883
uint8_t fourmvbp
Definition: vc1.h:346
#define av_log(a,...)
int range_y
MV range.
Definition: vc1.h:237
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:737
static const uint16_t table[]
Definition: prosumer.c:206
uint8_t ttmbf
Transform type flag.
Definition: vc1.h:258
Definition: vc1.h:119
int k_y
Number of bits for MVs (depends on MV range)
Definition: vc1.h:236
void(* vc1_inv_trans_4x4)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:40
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
int16_t * dc_val[3]
used for MPEG-4 DC prediction, all 3 arrays must be continuous
Definition: mpegvideo.h:187
uint8_t twomvbp
Definition: vc1.h:345
int dmb_is_raw
direct mb plane is raw
Definition: vc1.h:290
const uint8_t ff_vc1_simple_progressive_4x4_zz[16]
Definition: vc1data.c:1022
int16_t(* block)[6][64]
Definition: vc1.h:390
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
#define VC1_CBPCY_P_VLC_BITS
Definition: vc1data.c:118
static void vc1_decode_b_mb(VC1Context *v)
Decode one B-frame MB (in Main profile)
Definition: vc1_block.c:1856
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int overlap
overlapped transforms in use
Definition: vc1.h:226
in the bitstream is reported as 11b
Definition: vc1.h:151
static int vc1_decode_b_mb_intfr(VC1Context *v)
Decode one B-frame MB (in interlaced frame B picture)
Definition: vc1_block.c:2174
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n, int coded, int codingset, int mquant)
Decode intra block in intra frames - should be faster than decode_intra_block.
Definition: vc1_block.c:720
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:37
void ff_vc1_mc_4mv_chroma4(VC1Context *v, int dir, int dir2, int avg)
Do motion compensation for 4-MV interlaced frame chroma macroblock (both U and V) ...
Definition: vc1_mc.c:839
ERContext er
Definition: mpegvideo.h:566
static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
Definition: vc1_block.c:72
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1645
VLC * mbmode_vlc
Definition: vc1.h:341
#define wrap(func)
Definition: neontest.h:65
uint8_t bits
Definition: vp3data.h:202
int quarter_sample
1->qpel, 0->half pel ME/MC
Definition: mpegvideo.h:401
int low_delay
no reordering needed / has no B-frames
Definition: mpegvideo.h:406
GetBitContext gb
Definition: mpegvideo.h:448
void ff_vc1_mc_4mv_chroma(VC1Context *v, int dir)
Do motion compensation for 4-MV macroblock - both chroma blocks.
Definition: vc1_mc.c:634
void(* put_signed_pixels_clamped)(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.h:58
#define scale_mv(n, dim)
const uint8_t * zz_8x4
Zigzag scan table for TT_8x4 coding mode.
Definition: vc1.h:241
int res_rtm_flag
reserved, set to 1
Definition: vc1.h:191
int a_avail
Definition: vc1.h:263
uint8_t * blk_mv_type
0: frame MV, 1: field MV (interlaced frame)
Definition: vc1.h:350
const uint8_t ff_vc1_adv_interlaced_8x4_zz[32]
Definition: vc1data.c:1058
#define B_FRACTION_DEN
Definition: vc1data.h:99
VLC ff_vc1_ttmb_vlc[3]
Definition: vc1data.c:115
void ff_vc1_i_loop_filter(VC1Context *v)
VLC * twomvbp_vlc
Definition: vc1.h:343
static void vc1_decode_b_blocks(VC1Context *v)
Definition: vc1_block.c:2867
const uint8_t * zz_4x8
Zigzag scan table for TT_4x8 coding mode.
Definition: vc1.h:242
void ff_vc1_decode_blocks(VC1Context *v)
Definition: vc1_block.c:2967
#define b
Definition: input.c:41
static int vc1_decode_p_mb_intfr(VC1Context *v)
Definition: vc1_block.c:1526
int x8_type
Definition: vc1.h:388
#define MB_INTRA_VLC_BITS
Definition: vc1_block.c:39
int field_mode
1 for interlaced field pictures
Definition: vc1.h:353
#define VC1_SUBBLKPAT_VLC_BITS
Definition: vc1data.c:128
uint8_t * mbskip_table
used to avoid copy if macroblock skipped (for black regions for example) and used for B-frame encodin...
Definition: mpegvideo.h:196
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:53
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:184
int fourmvswitch
Definition: vc1.h:337
int mb_off
Definition: vc1.h:365
void ff_vc1_b_intfi_loop_filter(VC1Context *v)
static void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode)
Reconstruct motion vector for B-frame and do motion compensation.
Definition: vc1_block.c:313
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:797
#define inc_blk_idx(idx)
Definition: vc1_block.c:164
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:86
int n
Definition: avisynth_c.h:760
static const int block_map[6]
Definition: vc1_block.c:49
void ff_vc1_p_loop_filter(VC1Context *v)
void(* vc1_inv_trans_8x8_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:41
uint32_t * cbp
Definition: vc1.h:392
int left_blk_sh
Definition: vc1.h:240
int16_t(* luma_mv_base)[2]
Definition: vc1.h:394
uint8_t * fieldtx_plane
Definition: vc1.h:347
int block_index[6]
index to current MB in block based arrays with edges
Definition: mpegvideo.h:293
int * ttblk_base
Definition: vc1.h:259
VLC * cbpcy_vlc
CBPCY VLC table.
Definition: vc1.h:284
static int decode210(GetBitContext *gb)
Definition: get_bits.h:841
if(ret)
static const float pred[4]
Definition: siprdata.h:259
int first_slice_line
used in MPEG-4 too to handle resync markers
Definition: mpegvideo.h:436
static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int yend)
Definition: vp3.c:1778
int top_blk_sh
Either 3 or 0, positions of l/t in blk[].
Definition: vc1.h:240
Libavcodec external API header.
void ff_vc1_mc_1mv(VC1Context *v, int dir)
Do motion compensation over 1 macroblock Mostly adapted hpel_motion and qpel_motion from mpegvideo...
Definition: vc1_mc.c:172
ptrdiff_t linesize
line size, in bytes, may be different from width
Definition: mpegvideo.h:134
BlockDSPContext bdsp
Definition: mpegvideo.h:226
int c_avail
Definition: vc1.h:263
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
static const uint8_t vc1_delta_run_table[AC_MODES][57]
Definition: vc1acdata.h:295
#define abs(x)
Definition: cuda_runtime.h:35
#define GET_MVDATA(_dmv_x, _dmv_y)
Get MV differentials.
Definition: vc1_block.c:224
uint32_t * cbp_base
Definition: vc1.h:392
uint8_t * is_intra
Definition: vc1.h:393
uint8_t * coded_block
used for coded block pattern prediction (msmpeg4v3, wmv1)
Definition: mpegvideo.h:192
void(* vc1_inv_trans_4x8)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:39
void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
Definition: vc1_pred.c:690
const uint8_t ff_vc1_mbmode_intfrp[2][15][4]
Definition: vc1data.c:53
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
static void vc1_decode_i_blocks_adv(VC1Context *v)
Decode blocks of I-frame for advanced profile.
Definition: vc1_block.c:2647
int fmb_is_raw
forward mb plane is raw
Definition: vc1.h:291
void(* vc1_inv_trans_8x4_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:42
uint8_t * is_intra_base
Definition: vc1.h:393
Definition: vc1.h:115
int index
Definition: gxfenc.c:89
struct AVFrame * f
Definition: mpegpicture.h:46
#define VC1_2MV_BLOCK_PATTERN_VLC_BITS
Definition: vc1data.c:124
static int vc1_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: vc1_block.c:475
ptrdiff_t uvlinesize
line size, for chroma in bytes, may be different from width
Definition: mpegvideo.h:135
int skip_is_raw
skip mb plane is not coded
Definition: vc1.h:292
static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x, int *dmv_y, int *pred_flag)
Definition: vc1_block.c:262
static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
Decode one AC coefficient.
Definition: vc1_block.c:511
#define MB_TYPE_SKIP
Definition: mpegutils.h:62
void ff_vc1_p_overlap_filter(VC1Context *v)
uint8_t * direct_mb_plane
bitplane for "direct" MBs
Definition: vc1.h:287
static const uint8_t vc1_last_delta_run_table[AC_MODES][10]
Definition: vc1acdata.h:339
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:212
uint8_t * mv_type_mb_plane
bitplane for mv_type == (4MV)
Definition: vc1.h:286
const uint8_t * quant
int numref
number of past field pictures used as reference
Definition: vc1.h:357
const int32_t ff_vc1_dqscale[63]
Definition: vc1data.c:1085
int blocks_off
Definition: vc1.h:365
void(* vc1_inv_trans_4x4_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:44
uint8_t tff
Definition: vc1.h:312
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:189
uint8_t level
Definition: svq3.c:207
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:276
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
Definition: mpegvideo.h:131
MpegEncContext s
Definition: vc1.h:174
in the bitstream is reported as 10b
Definition: vc1.h:150
MpegEncContext.
Definition: mpegvideo.h:81
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
Definition: mpegvideo.h:183
void ff_vc1_i_overlap_filter(VC1Context *v)
int8_t * qscale_table
Definition: mpegpicture.h:50
struct AVCodecContext * avctx
Definition: mpegvideo.h:98
int cur_blk_idx
Definition: vc1.h:391
uint8_t pq
Definition: vc1.h:238
void ff_vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg)
Do motion compensation for 4-MV macroblock - luminance block.
Definition: vc1_mc.c:452
static int vc1_decode_p_mb_intfi(VC1Context *v)
Definition: vc1_block.c:1734
#define GET_MQUANT()
Get macroblock-level quantizer scale.
Definition: vc1_block.c:181
int
int pqindex
raw pqindex used in coding set selection
Definition: vc1.h:262
static const uint8_t vc1_last_delta_level_table[AC_MODES][44]
Definition: vc1acdata.h:246
#define VC1_1REF_MVDATA_VLC_BITS
Definition: vc1data.c:138
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:130
#define VC1_TTMB_VLC_BITS
Definition: vc1data.c:114
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
uint8_t * dest[3]
Definition: mpegvideo.h:295
static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n, int coded, int mquant, int codingset)
Decode intra block in inter frames - more generic version than vc1_decode_i_block.
Definition: vc1_block.c:915
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:309
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:162
uint8_t dquantfrm
pquant parameters
Definition: vc1.h:245
Bi-dir predicted.
Definition: avutil.h:276
const uint8_t ff_vc1_adv_interlaced_4x4_zz[16]
Definition: vc1data.c:1076
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
Definition: avcodec.h:3026
int * ttblk
Transform type at the block level.
Definition: vc1.h:259
VLC ff_vc1_ac_coeff_table[8]
Definition: vc1data.c:143
void ff_vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, int mvn, int r_x, int r_y, uint8_t *is_intra, int dir)
Predict and set motion vector for interlaced frame picture MBs.
Definition: vc1_pred.c:469
uint8_t condover
Definition: vc1.h:326
#define VC1_INTFR_4MV_MBMODE_VLC_BITS
Definition: vc1data.c:130
static void vc1_decode_p_blocks(VC1Context *v)
Definition: vc1_block.c:2781
uint8_t pquantizer
Uniform (over sequence) quantizer in use.
Definition: vc1.h:283
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n, int coded, int codingset)
Decode intra block in intra frames - should be faster than decode_intra_block.
Definition: vc1_block.c:578
Definition: vc1.h:118
void ff_vc1_p_intfr_loop_filter(VC1Context *v)
int acpred_is_raw
Definition: vc1.h:323
uint8_t zzi_8x8[64]
Definition: vc1.h:349
void ff_vc1_interp_mc(VC1Context *v)
Motion compensation for direct or interpolated blocks in B-frames.
Definition: vc1_mc.c:1004
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:508
static int decode012(GetBitContext *gb)
Definition: get_bits.h:831
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
int bmvtype
Definition: vc1.h:367
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:168
int overflg_is_raw
Definition: vc1.h:325
Definition: vc1.h:112
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:56
VLC ff_msmp4_mb_i_vlc
Definition: msmpeg4data.c:38
#define av_always_inline
Definition: attributes.h:39
static void vc1_decode_i_blocks(VC1Context *v)
Decode blocks of I-frame.
Definition: vc1_block.c:2522
int codingset
index of current table set from 11.8 to use for luma block decoding
Definition: vc1.h:260
uint8_t * mb_type[3]
Definition: vc1.h:264
#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS
Definition: vc1data.c:132
VLC * fourmvbp_vlc
Definition: vc1.h:344
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
int dc_table_index
Definition: mpegvideo.h:433
VLC ff_msmp4_dc_luma_vlc[2]
Definition: msmpeg4data.c:39
VLC ff_vc1_subblkpat_vlc[3]
Definition: vc1data.c:129
uint8_t halfpq
Uniform quant over image and qp+.5.
Definition: vc1.h:273
static const uint8_t vc1_delta_level_table[AC_MODES][31]
Definition: vc1acdata.h:203
VC1DSPContext vc1dsp
Definition: vc1.h:177
Predicted.
Definition: avutil.h:275
static void init_block_index(VC1Context *v)
Definition: vc1_block.c:59
VLC ff_msmp4_dc_chroma_vlc[2]
Definition: msmpeg4data.c:40
void(* add_pixels_clamped)(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp.h:61