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