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 "mpegvideodec.h"
33 #include "msmpeg4data.h"
34 #include "unary.h"
35 #include "vc1.h"
36 #include "vc1_pred.h"
37 #include "vc1acdata.h"
38 #include "vc1data.h"
39 
40 #define MB_INTRA_VLC_BITS 9
41 #define DC_VLC_BITS 9
42 
43 // offset tables for interlaced picture MVDATA decoding
44 static const uint8_t offset_table[2][9] = {
45  { 0, 1, 2, 4, 8, 16, 32, 64, 128 },
46  { 0, 1, 3, 7, 15, 31, 63, 127, 255 },
47 };
48 
49 // mapping table for internal block representation
50 static const int block_map[6] = {0, 2, 1, 3, 4, 5};
51 
52 /***********************************************************************/
53 /**
54  * @name VC-1 Bitplane decoding
55  * @see 8.7, p56
56  * @{
57  */
58 
59 
60 static inline void init_block_index(VC1Context *v)
61 {
62  MpegEncContext *s = &v->s;
64  if (v->field_mode && !(v->second_field ^ v->tff)) {
65  s->dest[0] += s->current_picture_ptr->f->linesize[0];
66  s->dest[1] += s->current_picture_ptr->f->linesize[1];
67  s->dest[2] += s->current_picture_ptr->f->linesize[2];
68  }
69 }
70 
71 static inline void update_block_index(MpegEncContext *s)
72 {
73  /* VC1 is always 420 except when using AV_CODEC_FLAG_GRAY
74  * (or a HWAccel). Shall we inline this value? */
75  ff_update_block_index(s, 8, 0, s->chroma_x_shift);
76 }
77 
78 /** @} */ //Bitplane group
79 
80 static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
81 {
82  MpegEncContext *s = &v->s;
83  uint8_t *dest;
84  int block_count = CONFIG_GRAY && (s->avctx->flags & AV_CODEC_FLAG_GRAY) ? 4 : 6;
85  int fieldtx = 0;
86  int i;
87 
88  /* The put pixels loop is one MB row and one MB column behind the decoding
89  * loop because we can only put pixels when overlap filtering is done. For
90  * interlaced frame pictures, however, the put pixels loop is only one
91  * column behind the decoding loop as interlaced frame pictures only need
92  * horizontal overlap filtering. */
93  if (!s->first_slice_line && v->fcm != ILACE_FRAME) {
94  if (s->mb_x) {
95  for (i = 0; i < block_count; i++) {
96  if (i > 3 ? v->mb_type[0][s->block_index[i] - s->block_wrap[i] - 1] :
97  v->mb_type[0][s->block_index[i] - 2 * s->block_wrap[i] - 2]) {
98  dest = s->dest[0] + ((i & 2) - 4) * 4 * s->linesize + ((i & 1) - 2) * 8;
99  if (put_signed)
100  s->idsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][block_map[i]],
101  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize - 8 : dest,
102  i > 3 ? s->uvlinesize : s->linesize);
103  else
104  s->idsp.put_pixels_clamped(v->block[v->topleft_blk_idx][block_map[i]],
105  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize - 8 : dest,
106  i > 3 ? s->uvlinesize : s->linesize);
107  }
108  }
109  }
110  if (s->mb_x == v->end_mb_x - 1) {
111  for (i = 0; i < block_count; i++) {
112  if (i > 3 ? v->mb_type[0][s->block_index[i] - s->block_wrap[i]] :
113  v->mb_type[0][s->block_index[i] - 2 * s->block_wrap[i]]) {
114  dest = s->dest[0] + ((i & 2) - 4) * 4 * s->linesize + (i & 1) * 8;
115  if (put_signed)
116  s->idsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][block_map[i]],
117  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize : dest,
118  i > 3 ? s->uvlinesize : s->linesize);
119  else
120  s->idsp.put_pixels_clamped(v->block[v->top_blk_idx][block_map[i]],
121  i > 3 ? s->dest[i - 3] - 8 * s->uvlinesize : dest,
122  i > 3 ? s->uvlinesize : s->linesize);
123  }
124  }
125  }
126  }
127  if (s->mb_y == s->end_mb_y - 1 || v->fcm == ILACE_FRAME) {
128  if (s->mb_x) {
129  if (v->fcm == ILACE_FRAME)
130  fieldtx = v->fieldtx_plane[s->mb_y * s->mb_stride + s->mb_x - 1];
131  for (i = 0; i < block_count; i++) {
132  if (i > 3 ? v->mb_type[0][s->block_index[i] - 1] :
133  v->mb_type[0][s->block_index[i] - 2]) {
134  if (fieldtx)
135  dest = s->dest[0] + ((i & 2) >> 1) * s->linesize + ((i & 1) - 2) * 8;
136  else
137  dest = s->dest[0] + (i & 2) * 4 * s->linesize + ((i & 1) - 2) * 8;
138  if (put_signed)
139  s->idsp.put_signed_pixels_clamped(v->block[v->left_blk_idx][block_map[i]],
140  i > 3 ? s->dest[i - 3] - 8 : dest,
141  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
142  else
143  s->idsp.put_pixels_clamped(v->block[v->left_blk_idx][block_map[i]],
144  i > 3 ? s->dest[i - 3] - 8 : dest,
145  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
146  }
147  }
148  }
149  if (s->mb_x == v->end_mb_x - 1) {
150  if (v->fcm == ILACE_FRAME)
151  fieldtx = v->fieldtx_plane[s->mb_y * s->mb_stride + s->mb_x];
152  for (i = 0; i < block_count; i++) {
153  if (v->mb_type[0][s->block_index[i]]) {
154  if (fieldtx)
155  dest = s->dest[0] + ((i & 2) >> 1) * s->linesize + (i & 1) * 8;
156  else
157  dest = s->dest[0] + (i & 2) * 4 * s->linesize + (i & 1) * 8;
158  if (put_signed)
159  s->idsp.put_signed_pixels_clamped(v->block[v->cur_blk_idx][block_map[i]],
160  i > 3 ? s->dest[i - 3] : dest,
161  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
162  else
163  s->idsp.put_pixels_clamped(v->block[v->cur_blk_idx][block_map[i]],
164  i > 3 ? s->dest[i - 3] : dest,
165  i > 3 ? s->uvlinesize : s->linesize << fieldtx);
166  }
167  }
168  }
169  }
170 }
171 
172 #define inc_blk_idx(idx) do { \
173  idx++; \
174  if (idx >= v->n_allocated_blks) \
175  idx = 0; \
176  } while (0)
177 
178 /***********************************************************************/
179 /**
180  * @name VC-1 Block-level functions
181  * @see 7.1.4, p91 and 8.1.1.7, p(1)04
182  * @{
183  */
184 
185 /**
186  * @def GET_MQUANT
187  * @brief Get macroblock-level quantizer scale
188  */
189 #define GET_MQUANT() \
190  if (v->dquantfrm) { \
191  int edges = 0; \
192  if (v->dqprofile == DQPROFILE_ALL_MBS) { \
193  if (v->dqbilevel) { \
194  mquant = (get_bits1(gb)) ? -v->altpq : v->pq; \
195  } else { \
196  mqdiff = get_bits(gb, 3); \
197  if (mqdiff != 7) \
198  mquant = -v->pq - mqdiff; \
199  else \
200  mquant = -get_bits(gb, 5); \
201  } \
202  } \
203  if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
204  edges = 1 << v->dqsbedge; \
205  else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
206  edges = (3 << v->dqsbedge) % 15; \
207  else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
208  edges = 15; \
209  if ((edges&1) && !s->mb_x) \
210  mquant = -v->altpq; \
211  if ((edges&2) && !s->mb_y) \
212  mquant = -v->altpq; \
213  if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
214  mquant = -v->altpq; \
215  if ((edges&8) && \
216  s->mb_y == ((s->mb_height >> v->field_mode) - 1)) \
217  mquant = -v->altpq; \
218  if (!mquant || mquant > 31 || mquant < -31) { \
219  av_log(v->s.avctx, AV_LOG_ERROR, \
220  "Overriding invalid mquant %d\n", mquant); \
221  mquant = 1; \
222  } \
223  }
224 
225 /**
226  * @def GET_MVDATA(_dmv_x, _dmv_y)
227  * @brief Get MV differentials
228  * @see MVDATA decoding from 8.3.5.2, p(1)20
229  * @param _dmv_x Horizontal differential for decoded MV
230  * @param _dmv_y Vertical differential for decoded MV
231  */
232 #define GET_MVDATA(_dmv_x, _dmv_y) \
233  index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
234  VC1_MV_DIFF_VLC_BITS, 2); \
235  if (index > 36) { \
236  mb_has_coeffs = 1; \
237  index -= 37; \
238  } else \
239  mb_has_coeffs = 0; \
240  s->mb_intra = 0; \
241  if (!index) { \
242  _dmv_x = _dmv_y = 0; \
243  } else if (index == 35) { \
244  _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
245  _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
246  } else if (index == 36) { \
247  _dmv_x = 0; \
248  _dmv_y = 0; \
249  s->mb_intra = 1; \
250  } else { \
251  index1 = index % 6; \
252  _dmv_x = offset_table[1][index1]; \
253  val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
254  if (val > 0) { \
255  val = get_bits(gb, val); \
256  sign = 0 - (val & 1); \
257  _dmv_x = (sign ^ ((val >> 1) + _dmv_x)) - sign; \
258  } \
259  \
260  index1 = index / 6; \
261  _dmv_y = offset_table[1][index1]; \
262  val = size_table[index1] - (!s->quarter_sample && index1 == 5); \
263  if (val > 0) { \
264  val = get_bits(gb, val); \
265  sign = 0 - (val & 1); \
266  _dmv_y = (sign ^ ((val >> 1) + _dmv_y)) - sign; \
267  } \
268  }
269 
271  int *dmv_y, int *pred_flag)
272 {
273  int index, index1;
274  int extend_x, extend_y;
275  GetBitContext *gb = &v->s.gb;
276  int bits, esc;
277  int val, sign;
278 
279  if (v->numref) {
281  esc = 125;
282  } else {
284  esc = 71;
285  }
286  extend_x = v->dmvrange & 1;
287  extend_y = (v->dmvrange >> 1) & 1;
288  index = get_vlc2(gb, v->imv_vlc->table, bits, 3);
289  if (index == esc) {
290  *dmv_x = get_bits(gb, v->k_x);
291  *dmv_y = get_bits(gb, v->k_y);
292  if (v->numref) {
293  if (pred_flag)
294  *pred_flag = *dmv_y & 1;
295  *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1;
296  }
297  }
298  else {
299  av_assert0(index < esc);
300  index1 = (index + 1) % 9;
301  if (index1 != 0) {
302  val = get_bits(gb, index1 + extend_x);
303  sign = 0 - (val & 1);
304  *dmv_x = (sign ^ ((val >> 1) + offset_table[extend_x][index1])) - sign;
305  } else
306  *dmv_x = 0;
307  index1 = (index + 1) / 9;
308  if (index1 > v->numref) {
309  val = get_bits(gb, (index1 >> v->numref) + extend_y);
310  sign = 0 - (val & 1);
311  *dmv_y = (sign ^ ((val >> 1) + offset_table[extend_y][index1 >> v->numref])) - sign;
312  } else
313  *dmv_y = 0;
314  if (v->numref && pred_flag)
315  *pred_flag = index1 & 1;
316  }
317 }
318 
319 /** Reconstruct motion vector for B-frame and do motion compensation
320  */
321 static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2],
322  int direct, int mode)
323 {
324  if (direct) {
325  ff_vc1_mc_1mv(v, 0);
326  ff_vc1_interp_mc(v);
327  return;
328  }
329  if (mode == BMV_TYPE_INTERPOLATED) {
330  ff_vc1_mc_1mv(v, 0);
331  ff_vc1_interp_mc(v);
332  return;
333  }
334 
336 }
337 
338 /** Get predicted DC value for I-frames only
339  * prediction dir: left=0, top=1
340  * @param s MpegEncContext
341  * @param overlap flag indicating that overlap filtering is used
342  * @param pq integer part of picture quantizer
343  * @param[in] n block index in the current MB
344  * @param dc_val_ptr Pointer to DC predictor
345  * @param dir_ptr Prediction direction for use in AC prediction
346  */
347 static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
348  int16_t **dc_val_ptr, int *dir_ptr)
349 {
350  int a, b, c, wrap, pred, scale;
351  int16_t *dc_val;
352  static const uint16_t dcpred[32] = {
353  -1, 1024, 512, 341, 256, 205, 171, 146, 128,
354  114, 102, 93, 85, 79, 73, 68, 64,
355  60, 57, 54, 51, 49, 47, 45, 43,
356  41, 39, 38, 37, 35, 34, 33
357  };
358 
359  /* find prediction - wmv3_dc_scale always used here in fact */
360  if (n < 4) scale = s->y_dc_scale;
361  else scale = s->c_dc_scale;
362 
363  wrap = s->block_wrap[n];
364  dc_val = s->dc_val[0] + s->block_index[n];
365 
366  /* B A
367  * C X
368  */
369  c = dc_val[ - 1];
370  b = dc_val[ - 1 - wrap];
371  a = dc_val[ - wrap];
372 
373  if (pq < 9 || !overlap) {
374  /* Set outer values */
375  if (s->first_slice_line && (n != 2 && n != 3))
376  b = a = dcpred[scale];
377  if (s->mb_x == 0 && (n != 1 && n != 3))
378  b = c = dcpred[scale];
379  } else {
380  /* Set outer values */
381  if (s->first_slice_line && (n != 2 && n != 3))
382  b = a = 0;
383  if (s->mb_x == 0 && (n != 1 && n != 3))
384  b = c = 0;
385  }
386 
387  if (abs(a - b) <= abs(b - c)) {
388  pred = c;
389  *dir_ptr = 1; // left
390  } else {
391  pred = a;
392  *dir_ptr = 0; // top
393  }
394 
395  /* update predictor */
396  *dc_val_ptr = &dc_val[0];
397  return pred;
398 }
399 
400 
401 /** Get predicted DC value
402  * prediction dir: left=0, top=1
403  * @param s MpegEncContext
404  * @param overlap flag indicating that overlap filtering is used
405  * @param pq integer part of picture quantizer
406  * @param[in] n block index in the current MB
407  * @param a_avail flag indicating top block availability
408  * @param c_avail flag indicating left block availability
409  * @param dc_val_ptr Pointer to DC predictor
410  * @param dir_ptr Prediction direction for use in AC prediction
411  */
412 static inline int ff_vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
413  int a_avail, int c_avail,
414  int16_t **dc_val_ptr, int *dir_ptr)
415 {
416  int a, b, c, wrap, pred;
417  int16_t *dc_val;
418  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
419  int q1, q2 = 0;
420  int dqscale_index;
421 
422  /* scale predictors if needed */
423  q1 = FFABS(s->current_picture.qscale_table[mb_pos]);
424  dqscale_index = s->y_dc_scale_table[q1] - 1;
425  if (dqscale_index < 0)
426  return 0;
427 
428  wrap = s->block_wrap[n];
429  dc_val = s->dc_val[0] + s->block_index[n];
430 
431  /* B A
432  * C X
433  */
434  c = dc_val[ - 1];
435  b = dc_val[ - 1 - wrap];
436  a = dc_val[ - wrap];
437 
438  if (c_avail && (n != 1 && n != 3)) {
439  q2 = FFABS(s->current_picture.qscale_table[mb_pos - 1]);
440  if (q2 && q2 != q1)
441  c = (int)((unsigned)c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
442  }
443  if (a_avail && (n != 2 && n != 3)) {
444  q2 = FFABS(s->current_picture.qscale_table[mb_pos - s->mb_stride]);
445  if (q2 && q2 != q1)
446  a = (int)((unsigned)a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
447  }
448  if (a_avail && c_avail && (n != 3)) {
449  int off = mb_pos;
450  if (n != 1)
451  off--;
452  if (n != 2)
453  off -= s->mb_stride;
454  q2 = FFABS(s->current_picture.qscale_table[off]);
455  if (q2 && q2 != q1)
456  b = (int)((unsigned)b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
457  }
458 
459  if (c_avail && (!a_avail || abs(a - b) <= abs(b - c))) {
460  pred = c;
461  *dir_ptr = 1; // left
462  } else if (a_avail) {
463  pred = a;
464  *dir_ptr = 0; // top
465  } else {
466  pred = 0;
467  *dir_ptr = 1; // left
468  }
469 
470  /* update predictor */
471  *dc_val_ptr = &dc_val[0];
472  return pred;
473 }
474 
475 /** @} */ // Block group
476 
477 /**
478  * @name VC1 Macroblock-level functions in Simple/Main Profiles
479  * @see 7.1.4, p91 and 8.1.1.7, p(1)04
480  * @{
481  */
482 
483 static inline int vc1_coded_block_pred(MpegEncContext * s, int n,
484  uint8_t **coded_block_ptr)
485 {
486  int xy, wrap, pred, a, b, c;
487 
488  xy = s->block_index[n];
489  wrap = s->b8_stride;
490 
491  /* B C
492  * A X
493  */
494  a = s->coded_block[xy - 1 ];
495  b = s->coded_block[xy - 1 - wrap];
496  c = s->coded_block[xy - wrap];
497 
498  if (b == c) {
499  pred = a;
500  } else {
501  pred = c;
502  }
503 
504  /* store value */
505  *coded_block_ptr = &s->coded_block[xy];
506 
507  return pred;
508 }
509 
510 /**
511  * Decode one AC coefficient
512  * @param v The VC1 context
513  * @param last Last coefficient
514  * @param skip How much zero coefficients to skip
515  * @param value Decoded AC coefficient value
516  * @param codingset set of VLC to decode data
517  * @see 8.1.3.4
518  */
519 static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
520  int *value, int codingset)
521 {
522  GetBitContext *gb = &v->s.gb;
523  int index, run, level, lst, sign;
524 
525  index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
526  if (index < 0)
527  return index;
528  if (index != ff_vc1_ac_sizes[codingset] - 1) {
529  run = vc1_index_decode_table[codingset][index][0];
530  level = vc1_index_decode_table[codingset][index][1];
531  lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;
532  sign = get_bits1(gb);
533  } else {
534  int escape = decode210(gb);
535  if (escape != 2) {
536  index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
537  if (index >= ff_vc1_ac_sizes[codingset] - 1U)
538  return AVERROR_INVALIDDATA;
539  run = vc1_index_decode_table[codingset][index][0];
540  level = vc1_index_decode_table[codingset][index][1];
541  lst = index >= vc1_last_decode_table[codingset];
542  if (escape == 0) {
543  if (lst)
544  level += vc1_last_delta_level_table[codingset][run];
545  else
546  level += vc1_delta_level_table[codingset][run];
547  } else {
548  if (lst)
549  run += vc1_last_delta_run_table[codingset][level] + 1;
550  else
551  run += vc1_delta_run_table[codingset][level] + 1;
552  }
553  sign = get_bits1(gb);
554  } else {
555  lst = get_bits1(gb);
556  if (v->s.esc3_level_length == 0) {
557  if (v->pq < 8 || v->dquantfrm) { // table 59
558  v->s.esc3_level_length = get_bits(gb, 3);
559  if (!v->s.esc3_level_length)
560  v->s.esc3_level_length = get_bits(gb, 2) + 8;
561  } else { // table 60
562  v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
563  }
564  v->s.esc3_run_length = 3 + get_bits(gb, 2);
565  }
566  run = get_bits(gb, v->s.esc3_run_length);
567  sign = get_bits1(gb);
568  level = get_bits(gb, v->s.esc3_level_length);
569  }
570  }
571 
572  *last = lst;
573  *skip = run;
574  *value = (level ^ -sign) + sign;
575 
576  return 0;
577 }
578 
579 /** Decode intra block in intra frames - should be faster than decode_intra_block
580  * @param v VC1Context
581  * @param block block to decode
582  * @param[in] n subblock index
583  * @param coded are AC coeffs present or not
584  * @param codingset set of VLC to decode data
585  */
586 static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
587  int coded, int codingset)
588 {
589  GetBitContext *gb = &v->s.gb;
590  MpegEncContext *s = &v->s;
591  int dc_pred_dir = 0; /* Direction of the DC prediction used */
592  int i;
593  int16_t *dc_val;
594  int16_t *ac_val, *ac_val2;
595  int dcdiff, scale;
596 
597  /* Get DC differential */
598  if (n < 4) {
599  dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
600  } else {
601  dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
602  }
603  if (dcdiff) {
604  const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0;
605  if (dcdiff == 119 /* ESC index value */) {
606  dcdiff = get_bits(gb, 8 + m);
607  } else {
608  if (m)
609  dcdiff = (dcdiff << m) + get_bits(gb, m) - ((1 << m) - 1);
610  }
611  if (get_bits1(gb))
612  dcdiff = -dcdiff;
613  }
614 
615  /* Prediction */
616  dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
617  *dc_val = dcdiff;
618 
619  /* Store the quantized DC coeff, used for prediction */
620  if (n < 4)
621  scale = s->y_dc_scale;
622  else
623  scale = s->c_dc_scale;
624  block[0] = dcdiff * scale;
625 
626  ac_val = s->ac_val[0][s->block_index[n]];
627  ac_val2 = ac_val;
628  if (dc_pred_dir) // left
629  ac_val -= 16;
630  else // top
631  ac_val -= 16 * s->block_wrap[n];
632 
633  scale = v->pq * 2 + v->halfpq;
634 
635  //AC Decoding
636  i = !!coded;
637 
638  if (coded) {
639  int last = 0, skip, value;
640  const uint8_t *zz_table;
641  int k;
642 
643  if (v->s.ac_pred) {
644  if (!dc_pred_dir)
645  zz_table = v->zz_8x8[2];
646  else
647  zz_table = v->zz_8x8[3];
648  } else
649  zz_table = v->zz_8x8[1];
650 
651  while (!last) {
652  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
653  if (ret < 0)
654  return ret;
655  i += skip;
656  if (i > 63)
657  break;
658  block[zz_table[i++]] = value;
659  }
660 
661  /* apply AC prediction if needed */
662  if (s->ac_pred) {
663  int sh;
664  if (dc_pred_dir) { // left
665  sh = v->left_blk_sh;
666  } else { // top
667  sh = v->top_blk_sh;
668  ac_val += 8;
669  }
670  for (k = 1; k < 8; k++)
671  block[k << sh] += ac_val[k];
672  }
673  /* save AC coeffs for further prediction */
674  for (k = 1; k < 8; k++) {
675  ac_val2[k] = block[k << v->left_blk_sh];
676  ac_val2[k + 8] = block[k << v->top_blk_sh];
677  }
678 
679  /* scale AC coeffs */
680  for (k = 1; k < 64; k++)
681  if (block[k]) {
682  block[k] *= scale;
683  if (!v->pquantizer)
684  block[k] += (block[k] < 0) ? -v->pq : v->pq;
685  }
686 
687  } else {
688  int k;
689 
690  memset(ac_val2, 0, 16 * 2);
691 
692  /* apply AC prediction if needed */
693  if (s->ac_pred) {
694  int sh;
695  if (dc_pred_dir) { //left
696  sh = v->left_blk_sh;
697  } else { // top
698  sh = v->top_blk_sh;
699  ac_val += 8;
700  ac_val2 += 8;
701  }
702  memcpy(ac_val2, ac_val, 8 * 2);
703  for (k = 1; k < 8; k++) {
704  block[k << sh] = ac_val[k] * scale;
705  if (!v->pquantizer && block[k << sh])
706  block[k << sh] += (block[k << sh] < 0) ? -v->pq : v->pq;
707  }
708  }
709  }
710  if (s->ac_pred) i = 63;
711  s->block_last_index[n] = i;
712 
713  return 0;
714 }
715 
716 /** Decode intra block in intra frames - should be faster than decode_intra_block
717  * @param v VC1Context
718  * @param block block to decode
719  * @param[in] n subblock number
720  * @param coded are AC coeffs present or not
721  * @param codingset set of VLC to decode data
722  * @param mquant quantizer value for this macroblock
723  */
724 static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
725  int coded, int codingset, int mquant)
726 {
727  GetBitContext *gb = &v->s.gb;
728  MpegEncContext *s = &v->s;
729  int dc_pred_dir = 0; /* Direction of the DC prediction used */
730  int i;
731  int16_t *dc_val = NULL;
732  int16_t *ac_val, *ac_val2;
733  int dcdiff;
734  int a_avail = v->a_avail, c_avail = v->c_avail;
735  int use_pred = s->ac_pred;
736  int scale;
737  int q1, q2 = 0;
738  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
739  int quant = FFABS(mquant);
740 
741  /* Get DC differential */
742  if (n < 4) {
743  dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
744  } else {
745  dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
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] += (int)(ac_val[k] * (unsigned)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] = (int)(ac_val2[k] * q2 * (unsigned)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 */
938  s->y_dc_scale = s->y_dc_scale_table[quant];
939  s->c_dc_scale = s->c_dc_scale_table[quant];
940 
941  /* Get DC differential */
942  if (n < 4) {
943  dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
944  } else {
945  dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
946  }
947  if (dcdiff) {
948  const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
949  if (dcdiff == 119 /* ESC index value */) {
950  dcdiff = get_bits(gb, 8 + m);
951  } else {
952  if (m)
953  dcdiff = (dcdiff << m) + get_bits(gb, m) - ((1 << m) - 1);
954  }
955  if (get_bits1(gb))
956  dcdiff = -dcdiff;
957  }
958 
959  /* Prediction */
960  dcdiff += ff_vc1_pred_dc(&v->s, v->overlap, quant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
961  *dc_val = dcdiff;
962 
963  /* Store the quantized DC coeff, used for prediction */
964 
965  if (n < 4) {
966  block[0] = dcdiff * s->y_dc_scale;
967  } else {
968  block[0] = dcdiff * s->c_dc_scale;
969  }
970 
971  //AC Decoding
972  i = 1;
973 
974  /* check if AC is needed at all and adjust direction if needed */
975  if (!a_avail) dc_pred_dir = 1;
976  if (!c_avail) dc_pred_dir = 0;
977  if (!a_avail && !c_avail) use_pred = 0;
978  ac_val = s->ac_val[0][s->block_index[n]];
979  ac_val2 = ac_val;
980 
981  scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
982 
983  if (dc_pred_dir) //left
984  ac_val -= 16;
985  else //top
986  ac_val -= 16 * s->block_wrap[n];
987 
988  q1 = s->current_picture.qscale_table[mb_pos];
989  if (dc_pred_dir && c_avail && mb_pos)
990  q2 = s->current_picture.qscale_table[mb_pos - 1];
991  if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)
992  q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
993  if (dc_pred_dir && n == 1)
994  q2 = q1;
995  if (!dc_pred_dir && n == 2)
996  q2 = q1;
997  if (n == 3) q2 = q1;
998 
999  if (coded) {
1000  int last = 0, skip, value;
1001  int k;
1002 
1003  while (!last) {
1004  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
1005  if (ret < 0)
1006  return ret;
1007  i += skip;
1008  if (i > 63)
1009  break;
1010  if (v->fcm == PROGRESSIVE)
1011  block[v->zz_8x8[0][i++]] = value;
1012  else {
1013  if (use_pred && (v->fcm == ILACE_FRAME)) {
1014  if (!dc_pred_dir) // top
1015  block[v->zz_8x8[2][i++]] = value;
1016  else // left
1017  block[v->zz_8x8[3][i++]] = value;
1018  } else {
1019  block[v->zzi_8x8[i++]] = value;
1020  }
1021  }
1022  }
1023 
1024  /* apply AC prediction if needed */
1025  if (use_pred) {
1026  /* scale predictors if needed*/
1027  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
1028  if (q1 < 1)
1029  return AVERROR_INVALIDDATA;
1030  if (q2)
1031  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
1032  if (q2 && q1 != q2) {
1033  if (dc_pred_dir) { // left
1034  for (k = 1; k < 8; k++)
1035  block[k << v->left_blk_sh] += (int)(ac_val[k] * q2 * (unsigned)ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1036  } else { //top
1037  for (k = 1; k < 8; k++)
1038  block[k << v->top_blk_sh] += (int)(ac_val[k + 8] * q2 * (unsigned)ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1039  }
1040  } else {
1041  if (dc_pred_dir) { // left
1042  for (k = 1; k < 8; k++)
1043  block[k << v->left_blk_sh] += ac_val[k];
1044  } else { // top
1045  for (k = 1; k < 8; k++)
1046  block[k << v->top_blk_sh] += ac_val[k + 8];
1047  }
1048  }
1049  }
1050  /* save AC coeffs for further prediction */
1051  for (k = 1; k < 8; k++) {
1052  ac_val2[k ] = block[k << v->left_blk_sh];
1053  ac_val2[k + 8] = block[k << v->top_blk_sh];
1054  }
1055 
1056  /* scale AC coeffs */
1057  for (k = 1; k < 64; k++)
1058  if (block[k]) {
1059  block[k] *= scale;
1060  if (!v->pquantizer)
1061  block[k] += (block[k] < 0) ? -quant : quant;
1062  }
1063 
1064  if (use_pred) i = 63;
1065  } else { // no AC coeffs
1066  int k;
1067 
1068  memset(ac_val2, 0, 16 * 2);
1069  if (dc_pred_dir) { // left
1070  if (use_pred) {
1071  memcpy(ac_val2, ac_val, 8 * 2);
1072  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
1073  if (q1 < 1)
1074  return AVERROR_INVALIDDATA;
1075  if (q2)
1076  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
1077  if (q2 && q1 != q2) {
1078  for (k = 1; k < 8; k++)
1079  ac_val2[k] = (int)(ac_val2[k] * (unsigned)q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1080  }
1081  }
1082  } else { // top
1083  if (use_pred) {
1084  memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
1085  q1 = FFABS(q1) * 2 + ((q1 < 0) ? 0 : v->halfpq) - 1;
1086  if (q1 < 1)
1087  return AVERROR_INVALIDDATA;
1088  if (q2)
1089  q2 = FFABS(q2) * 2 + ((q2 < 0) ? 0 : v->halfpq) - 1;
1090  if (q2 && q1 != q2) {
1091  for (k = 1; k < 8; k++)
1092  ac_val2[k + 8] = (int)(ac_val2[k + 8] * (unsigned)q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
1093  }
1094  }
1095  }
1096 
1097  /* apply AC prediction if needed */
1098  if (use_pred) {
1099  if (dc_pred_dir) { // left
1100  for (k = 1; k < 8; k++) {
1101  block[k << v->left_blk_sh] = ac_val2[k] * scale;
1102  if (!v->pquantizer && block[k << v->left_blk_sh])
1103  block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -quant : quant;
1104  }
1105  } else { // top
1106  for (k = 1; k < 8; k++) {
1107  block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
1108  if (!v->pquantizer && block[k << v->top_blk_sh])
1109  block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -quant : quant;
1110  }
1111  }
1112  i = 63;
1113  }
1114  }
1115  s->block_last_index[n] = i;
1116 
1117  return 0;
1118 }
1119 
1120 /** Decode P block
1121  */
1122 static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
1123  int mquant, int ttmb, int first_block,
1124  uint8_t *dst, int linesize, int skip_block,
1125  int *ttmb_out)
1126 {
1127  MpegEncContext *s = &v->s;
1128  GetBitContext *gb = &s->gb;
1129  int i, j;
1130  int subblkpat = 0;
1131  int scale, off, idx, last, skip, value;
1132  int ttblk = ttmb & 7;
1133  int pat = 0;
1134  int quant = FFABS(mquant);
1135 
1136  s->bdsp.clear_block(block);
1137 
1138  if (ttmb == -1) {
1140  }
1141  if (ttblk == TT_4X4) {
1142  subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
1143  }
1144  if ((ttblk != TT_8X8 && ttblk != TT_4X4)
1145  && ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
1146  || (!v->res_rtm_flag && !first_block))) {
1147  subblkpat = decode012(gb);
1148  if (subblkpat)
1149  subblkpat ^= 3; // swap decoded pattern bits
1150  if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM)
1151  ttblk = TT_8X4;
1152  if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT)
1153  ttblk = TT_4X8;
1154  }
1155  scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
1156 
1157  // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
1158  if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
1159  subblkpat = 2 - (ttblk == TT_8X4_TOP);
1160  ttblk = TT_8X4;
1161  }
1162  if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
1163  subblkpat = 2 - (ttblk == TT_4X8_LEFT);
1164  ttblk = TT_4X8;
1165  }
1166  switch (ttblk) {
1167  case TT_8X8:
1168  pat = 0xF;
1169  i = 0;
1170  last = 0;
1171  while (!last) {
1172  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1173  if (ret < 0)
1174  return ret;
1175  i += skip;
1176  if (i > 63)
1177  break;
1178  if (!v->fcm)
1179  idx = v->zz_8x8[0][i++];
1180  else
1181  idx = v->zzi_8x8[i++];
1182  block[idx] = value * scale;
1183  if (!v->pquantizer)
1184  block[idx] += (block[idx] < 0) ? -quant : quant;
1185  }
1186  if (!skip_block) {
1187  if (i == 1)
1188  v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block);
1189  else {
1191  s->idsp.add_pixels_clamped(block, dst, linesize);
1192  }
1193  }
1194  break;
1195  case TT_4X4:
1196  pat = ~subblkpat & 0xF;
1197  for (j = 0; j < 4; j++) {
1198  last = subblkpat & (1 << (3 - j));
1199  i = 0;
1200  off = (j & 1) * 4 + (j & 2) * 16;
1201  while (!last) {
1202  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1203  if (ret < 0)
1204  return ret;
1205  i += skip;
1206  if (i > 15)
1207  break;
1208  if (!v->fcm)
1210  else
1212  block[idx + off] = value * scale;
1213  if (!v->pquantizer)
1214  block[idx + off] += (block[idx + off] < 0) ? -quant : quant;
1215  }
1216  if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
1217  if (i == 1)
1218  v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
1219  else
1220  v->vc1dsp.vc1_inv_trans_4x4(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
1221  }
1222  }
1223  break;
1224  case TT_8X4:
1225  pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
1226  for (j = 0; j < 2; j++) {
1227  last = subblkpat & (1 << (1 - j));
1228  i = 0;
1229  off = j * 32;
1230  while (!last) {
1231  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1232  if (ret < 0)
1233  return ret;
1234  i += skip;
1235  if (i > 31)
1236  break;
1237  if (!v->fcm)
1238  idx = v->zz_8x4[i++] + off;
1239  else
1240  idx = ff_vc1_adv_interlaced_8x4_zz[i++] + off;
1241  block[idx] = value * scale;
1242  if (!v->pquantizer)
1243  block[idx] += (block[idx] < 0) ? -quant : quant;
1244  }
1245  if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1246  if (i == 1)
1247  v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j * 4 * linesize, linesize, block + off);
1248  else
1249  v->vc1dsp.vc1_inv_trans_8x4(dst + j * 4 * linesize, linesize, block + off);
1250  }
1251  }
1252  break;
1253  case TT_4X8:
1254  pat = ~(subblkpat * 5) & 0xF;
1255  for (j = 0; j < 2; j++) {
1256  last = subblkpat & (1 << (1 - j));
1257  i = 0;
1258  off = j * 4;
1259  while (!last) {
1260  int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
1261  if (ret < 0)
1262  return ret;
1263  i += skip;
1264  if (i > 31)
1265  break;
1266  if (!v->fcm)
1267  idx = v->zz_4x8[i++] + off;
1268  else
1269  idx = ff_vc1_adv_interlaced_4x8_zz[i++] + off;
1270  block[idx] = value * scale;
1271  if (!v->pquantizer)
1272  block[idx] += (block[idx] < 0) ? -quant : quant;
1273  }
1274  if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
1275  if (i == 1)
1276  v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j * 4, linesize, block + off);
1277  else
1278  v->vc1dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off);
1279  }
1280  }
1281  break;
1282  }
1283  if (ttmb_out)
1284  *ttmb_out |= ttblk << (n * 4);
1285  return pat;
1286 }
1287 
1288 /** @} */ // Macroblock group
1289 
1290 static const uint8_t size_table[6] = { 0, 2, 3, 4, 5, 8 };
1291 
1292 /** Decode one P-frame MB
1293  */
1295 {
1296  MpegEncContext *s = &v->s;
1297  GetBitContext *gb = &s->gb;
1298  int i, j;
1299  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1300  int cbp; /* cbp decoding stuff */
1301  int mqdiff, mquant; /* MB quantization */
1302  int ttmb = v->ttfrm; /* MB Transform type */
1303 
1304  int mb_has_coeffs = 1; /* last_flag */
1305  int dmv_x, dmv_y; /* Differential MV components */
1306  int index, index1; /* LUT indexes */
1307  int val, sign; /* temp values */
1308  int first_block = 1;
1309  int dst_idx, off;
1310  int skipped, fourmv;
1311  int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
1312 
1313  mquant = v->pq; /* lossy initialization */
1314 
1315  if (v->mv_type_is_raw)
1316  fourmv = get_bits1(gb);
1317  else
1318  fourmv = v->mv_type_mb_plane[mb_pos];
1319  if (v->skip_is_raw)
1320  skipped = get_bits1(gb);
1321  else
1322  skipped = v->s.mbskip_table[mb_pos];
1323 
1324  if (!fourmv) { /* 1MV mode */
1325  if (!skipped) {
1326  GET_MVDATA(dmv_x, dmv_y);
1327 
1328  if (s->mb_intra) {
1329  s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
1330  s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
1331  }
1332  s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
1333  ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1334 
1335  /* FIXME Set DC val for inter block ? */
1336  if (s->mb_intra && !mb_has_coeffs) {
1337  GET_MQUANT();
1338  s->ac_pred = get_bits1(gb);
1339  cbp = 0;
1340  } else if (mb_has_coeffs) {
1341  if (s->mb_intra)
1342  s->ac_pred = get_bits1(gb);
1343  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1344  GET_MQUANT();
1345  } else {
1346  mquant = v->pq;
1347  cbp = 0;
1348  }
1349  s->current_picture.qscale_table[mb_pos] = mquant;
1350 
1351  if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
1352  ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
1353  VC1_TTMB_VLC_BITS, 2);
1354  if (!s->mb_intra) ff_vc1_mc_1mv(v, 0);
1355  dst_idx = 0;
1356  for (i = 0; i < 6; i++) {
1357  s->dc_val[0][s->block_index[i]] = 0;
1358  dst_idx += i >> 2;
1359  val = ((cbp >> (5 - i)) & 1);
1360  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1361  v->mb_type[0][s->block_index[i]] = s->mb_intra;
1362  if (s->mb_intra) {
1363  /* check if prediction blocks A and C are available */
1364  v->a_avail = v->c_avail = 0;
1365  if (i == 2 || i == 3 || !s->first_slice_line)
1366  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1367  if (i == 1 || i == 3 || s->mb_x)
1368  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1369 
1370  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
1371  (i & 4) ? v->codingset2 : v->codingset);
1372  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1373  continue;
1375  if (v->rangeredfrm)
1376  for (j = 0; j < 64; j++)
1377  v->block[v->cur_blk_idx][block_map[i]][j] *= 2;
1378  block_cbp |= 0xF << (i << 2);
1379  block_intra |= 1 << i;
1380  } else if (val) {
1381  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb, first_block,
1382  s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,
1383  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
1384  if (pat < 0)
1385  return pat;
1386  block_cbp |= pat << (i << 2);
1387  if (!v->ttmbf && ttmb < 8)
1388  ttmb = -1;
1389  first_block = 0;
1390  }
1391  }
1392  } else { // skipped
1393  s->mb_intra = 0;
1394  for (i = 0; i < 6; i++) {
1395  v->mb_type[0][s->block_index[i]] = 0;
1396  s->dc_val[0][s->block_index[i]] = 0;
1397  }
1398  s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
1399  s->current_picture.qscale_table[mb_pos] = 0;
1400  ff_vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1401  ff_vc1_mc_1mv(v, 0);
1402  }
1403  } else { // 4MV mode
1404  if (!skipped /* unskipped MB */) {
1405  int intra_count = 0, coded_inter = 0;
1406  int is_intra[6], is_coded[6];
1407  /* Get CBPCY */
1408  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1409  for (i = 0; i < 6; i++) {
1410  val = ((cbp >> (5 - i)) & 1);
1411  s->dc_val[0][s->block_index[i]] = 0;
1412  s->mb_intra = 0;
1413  if (i < 4) {
1414  dmv_x = dmv_y = 0;
1415  s->mb_intra = 0;
1416  mb_has_coeffs = 0;
1417  if (val) {
1418  GET_MVDATA(dmv_x, dmv_y);
1419  }
1420  ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
1421  if (!s->mb_intra)
1422  ff_vc1_mc_4mv_luma(v, i, 0, 0);
1423  intra_count += s->mb_intra;
1424  is_intra[i] = s->mb_intra;
1425  is_coded[i] = mb_has_coeffs;
1426  }
1427  if (i & 4) {
1428  is_intra[i] = (intra_count >= 3);
1429  is_coded[i] = val;
1430  }
1431  if (i == 4)
1432  ff_vc1_mc_4mv_chroma(v, 0);
1433  v->mb_type[0][s->block_index[i]] = is_intra[i];
1434  if (!coded_inter)
1435  coded_inter = !is_intra[i] & is_coded[i];
1436  }
1437  // if there are no coded blocks then don't do anything more
1438  dst_idx = 0;
1439  if (!intra_count && !coded_inter)
1440  goto end;
1441  GET_MQUANT();
1442  s->current_picture.qscale_table[mb_pos] = mquant;
1443  /* test if block is intra and has pred */
1444  {
1445  int intrapred = 0;
1446  for (i = 0; i < 6; i++)
1447  if (is_intra[i]) {
1448  if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
1449  || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {
1450  intrapred = 1;
1451  break;
1452  }
1453  }
1454  if (intrapred)
1455  s->ac_pred = get_bits1(gb);
1456  else
1457  s->ac_pred = 0;
1458  }
1459  if (!v->ttmbf && coded_inter)
1461  for (i = 0; i < 6; i++) {
1462  dst_idx += i >> 2;
1463  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1464  s->mb_intra = is_intra[i];
1465  if (is_intra[i]) {
1466  /* check if prediction blocks A and C are available */
1467  v->a_avail = v->c_avail = 0;
1468  if (i == 2 || i == 3 || !s->first_slice_line)
1469  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1470  if (i == 1 || i == 3 || s->mb_x)
1471  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1472 
1473  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, is_coded[i], mquant,
1474  (i & 4) ? v->codingset2 : v->codingset);
1475  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1476  continue;
1478  if (v->rangeredfrm)
1479  for (j = 0; j < 64; j++)
1480  v->block[v->cur_blk_idx][block_map[i]][j] *= 2;
1481  block_cbp |= 0xF << (i << 2);
1482  block_intra |= 1 << i;
1483  } else if (is_coded[i]) {
1484  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb,
1485  first_block, s->dest[dst_idx] + off,
1486  (i & 4) ? s->uvlinesize : s->linesize,
1487  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY),
1488  &block_tt);
1489  if (pat < 0)
1490  return pat;
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, 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, 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, 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, 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  if (pat < 0)
1702  return pat;
1703  block_cbp |= pat << (i << 2);
1704  if (!v->ttmbf && ttmb < 8)
1705  ttmb = -1;
1706  first_block = 0;
1707  }
1708  }
1709  }
1710  } else { // skipped
1711  s->mb_intra = v->is_intra[s->mb_x] = 0;
1712  for (i = 0; i < 6; i++) {
1713  v->mb_type[0][s->block_index[i]] = 0;
1714  s->dc_val[0][s->block_index[i]] = 0;
1715  }
1716  s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
1717  s->current_picture.qscale_table[mb_pos] = 0;
1718  v->blk_mv_type[s->block_index[0]] = 0;
1719  v->blk_mv_type[s->block_index[1]] = 0;
1720  v->blk_mv_type[s->block_index[2]] = 0;
1721  v->blk_mv_type[s->block_index[3]] = 0;
1722  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, 0);
1723  ff_vc1_mc_1mv(v, 0);
1724  v->fieldtx_plane[mb_pos] = 0;
1725  }
1726  if (v->overlap && v->pq >= 9)
1728  vc1_put_blocks_clamped(v, 1);
1729 
1730  v->cbp[s->mb_x] = block_cbp;
1731  v->ttblk[s->mb_x] = block_tt;
1732 
1733  return 0;
1734 }
1735 
1737 {
1738  MpegEncContext *s = &v->s;
1739  GetBitContext *gb = &s->gb;
1740  int i;
1741  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1742  int cbp = 0; /* cbp decoding stuff */
1743  int mqdiff, mquant; /* MB quantization */
1744  int ttmb = v->ttfrm; /* MB Transform type */
1745 
1746  int mb_has_coeffs = 1; /* last_flag */
1747  int dmv_x, dmv_y; /* Differential MV components */
1748  int val; /* temp values */
1749  int first_block = 1;
1750  int dst_idx, off;
1751  int pred_flag = 0;
1752  int block_cbp = 0, pat, block_tt = 0;
1753  int idx_mbmode = 0;
1754 
1755  mquant = v->pq; /* Lossy initialization */
1756 
1757  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
1758  if (idx_mbmode <= 1) { // intra MB
1759  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
1760  s->mb_intra = 1;
1761  s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
1762  s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
1763  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
1764  GET_MQUANT();
1765  s->current_picture.qscale_table[mb_pos] = mquant;
1766  /* Set DC scale - y and c use the same (not sure if necessary here) */
1767  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
1768  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
1769  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
1770  mb_has_coeffs = idx_mbmode & 1;
1771  if (mb_has_coeffs)
1772  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
1773  dst_idx = 0;
1774  for (i = 0; i < 6; i++) {
1775  v->a_avail = v->c_avail = 0;
1776  v->mb_type[0][s->block_index[i]] = 1;
1777  s->dc_val[0][s->block_index[i]] = 0;
1778  dst_idx += i >> 2;
1779  val = ((cbp >> (5 - i)) & 1);
1780  if (i == 2 || i == 3 || !s->first_slice_line)
1781  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1782  if (i == 1 || i == 3 || s->mb_x)
1783  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1784 
1785  vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
1786  (i & 4) ? v->codingset2 : v->codingset);
1787  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1788  continue;
1790  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1791  block_cbp |= 0xf << (i << 2);
1792  }
1793  } else {
1794  s->mb_intra = v->is_intra[s->mb_x] = 0;
1795  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
1796  for (i = 0; i < 6; i++)
1797  v->mb_type[0][s->block_index[i]] = 0;
1798  if (idx_mbmode <= 5) { // 1-MV
1799  dmv_x = dmv_y = pred_flag = 0;
1800  if (idx_mbmode & 1) {
1801  get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
1802  }
1803  ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
1804  ff_vc1_mc_1mv(v, 0);
1805  mb_has_coeffs = !(idx_mbmode & 2);
1806  } else { // 4-MV
1808  for (i = 0; i < 4; i++) {
1809  dmv_x = dmv_y = pred_flag = 0;
1810  if (v->fourmvbp & (8 >> i))
1811  get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
1812  ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
1813  ff_vc1_mc_4mv_luma(v, i, 0, 0);
1814  }
1815  ff_vc1_mc_4mv_chroma(v, 0);
1816  mb_has_coeffs = idx_mbmode & 1;
1817  }
1818  if (mb_has_coeffs)
1819  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1820  if (cbp) {
1821  GET_MQUANT();
1822  }
1823  s->current_picture.qscale_table[mb_pos] = mquant;
1824  if (!v->ttmbf && cbp) {
1826  }
1827  dst_idx = 0;
1828  for (i = 0; i < 6; i++) {
1829  s->dc_val[0][s->block_index[i]] = 0;
1830  dst_idx += i >> 2;
1831  val = ((cbp >> (5 - i)) & 1);
1832  off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
1833  if (val) {
1834  pat = vc1_decode_p_block(v, v->block[v->cur_blk_idx][block_map[i]], i, mquant, ttmb,
1835  first_block, s->dest[dst_idx] + off,
1836  (i & 4) ? s->uvlinesize : s->linesize,
1837  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY),
1838  &block_tt);
1839  if (pat < 0)
1840  return pat;
1841  block_cbp |= pat << (i << 2);
1842  if (!v->ttmbf && ttmb < 8)
1843  ttmb = -1;
1844  first_block = 0;
1845  }
1846  }
1847  }
1848  if (v->overlap && v->pq >= 9)
1850  vc1_put_blocks_clamped(v, 1);
1851 
1852  v->cbp[s->mb_x] = block_cbp;
1853  v->ttblk[s->mb_x] = block_tt;
1854 
1855  return 0;
1856 }
1857 
1858 /** Decode one B-frame MB (in Main profile)
1859  */
1861 {
1862  MpegEncContext *s = &v->s;
1863  GetBitContext *gb = &s->gb;
1864  int i, j;
1865  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1866  int cbp = 0; /* cbp decoding stuff */
1867  int mqdiff, mquant; /* MB quantization */
1868  int ttmb = v->ttfrm; /* MB Transform type */
1869  int mb_has_coeffs = 0; /* last_flag */
1870  int index, index1; /* LUT indexes */
1871  int val, sign; /* temp values */
1872  int first_block = 1;
1873  int dst_idx, off;
1874  int skipped, direct;
1875  int dmv_x[2], dmv_y[2];
1876  int bmvtype = BMV_TYPE_BACKWARD;
1877 
1878  mquant = v->pq; /* lossy initialization */
1879  s->mb_intra = 0;
1880 
1881  if (v->dmb_is_raw)
1882  direct = get_bits1(gb);
1883  else
1884  direct = v->direct_mb_plane[mb_pos];
1885  if (v->skip_is_raw)
1886  skipped = get_bits1(gb);
1887  else
1888  skipped = v->s.mbskip_table[mb_pos];
1889 
1890  dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
1891  for (i = 0; i < 6; i++) {
1892  v->mb_type[0][s->block_index[i]] = 0;
1893  s->dc_val[0][s->block_index[i]] = 0;
1894  }
1895  s->current_picture.qscale_table[mb_pos] = 0;
1896 
1897  if (!direct) {
1898  if (!skipped) {
1899  GET_MVDATA(dmv_x[0], dmv_y[0]);
1900  dmv_x[1] = dmv_x[0];
1901  dmv_y[1] = dmv_y[0];
1902  }
1903  if (skipped || !s->mb_intra) {
1904  bmvtype = decode012(gb);
1905  switch (bmvtype) {
1906  case 0:
1907  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
1908  break;
1909  case 1:
1910  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
1911  break;
1912  case 2:
1913  bmvtype = BMV_TYPE_INTERPOLATED;
1914  dmv_x[0] = dmv_y[0] = 0;
1915  }
1916  }
1917  }
1918  for (i = 0; i < 6; i++)
1919  v->mb_type[0][s->block_index[i]] = s->mb_intra;
1920 
1921  if (skipped) {
1922  if (direct)
1923  bmvtype = BMV_TYPE_INTERPOLATED;
1924  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1925  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1926  return 0;
1927  }
1928  if (direct) {
1929  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1930  GET_MQUANT();
1931  s->mb_intra = 0;
1932  s->current_picture.qscale_table[mb_pos] = mquant;
1933  if (!v->ttmbf)
1935  dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
1936  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1937  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1938  } else {
1939  if (!mb_has_coeffs && !s->mb_intra) {
1940  /* no coded blocks - effectively skipped */
1941  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1942  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1943  return 0;
1944  }
1945  if (s->mb_intra && !mb_has_coeffs) {
1946  GET_MQUANT();
1947  s->current_picture.qscale_table[mb_pos] = mquant;
1948  s->ac_pred = get_bits1(gb);
1949  cbp = 0;
1950  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1951  } else {
1952  if (bmvtype == BMV_TYPE_INTERPOLATED) {
1953  GET_MVDATA(dmv_x[0], dmv_y[0]);
1954  if (!mb_has_coeffs) {
1955  /* interpolated skipped block */
1956  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1957  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1958  return 0;
1959  }
1960  }
1961  ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
1962  if (!s->mb_intra) {
1963  vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
1964  }
1965  if (s->mb_intra)
1966  s->ac_pred = get_bits1(gb);
1967  cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
1968  GET_MQUANT();
1969  s->current_picture.qscale_table[mb_pos] = mquant;
1970  if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
1972  }
1973  }
1974  dst_idx = 0;
1975  for (i = 0; i < 6; i++) {
1976  s->dc_val[0][s->block_index[i]] = 0;
1977  dst_idx += i >> 2;
1978  val = ((cbp >> (5 - i)) & 1);
1979  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
1980  v->mb_type[0][s->block_index[i]] = s->mb_intra;
1981  if (s->mb_intra) {
1982  /* check if prediction blocks A and C are available */
1983  v->a_avail = v->c_avail = 0;
1984  if (i == 2 || i == 3 || !s->first_slice_line)
1985  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
1986  if (i == 1 || i == 3 || s->mb_x)
1987  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
1988 
1989  vc1_decode_intra_block(v, s->block[i], i, val, mquant,
1990  (i & 4) ? v->codingset2 : v->codingset);
1991  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
1992  continue;
1993  v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
1994  if (v->rangeredfrm)
1995  for (j = 0; j < 64; j++)
1996  s->block[i][j] *= 2;
1997  s->idsp.put_signed_pixels_clamped(s->block[i],
1998  s->dest[dst_idx] + off,
1999  i & 4 ? s->uvlinesize
2000  : s->linesize);
2001  } else if (val) {
2002  int pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
2003  first_block, s->dest[dst_idx] + off,
2004  (i & 4) ? s->uvlinesize : s->linesize,
2005  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), NULL);
2006  if (pat < 0)
2007  return pat;
2008  if (!v->ttmbf && ttmb < 8)
2009  ttmb = -1;
2010  first_block = 0;
2011  }
2012  }
2013  return 0;
2014 }
2015 
2016 /** Decode one B-frame MB (in interlaced field B picture)
2017  */
2019 {
2020  MpegEncContext *s = &v->s;
2021  GetBitContext *gb = &s->gb;
2022  int i, j;
2023  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2024  int cbp = 0; /* cbp decoding stuff */
2025  int mqdiff, mquant; /* MB quantization */
2026  int ttmb = v->ttfrm; /* MB Transform type */
2027  int mb_has_coeffs = 0; /* last_flag */
2028  int val; /* temp value */
2029  int first_block = 1;
2030  int dst_idx, off;
2031  int fwd;
2032  int dmv_x[2], dmv_y[2], pred_flag[2];
2033  int bmvtype = BMV_TYPE_BACKWARD;
2034  int block_cbp = 0, pat, block_tt = 0;
2035  int idx_mbmode;
2036 
2037  mquant = v->pq; /* Lossy initialization */
2038  s->mb_intra = 0;
2039 
2040  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
2041  if (idx_mbmode <= 1) { // intra MB
2042  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
2043  s->mb_intra = 1;
2044  s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
2045  s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
2046  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
2047  GET_MQUANT();
2048  s->current_picture.qscale_table[mb_pos] = mquant;
2049  /* Set DC scale - y and c use the same (not sure if necessary here) */
2050  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
2051  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
2052  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
2053  mb_has_coeffs = idx_mbmode & 1;
2054  if (mb_has_coeffs)
2055  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
2056  dst_idx = 0;
2057  for (i = 0; i < 6; i++) {
2058  v->a_avail = v->c_avail = 0;
2059  v->mb_type[0][s->block_index[i]] = 1;
2060  s->dc_val[0][s->block_index[i]] = 0;
2061  dst_idx += i >> 2;
2062  val = ((cbp >> (5 - i)) & 1);
2063  if (i == 2 || i == 3 || !s->first_slice_line)
2064  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2065  if (i == 1 || i == 3 || s->mb_x)
2066  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2067 
2068  vc1_decode_intra_block(v, s->block[i], i, val, mquant,
2069  (i & 4) ? v->codingset2 : v->codingset);
2070  if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2071  continue;
2072  v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
2073  if (v->rangeredfrm)
2074  for (j = 0; j < 64; j++)
2075  s->block[i][j] <<= 1;
2076  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2077  s->idsp.put_signed_pixels_clamped(s->block[i],
2078  s->dest[dst_idx] + off,
2079  (i & 4) ? s->uvlinesize
2080  : s->linesize);
2081  }
2082  } else {
2083  s->mb_intra = v->is_intra[s->mb_x] = 0;
2084  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
2085  for (i = 0; i < 6; i++)
2086  v->mb_type[0][s->block_index[i]] = 0;
2087  if (v->fmb_is_raw)
2088  fwd = v->forward_mb_plane[mb_pos] = get_bits1(gb);
2089  else
2090  fwd = v->forward_mb_plane[mb_pos];
2091  if (idx_mbmode <= 5) { // 1-MV
2092  int interpmvp = 0;
2093  dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
2094  pred_flag[0] = pred_flag[1] = 0;
2095  if (fwd)
2096  bmvtype = BMV_TYPE_FORWARD;
2097  else {
2098  bmvtype = decode012(gb);
2099  switch (bmvtype) {
2100  case 0:
2101  bmvtype = BMV_TYPE_BACKWARD;
2102  break;
2103  case 1:
2104  bmvtype = BMV_TYPE_DIRECT;
2105  break;
2106  case 2:
2107  bmvtype = BMV_TYPE_INTERPOLATED;
2108  interpmvp = get_bits1(gb);
2109  }
2110  }
2111  v->bmvtype = bmvtype;
2112  if (bmvtype != BMV_TYPE_DIRECT && idx_mbmode & 1) {
2113  get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD], &dmv_y[bmvtype == BMV_TYPE_BACKWARD], &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
2114  }
2115  if (interpmvp) {
2116  get_mvdata_interlaced(v, &dmv_x[1], &dmv_y[1], &pred_flag[1]);
2117  }
2118  if (bmvtype == BMV_TYPE_DIRECT) {
2119  dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2120  dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
2121  if (!s->next_picture_ptr->field_picture) {
2122  av_log(s->avctx, AV_LOG_ERROR, "Mixed field/frame direct mode not supported\n");
2123  return AVERROR_INVALIDDATA;
2124  }
2125  }
2126  ff_vc1_pred_b_mv_intfi(v, 0, dmv_x, dmv_y, 1, pred_flag);
2127  vc1_b_mc(v, dmv_x, dmv_y, (bmvtype == BMV_TYPE_DIRECT), bmvtype);
2128  mb_has_coeffs = !(idx_mbmode & 2);
2129  } else { // 4-MV
2130  if (fwd)
2131  bmvtype = BMV_TYPE_FORWARD;
2132  v->bmvtype = bmvtype;
2134  for (i = 0; i < 4; i++) {
2135  dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
2136  dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
2137  if (v->fourmvbp & (8 >> i)) {
2138  get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD],
2139  &dmv_y[bmvtype == BMV_TYPE_BACKWARD],
2140  &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
2141  }
2142  ff_vc1_pred_b_mv_intfi(v, i, dmv_x, dmv_y, 0, pred_flag);
2143  ff_vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD, 0);
2144  }
2145  ff_vc1_mc_4mv_chroma(v, bmvtype == BMV_TYPE_BACKWARD);
2146  mb_has_coeffs = idx_mbmode & 1;
2147  }
2148  if (mb_has_coeffs)
2149  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2150  if (cbp) {
2151  GET_MQUANT();
2152  }
2153  s->current_picture.qscale_table[mb_pos] = mquant;
2154  if (!v->ttmbf && cbp) {
2156  }
2157  dst_idx = 0;
2158  for (i = 0; i < 6; i++) {
2159  s->dc_val[0][s->block_index[i]] = 0;
2160  dst_idx += i >> 2;
2161  val = ((cbp >> (5 - i)) & 1);
2162  off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
2163  if (val) {
2164  pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
2165  first_block, s->dest[dst_idx] + off,
2166  (i & 4) ? s->uvlinesize : s->linesize,
2167  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
2168  if (pat < 0)
2169  return pat;
2170  block_cbp |= pat << (i << 2);
2171  if (!v->ttmbf && ttmb < 8)
2172  ttmb = -1;
2173  first_block = 0;
2174  }
2175  }
2176  }
2177  v->cbp[s->mb_x] = block_cbp;
2178  v->ttblk[s->mb_x] = block_tt;
2179 
2180  return 0;
2181 }
2182 
2183 /** Decode one B-frame MB (in interlaced frame B picture)
2184  */
2186 {
2187  MpegEncContext *s = &v->s;
2188  GetBitContext *gb = &s->gb;
2189  int i, j;
2190  int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2191  int cbp = 0; /* cbp decoding stuff */
2192  int mqdiff, mquant; /* MB quantization */
2193  int ttmb = v->ttfrm; /* MB Transform type */
2194  int mvsw = 0; /* motion vector switch */
2195  int mb_has_coeffs = 1; /* last_flag */
2196  int dmv_x, dmv_y; /* Differential MV components */
2197  int val; /* temp value */
2198  int first_block = 1;
2199  int dst_idx, off;
2200  int skipped, direct, twomv = 0;
2201  int block_cbp = 0, pat, block_tt = 0;
2202  int idx_mbmode = 0, mvbp;
2203  int stride_y, fieldtx;
2204  int bmvtype = BMV_TYPE_BACKWARD;
2205  int dir, dir2;
2206 
2207  mquant = v->pq; /* Lossy initialization */
2208  s->mb_intra = 0;
2209  if (v->skip_is_raw)
2210  skipped = get_bits1(gb);
2211  else
2212  skipped = v->s.mbskip_table[mb_pos];
2213 
2214  if (!skipped) {
2215  idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
2216  if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
2217  twomv = 1;
2218  v->blk_mv_type[s->block_index[0]] = 1;
2219  v->blk_mv_type[s->block_index[1]] = 1;
2220  v->blk_mv_type[s->block_index[2]] = 1;
2221  v->blk_mv_type[s->block_index[3]] = 1;
2222  } else {
2223  v->blk_mv_type[s->block_index[0]] = 0;
2224  v->blk_mv_type[s->block_index[1]] = 0;
2225  v->blk_mv_type[s->block_index[2]] = 0;
2226  v->blk_mv_type[s->block_index[3]] = 0;
2227  }
2228  }
2229 
2230  if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
2231  for (i = 0; i < 4; i++) {
2232  s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = 0;
2233  s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = 0;
2234  s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
2235  s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
2236  }
2237  v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
2238  s->mb_intra = 1;
2239  s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
2240  fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
2241  mb_has_coeffs = get_bits1(gb);
2242  if (mb_has_coeffs)
2243  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2244  v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
2245  GET_MQUANT();
2246  s->current_picture.qscale_table[mb_pos] = mquant;
2247  /* Set DC scale - y and c use the same (not sure if necessary here) */
2248  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
2249  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
2250  dst_idx = 0;
2251  for (i = 0; i < 6; i++) {
2252  v->a_avail = v->c_avail = 0;
2253  v->mb_type[0][s->block_index[i]] = 1;
2254  s->dc_val[0][s->block_index[i]] = 0;
2255  dst_idx += i >> 2;
2256  val = ((cbp >> (5 - i)) & 1);
2257  if (i == 2 || i == 3 || !s->first_slice_line)
2258  v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
2259  if (i == 1 || i == 3 || s->mb_x)
2260  v->c_avail = v->mb_type[0][s->block_index[i] - 1];
2261 
2262  vc1_decode_intra_block(v, s->block[i], i, val, mquant,
2263  (i & 4) ? v->codingset2 : v->codingset);
2264  if (CONFIG_GRAY && i > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2265  continue;
2266  v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
2267  if (i < 4) {
2268  stride_y = s->linesize << fieldtx;
2269  off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
2270  } else {
2271  stride_y = s->uvlinesize;
2272  off = 0;
2273  }
2274  s->idsp.put_signed_pixels_clamped(s->block[i],
2275  s->dest[dst_idx] + off,
2276  stride_y);
2277  }
2278  } else {
2279  s->mb_intra = v->is_intra[s->mb_x] = 0;
2280 
2281  if (v->dmb_is_raw)
2282  direct = get_bits1(gb);
2283  else
2284  direct = v->direct_mb_plane[mb_pos];
2285 
2286  if (direct) {
2287  if (s->next_picture_ptr->field_picture)
2288  av_log(s->avctx, AV_LOG_WARNING, "Mixed frame/field direct mode not supported\n");
2289  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);
2290  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);
2291  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);
2292  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);
2293 
2294  if (twomv) {
2295  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);
2296  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);
2297  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);
2298  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);
2299 
2300  for (i = 1; i < 4; i += 2) {
2301  s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][i-1][0];
2302  s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][i-1][1];
2303  s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][i-1][0];
2304  s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][i-1][1];
2305  }
2306  } else {
2307  for (i = 1; i < 4; i++) {
2308  s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][0][0];
2309  s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][0][1];
2310  s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][0][0];
2311  s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][0][1];
2312  }
2313  }
2314  }
2315 
2316  if (!direct) {
2317  if (skipped || !s->mb_intra) {
2318  bmvtype = decode012(gb);
2319  switch (bmvtype) {
2320  case 0:
2321  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
2322  break;
2323  case 1:
2324  bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
2325  break;
2326  case 2:
2327  bmvtype = BMV_TYPE_INTERPOLATED;
2328  }
2329  }
2330 
2331  if (twomv && bmvtype != BMV_TYPE_INTERPOLATED)
2332  mvsw = get_bits1(gb);
2333  }
2334 
2335  if (!skipped) { // inter MB
2336  mb_has_coeffs = ff_vc1_mbmode_intfrp[0][idx_mbmode][3];
2337  if (mb_has_coeffs)
2338  cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2339  if (!direct) {
2340  if (bmvtype == BMV_TYPE_INTERPOLATED && twomv) {
2342  } else if (bmvtype == BMV_TYPE_INTERPOLATED || twomv) {
2344  }
2345  }
2346 
2347  for (i = 0; i < 6; i++)
2348  v->mb_type[0][s->block_index[i]] = 0;
2349  fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[0][idx_mbmode][1];
2350  /* for all motion vector read MVDATA and motion compensate each block */
2351  dst_idx = 0;
2352  if (direct) {
2353  if (twomv) {
2354  for (i = 0; i < 4; i++) {
2355  ff_vc1_mc_4mv_luma(v, i, 0, 0);
2356  ff_vc1_mc_4mv_luma(v, i, 1, 1);
2357  }
2358  ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
2359  ff_vc1_mc_4mv_chroma4(v, 1, 1, 1);
2360  } else {
2361  ff_vc1_mc_1mv(v, 0);
2362  ff_vc1_interp_mc(v);
2363  }
2364  } else if (twomv && bmvtype == BMV_TYPE_INTERPOLATED) {
2365  mvbp = v->fourmvbp;
2366  for (i = 0; i < 4; i++) {
2367  dir = i==1 || i==3;
2368  dmv_x = dmv_y = 0;
2369  val = ((mvbp >> (3 - i)) & 1);
2370  if (val)
2371  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2372  j = i > 1 ? 2 : 0;
2373  ff_vc1_pred_mv_intfr(v, j, dmv_x, dmv_y, 2, v->range_x, v->range_y, dir);
2374  ff_vc1_mc_4mv_luma(v, j, dir, dir);
2375  ff_vc1_mc_4mv_luma(v, j+1, dir, dir);
2376  }
2377 
2378  ff_vc1_mc_4mv_chroma4(v, 0, 0, 0);
2379  ff_vc1_mc_4mv_chroma4(v, 1, 1, 1);
2380  } else if (bmvtype == BMV_TYPE_INTERPOLATED) {
2381  mvbp = v->twomvbp;
2382  dmv_x = dmv_y = 0;
2383  if (mvbp & 2)
2384  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2385 
2386  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, 0);
2387  ff_vc1_mc_1mv(v, 0);
2388 
2389  dmv_x = dmv_y = 0;
2390  if (mvbp & 1)
2391  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2392 
2393  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, 1);
2394  ff_vc1_interp_mc(v);
2395  } else if (twomv) {
2396  dir = bmvtype == BMV_TYPE_BACKWARD;
2397  dir2 = dir;
2398  if (mvsw)
2399  dir2 = !dir;
2400  mvbp = v->twomvbp;
2401  dmv_x = dmv_y = 0;
2402  if (mvbp & 2)
2403  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2404  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, dir);
2405 
2406  dmv_x = dmv_y = 0;
2407  if (mvbp & 1)
2408  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2409  ff_vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, dir2);
2410 
2411  if (mvsw) {
2412  for (i = 0; i < 2; i++) {
2413  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];
2414  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];
2415  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];
2416  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];
2417  }
2418  } else {
2419  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, !dir);
2420  ff_vc1_pred_mv_intfr(v, 2, 0, 0, 2, v->range_x, v->range_y, !dir);
2421  }
2422 
2423  ff_vc1_mc_4mv_luma(v, 0, dir, 0);
2424  ff_vc1_mc_4mv_luma(v, 1, dir, 0);
2425  ff_vc1_mc_4mv_luma(v, 2, dir2, 0);
2426  ff_vc1_mc_4mv_luma(v, 3, dir2, 0);
2427  ff_vc1_mc_4mv_chroma4(v, dir, dir2, 0);
2428  } else {
2429  dir = bmvtype == BMV_TYPE_BACKWARD;
2430 
2431  mvbp = ff_vc1_mbmode_intfrp[0][idx_mbmode][2];
2432  dmv_x = dmv_y = 0;
2433  if (mvbp)
2434  get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
2435 
2436  ff_vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, dir);
2437  v->blk_mv_type[s->block_index[0]] = 1;
2438  v->blk_mv_type[s->block_index[1]] = 1;
2439  v->blk_mv_type[s->block_index[2]] = 1;
2440  v->blk_mv_type[s->block_index[3]] = 1;
2441  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, !dir);
2442  for (i = 0; i < 2; i++) {
2443  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];
2444  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];
2445  }
2446  ff_vc1_mc_1mv(v, dir);
2447  }
2448 
2449  if (cbp)
2450  GET_MQUANT(); // p. 227
2451  s->current_picture.qscale_table[mb_pos] = mquant;
2452  if (!v->ttmbf && cbp)
2454  for (i = 0; i < 6; i++) {
2455  s->dc_val[0][s->block_index[i]] = 0;
2456  dst_idx += i >> 2;
2457  val = ((cbp >> (5 - i)) & 1);
2458  if (!fieldtx)
2459  off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
2460  else
2461  off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
2462  if (val) {
2463  pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
2464  first_block, s->dest[dst_idx] + off,
2465  (i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
2466  CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
2467  if (pat < 0)
2468  return pat;
2469  block_cbp |= pat << (i << 2);
2470  if (!v->ttmbf && ttmb < 8)
2471  ttmb = -1;
2472  first_block = 0;
2473  }
2474  }
2475 
2476  } else { // skipped
2477  dir = 0;
2478  for (i = 0; i < 6; i++) {
2479  v->mb_type[0][s->block_index[i]] = 0;
2480  s->dc_val[0][s->block_index[i]] = 0;
2481  }
2482  s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
2483  s->current_picture.qscale_table[mb_pos] = 0;
2484  v->blk_mv_type[s->block_index[0]] = 0;
2485  v->blk_mv_type[s->block_index[1]] = 0;
2486  v->blk_mv_type[s->block_index[2]] = 0;
2487  v->blk_mv_type[s->block_index[3]] = 0;
2488 
2489  if (!direct) {
2490  if (bmvtype == BMV_TYPE_INTERPOLATED) {
2491  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, 0);
2492  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, 1);
2493  } else {
2494  dir = bmvtype == BMV_TYPE_BACKWARD;
2495  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, dir);
2496  if (mvsw) {
2497  int dir2 = dir;
2498  if (mvsw)
2499  dir2 = !dir;
2500  for (i = 0; i < 2; i++) {
2501  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];
2502  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];
2503  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];
2504  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];
2505  }
2506  } else {
2507  v->blk_mv_type[s->block_index[0]] = 1;
2508  v->blk_mv_type[s->block_index[1]] = 1;
2509  v->blk_mv_type[s->block_index[2]] = 1;
2510  v->blk_mv_type[s->block_index[3]] = 1;
2511  ff_vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, !dir);
2512  for (i = 0; i < 2; i++) {
2513  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];
2514  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];
2515  }
2516  }
2517  }
2518  }
2519 
2520  ff_vc1_mc_1mv(v, dir);
2521  if (direct || bmvtype == BMV_TYPE_INTERPOLATED) {
2522  ff_vc1_interp_mc(v);
2523  }
2524  v->fieldtx_plane[mb_pos] = 0;
2525  }
2526  }
2527  v->cbp[s->mb_x] = block_cbp;
2528  v->ttblk[s->mb_x] = block_tt;
2529 
2530  return 0;
2531 }
2532 
2533 /** Decode blocks of I-frame
2534  */
2536 {
2537  int k, j;
2538  MpegEncContext *s = &v->s;
2539  int cbp, val;
2540  uint8_t *coded_val;
2541  int mb_pos;
2542 
2543  /* select coding mode used for VLC tables selection */
2544  switch (v->y_ac_table_index) {
2545  case 0:
2547  break;
2548  case 1:
2550  break;
2551  case 2:
2553  break;
2554  }
2555 
2556  switch (v->c_ac_table_index) {
2557  case 0:
2559  break;
2560  case 1:
2562  break;
2563  case 2:
2565  break;
2566  }
2567 
2568  /* Set DC scale - y and c use the same */
2569  s->y_dc_scale = s->y_dc_scale_table[v->pq];
2570  s->c_dc_scale = s->c_dc_scale_table[v->pq];
2571 
2572  //do frame decode
2573  s->mb_x = s->mb_y = 0;
2574  s->mb_intra = 1;
2575  s->first_slice_line = 1;
2576  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2577  s->mb_x = 0;
2578  init_block_index(v);
2579  for (; s->mb_x < v->end_mb_x; s->mb_x++) {
2581  s->bdsp.clear_blocks(v->block[v->cur_blk_idx][0]);
2582  mb_pos = s->mb_x + s->mb_y * s->mb_width;
2583  s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
2584  s->current_picture.qscale_table[mb_pos] = v->pq;
2585  for (int i = 0; i < 4; i++) {
2586  s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
2587  s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
2588  }
2589 
2590  // do actual MB decoding and displaying
2592  v->s.ac_pred = get_bits1(&v->s.gb);
2593 
2594  for (k = 0; k < 6; k++) {
2595  v->mb_type[0][s->block_index[k]] = 1;
2596 
2597  val = ((cbp >> (5 - k)) & 1);
2598 
2599  if (k < 4) {
2600  int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
2601  val = val ^ pred;
2602  *coded_val = val;
2603  }
2604  cbp |= val << (5 - k);
2605 
2606  vc1_decode_i_block(v, v->block[v->cur_blk_idx][block_map[k]], k, val, (k < 4) ? v->codingset : v->codingset2);
2607 
2608  if (CONFIG_GRAY && k > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2609  continue;
2611  }
2612 
2613  if (v->overlap && v->pq >= 9) {
2615  if (v->rangeredfrm)
2616  for (k = 0; k < 6; k++)
2617  for (j = 0; j < 64; j++)
2618  v->block[v->cur_blk_idx][block_map[k]][j] *= 2;
2619  vc1_put_blocks_clamped(v, 1);
2620  } else {
2621  if (v->rangeredfrm)
2622  for (k = 0; k < 6; k++)
2623  for (j = 0; j < 64; j++)
2624  v->block[v->cur_blk_idx][block_map[k]][j] = (v->block[v->cur_blk_idx][block_map[k]][j] - 64) * 2;
2625  vc1_put_blocks_clamped(v, 0);
2626  }
2627 
2628  if (v->s.loop_filter)
2630 
2631  if (get_bits_left(&s->gb) < 0) {
2632  ff_er_add_slice(&s->er, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);
2633  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
2634  get_bits_count(&s->gb), s->gb.size_in_bits);
2635  return;
2636  }
2637 
2638  v->topleft_blk_idx = (v->topleft_blk_idx + 1) % (v->end_mb_x + 2);
2639  v->top_blk_idx = (v->top_blk_idx + 1) % (v->end_mb_x + 2);
2640  v->left_blk_idx = (v->left_blk_idx + 1) % (v->end_mb_x + 2);
2641  v->cur_blk_idx = (v->cur_blk_idx + 1) % (v->end_mb_x + 2);
2642  }
2643  if (!v->s.loop_filter)
2644  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2645  else if (s->mb_y)
2646  ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
2647 
2648  s->first_slice_line = 0;
2649  }
2650  if (v->s.loop_filter)
2651  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2652 
2653  /* This is intentionally mb_height and not end_mb_y - unlike in advanced
2654  * profile, these only differ are when decoding MSS2 rectangles. */
2655  ff_er_add_slice(&s->er, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END);
2656 }
2657 
2658 /** Decode blocks of I-frame for advanced profile
2659  */
2661 {
2662  int k;
2663  MpegEncContext *s = &v->s;
2664  int cbp, val;
2665  uint8_t *coded_val;
2666  int mb_pos;
2667  int mquant;
2668  int mqdiff;
2669  GetBitContext *gb = &s->gb;
2670 
2671  if (get_bits_left(gb) <= 1)
2672  return AVERROR_INVALIDDATA;
2673 
2674  /* select coding mode used for VLC tables selection */
2675  switch (v->y_ac_table_index) {
2676  case 0:
2678  break;
2679  case 1:
2681  break;
2682  case 2:
2684  break;
2685  }
2686 
2687  switch (v->c_ac_table_index) {
2688  case 0:
2690  break;
2691  case 1:
2693  break;
2694  case 2:
2696  break;
2697  }
2698 
2699  // do frame decode
2700  s->mb_x = s->mb_y = 0;
2701  s->mb_intra = 1;
2702  s->first_slice_line = 1;
2703  s->mb_y = s->start_mb_y;
2704  if (s->start_mb_y) {
2705  s->mb_x = 0;
2706  init_block_index(v);
2707  memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
2708  (1 + s->b8_stride) * sizeof(*s->coded_block));
2709  }
2710  for (; s->mb_y < s->end_mb_y; s->mb_y++) {
2711  s->mb_x = 0;
2712  init_block_index(v);
2713  for (;s->mb_x < s->mb_width; s->mb_x++) {
2714  mquant = v->pq;
2716  s->bdsp.clear_blocks(v->block[v->cur_blk_idx][0]);
2717  mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2718  s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
2719  for (int i = 0; i < 4; i++) {
2720  s->current_picture.motion_val[1][s->block_index[i] + v->blocks_off][0] = 0;
2721  s->current_picture.motion_val[1][s->block_index[i] + v->blocks_off][1] = 0;
2722  }
2723 
2724  // do actual MB decoding and displaying
2725  if (v->fieldtx_is_raw)
2726  v->fieldtx_plane[mb_pos] = get_bits1(&v->s.gb);
2727  if (get_bits_left(&v->s.gb) <= 1) {
2728  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2729  return 0;
2730  }
2731 
2733  if (v->acpred_is_raw)
2734  v->s.ac_pred = get_bits1(&v->s.gb);
2735  else
2736  v->s.ac_pred = v->acpred_plane[mb_pos];
2737 
2738  if (v->condover == CONDOVER_SELECT && v->overflg_is_raw)
2739  v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb);
2740 
2741  GET_MQUANT();
2742 
2743  s->current_picture.qscale_table[mb_pos] = mquant;
2744  /* Set DC scale - y and c use the same */
2745  s->y_dc_scale = s->y_dc_scale_table[FFABS(mquant)];
2746  s->c_dc_scale = s->c_dc_scale_table[FFABS(mquant)];
2747 
2748  for (k = 0; k < 6; k++) {
2749  v->mb_type[0][s->block_index[k]] = 1;
2750 
2751  val = ((cbp >> (5 - k)) & 1);
2752 
2753  if (k < 4) {
2754  int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
2755  val = val ^ pred;
2756  *coded_val = val;
2757  }
2758  cbp |= val << (5 - k);
2759 
2760  v->a_avail = !s->first_slice_line || (k == 2 || k == 3);
2761  v->c_avail = !!s->mb_x || (k == 1 || k == 3);
2762 
2764  (k < 4) ? v->codingset : v->codingset2, mquant);
2765 
2766  if (CONFIG_GRAY && k > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2767  continue;
2769  }
2770 
2771  if (v->overlap && (v->pq >= 9 || v->condover != CONDOVER_NONE))
2773  vc1_put_blocks_clamped(v, 1);
2774  if (v->s.loop_filter)
2776 
2777  if (get_bits_left(&s->gb) < 0) {
2778  // TODO: may need modification to handle slice coding
2779  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2780  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
2781  get_bits_count(&s->gb), s->gb.size_in_bits);
2782  return 0;
2783  }
2788  }
2789  if (!v->s.loop_filter)
2790  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2791  else if (s->mb_y)
2792  ff_mpeg_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
2793  s->first_slice_line = 0;
2794  }
2795 
2796  if (v->s.loop_filter)
2797  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2798  ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
2799  (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
2800  return 0;
2801 }
2802 
2804 {
2805  MpegEncContext *s = &v->s;
2806  int apply_loop_filter;
2807 
2808  /* select coding mode used for VLC tables selection */
2809  switch (v->c_ac_table_index) {
2810  case 0:
2812  break;
2813  case 1:
2815  break;
2816  case 2:
2818  break;
2819  }
2820 
2821  switch (v->c_ac_table_index) {
2822  case 0:
2824  break;
2825  case 1:
2827  break;
2828  case 2:
2830  break;
2831  }
2832 
2833  apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
2834  s->first_slice_line = 1;
2835  memset(v->cbp_base, 0, sizeof(v->cbp_base[0]) * 3 * s->mb_stride);
2836  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2837  s->mb_x = 0;
2838  init_block_index(v);
2839  for (; s->mb_x < s->mb_width; s->mb_x++) {
2841 
2842  if (v->fcm == ILACE_FIELD || (v->fcm == PROGRESSIVE && v->mv_type_is_raw) || v->skip_is_raw)
2843  if (get_bits_left(&v->s.gb) <= 1) {
2844  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2845  return;
2846  }
2847 
2848  if (v->fcm == ILACE_FIELD) {
2850  if (apply_loop_filter)
2852  } else if (v->fcm == ILACE_FRAME) {
2854  if (apply_loop_filter)
2856  } else {
2857  vc1_decode_p_mb(v);
2858  if (apply_loop_filter)
2860  }
2861  if (get_bits_left(&s->gb) < 0 || get_bits_count(&s->gb) < 0) {
2862  // TODO: may need modification to handle slice coding
2863  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2864  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
2865  get_bits_count(&s->gb), s->gb.size_in_bits, s->mb_x, s->mb_y);
2866  return;
2867  }
2872  }
2873  memmove(v->cbp_base,
2874  v->cbp - s->mb_stride,
2875  sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
2876  memmove(v->ttblk_base,
2877  v->ttblk - s->mb_stride,
2878  sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
2879  memmove(v->is_intra_base,
2880  v->is_intra - s->mb_stride,
2881  sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
2882  memmove(v->luma_mv_base,
2883  v->luma_mv - s->mb_stride,
2884  sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
2885  if (s->mb_y != s->start_mb_y)
2886  ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
2887  s->first_slice_line = 0;
2888  }
2889  if (s->end_mb_y >= s->start_mb_y)
2890  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2891  ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
2892  (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
2893 }
2894 
2896 {
2897  MpegEncContext *s = &v->s;
2898 
2899  /* select coding mode used for VLC tables selection */
2900  switch (v->c_ac_table_index) {
2901  case 0:
2903  break;
2904  case 1:
2906  break;
2907  case 2:
2909  break;
2910  }
2911 
2912  switch (v->c_ac_table_index) {
2913  case 0:
2915  break;
2916  case 1:
2918  break;
2919  case 2:
2921  break;
2922  }
2923 
2924  s->first_slice_line = 1;
2925  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2926  s->mb_x = 0;
2927  init_block_index(v);
2928  for (; s->mb_x < s->mb_width; s->mb_x++) {
2930 
2931  if (v->fcm == ILACE_FIELD || v->skip_is_raw || v->dmb_is_raw)
2932  if (get_bits_left(&v->s.gb) <= 1) {
2933  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2934  return;
2935  }
2936 
2937  if (v->fcm == ILACE_FIELD) {
2939  if (v->s.loop_filter)
2941  } else if (v->fcm == ILACE_FRAME) {
2943  if (v->s.loop_filter)
2945  } else {
2946  vc1_decode_b_mb(v);
2947  if (v->s.loop_filter)
2949  }
2950  if (get_bits_left(&s->gb) < 0 || get_bits_count(&s->gb) < 0) {
2951  // TODO: may need modification to handle slice coding
2952  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
2953  av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
2954  get_bits_count(&s->gb), s->gb.size_in_bits, s->mb_x, s->mb_y);
2955  return;
2956  }
2957  }
2958  memmove(v->cbp_base,
2959  v->cbp - s->mb_stride,
2960  sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
2961  memmove(v->ttblk_base,
2962  v->ttblk - s->mb_stride,
2963  sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
2964  memmove(v->is_intra_base,
2965  v->is_intra - s->mb_stride,
2966  sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
2967  if (!v->s.loop_filter)
2968  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2969  else if (s->mb_y)
2970  ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
2971  s->first_slice_line = 0;
2972  }
2973  if (v->s.loop_filter)
2974  ff_mpeg_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
2975  ff_er_add_slice(&s->er, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
2976  (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
2977 }
2978 
2980 {
2981  MpegEncContext *s = &v->s;
2982 
2983  if (!v->s.last_picture.f->data[0])
2984  return;
2985 
2986  ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END);
2987  s->first_slice_line = 1;
2988  for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
2989  s->mb_x = 0;
2990  init_block_index(v);
2992  memcpy(s->dest[0], s->last_picture.f->data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
2993  memcpy(s->dest[1], s->last_picture.f->data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
2994  memcpy(s->dest[2], s->last_picture.f->data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
2995  ff_mpeg_draw_horiz_band(s, s->mb_y * 16, 16);
2996  s->first_slice_line = 0;
2997  }
2998  s->pict_type = AV_PICTURE_TYPE_P;
2999 }
3000 
3002 {
3003 
3004  v->s.esc3_level_length = 0;
3005  if (v->x8_type) {
3007  &v->s.gb, &v->s.mb_x, &v->s.mb_y,
3008  2 * v->pq + v->halfpq, v->pq * !v->pquantizer,
3009  v->s.loop_filter, v->s.low_delay);
3010 
3011  ff_er_add_slice(&v->s.er, 0, 0,
3012  (v->s.mb_x >> 1) - 1, (v->s.mb_y >> 1) - 1,
3013  ER_MB_END);
3014  } else {
3015  v->cur_blk_idx = 0;
3016  v->left_blk_idx = -1;
3017  v->topleft_blk_idx = 1;
3018  v->top_blk_idx = 2;
3019  switch (v->s.pict_type) {
3020  case AV_PICTURE_TYPE_I:
3021  if (v->profile == PROFILE_ADVANCED)
3023  else
3025  break;
3026  case AV_PICTURE_TYPE_P:
3027  if (v->p_frame_skipped)
3029  else
3031  break;
3032  case AV_PICTURE_TYPE_B:
3033  if (v->bi_type) {
3034  if (v->profile == PROFILE_ADVANCED)
3036  else
3038  } else
3040  break;
3041  }
3042  }
3043 }
vc1_decode_p_block
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:1122
VC1_ICBPCY_VLC_BITS
#define VC1_ICBPCY_VLC_BITS
Definition: vc1data.c:120
VC1Context::zz_8x8
uint8_t zz_8x8[4][64]
Zigzag table for TT_8x8, permuted for IDCT.
Definition: vc1.h:237
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
q1
static const uint8_t q1[256]
Definition: twofish.c:100
level
uint8_t level
Definition: svq3.c:206
vc1_index_decode_table
static const uint8_t vc1_index_decode_table[AC_MODES][185][2]
Definition: vc1acdata.h:34
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:839
VC1Context
The VC1 Context.
Definition: vc1.h:173
PROGRESSIVE
@ PROGRESSIVE
in the bitstream is reported as 00b
Definition: vc1.h:149
ff_vc1_ttblk_to_tt
const int ff_vc1_ttblk_to_tt[3][8]
Table for conversion between TTBLK and TTMB.
Definition: vc1data.c:34
VC1Context::condover
uint8_t condover
Definition: vc1.h:324
VC1Context::left_blk_idx
int left_blk_idx
Definition: vc1.h:387
AC_VLC_BITS
#define AC_VLC_BITS
Definition: intrax8.c:40
VC1_TTBLK_VLC_BITS
#define VC1_TTBLK_VLC_BITS
Definition: vc1data.c:126
MpegEncContext::gb
GetBitContext gb
Definition: mpegvideo.h:427
block_map
static const int block_map[6]
Definition: vc1_block.c:50
VC1Context::topleft_blk_idx
int topleft_blk_idx
Definition: vc1.h:387
VC1Context::cbp
uint32_t * cbp
Definition: vc1.h:388
VC1Context::end_mb_x
int end_mb_x
Horizontal macroblock limit (used only by mss2)
Definition: vc1.h:395
vc1_b_mc
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:321
VC1Context::overlap
int overlap
overlapped transforms in use
Definition: vc1.h:224
get_mvdata_interlaced
static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x, int *dmv_y, int *pred_flag)
Definition: vc1_block.c:270
VC1_IF_MBMODE_VLC_BITS
#define VC1_IF_MBMODE_VLC_BITS
Definition: vc1data.c:145
vc1.h
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:119
ILACE_FRAME
@ ILACE_FRAME
in the bitstream is reported as 10b
Definition: vc1.h:150
vc1_decode_p_blocks
static void vc1_decode_p_blocks(VC1Context *v)
Definition: vc1_block.c:2803
GET_MVDATA
#define GET_MVDATA(_dmv_x, _dmv_y)
Get MV differentials.
Definition: vc1_block.c:232
VC1DSPContext::vc1_inv_trans_4x4
void(* vc1_inv_trans_4x4)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:40
vc1_i_pred_dc
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:347
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
MpegEncContext::current_picture
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:163
TT_8X4_BOTTOM
@ TT_8X4_BOTTOM
Definition: vc1.h:113
TT_8X4_TOP
@ TT_8X4_TOP
Definition: vc1.h:114
VC1Context::left_blk_sh
int left_blk_sh
Definition: vc1.h:238
BMV_TYPE_DIRECT
@ BMV_TYPE_DIRECT
Definition: vc1.h:105
VC1_INTFR_NON4MV_MBMODE_VLC_BITS
#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS
Definition: vc1data.c:132
vc1acdata.h
ff_vc1_mc_4mv_luma
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
ff_vc1_ttblk_vlc
VLC ff_vc1_ttblk_vlc[3]
Definition: vc1data.c:127
vc1_decode_i_block
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:586
ff_vc1_ac_sizes
const int ff_vc1_ac_sizes[AC_MODES]
Definition: vc1data.c:1133
CS_HIGH_RATE_INTER
@ CS_HIGH_RATE_INTER
Definition: vc1.h:131
vc1_coded_block_pred
static int vc1_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: vc1_block.c:483
b
#define b
Definition: input.c:34
table
static const uint16_t table[]
Definition: prosumer.c:206
VC1Context::cbp_base
uint32_t * cbp_base
Definition: vc1.h:388
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:47
VC1Context::mv_type_mb_plane
uint8_t * mv_type_mb_plane
bitplane for mv_type == (4MV)
Definition: vc1.h:284
GET_MQUANT
#define GET_MQUANT()
Get macroblock-level quantizer scale.
Definition: vc1_block.c:189
ff_vc1_adv_interlaced_4x8_zz
const uint8_t ff_vc1_adv_interlaced_4x8_zz[32]
Definition: vc1data.c:1065
VC1Context::zz_8x4
const uint8_t * zz_8x4
Zigzag scan table for TT_8x4 coding mode.
Definition: vc1.h:239
ff_er_add_slice
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
Definition: error_resilience.c:822
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:1673
VC1DSPContext::vc1_inv_trans_8x8_dc
void(* vc1_inv_trans_8x8_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:41
mpegvideo.h
VC1Context::dmvrange
uint8_t dmvrange
Frame decoding info for interlaced picture.
Definition: vc1.h:332
VC1DSPContext::vc1_inv_trans_4x4_dc
void(* vc1_inv_trans_4x4_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:44
VC1Context::luma_mv
int16_t((* luma_mv)[2]
Definition: vc1.h:390
mpegutils.h
vc1_decode_p_mb_intfr
static int vc1_decode_p_mb_intfr(VC1Context *v)
Definition: vc1_block.c:1526
CS_HIGH_RATE_INTRA
@ CS_HIGH_RATE_INTRA
Definition: vc1.h:130
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:346
ff_vc1_interp_mc
void ff_vc1_interp_mc(VC1Context *v)
Motion compensation for direct or interpolated blocks in B-frames.
Definition: vc1_mc.c:1004
VC1_CBPCY_P_VLC_BITS
#define VC1_CBPCY_P_VLC_BITS
Definition: vc1data.c:118
VC1Context::fieldtx_is_raw
int fieldtx_is_raw
Definition: vc1.h:344
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
MpegEncContext::pict_type
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:194
ILACE_FIELD
@ ILACE_FIELD
in the bitstream is reported as 11b
Definition: vc1.h:151
wrap
#define wrap(func)
Definition: neontest.h:65
ff_intrax8_decode_picture
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:737
CS_LOW_MOT_INTER
@ CS_LOW_MOT_INTER
Definition: vc1.h:127
GetBitContext
Definition: get_bits.h:61
VC1Context::numref
int numref
number of past field pictures used as reference
Definition: vc1.h:353
val
static double val(void *priv, double ch)
Definition: aeval.c:77
MV_PMODE_INTFR_2MV_FIELD
@ MV_PMODE_INTFR_2MV_FIELD
Definition: vc1.h:91
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
ff_vc1_p_overlap_filter
void ff_vc1_p_overlap_filter(VC1Context *v)
Definition: vc1_loopfilter.c:161
init_block_index
static void init_block_index(VC1Context *v)
Definition: vc1_block.c:60
vc1_put_blocks_clamped
static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
Definition: vc1_block.c:80
quant
static int quant(float coef, const float Q, const float rounding)
Quantize one coefficient.
Definition: aacenc_utils.h:59
VC1Context::c_ac_table_index
int c_ac_table_index
AC coding set indexes.
Definition: vc1.h:252
VC1Context::k_y
int k_y
Number of bits for MVs (depends on MV range)
Definition: vc1.h:234
ff_vc1_decode_blocks
void ff_vc1_decode_blocks(VC1Context *v)
Definition: vc1_block.c:3001
CONDOVER_NONE
@ CONDOVER_NONE
Definition: vc1.h:137
CS_MID_RATE_INTER
@ CS_MID_RATE_INTER
Definition: vc1.h:129
mpegvideodec.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
VC1DSPContext::vc1_inv_trans_8x4_dc
void(* vc1_inv_trans_8x4_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:42
msmpeg4data.h
ff_vc1_pred_b_mv_intfi
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:891
VC1Context::mb_type
uint8_t * mb_type[3]
Definition: vc1.h:262
s
#define s(width, name)
Definition: cbs_vp9.c:256
ff_vc1_mc_1mv
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
VC1Context::imv_vlc
VLC * imv_vlc
Definition: vc1.h:338
VC1Context::x8
IntraX8Context x8
Definition: vc1.h:175
ff_msmp4_dc_luma_vlc
VLC ff_msmp4_dc_luma_vlc[2]
Definition: msmpeg4data.c:38
vc1_decode_b_blocks
static void vc1_decode_b_blocks(VC1Context *v)
Definition: vc1_block.c:2895
direct
static void fn() direct(const ftype *in, const ctype *ir, int len, ftype *out)
Definition: afir_template.c:248
VC1Context::over_flags_plane
uint8_t * over_flags_plane
Overflags bitplane.
Definition: vc1.h:322
bits
uint8_t bits
Definition: vp3data.h:141
TT_8X4
@ TT_8X4
Definition: vc1.h:115
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
PROFILE_ADVANCED
@ PROFILE_ADVANCED
Definition: vc1_common.h:52
MpegEncContext::loop_filter
int loop_filter
Definition: mpegvideo.h:365
vc1_decode_ac_coeff
static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset)
Decode one AC coefficient.
Definition: vc1_block.c:519
VC1_4MV_BLOCK_PATTERN_VLC_BITS
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS
Definition: vc1data.c:122
vc1_decode_i_block_adv
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:724
VC1Context::tt_index
int tt_index
Index for Transform Type tables (to decode TTMB)
Definition: vc1.h:283
ff_vc1_i_overlap_filter
void ff_vc1_i_overlap_filter(VC1Context *v)
Definition: vc1_loopfilter.c:105
decode012
static int decode012(GetBitContext *gb)
Definition: get_bits.h:821
CS_HIGH_MOT_INTER
@ CS_HIGH_MOT_INTER
Definition: vc1.h:125
TT_4X8_LEFT
@ TT_4X8_LEFT
Definition: vc1.h:117
ff_msmp4_dc_chroma_vlc
VLC ff_msmp4_dc_chroma_vlc[2]
Definition: msmpeg4data.c:39
B_FRACTION_DEN
#define B_FRACTION_DEN
Definition: vc1data.h:99
ff_vc1_mc_4mv_chroma4
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
size_table
static const uint8_t size_table[6]
Definition: vc1_block.c:1290
VC1Context::top_blk_sh
int top_blk_sh
Either 3 or 0, positions of l/t in blk[].
Definition: vc1.h:238
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
if
if(ret)
Definition: filter_design.txt:179
VC1Context::pq
uint8_t pq
Definition: vc1.h:236
MpegEncContext::low_delay
int low_delay
no reordering needed / has no B-frames
Definition: mpegvideo.h:390
VC1Context::forward_mb_plane
uint8_t * forward_mb_plane
bitplane for "forward" MBs
Definition: vc1.h:286
vc1_decode_p_mb_intfi
static int vc1_decode_p_mb_intfi(VC1Context *v)
Definition: vc1_block.c:1736
VC1Context::pqindex
int pqindex
raw pqindex used in coding set selection
Definition: vc1.h:260
VC1Context::skip_is_raw
int skip_is_raw
skip mb plane is not coded
Definition: vc1.h:290
NULL
#define NULL
Definition: coverity.c:32
vc1_decode_b_mb_intfi
static int vc1_decode_b_mb_intfi(VC1Context *v)
Decode one B-frame MB (in interlaced field B picture)
Definition: vc1_block.c:2018
run
uint8_t run
Definition: svq3.c:205
VC1_SUBBLKPAT_VLC_BITS
#define VC1_SUBBLKPAT_VLC_BITS
Definition: vc1data.c:128
VC1Context::direct_mb_plane
uint8_t * direct_mb_plane
bitplane for "direct" MBs
Definition: vc1.h:285
VC1DSPContext::vc1_inv_trans_8x4
void(* vc1_inv_trans_8x4)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:38
vc1_decode_b_mb
static int vc1_decode_b_mb(VC1Context *v)
Decode one B-frame MB (in Main profile)
Definition: vc1_block.c:1860
MpegEncContext::mb_y
int mb_y
Definition: mpegvideo.h:277
VC1Context::field_mode
int field_mode
1 for interlaced field pictures
Definition: vc1.h:349
MpegEncContext::esc3_run_length
int esc3_run_length
Definition: mpegvideo.h:422
VC1Context::a_avail
int a_avail
Definition: vc1.h:261
ER_MB_ERROR
#define ER_MB_ERROR
Definition: error_resilience.h:38
VC1Context::block
int16_t(* block)[6][64]
Definition: vc1.h:386
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
CS_LOW_MOT_INTRA
@ CS_LOW_MOT_INTRA
Definition: vc1.h:126
VC1Context::fmb_is_raw
int fmb_is_raw
forward mb plane is raw
Definition: vc1.h:289
VC1Context::vc1dsp
VC1DSPContext vc1dsp
Definition: vc1.h:177
VC1Context::twomvbp_vlc
VLC * twomvbp_vlc
Definition: vc1.h:339
offset_table
static const uint8_t offset_table[2][9]
Definition: vc1_block.c:44
abs
#define abs(x)
Definition: cuda_runtime.h:35
inc_blk_idx
#define inc_blk_idx(idx)
Definition: vc1_block.c:172
VC1Context::luma_mv_base
int16_t(* luma_mv_base)[2]
Definition: vc1.h:390
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:787
VC1Context::halfpq
uint8_t halfpq
Uniform quant over image and qp+.5.
Definition: vc1.h:271
VC1DSPContext::vc1_inv_trans_4x8_dc
void(* vc1_inv_trans_4x8_dc)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:43
VC1Context::ttmbf
uint8_t ttmbf
Transform type flag.
Definition: vc1.h:256
index
int index
Definition: gxfenc.c:89
c
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
ff_vc1_i_loop_filter
void ff_vc1_i_loop_filter(VC1Context *v)
Definition: vc1_loopfilter.c:271
ff_vc1_simple_progressive_4x4_zz
const uint8_t ff_vc1_simple_progressive_4x4_zz[16]
Definition: vc1data.c:1022
get_unary
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
VC1Context::fieldtx_plane
uint8_t * fieldtx_plane
Definition: vc1.h:343
VC1Context::fourmvbp
uint8_t fourmvbp
Definition: vc1.h:342
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:53
ff_vc1_p_intfr_loop_filter
void ff_vc1_p_intfr_loop_filter(VC1Context *v)
Definition: vc1_loopfilter.c:909
vc1_pred.h
MV_PMODE_INTFR_4MV
@ MV_PMODE_INTFR_4MV
Definition: vc1.h:94
VC1Context::is_intra
uint8_t * is_intra
Definition: vc1.h:389
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:259
VC1Context::ttfrm
int ttfrm
Transform type info present at frame level.
Definition: vc1.h:255
VC1Context::codingset
int codingset
index of current table set from 11.8 to use for luma block decoding
Definition: vc1.h:258
VC1Context::ttblk_base
int * ttblk_base
Definition: vc1.h:257
VC1Context::mb_off
int mb_off
Definition: vc1.h:361
ff_update_block_index
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
Definition: mpegvideo.h:602
VC1Context::bfraction
int16_t bfraction
Relative position % anchors=> how to scale MVs.
Definition: vc1.h:270
update_block_index
static void update_block_index(MpegEncContext *s)
Definition: vc1_block.c:71
ff_vc1_p_loop_filter
void ff_vc1_p_loop_filter(VC1Context *v)
Definition: vc1_loopfilter.c:470
VC1Context::zzi_8x8
uint8_t zzi_8x8[64]
Definition: vc1.h:345
BMV_TYPE_INTERPOLATED
@ BMV_TYPE_INTERPOLATED
Definition: vc1.h:104
ff_vc1_pred_b_mv
void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype)
Definition: vc1_pred.c:691
scale_mv
#define scale_mv(n, dim)
VC1Context::fourmvswitch
int fourmvswitch
Definition: vc1.h:333
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:55
ff_mpeg_draw_horiz_band
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo_dec.c:537
VC1Context::rangeredfrm
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition: vc1.h:301
VC1Context::top_blk_idx
int top_blk_idx
Definition: vc1.h:387
MpegEncContext::mbskip_table
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:179
VC1Context::mbmode_vlc
VLC * mbmode_vlc
Definition: vc1.h:337
a
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:41
vc1data.h
CS_HIGH_MOT_INTRA
@ CS_HIGH_MOT_INTRA
Definition: vc1.h:124
ff_vc1_adv_interlaced_8x4_zz
const uint8_t ff_vc1_adv_interlaced_8x4_zz[32]
Definition: vc1data.c:1058
ff_vc1_ttmb_vlc
VLC ff_vc1_ttmb_vlc[3]
Definition: vc1data.c:115
MV_PMODE_INTFR_INTRA
@ MV_PMODE_INTFR_INTRA
Definition: vc1.h:95
VC1DSPContext::vc1_inv_trans_8x8
void(* vc1_inv_trans_8x8)(int16_t *b)
Definition: vc1dsp.h:37
unary.h
apply_loop_filter
static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int yend)
Definition: vp3.c:1796
ff_vc1_pred_dc
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:412
VC1Context::k_x
int k_x
Number of bits for MVs (depends on MV range)
Definition: vc1.h:233
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
MV_PMODE_INTFR_4MV_FIELD
@ MV_PMODE_INTFR_4MV_FIELD
Definition: vc1.h:93
VC1Context::range_x
int range_x
Definition: vc1.h:235
MpegEncContext::esc3_level_length
int esc3_level_length
Definition: mpegvideo.h:421
BMV_TYPE_FORWARD
@ BMV_TYPE_FORWARD
Definition: vc1.h:103
MpegEncContext::mb_x
int mb_x
Definition: mpegvideo.h:277
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
av_always_inline
#define av_always_inline
Definition: attributes.h:49
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
VC1Context::s
MpegEncContext s
Definition: vc1.h:174
VC1Context::zz_4x8
const uint8_t * zz_4x8
Zigzag scan table for TT_4x8 coding mode.
Definition: vc1.h:240
VC1Context::ttblk
int * ttblk
Transform type at the block level.
Definition: vc1.h:257
ff_vc1_pred_mv_intfr
void ff_vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, int mvn, int r_x, int r_y, int dir)
Predict and set motion vector for interlaced frame picture MBs.
Definition: vc1_pred.c:470
ff_vc1_mbmode_intfrp
const uint8_t ff_vc1_mbmode_intfrp[2][15][4]
Definition: vc1data.c:53
MpegEncContext::er
ERContext er
Definition: mpegvideo.h:529
VC1Context::is_intra_base
uint8_t * is_intra_base
Definition: vc1.h:389
vc1_last_delta_level_table
static const uint8_t vc1_last_delta_level_table[AC_MODES][44]
Definition: vc1acdata.h:246
avcodec.h
VC1Context::second_field
int second_field
Definition: vc1.h:351
ret
ret
Definition: filter_design.txt:187
VC1Context::y_ac_table_index
int y_ac_table_index
Luma index from AC2FRM element.
Definition: vc1.h:253
pred
static const float pred[4]
Definition: siprdata.h:259
vc1_decode_intra_block
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
VC1Context::twomvbp
uint8_t twomvbp
Definition: vc1.h:341
VC1Context::overflg_is_raw
int overflg_is_raw
Definition: vc1.h:323
VC1Context::pquantizer
uint8_t pquantizer
Uniform (over sequence) quantizer in use.
Definition: vc1.h:281
CS_MID_RATE_INTRA
@ CS_MID_RATE_INTRA
Definition: vc1.h:128
VC1Context::codingset2
int codingset2
index of current table set from 11.8 to use for chroma block decoding
Definition: vc1.h:259
U
#define U(x)
Definition: vpx_arith.h:37
BMV_TYPE_BACKWARD
@ BMV_TYPE_BACKWARD
Definition: vc1.h:102
ff_vc1_ac_coeff_table
VLC ff_vc1_ac_coeff_table[8]
Definition: vc1data.c:143
vc1_decode_p_mb
static int vc1_decode_p_mb(VC1Context *v)
Decode one P-frame MB.
Definition: vc1_block.c:1294
VC1Context::p_frame_skipped
int p_frame_skipped
Definition: vc1.h:382
ff_vc1_subblkpat_vlc
VLC ff_vc1_subblkpat_vlc[3]
Definition: vc1data.c:129
vc1_last_delta_run_table
static const uint8_t vc1_last_delta_run_table[AC_MODES][10]
Definition: vc1acdata.h:339
VC1Context::cbpcy_vlc
VLC * cbpcy_vlc
CBPCY VLC table.
Definition: vc1.h:282
ff_vc1_adv_interlaced_4x4_zz
const uint8_t ff_vc1_adv_interlaced_4x4_zz[16]
Definition: vc1data.c:1076
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
mode
mode
Definition: ebur128.h:83
Picture::f
struct AVFrame * f
Definition: mpegpicture.h:47
VC1Context::tff
uint8_t tff
Definition: vc1.h:310
VC1Context::x8_type
int x8_type
Definition: vc1.h:384
vc1_decode_skip_blocks
static void vc1_decode_skip_blocks(VC1Context *v)
Definition: vc1_block.c:2979
VC1Context::res_rtm_flag
int res_rtm_flag
reserved, set to 1
Definition: vc1.h:189
VC1Context::profile
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags.
Definition: vc1.h:216
vc1_decode_i_blocks
static void vc1_decode_i_blocks(VC1Context *v)
Decode blocks of I-frame.
Definition: vc1_block.c:2535
VC1Context::c_avail
int c_avail
Definition: vc1.h:261
MpegEncContext::last_picture
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:145
VLC::table
VLCElem * table
Definition: vlc.h:33
ff_vc1_mc_4mv_chroma
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
VC1_2MV_BLOCK_PATTERN_VLC_BITS
#define VC1_2MV_BLOCK_PATTERN_VLC_BITS
Definition: vc1data.c:124
decode210
static int decode210(GetBitContext *gb)
Definition: get_bits.h:831
VC1Context::bi_type
int bi_type
Definition: vc1.h:383
vc1_last_decode_table
static const int vc1_last_decode_table[AC_MODES]
Definition: vc1acdata.h:30
VC1Context::range_y
int range_y
MV range.
Definition: vc1.h:235
MV_PMODE_INTFR_1MV
@ MV_PMODE_INTFR_1MV
Definition: vc1.h:90
TT_4X8
@ TT_4X8
Definition: vc1.h:118
VC1Context::fcm
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition: vc1.h:307
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
VC1Context::mv_type_is_raw
int mv_type_is_raw
mv type mb plane is not coded
Definition: vc1.h:287
ER_MB_END
#define ER_MB_END
Definition: error_resilience.h:39
vc1_delta_run_table
static const uint8_t vc1_delta_run_table[AC_MODES][57]
Definition: vc1acdata.h:295
VC1Context::bmvtype
int bmvtype
Definition: vc1.h:363
VC1Context::dmb_is_raw
int dmb_is_raw
direct mb plane is raw
Definition: vc1.h:288
VC1Context::cur_blk_idx
int cur_blk_idx
Definition: vc1.h:387
VC1Context::acpred_plane
uint8_t * acpred_plane
AC prediction flags bitplane.
Definition: vc1.h:320
TT_8X8
@ TT_8X8
Definition: vc1.h:112
VC1Context::fourmvbp_vlc
VLC * fourmvbp_vlc
Definition: vc1.h:340
VC1Context::acpred_is_raw
int acpred_is_raw
Definition: vc1.h:321
TT_4X8_RIGHT
@ TT_4X8_RIGHT
Definition: vc1.h:116
ff_vc1_pred_mv
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:212
ff_vc1_dqscale
const int32_t ff_vc1_dqscale[63]
Definition: vc1data.c:1085
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
VC1_INTFR_4MV_MBMODE_VLC_BITS
#define VC1_INTFR_4MV_MBMODE_VLC_BITS
Definition: vc1data.c:130
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
VC1Context::blk_mv_type
uint8_t * blk_mv_type
0: frame MV, 1: field MV (interlaced frame)
Definition: vc1.h:346
VC1_1REF_MVDATA_VLC_BITS
#define VC1_1REF_MVDATA_VLC_BITS
Definition: vc1data.c:138
vc1_decode_i_blocks_adv
static int vc1_decode_i_blocks_adv(VC1Context *v)
Decode blocks of I-frame for advanced profile.
Definition: vc1_block.c:2660
ff_vc1_b_intfi_loop_filter
void ff_vc1_b_intfi_loop_filter(VC1Context *v)
Definition: vc1_loopfilter.c:1172
VC1Context::dquantfrm
uint8_t dquantfrm
pquant parameters
Definition: vc1.h:243
vc1_delta_level_table
static const uint8_t vc1_delta_level_table[AC_MODES][31]
Definition: vc1acdata.h:203
DC_VLC_BITS
#define DC_VLC_BITS
Definition: vc1_block.c:41
CONDOVER_SELECT
@ CONDOVER_SELECT
Definition: vc1.h:139
VC1DSPContext::vc1_inv_trans_4x8
void(* vc1_inv_trans_4x8)(uint8_t *dest, ptrdiff_t stride, int16_t *block)
Definition: vc1dsp.h:39
vc1_decode_b_mb_intfr
static int vc1_decode_b_mb_intfr(VC1Context *v)
Decode one B-frame MB (in interlaced frame B picture)
Definition: vc1_block.c:2185
VC1Context::blocks_off
int blocks_off
Definition: vc1.h:361
TT_4X4
@ TT_4X4
Definition: vc1.h:119
VC1_2REF_MVDATA_VLC_BITS
#define VC1_2REF_MVDATA_VLC_BITS
Definition: vc1data.c:140
int
int
Definition: ffmpeg_filter.c:155
ff_msmp4_mb_i_vlc
VLC ff_msmp4_mb_i_vlc
Definition: msmpeg4data.c:37
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:62
MB_INTRA_VLC_BITS
#define MB_INTRA_VLC_BITS
Definition: vc1_block.c:40
VC1_TTMB_VLC_BITS
#define VC1_TTMB_VLC_BITS
Definition: vc1data.c:114
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:66
MpegEncContext::ac_pred
int ac_pred
Definition: mpegvideo.h:66