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