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