Libav
vc1dec.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 Libav.
8  *
9  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
29 #include "avcodec.h"
30 #include "blockdsp.h"
31 #include "get_bits.h"
32 #include "internal.h"
33 #include "mpeg_er.h"
34 #include "mpegvideo.h"
35 #include "msmpeg4.h"
36 #include "msmpeg4data.h"
37 #include "profiles.h"
38 #include "vc1.h"
39 #include "vc1data.h"
40 
41 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
42 
43 typedef struct SpriteData {
55  int coefs[2][7];
56 
57  int effect_type, effect_flag;
58  int effect_pcount1, effect_pcount2;
59  int effect_params1[15], effect_params2[10];
60 } SpriteData;
61 
62 static inline int get_fp_val(GetBitContext* gb)
63 {
64  return (get_bits_long(gb, 30) - (1 << 29)) << 1;
65 }
66 
67 static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7])
68 {
69  c[1] = c[3] = 0;
70 
71  switch (get_bits(gb, 2)) {
72  case 0:
73  c[0] = 1 << 16;
74  c[2] = get_fp_val(gb);
75  c[4] = 1 << 16;
76  break;
77  case 1:
78  c[0] = c[4] = get_fp_val(gb);
79  c[2] = get_fp_val(gb);
80  break;
81  case 2:
82  c[0] = get_fp_val(gb);
83  c[2] = get_fp_val(gb);
84  c[4] = get_fp_val(gb);
85  break;
86  case 3:
87  c[0] = get_fp_val(gb);
88  c[1] = get_fp_val(gb);
89  c[2] = get_fp_val(gb);
90  c[3] = get_fp_val(gb);
91  c[4] = get_fp_val(gb);
92  break;
93  }
94  c[5] = get_fp_val(gb);
95  if (get_bits1(gb))
96  c[6] = get_fp_val(gb);
97  else
98  c[6] = 1 << 16;
99 }
100 
101 static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd)
102 {
103  AVCodecContext *avctx = v->s.avctx;
104  int sprite, i;
105 
106  for (sprite = 0; sprite <= v->two_sprites; sprite++) {
107  vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
108  if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
109  avpriv_request_sample(avctx, "Non-zero rotation coefficients");
110  av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:");
111  for (i = 0; i < 7; i++)
112  av_log(avctx, AV_LOG_DEBUG, " %d.%.3d",
113  sd->coefs[sprite][i] / (1<<16),
114  (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
115  av_log(avctx, AV_LOG_DEBUG, "\n");
116  }
117 
118  skip_bits(gb, 2);
119  if (sd->effect_type = get_bits_long(gb, 30)) {
120  switch (sd->effect_pcount1 = get_bits(gb, 4)) {
121  case 7:
122  vc1_sprite_parse_transform(gb, sd->effect_params1);
123  break;
124  case 14:
125  vc1_sprite_parse_transform(gb, sd->effect_params1);
126  vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
127  break;
128  default:
129  for (i = 0; i < sd->effect_pcount1; i++)
130  sd->effect_params1[i] = get_fp_val(gb);
131  }
132  if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
133  // effect 13 is simple alpha blending and matches the opacity above
134  av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type);
135  for (i = 0; i < sd->effect_pcount1; i++)
136  av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
137  sd->effect_params1[i] / (1 << 16),
138  (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
139  av_log(avctx, AV_LOG_DEBUG, "\n");
140  }
141 
142  sd->effect_pcount2 = get_bits(gb, 16);
143  if (sd->effect_pcount2 > 10) {
144  av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n");
145  return;
146  } else if (sd->effect_pcount2) {
147  i = -1;
148  av_log(avctx, AV_LOG_DEBUG, "Effect params 2: ");
149  while (++i < sd->effect_pcount2) {
150  sd->effect_params2[i] = get_fp_val(gb);
151  av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
152  sd->effect_params2[i] / (1 << 16),
153  (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
154  }
155  av_log(avctx, AV_LOG_DEBUG, "\n");
156  }
157  }
158  if (sd->effect_flag = get_bits1(gb))
159  av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n");
160 
161  if (get_bits_count(gb) >= gb->size_in_bits +
162  (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0))
163  av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n");
164  if (get_bits_count(gb) < gb->size_in_bits - 8)
165  av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n");
166 }
167 
168 static void vc1_draw_sprites(VC1Context *v, SpriteData* sd)
169 {
170  int i, plane, row, sprite;
171  int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
172  uint8_t* src_h[2][2];
173  int xoff[2], xadv[2], yoff[2], yadv[2], alpha;
174  int ysub[2];
175  MpegEncContext *s = &v->s;
176 
177  for (i = 0; i < 2; i++) {
178  xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16);
179  xadv[i] = sd->coefs[i][0];
180  if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i])
181  xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width);
182 
183  yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16);
184  yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height);
185  }
186  alpha = av_clip_uint16(sd->coefs[1][6]);
187 
188  for (plane = 0; plane < (s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++) {
189  int width = v->output_width>>!!plane;
190 
191  for (row = 0; row < v->output_height>>!!plane; row++) {
192  uint8_t *dst = v->sprite_output_frame->data[plane] +
193  v->sprite_output_frame->linesize[plane] * row;
194 
195  for (sprite = 0; sprite <= v->two_sprites; sprite++) {
196  uint8_t *iplane = s->current_picture.f->data[plane];
197  int iline = s->current_picture.f->linesize[plane];
198  int ycoord = yoff[sprite] + yadv[sprite] * row;
199  int yline = ycoord >> 16;
200  int next_line;
201  ysub[sprite] = ycoord & 0xFFFF;
202  if (sprite) {
203  iplane = s->last_picture.f->data[plane];
204  iline = s->last_picture.f->linesize[plane];
205  }
206  next_line = FFMIN(yline + 1, (v->sprite_height >> !!plane) - 1) * iline;
207  if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
208  src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
209  if (ysub[sprite])
210  src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
211  } else {
212  if (sr_cache[sprite][0] != yline) {
213  if (sr_cache[sprite][1] == yline) {
214  FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]);
215  FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]);
216  } else {
217  v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
218  sr_cache[sprite][0] = yline;
219  }
220  }
221  if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
222  v->vc1dsp.sprite_h(v->sr_rows[sprite][1],
223  iplane + next_line, xoff[sprite],
224  xadv[sprite], width);
225  sr_cache[sprite][1] = yline + 1;
226  }
227  src_h[sprite][0] = v->sr_rows[sprite][0];
228  src_h[sprite][1] = v->sr_rows[sprite][1];
229  }
230  }
231 
232  if (!v->two_sprites) {
233  if (ysub[0]) {
234  v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width);
235  } else {
236  memcpy(dst, src_h[0][0], width);
237  }
238  } else {
239  if (ysub[0] && ysub[1]) {
240  v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0],
241  src_h[1][0], src_h[1][1], ysub[1], alpha, width);
242  } else if (ysub[0]) {
243  v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0],
244  src_h[1][0], alpha, width);
245  } else if (ysub[1]) {
246  v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1],
247  src_h[0][0], (1<<16)-1-alpha, width);
248  } else {
249  v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width);
250  }
251  }
252  }
253 
254  if (!plane) {
255  for (i = 0; i < 2; i++) {
256  xoff[i] >>= 1;
257  yoff[i] >>= 1;
258  }
259  }
260 
261  }
262 }
263 
264 
265 static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb)
266 {
267  MpegEncContext *s = &v->s;
268  AVCodecContext *avctx = s->avctx;
269  SpriteData sd;
270 
271  vc1_parse_sprites(v, gb, &sd);
272 
273  if (!s->current_picture.f || !s->current_picture.f->data[0]) {
274  av_log(avctx, AV_LOG_ERROR, "Got no sprites\n");
275  return -1;
276  }
277 
278  if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f->data[0])) {
279  av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
280  v->two_sprites = 0;
281  }
282 
284  if (ff_get_buffer(avctx, v->sprite_output_frame, 0) < 0) {
285  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
286  return -1;
287  }
288 
289  vc1_draw_sprites(v, &sd);
290 
291  return 0;
292 }
293 
294 static void vc1_sprite_flush(AVCodecContext *avctx)
295 {
296  VC1Context *v = avctx->priv_data;
297  MpegEncContext *s = &v->s;
298  AVFrame *f = s->current_picture.f;
299  int plane, i;
300 
301  /* Windows Media Image codecs have a convergence interval of two keyframes.
302  Since we can't enforce it, clear to black the missing sprite. This is
303  wrong but it looks better than doing nothing. */
304 
305  if (f && f->data[0])
306  for (plane = 0; plane < (s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++)
307  for (i = 0; i < v->sprite_height>>!!plane; i++)
308  memset(f->data[plane] + i * f->linesize[plane],
309  plane ? 128 : 0, f->linesize[plane]);
310 }
311 
312 #endif
313 
315 {
316  MpegEncContext *s = &v->s;
317  int i, ret = AVERROR(ENOMEM);
318  int mb_height = FFALIGN(s->mb_height, 2);
319 
320  /* Allocate mb bitplanes */
321  v->mv_type_mb_plane = av_malloc (s->mb_stride * mb_height);
322  v->direct_mb_plane = av_malloc (s->mb_stride * mb_height);
323  v->forward_mb_plane = av_malloc (s->mb_stride * mb_height);
324  v->fieldtx_plane = av_mallocz(s->mb_stride * mb_height);
325  v->acpred_plane = av_malloc (s->mb_stride * mb_height);
326  v->over_flags_plane = av_malloc (s->mb_stride * mb_height);
327  if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->forward_mb_plane ||
328  !v->fieldtx_plane || !v->acpred_plane || !v->over_flags_plane)
329  goto error;
330 
331  v->n_allocated_blks = s->mb_width + 2;
332  v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
333  v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
334  if (!v->block || !v->cbp_base)
335  goto error;
336  v->cbp = v->cbp_base + s->mb_stride;
337  v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
338  if (!v->ttblk_base)
339  goto error;
340  v->ttblk = v->ttblk_base + s->mb_stride;
341  v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
342  if (!v->is_intra_base)
343  goto error;
344  v->is_intra = v->is_intra_base + s->mb_stride;
345  v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
346  if (!v->luma_mv_base)
347  goto error;
348  v->luma_mv = v->luma_mv_base + s->mb_stride;
349 
350  /* allocate block type info in that way so it could be used with s->block_index[] */
351  v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
352  if (!v->mb_type_base)
353  goto error;
354  v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
355  v->mb_type[1] = v->mb_type_base + s->b8_stride * (mb_height * 2 + 1) + s->mb_stride + 1;
356  v->mb_type[2] = v->mb_type[1] + s->mb_stride * (mb_height + 1);
357 
358  /* allocate memory to store block level MV info */
359  v->blk_mv_type_base = av_mallocz( s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
360  if (!v->blk_mv_type_base)
361  goto error;
362  v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1;
363  v->mv_f_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
364  if (!v->mv_f_base)
365  goto error;
366  v->mv_f[0] = v->mv_f_base + s->b8_stride + 1;
367  v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
368  v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
369  if (!v->mv_f_next_base)
370  goto error;
371  v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1;
372  v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
373 
375  for (i = 0; i < 4; i++) {
376  v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width);
377  if (!v->sr_rows[i >> 1][i & 1])
378  goto error;
379  }
380  }
381 
382  ret = ff_intrax8_common_init(s->avctx, &v->x8, &s->idsp,
383  s->block, s->block_last_index,
384  s->mb_width, s->mb_height);
385  if (ret < 0)
386  goto error;
387 
388  return 0;
389 
390 error:
392  return ret;
393 }
394 
396 {
397  int i;
398  for (i = 0; i < 64; i++) {
399 #define transpose(x) ((x >> 3) | ((x & 7) << 3))
400  v->zz_8x8[0][i] = transpose(ff_wmv1_scantable[0][i]);
401  v->zz_8x8[1][i] = transpose(ff_wmv1_scantable[1][i]);
402  v->zz_8x8[2][i] = transpose(ff_wmv1_scantable[2][i]);
403  v->zz_8x8[3][i] = transpose(ff_wmv1_scantable[3][i]);
405  }
406  v->left_blk_sh = 0;
407  v->top_blk_sh = 3;
408 }
409 
415 {
416  VC1Context *v = avctx->priv_data;
417  MpegEncContext *s = &v->s;
418  GetBitContext gb;
419 
420  /* save the container output size for WMImage */
421  v->output_width = avctx->width;
422  v->output_height = avctx->height;
423 
424  if (!avctx->extradata_size || !avctx->extradata)
425  return -1;
426  if (!(avctx->flags & AV_CODEC_FLAG_GRAY))
427  avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
428  else
429  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
430  v->s.avctx = avctx;
431 
432  if (ff_vc1_init_common(v) < 0)
433  return -1;
434  ff_blockdsp_init(&s->bdsp, avctx);
436  ff_qpeldsp_init(&s->qdsp);
437 
438  if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) {
439  int count = 0;
440 
441  // looks like WMV3 has a sequence header stored in the extradata
442  // advanced sequence header may be before the first frame
443  // the last byte of the extradata is a version number, 1 for the
444  // samples we can decode
445 
446  init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
447 
448  if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0)
449  return -1;
450 
451  count = avctx->extradata_size*8 - get_bits_count(&gb);
452  if (count > 0) {
453  av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
454  count, get_bits_long(&gb, FFMIN(count, 32)));
455  } else if (count < 0) {
456  av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
457  }
458  } else { // VC1/WVC1/WVP2
459  const uint8_t *start = avctx->extradata;
460  uint8_t *end = avctx->extradata + avctx->extradata_size;
461  const uint8_t *next;
462  int size, buf2_size;
463  uint8_t *buf2 = NULL;
464  int seq_initialized = 0, ep_initialized = 0;
465 
466  if (avctx->extradata_size < 16) {
467  av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
468  return -1;
469  }
470 
472  start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
473  next = start;
474  for (; next < end; start = next) {
475  next = find_next_marker(start + 4, end);
476  size = next - start - 4;
477  if (size <= 0)
478  continue;
479  buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
480  init_get_bits(&gb, buf2, buf2_size * 8);
481  switch (AV_RB32(start)) {
482  case VC1_CODE_SEQHDR:
483  if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0) {
484  av_free(buf2);
485  return -1;
486  }
487  seq_initialized = 1;
488  break;
489  case VC1_CODE_ENTRYPOINT:
490  if (ff_vc1_decode_entry_point(avctx, v, &gb) < 0) {
491  av_free(buf2);
492  return -1;
493  }
494  ep_initialized = 1;
495  break;
496  }
497  }
498  av_free(buf2);
499  if (!seq_initialized || !ep_initialized) {
500  av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
501  return -1;
502  }
503  v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE);
504  }
505 
507  if (!v->sprite_output_frame)
508  return AVERROR(ENOMEM);
509 
510  avctx->profile = v->profile;
511  if (v->profile == PROFILE_ADVANCED)
512  avctx->level = v->level;
513 
514  avctx->has_b_frames = !!avctx->max_b_frames;
515 
516  if (v->color_prim == 1 || v->color_prim == 5 || v->color_prim == 6)
517  avctx->color_primaries = v->color_prim;
518  if (v->transfer_char == 1 || v->transfer_char == 7)
519  avctx->color_trc = v->transfer_char;
520  if (v->matrix_coef == 1 || v->matrix_coef == 6 || v->matrix_coef == 7)
521  avctx->colorspace = v->matrix_coef;
522 
523  s->mb_width = (avctx->coded_width + 15) >> 4;
524  s->mb_height = (avctx->coded_height + 15) >> 4;
525 
526  if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
528  } else {
529  memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64);
530  v->left_blk_sh = 3;
531  v->top_blk_sh = 0;
532  }
533 
534  if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
535  v->sprite_width = avctx->coded_width;
536  v->sprite_height = avctx->coded_height;
537 
538  avctx->coded_width = avctx->width = v->output_width;
539  avctx->coded_height = avctx->height = v->output_height;
540 
541  // prevent 16.16 overflows
542  if (v->sprite_width > 1 << 14 ||
543  v->sprite_height > 1 << 14 ||
544  v->output_width > 1 << 14 ||
545  v->output_height > 1 << 14) return -1;
546  }
547  return 0;
548 }
549 
554 {
555  VC1Context *v = avctx->priv_data;
556  int i;
557 
559 
560  for (i = 0; i < 4; i++)
561  av_freep(&v->sr_rows[i >> 1][i & 1]);
562  av_freep(&v->hrd_rate);
563  av_freep(&v->hrd_buffer);
564  ff_mpv_common_end(&v->s);
568  av_freep(&v->fieldtx_plane);
569  av_freep(&v->acpred_plane);
571  av_freep(&v->mb_type_base);
573  av_freep(&v->mv_f_base);
575  av_freep(&v->block);
576  av_freep(&v->cbp_base);
577  av_freep(&v->ttblk_base);
578  av_freep(&v->is_intra_base); // FIXME use v->mb_type[]
579  av_freep(&v->luma_mv_base);
581  return 0;
582 }
583 
584 
588 static int vc1_decode_frame(AVCodecContext *avctx, void *data,
589  int *got_frame, AVPacket *avpkt)
590 {
591  const uint8_t *buf = avpkt->data;
592  int buf_size = avpkt->size, n_slices = 0, i, ret;
593  VC1Context *v = avctx->priv_data;
594  MpegEncContext *s = &v->s;
595  AVFrame *pict = data;
596  uint8_t *buf2 = NULL;
597  const uint8_t *buf_start = buf;
598  int mb_height, n_slices1;
599  struct {
600  uint8_t *buf;
601  GetBitContext gb;
602  int mby_start;
603  } *slices = NULL, *tmp;
604 
605  /* no supplementary picture */
606  if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
607  /* special case for last picture */
608  if (s->low_delay == 0 && s->next_picture_ptr) {
609  if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0)
610  return ret;
611  s->next_picture_ptr = NULL;
612 
613  *got_frame = 1;
614  }
615 
616  return 0;
617  }
618 
619  //for advanced profile we may need to parse and unescape data
620  if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
621  int buf_size2 = 0;
622  buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
623 
624  if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */
625  const uint8_t *start, *end, *next;
626  int size;
627 
628  next = buf;
629  for (start = buf, end = buf + buf_size; next < end; start = next) {
630  next = find_next_marker(start + 4, end);
631  size = next - start - 4;
632  if (size <= 0) continue;
633  switch (AV_RB32(start)) {
634  case VC1_CODE_FRAME:
635  if (avctx->hwaccel)
636  buf_start = start;
637  buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
638  break;
639  case VC1_CODE_FIELD: {
640  int buf_size3;
641  tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
642  if (!tmp)
643  goto err;
644  slices = tmp;
645  slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
646  if (!slices[n_slices].buf)
647  goto err;
648  buf_size3 = vc1_unescape_buffer(start + 4, size,
649  slices[n_slices].buf);
650  init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
651  buf_size3 << 3);
652  /* assuming that the field marker is at the exact middle,
653  hope it's correct */
654  slices[n_slices].mby_start = s->mb_height >> 1;
655  n_slices1 = n_slices - 1; // index of the last slice of the first field
656  n_slices++;
657  break;
658  }
659  case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
660  buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
661  init_get_bits(&s->gb, buf2, buf_size2 * 8);
662  ff_vc1_decode_entry_point(avctx, v, &s->gb);
663  break;
664  case VC1_CODE_SLICE: {
665  int buf_size3;
666  tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
667  if (!tmp)
668  goto err;
669  slices = tmp;
670  slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
671  if (!slices[n_slices].buf)
672  goto err;
673  buf_size3 = vc1_unescape_buffer(start + 4, size,
674  slices[n_slices].buf);
675  init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
676  buf_size3 << 3);
677  slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9);
678  n_slices++;
679  break;
680  }
681  }
682  }
683  } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */
684  const uint8_t *divider;
685  int buf_size3;
686 
687  divider = find_next_marker(buf, buf + buf_size);
688  if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) {
689  av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
690  goto err;
691  } else { // found field marker, unescape second field
692  tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
693  if (!tmp)
694  goto err;
695  slices = tmp;
696  slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
697  if (!slices[n_slices].buf)
698  goto err;
699  buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
700  init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
701  buf_size3 << 3);
702  slices[n_slices].mby_start = s->mb_height >> 1;
703  n_slices1 = n_slices - 1;
704  n_slices++;
705  }
706  buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
707  } else {
708  buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
709  }
710  init_get_bits(&s->gb, buf2, buf_size2*8);
711  } else
712  init_get_bits(&s->gb, buf, buf_size*8);
713 
714  if (v->res_sprite) {
715  v->new_sprite = !get_bits1(&s->gb);
716  v->two_sprites = get_bits1(&s->gb);
717  /* res_sprite means a Windows Media Image stream, AV_CODEC_ID_*IMAGE means
718  we're using the sprite compositor. These are intentionally kept separate
719  so you can get the raw sprites by using the wmv3 decoder for WMVP or
720  the vc1 one for WVP2 */
721  if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
722  if (v->new_sprite) {
723  // switch AVCodecContext parameters to those of the sprites
724  avctx->width = avctx->coded_width = v->sprite_width;
725  avctx->height = avctx->coded_height = v->sprite_height;
726  } else {
727  goto image;
728  }
729  }
730  }
731 
732  if (s->context_initialized &&
733  (s->width != avctx->coded_width ||
734  s->height != avctx->coded_height)) {
735  ff_vc1_decode_end(avctx);
736  }
737 
738  if (!s->context_initialized) {
739  if (ff_msmpeg4_decode_init(avctx) < 0)
740  goto err;
741  if (ff_vc1_decode_init_alloc_tables(v) < 0) {
743  goto err;
744  }
745 
746  s->low_delay = !avctx->has_b_frames || v->res_sprite;
747 
748  if (v->profile == PROFILE_ADVANCED) {
749  s->h_edge_pos = avctx->coded_width;
750  s->v_edge_pos = avctx->coded_height;
751  }
752  }
753 
754  // do parse frame header
755  v->pic_header_flag = 0;
756  v->first_pic_header_flag = 1;
757  if (v->profile < PROFILE_ADVANCED) {
758  if (ff_vc1_parse_frame_header(v, &s->gb) < 0) {
759  goto err;
760  }
761  } else {
762  if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
763  goto err;
764  }
765  }
766  v->first_pic_header_flag = 0;
767 
768  if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
769  && s->pict_type != AV_PICTURE_TYPE_I) {
770  av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n");
771  goto err;
772  }
773 
774  // for skipping the frame
777 
778  /* skip B-frames if we don't have reference frames */
779  if (!s->last_picture_ptr && (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) {
780  goto end;
781  }
782  if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
784  avctx->skip_frame >= AVDISCARD_ALL) {
785  goto end;
786  }
787 
788  if (s->next_p_frame_damaged) {
789  if (s->pict_type == AV_PICTURE_TYPE_B)
790  goto end;
791  else
792  s->next_p_frame_damaged = 0;
793  }
794 
795  if (ff_mpv_frame_start(s, avctx) < 0) {
796  goto err;
797  }
798 
799  // process pulldown flags
801  // Pulldown flags are only valid when 'broadcast' has been set.
802  // So ticks_per_frame will be 2
803  if (v->rff) {
804  // repeat field
806  } else if (v->rptfrm) {
807  // repeat frames
808  s->current_picture_ptr->f->repeat_pict = v->rptfrm * 2;
809  }
810 
813 
814  if (avctx->hwaccel) {
815  if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
816  goto err;
817  if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
818  goto err;
819  if (avctx->hwaccel->end_frame(avctx) < 0)
820  goto err;
821  } else {
822  int header_ret = 0;
823 
825 
826  v->bits = buf_size * 8;
827  v->end_mb_x = s->mb_width;
828  if (v->field_mode) {
829  s->current_picture.f->linesize[0] <<= 1;
830  s->current_picture.f->linesize[1] <<= 1;
831  s->current_picture.f->linesize[2] <<= 1;
832  s->linesize <<= 1;
833  s->uvlinesize <<= 1;
834  }
835  mb_height = s->mb_height >> v->field_mode;
836 
837  if (!mb_height) {
838  av_log(v->s.avctx, AV_LOG_ERROR, "Invalid mb_height.\n");
839  goto err;
840  }
841 
842  for (i = 0; i <= n_slices; i++) {
843  if (i > 0 && slices[i - 1].mby_start >= mb_height) {
844  if (v->field_mode <= 0) {
845  av_log(v->s.avctx, AV_LOG_ERROR, "Slice %d starts beyond "
846  "picture boundary (%d >= %d)\n", i,
847  slices[i - 1].mby_start, mb_height);
848  continue;
849  }
850  v->second_field = 1;
851  v->blocks_off = s->mb_width * s->mb_height << 1;
852  v->mb_off = s->mb_stride * s->mb_height >> 1;
853  } else {
854  v->second_field = 0;
855  v->blocks_off = 0;
856  v->mb_off = 0;
857  }
858  if (i) {
859  v->pic_header_flag = 0;
860  if (v->field_mode && i == n_slices1 + 2) {
861  if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
862  av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
863  if (avctx->err_recognition & AV_EF_EXPLODE)
864  goto err;
865  continue;
866  }
867  } else if (get_bits1(&s->gb)) {
868  v->pic_header_flag = 1;
869  if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
870  av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
871  if (avctx->err_recognition & AV_EF_EXPLODE)
872  goto err;
873  continue;
874  }
875  }
876  }
877  if (header_ret < 0)
878  continue;
879  s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height);
880  if (!v->field_mode || v->second_field)
881  s->end_mb_y = (i == n_slices ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
882  else
883  s->end_mb_y = (i <= n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
884 
885  if (s->end_mb_y <= s->start_mb_y) {
886  av_log(v->s.avctx, AV_LOG_ERROR, "Invalid slice size\n");
887  goto err;
888  }
889 
891  if (i != n_slices)
892  s->gb = slices[i].gb;
893  }
894  if (v->field_mode) {
895  v->second_field = 0;
896  s->current_picture.f->linesize[0] >>= 1;
897  s->current_picture.f->linesize[1] >>= 1;
898  s->current_picture.f->linesize[2] >>= 1;
899  s->linesize >>= 1;
900  s->uvlinesize >>= 1;
902  FFSWAP(uint8_t *, v->mv_f_next[0], v->mv_f[0]);
903  FFSWAP(uint8_t *, v->mv_f_next[1], v->mv_f[1]);
904  }
905  }
906  ff_dlog(s->avctx, "Consumed %i/%i bits\n",
907  get_bits_count(&s->gb), s->gb.size_in_bits);
908 // if (get_bits_count(&s->gb) > buf_size * 8)
909 // return -1;
910  if (!v->field_mode)
911  ff_er_frame_end(&s->er);
912  }
913 
914  ff_mpv_frame_end(s);
915 
916  if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
917 image:
918  avctx->width = avctx->coded_width = v->output_width;
919  avctx->height = avctx->coded_height = v->output_height;
920  if (avctx->skip_frame >= AVDISCARD_NONREF)
921  goto end;
922 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
923  if (vc1_decode_sprites(v, &s->gb))
924  goto err;
925 #endif
926  if ((ret = av_frame_ref(pict, v->sprite_output_frame)) < 0)
927  goto err;
928  *got_frame = 1;
929  } else {
930  if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
931  if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
932  goto err;
934  *got_frame = 1;
935  } else if (s->last_picture_ptr) {
936  if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
937  goto err;
939  *got_frame = 1;
940  }
941  }
942 
943 end:
944  av_free(buf2);
945  for (i = 0; i < n_slices; i++)
946  av_free(slices[i].buf);
947  av_free(slices);
948  return buf_size;
949 
950 err:
951  av_free(buf2);
952  for (i = 0; i < n_slices; i++)
953  av_free(slices[i].buf);
954  av_free(slices);
955  return -1;
956 }
957 
958 
960 #if CONFIG_VC1_DXVA2_HWACCEL
962 #endif
963 #if CONFIG_VC1_D3D11VA_HWACCEL
965 #endif
966 #if CONFIG_VC1_VAAPI_HWACCEL
968 #endif
969 #if CONFIG_VC1_VDPAU_HWACCEL
971 #endif
974 };
975 
977  .name = "vc1",
978  .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
979  .type = AVMEDIA_TYPE_VIDEO,
980  .id = AV_CODEC_ID_VC1,
981  .priv_data_size = sizeof(VC1Context),
983  .close = ff_vc1_decode_end,
985  .flush = ff_mpeg_flush,
986  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
987  .pix_fmts = vc1_hwaccel_pixfmt_list_420,
989 };
990 
991 #if CONFIG_WMV3_DECODER
992 AVCodec ff_wmv3_decoder = {
993  .name = "wmv3",
994  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
995  .type = AVMEDIA_TYPE_VIDEO,
996  .id = AV_CODEC_ID_WMV3,
997  .priv_data_size = sizeof(VC1Context),
999  .close = ff_vc1_decode_end,
1001  .flush = ff_mpeg_flush,
1002  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1003  .pix_fmts = vc1_hwaccel_pixfmt_list_420,
1005 };
1006 #endif
1007 
1008 #if CONFIG_WMV3IMAGE_DECODER
1009 AVCodec ff_wmv3image_decoder = {
1010  .name = "wmv3image",
1011  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"),
1012  .type = AVMEDIA_TYPE_VIDEO,
1013  .id = AV_CODEC_ID_WMV3IMAGE,
1014  .priv_data_size = sizeof(VC1Context),
1015  .init = vc1_decode_init,
1016  .close = ff_vc1_decode_end,
1018  .capabilities = AV_CODEC_CAP_DR1,
1019  .flush = vc1_sprite_flush,
1020  .pix_fmts = (const enum AVPixelFormat[]) {
1022  AV_PIX_FMT_NONE
1023  },
1024 };
1025 #endif
1026 
1027 #if CONFIG_VC1IMAGE_DECODER
1028 AVCodec ff_vc1image_decoder = {
1029  .name = "vc1image",
1030  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"),
1031  .type = AVMEDIA_TYPE_VIDEO,
1032  .id = AV_CODEC_ID_VC1IMAGE,
1033  .priv_data_size = sizeof(VC1Context),
1034  .init = vc1_decode_init,
1035  .close = ff_vc1_decode_end,
1037  .capabilities = AV_CODEC_CAP_DR1,
1038  .flush = vc1_sprite_flush,
1039  .pix_fmts = (const enum AVPixelFormat[]) {
1041  AV_PIX_FMT_NONE
1042  },
1043 };
1044 #endif
int color_prim
8 bits, chroma coordinates of the color primaries
Definition: vc1.h:191
IDCTDSPContext idsp
Definition: mpegvideo.h:221
const struct AVCodec * codec
Definition: avcodec.h:1418
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
discard all frames except keyframes
Definition: avcodec.h:688
BI type.
Definition: avutil.h:266
qpel_mc_func avg_qpel_pixels_tab[2][16]
Definition: qpeldsp.h:74
The VC1 Context.
Definition: vc1.h:158
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
Definition: mpegvideo.h:148
void(* sprite_v_double_onescale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, const uint8_t *src2a, int alpha, int width)
Definition: vc1dsp.h:68
uint8_t * mv_f_base
Definition: vc1.h:334
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1595
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:228
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
int ff_msmpeg4_decode_init(AVCodecContext *avctx)
Definition: msmpeg4dec.c:282
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
Definition: mpegvideo.h:149
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:1679
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
Definition: mpegvideo.h:127
void ff_er_frame_end(ERContext *s)
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:258
int size
Definition: avcodec.h:1347
int transfer_char
8 bits, Opto-electronic transfer characteristics
Definition: vc1.h:192
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
void(* sprite_v_single)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width)
Definition: vc1dsp.h:66
void ff_print_debug_info(MpegEncContext *s, Picture *p)
Print debugging info for the given picture.
Definition: mpegvideo.c:1284
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
uint8_t zz_8x8[4][64]
Zigzag table for TT_8x8, permuted for IDCT.
Definition: vc1.h:223
av_cold void ff_h264chroma_init(H264ChromaContext *c, int bit_depth)
Definition: h264chroma.c:39
mpegvideo header.
IntraX8Context x8
Definition: vc1.h:160
uint8_t * mb_type_base
Definition: vc1.h:248
discard all
Definition: avcodec.h:689
uint8_t * mv_f[2]
0: MV obtained from same field, 1: opposite field
Definition: vc1.h:334
int sprite_height
Definition: vc1.h:360
int end_mb_x
Horizontal macroblock limit (used only by mss2)
Definition: vc1.h:377
int profile
profile
Definition: avcodec.h:2880
QpelDSPContext qdsp
Definition: mpegvideo.h:226
AVCodec.
Definition: avcodec.h:3120
av_cold int ff_intrax8_common_init(AVCodecContext *avctx, IntraX8Context *w, IDCTDSPContext *idsp, int16_t(*block)[64], int block_last_index[12], int mb_width, int mb_height)
Initialize IntraX8 frame decoder.
Definition: intrax8.c:732
uint8_t rff
Definition: vc1.h:295
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
enum AVDiscard skip_frame
Definition: avcodec.h:2989
int bits
Definition: vc1.h:164
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2696
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:863
uint8_t * acpred_plane
AC prediction flags bitplane.
Definition: vc1.h:305
VC-1 tables.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int matrix_coef
8 bits, Color primaries->YCbCr transform matrix
Definition: vc1.h:193
uint8_t
#define av_cold
Definition: attributes.h:66
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:68
int first_pic_header_flag
Definition: vc1.h:352
uint16_t * hrd_rate
Definition: vc1.h:310
av_cold int ff_vc1_init_common(VC1Context *v)
Init VC-1 specific tables and VC1Context members.
Definition: vc1.c:1564
#define AV_RB32
Definition: intreadwrite.h:130
int interlace
Progressive/interlaced (RPTFTM syntax element)
Definition: vc1.h:186
int second_field
Definition: vc1.h:338
int n_allocated_blks
Definition: vc1.h:369
qpel_mc_func(* qpel_put)[16]
Definition: motion_est.h:86
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:199
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1523
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:175
int16_t((* luma_mv)[2]
Definition: vc1.h:372
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags...
Definition: vc1.h:203
const char data[16]
Definition: mxf.c:70
MSMPEG4 data tables.
uint8_t * data
Definition: avcodec.h:1346
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:182
bitstream reader API header.
uint8_t * forward_mb_plane
bitplane for "forward" MBs
Definition: vc1.h:272
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:124
int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
Decode Simple/Main Profiles sequence header.
Definition: vc1.c:290
uint8_t * over_flags_plane
Overflags bitplane.
Definition: vc1.h:307
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:763
#define FFALIGN(x, a)
Definition: macros.h:48
#define transpose(x)
int16_t(* block)[6][64]
Definition: vc1.h:368
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1715
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:80
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
ERContext er
Definition: mpegvideo.h:528
static av_cold int vc1_decode_init(AVCodecContext *avctx)
Initialize a VC1/WMV3 decoder.
Definition: vc1dec.c:414
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
#define IS_MARKER(state)
Definition: dca_parser.c:45
uint8_t * mv_f_next_base
Definition: vc1.h:335
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1503
void ff_vc1_decode_blocks(VC1Context *v)
Definition: vc1_block.c:3020
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
int low_delay
no reordering needed / has no B-frames
Definition: mpegvideo.h:391
qpel_mc_func put_qpel_pixels_tab[2][16]
Definition: qpeldsp.h:73
GetBitContext gb
Definition: mpegvideo.h:431
void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:998
#define FFMAX(a, b)
Definition: common.h:64
uint8_t * blk_mv_type
0: frame MV, 1: field MV (interlaced frame)
Definition: vc1.h:333
void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo.c:1776
int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb)
Definition: vc1.c:835
const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64]
Definition: msmpeg4data.c:1809
AVCodec ff_vc1_decoder
Definition: vc1dec.c:976
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3141
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:201
av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
Close a VC1/WMV3 decoder.
Definition: vc1dec.c:553
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2670
#define FFMIN(a, b)
Definition: common.h:66
av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
Definition: vc1dec.c:395
int next_p_frame_damaged
set if the next p frame is damaged, to avoid showing trashed B-frames
Definition: mpegvideo.h:348
uint8_t * blk_mv_type_base
Definition: vc1.h:333
int field_mode
1 for interlaced field pictures
Definition: vc1.h:336
av_cold void ff_intrax8_common_end(IntraX8Context *w)
Destroy IntraX8 frame structure.
Definition: intrax8.c:767
int width
picture width / height.
Definition: avcodec.h:1580
int8_t zzi_8x8[64]
Definition: vc1.h:332
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:179
int mb_off
Definition: vc1.h:348
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:45
int size_in_bits
Definition: get_bits.h:57
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2106
av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v)
Definition: vc1dec.c:314
int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext *gb)
Definition: vc1.c:620
int level
level
Definition: avcodec.h:2970
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:81
MotionEstContext me
Definition: mpegvideo.h:276
#define AV_EF_EXPLODE
Definition: avcodec.h:2681
uint32_t * cbp
Definition: vc1.h:370
int left_blk_sh
Definition: vc1.h:224
int16_t(* luma_mv_base)[2]
Definition: vc1.h:372
uint8_t * fieldtx_plane
Definition: vc1.h:330
int * ttblk_base
Definition: vc1.h:243
uint8_t * sr_rows[2][2]
Sprite resizer line cache.
Definition: vc1.h:361
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:785
NULL
Definition: eval.c:55
static int width
Definition: utils.c:156
#define AV_LOG_INFO
Standard information.
Definition: log.h:135
int res_sprite
Simple/Main Profile sequence header.
Definition: vc1.h:168
int top_blk_sh
Either 3 or 0, positions of l/t in blk[].
Definition: vc1.h:224
Libavcodec external API header.
void(* sprite_v_double_noscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width)
Definition: vc1dsp.h:67
#define ff_dlog(ctx,...)
Definition: internal.h:60
static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
Definition: vc1_common.h:72
ptrdiff_t linesize
line size, in bytes, may be different from width
Definition: mpegvideo.h:129
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: avcodec.h:3325
enum AVCodecID codec_id
Definition: avcodec.h:1426
BlockDSPContext bdsp
Definition: mpegvideo.h:218
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
Definition: blockdsp.c:58
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
const int8_t ff_vc1_adv_interlaced_8x8_zz[64]
Definition: vc1data.c:1047
uint32_t * cbp_base
Definition: vc1.h:370
main external API structure.
Definition: avcodec.h:1409
uint8_t * is_intra
Definition: vc1.h:371
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:95
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
int extradata_size
Definition: avcodec.h:1524
static const AVProfile profiles[]
Definition: libdcadec.c:181
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:267
int sprite_width
Definition: vc1.h:360
uint8_t * is_intra_base
Definition: vc1.h:371
int coded_height
Definition: avcodec.h:1595
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:259
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2120
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2113
struct AVFrame * f
Definition: mpegpicture.h:46
void(* sprite_v_double_twoscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, const uint8_t *src2a, const uint8_t *src2b, int offset2, int alpha, int width)
Definition: vc1dsp.h:70
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:189
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:362
int context_initialized
Definition: mpegvideo.h:119
ptrdiff_t uvlinesize
line size, for chroma in bytes, may be different from width
Definition: mpegvideo.h:130
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
Definition: mpegvideo.c:1052
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:300
uint8_t * direct_mb_plane
bitplane for "direct" MBs
Definition: vc1.h:271
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
Definition: pixfmt.h:137
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:206
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:257
static int vc1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Decode a VC1/WMV3 frame.
Definition: vc1dec.c:588
uint8_t * mv_type_mb_plane
bitplane for mv_type == (4MV)
Definition: vc1.h:270
int blocks_off
Definition: vc1.h:348
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:302
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: avcodec.h:3314
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
qpel_mc_func(* qpel_avg)[16]
Definition: motion_est.h:87
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
Definition: mpegvideo.h:126
MpegEncContext s
Definition: vc1.h:159
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
Definition: avcodec.h:3301
MpegEncContext.
Definition: mpegvideo.h:76
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
Definition: mpegvideo.h:178
struct AVCodecContext * avctx
Definition: mpegvideo.h:93
const AVProfile ff_vc1_profiles[]
Definition: profiles.c:115
discard all non reference
Definition: avcodec.h:686
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
Y , 8bpp.
Definition: pixfmt.h:67
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:125
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
static enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[]
Definition: vc1dec.c:959
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1797
int output_width
Definition: vc1.h:360
Picture last_picture
copy of the previous picture structure.
Definition: mpegvideo.h:157
Picture * last_picture_ptr
pointer to the previous picture.
Definition: mpegvideo.h:177
Bi-dir predicted.
Definition: avutil.h:262
int res_fasttx
reserved, always 1
Definition: vc1.h:172
int pic_header_flag
Definition: vc1.h:353
int * ttblk
Transform type at the block level.
Definition: vc1.h:243
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
void * priv_data
Definition: avcodec.h:1451
int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
Definition: vc1.c:522
AVFrame * sprite_output_frame
Definition: vc1.h:359
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:1263
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:476
static uint8_t tmp[8]
Definition: des.c:38
uint8_t rptfrm
Definition: vc1.h:295
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:196
H264ChromaContext h264chroma
Definition: vc1.h:161
int level
Advanced Profile.
Definition: vc1.h:182
HW decoding through Direct3D11, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer...
Definition: pixfmt.h:222
int new_sprite
Frame decoding info for sprite modes.
Definition: vc1.h:357
uint8_t * mv_f_next[2]
Definition: vc1.h:335
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
Definition: qpeldsp.c:735
#define FFSWAP(type, a, b)
Definition: common.h:69
int two_sprites
Definition: vc1.h:358
uint8_t * mb_type[3]
Definition: vc1.h:248
void(* sprite_h)(uint8_t *dst, const uint8_t *src, int offset, int advance, int count)
Definition: vc1dsp.h:65
uint16_t * hrd_buffer
Definition: vc1.h:310
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
This structure stores compressed data.
Definition: avcodec.h:1323
static av_always_inline const uint8_t * find_next_marker(const uint8_t *src, const uint8_t *end)
Find VC-1 marker in buffer.
Definition: vc1_common.h:58
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838
VC1DSPContext vc1dsp
Definition: vc1.h:162
int output_height
Definition: vc1.h:360