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