FFmpeg
vp9.c
Go to the documentation of this file.
1 /*
2  * VP9 compatible video decoder
3  *
4  * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
5  * Copyright (C) 2013 Clément Bœsch <u pkh me>
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 #include "config_components.h"
25 
26 #include "avcodec.h"
27 #include "codec_internal.h"
28 #include "decode.h"
29 #include "get_bits.h"
30 #include "hwaccel_internal.h"
31 #include "hwconfig.h"
32 #include "profiles.h"
33 #include "progressframe.h"
34 #include "refstruct.h"
35 #include "thread.h"
36 #include "pthread_internal.h"
37 
38 #include "videodsp.h"
39 #include "vp89_rac.h"
40 #include "vp9.h"
41 #include "vp9data.h"
42 #include "vp9dec.h"
43 #include "vpx_rac.h"
44 #include "libavutil/avassert.h"
45 #include "libavutil/mem.h"
46 #include "libavutil/pixdesc.h"
48 
49 #define VP9_SYNCCODE 0x498342
50 
51 #if HAVE_THREADS
52 DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt,
53  (offsetof(VP9Context, progress_mutex)),
54  (offsetof(VP9Context, progress_cond)));
55 
56 static int vp9_alloc_entries(AVCodecContext *avctx, int n) {
57  VP9Context *s = avctx->priv_data;
58 
59  if (avctx->active_thread_type & FF_THREAD_SLICE) {
60  if (s->entries)
61  av_freep(&s->entries);
62 
63  s->entries = av_malloc_array(n, sizeof(atomic_int));
64  if (!s->entries)
65  return AVERROR(ENOMEM);
66  }
67  return 0;
68 }
69 
70 static void vp9_report_tile_progress(VP9Context *s, int field, int n) {
71  pthread_mutex_lock(&s->progress_mutex);
72  atomic_fetch_add_explicit(&s->entries[field], n, memory_order_release);
73  pthread_cond_signal(&s->progress_cond);
74  pthread_mutex_unlock(&s->progress_mutex);
75 }
76 
77 static void vp9_await_tile_progress(VP9Context *s, int field, int n) {
78  if (atomic_load_explicit(&s->entries[field], memory_order_acquire) >= n)
79  return;
80 
81  pthread_mutex_lock(&s->progress_mutex);
82  while (atomic_load_explicit(&s->entries[field], memory_order_relaxed) != n)
83  pthread_cond_wait(&s->progress_cond, &s->progress_mutex);
84  pthread_mutex_unlock(&s->progress_mutex);
85 }
86 #else
87 static int vp9_alloc_entries(AVCodecContext *avctx, int n) { return 0; }
88 #endif
89 
91 {
92  av_freep(&td->b_base);
93  av_freep(&td->block_base);
94  av_freep(&td->block_structure);
95 }
96 
97 static void vp9_frame_unref(VP9Frame *f)
98 {
100  ff_refstruct_unref(&f->extradata);
101  ff_refstruct_unref(&f->hwaccel_picture_private);
102  f->segmentation_map = NULL;
103 }
104 
106 {
107  VP9Context *s = avctx->priv_data;
108  int ret, sz;
109 
111  if (ret < 0)
112  return ret;
113 
114  sz = 64 * s->sb_cols * s->sb_rows;
115  if (sz != s->frame_extradata_pool_size) {
116  ff_refstruct_pool_uninit(&s->frame_extradata_pool);
117  s->frame_extradata_pool = ff_refstruct_pool_alloc(sz * (1 + sizeof(VP9mvrefPair)),
119  if (!s->frame_extradata_pool) {
120  s->frame_extradata_pool_size = 0;
121  ret = AVERROR(ENOMEM);
122  goto fail;
123  }
124  s->frame_extradata_pool_size = sz;
125  }
126  f->extradata = ff_refstruct_pool_get(s->frame_extradata_pool);
127  if (!f->extradata) {
128  ret = AVERROR(ENOMEM);
129  goto fail;
130  }
131 
132  f->segmentation_map = f->extradata;
133  f->mv = (VP9mvrefPair *) ((char*)f->extradata + sz);
134 
135  ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
136  if (ret < 0)
137  goto fail;
138 
139  return 0;
140 
141 fail:
143  return ret;
144 }
145 
146 static void vp9_frame_replace(VP9Frame *dst, const VP9Frame *src)
147 {
148  ff_progress_frame_replace(&dst->tf, &src->tf);
149 
150  ff_refstruct_replace(&dst->extradata, src->extradata);
151 
152  dst->segmentation_map = src->segmentation_map;
153  dst->mv = src->mv;
154  dst->uses_2pass = src->uses_2pass;
155 
157  src->hwaccel_picture_private);
158 }
159 
160 static int update_size(AVCodecContext *avctx, int w, int h)
161 {
162 #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
163  CONFIG_VP9_D3D11VA_HWACCEL * 2 + \
164  CONFIG_VP9_D3D12VA_HWACCEL + \
165  CONFIG_VP9_NVDEC_HWACCEL + \
166  CONFIG_VP9_VAAPI_HWACCEL + \
167  CONFIG_VP9_VDPAU_HWACCEL + \
168  CONFIG_VP9_VIDEOTOOLBOX_HWACCEL)
169  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
170  VP9Context *s = avctx->priv_data;
171  uint8_t *p;
172  int bytesperpixel = s->bytesperpixel, ret, cols, rows;
173  int lflvl_len, i;
174 
175  av_assert0(w > 0 && h > 0);
176 
177  if (!(s->pix_fmt == s->gf_fmt && w == s->w && h == s->h)) {
178  if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
179  return ret;
180 
181  switch (s->pix_fmt) {
182  case AV_PIX_FMT_YUV420P:
184 #if CONFIG_VP9_DXVA2_HWACCEL
185  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
186 #endif
187 #if CONFIG_VP9_D3D11VA_HWACCEL
188  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
189  *fmtp++ = AV_PIX_FMT_D3D11;
190 #endif
191 #if CONFIG_VP9_D3D12VA_HWACCEL
192  *fmtp++ = AV_PIX_FMT_D3D12;
193 #endif
194 #if CONFIG_VP9_NVDEC_HWACCEL
195  *fmtp++ = AV_PIX_FMT_CUDA;
196 #endif
197 #if CONFIG_VP9_VAAPI_HWACCEL
198  *fmtp++ = AV_PIX_FMT_VAAPI;
199 #endif
200 #if CONFIG_VP9_VDPAU_HWACCEL
201  *fmtp++ = AV_PIX_FMT_VDPAU;
202 #endif
203 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
204  *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
205 #endif
206  break;
208 #if CONFIG_VP9_NVDEC_HWACCEL
209  *fmtp++ = AV_PIX_FMT_CUDA;
210 #endif
211 #if CONFIG_VP9_VAAPI_HWACCEL
212  *fmtp++ = AV_PIX_FMT_VAAPI;
213 #endif
214 #if CONFIG_VP9_VDPAU_HWACCEL
215  *fmtp++ = AV_PIX_FMT_VDPAU;
216 #endif
217  break;
218  case AV_PIX_FMT_YUV444P:
221 #if CONFIG_VP9_VAAPI_HWACCEL
222  *fmtp++ = AV_PIX_FMT_VAAPI;
223 #endif
224  break;
225  case AV_PIX_FMT_GBRP:
226  case AV_PIX_FMT_GBRP10:
227  case AV_PIX_FMT_GBRP12:
228 #if CONFIG_VP9_VAAPI_HWACCEL
229  *fmtp++ = AV_PIX_FMT_VAAPI;
230 #endif
231  break;
232  }
233 
234  *fmtp++ = s->pix_fmt;
235  *fmtp = AV_PIX_FMT_NONE;
236 
237  ret = ff_get_format(avctx, pix_fmts);
238  if (ret < 0)
239  return ret;
240 
241  avctx->pix_fmt = ret;
242  s->gf_fmt = s->pix_fmt;
243  s->w = w;
244  s->h = h;
245  }
246 
247  cols = (w + 7) >> 3;
248  rows = (h + 7) >> 3;
249 
250  if (s->intra_pred_data[0] && cols == s->cols && rows == s->rows && s->pix_fmt == s->last_fmt)
251  return 0;
252 
253  s->last_fmt = s->pix_fmt;
254  s->sb_cols = (w + 63) >> 6;
255  s->sb_rows = (h + 63) >> 6;
256  s->cols = (w + 7) >> 3;
257  s->rows = (h + 7) >> 3;
258  lflvl_len = avctx->active_thread_type == FF_THREAD_SLICE ? s->sb_rows : 1;
259 
260 #define assign(var, type, n) var = (type) p; p += s->sb_cols * (n) * sizeof(*var)
261  av_freep(&s->intra_pred_data[0]);
262  // FIXME we slightly over-allocate here for subsampled chroma, but a little
263  // bit of padding shouldn't affect performance...
264  p = av_malloc(s->sb_cols * (128 + 192 * bytesperpixel +
265  lflvl_len * sizeof(*s->lflvl) + 16 * sizeof(*s->above_mv_ctx)));
266  if (!p)
267  return AVERROR(ENOMEM);
268  assign(s->intra_pred_data[0], uint8_t *, 64 * bytesperpixel);
269  assign(s->intra_pred_data[1], uint8_t *, 64 * bytesperpixel);
270  assign(s->intra_pred_data[2], uint8_t *, 64 * bytesperpixel);
271  assign(s->above_y_nnz_ctx, uint8_t *, 16);
272  assign(s->above_mode_ctx, uint8_t *, 16);
273  assign(s->above_mv_ctx, VP9mv(*)[2], 16);
274  assign(s->above_uv_nnz_ctx[0], uint8_t *, 16);
275  assign(s->above_uv_nnz_ctx[1], uint8_t *, 16);
276  assign(s->above_partition_ctx, uint8_t *, 8);
277  assign(s->above_skip_ctx, uint8_t *, 8);
278  assign(s->above_txfm_ctx, uint8_t *, 8);
279  assign(s->above_segpred_ctx, uint8_t *, 8);
280  assign(s->above_intra_ctx, uint8_t *, 8);
281  assign(s->above_comp_ctx, uint8_t *, 8);
282  assign(s->above_ref_ctx, uint8_t *, 8);
283  assign(s->above_filter_ctx, uint8_t *, 8);
284  assign(s->lflvl, VP9Filter *, lflvl_len);
285 #undef assign
286 
287  if (s->td) {
288  for (i = 0; i < s->active_tile_cols; i++)
289  vp9_tile_data_free(&s->td[i]);
290  }
291 
292  if (s->s.h.bpp != s->last_bpp) {
293  ff_vp9dsp_init(&s->dsp, s->s.h.bpp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
294  ff_videodsp_init(&s->vdsp, s->s.h.bpp);
295  s->last_bpp = s->s.h.bpp;
296  }
297 
298  return 0;
299 }
300 
302 {
303  int i;
304  VP9Context *s = avctx->priv_data;
305  int chroma_blocks, chroma_eobs, bytesperpixel = s->bytesperpixel;
306  VP9TileData *td = &s->td[0];
307 
308  if (td->b_base && td->block_base && s->block_alloc_using_2pass == s->s.frames[CUR_FRAME].uses_2pass)
309  return 0;
310 
312  chroma_blocks = 64 * 64 >> (s->ss_h + s->ss_v);
313  chroma_eobs = 16 * 16 >> (s->ss_h + s->ss_v);
314  if (s->s.frames[CUR_FRAME].uses_2pass) {
315  int sbs = s->sb_cols * s->sb_rows;
316 
317  td->b_base = av_malloc_array(s->cols * s->rows, sizeof(VP9Block));
318  td->block_base = av_mallocz(((64 * 64 + 2 * chroma_blocks) * bytesperpixel * sizeof(int16_t) +
319  16 * 16 + 2 * chroma_eobs) * sbs);
320  if (!td->b_base || !td->block_base)
321  return AVERROR(ENOMEM);
322  td->uvblock_base[0] = td->block_base + sbs * 64 * 64 * bytesperpixel;
323  td->uvblock_base[1] = td->uvblock_base[0] + sbs * chroma_blocks * bytesperpixel;
324  td->eob_base = (uint8_t *) (td->uvblock_base[1] + sbs * chroma_blocks * bytesperpixel);
325  td->uveob_base[0] = td->eob_base + 16 * 16 * sbs;
326  td->uveob_base[1] = td->uveob_base[0] + chroma_eobs * sbs;
327 
329  td->block_structure = av_malloc_array(s->cols * s->rows, sizeof(*td->block_structure));
330  if (!td->block_structure)
331  return AVERROR(ENOMEM);
332  }
333  } else {
334  for (i = 1; i < s->active_tile_cols; i++)
335  vp9_tile_data_free(&s->td[i]);
336 
337  for (i = 0; i < s->active_tile_cols; i++) {
338  s->td[i].b_base = av_malloc(sizeof(VP9Block));
339  s->td[i].block_base = av_mallocz((64 * 64 + 2 * chroma_blocks) * bytesperpixel * sizeof(int16_t) +
340  16 * 16 + 2 * chroma_eobs);
341  if (!s->td[i].b_base || !s->td[i].block_base)
342  return AVERROR(ENOMEM);
343  s->td[i].uvblock_base[0] = s->td[i].block_base + 64 * 64 * bytesperpixel;
344  s->td[i].uvblock_base[1] = s->td[i].uvblock_base[0] + chroma_blocks * bytesperpixel;
345  s->td[i].eob_base = (uint8_t *) (s->td[i].uvblock_base[1] + chroma_blocks * bytesperpixel);
346  s->td[i].uveob_base[0] = s->td[i].eob_base + 16 * 16;
347  s->td[i].uveob_base[1] = s->td[i].uveob_base[0] + chroma_eobs;
348 
350  s->td[i].block_structure = av_malloc_array(s->cols * s->rows, sizeof(*td->block_structure));
351  if (!s->td[i].block_structure)
352  return AVERROR(ENOMEM);
353  }
354  }
355  }
356  s->block_alloc_using_2pass = s->s.frames[CUR_FRAME].uses_2pass;
357 
358  return 0;
359 }
360 
361 // The sign bit is at the end, not the start, of a bit sequence
363 {
364  int v = get_bits(gb, n);
365  return get_bits1(gb) ? -v : v;
366 }
367 
368 static av_always_inline int inv_recenter_nonneg(int v, int m)
369 {
370  if (v > 2 * m)
371  return v;
372  if (v & 1)
373  return m - ((v + 1) >> 1);
374  return m + (v >> 1);
375 }
376 
377 // differential forward probability updates
378 static int update_prob(VPXRangeCoder *c, int p)
379 {
380  static const uint8_t inv_map_table[255] = {
381  7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
382  189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
383  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
384  25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
385  40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
386  55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
387  70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
388  86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
389  101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
390  116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
391  131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
392  146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
393  161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
394  177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
395  192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
396  207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
397  222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
398  237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
399  252, 253, 253,
400  };
401  int d;
402 
403  /* This code is trying to do a differential probability update. For a
404  * current probability A in the range [1, 255], the difference to a new
405  * probability of any value can be expressed differentially as 1-A, 255-A
406  * where some part of this (absolute range) exists both in positive as
407  * well as the negative part, whereas another part only exists in one
408  * half. We're trying to code this shared part differentially, i.e.
409  * times two where the value of the lowest bit specifies the sign, and
410  * the single part is then coded on top of this. This absolute difference
411  * then again has a value of [0, 254], but a bigger value in this range
412  * indicates that we're further away from the original value A, so we
413  * can code this as a VLC code, since higher values are increasingly
414  * unlikely. The first 20 values in inv_map_table[] allow 'cheap, rough'
415  * updates vs. the 'fine, exact' updates further down the range, which
416  * adds one extra dimension to this differential update model. */
417 
418  if (!vp89_rac_get(c)) {
419  d = vp89_rac_get_uint(c, 4) + 0;
420  } else if (!vp89_rac_get(c)) {
421  d = vp89_rac_get_uint(c, 4) + 16;
422  } else if (!vp89_rac_get(c)) {
423  d = vp89_rac_get_uint(c, 5) + 32;
424  } else {
425  d = vp89_rac_get_uint(c, 7);
426  if (d >= 65)
427  d = (d << 1) - 65 + vp89_rac_get(c);
428  d += 64;
429  av_assert2(d < FF_ARRAY_ELEMS(inv_map_table));
430  }
431 
432  return p <= 128 ? 1 + inv_recenter_nonneg(inv_map_table[d], p - 1) :
433  255 - inv_recenter_nonneg(inv_map_table[d], 255 - p);
434 }
435 
437 {
438  static const enum AVColorSpace colorspaces[8] = {
441  };
442  VP9Context *s = avctx->priv_data;
443  int bits = avctx->profile <= 1 ? 0 : 1 + get_bits1(&s->gb); // 0:8, 1:10, 2:12
444 
445  s->bpp_index = bits;
446  s->s.h.bpp = 8 + bits * 2;
447  s->bytesperpixel = (7 + s->s.h.bpp) >> 3;
448  avctx->colorspace = colorspaces[get_bits(&s->gb, 3)];
449  if (avctx->colorspace == AVCOL_SPC_RGB) { // RGB = profile 1
450  static const enum AVPixelFormat pix_fmt_rgb[3] = {
452  };
453  s->ss_h = s->ss_v = 0;
454  avctx->color_range = AVCOL_RANGE_JPEG;
455  s->pix_fmt = pix_fmt_rgb[bits];
456  if (avctx->profile & 1) {
457  if (get_bits1(&s->gb)) {
458  av_log(avctx, AV_LOG_ERROR, "Reserved bit set in RGB\n");
459  return AVERROR_INVALIDDATA;
460  }
461  } else {
462  av_log(avctx, AV_LOG_ERROR, "RGB not supported in profile %d\n",
463  avctx->profile);
464  return AVERROR_INVALIDDATA;
465  }
466  } else {
467  static const enum AVPixelFormat pix_fmt_for_ss[3][2 /* v */][2 /* h */] = {
474  };
476  if (avctx->profile & 1) {
477  s->ss_h = get_bits1(&s->gb);
478  s->ss_v = get_bits1(&s->gb);
479  s->pix_fmt = pix_fmt_for_ss[bits][s->ss_v][s->ss_h];
480  if (s->pix_fmt == AV_PIX_FMT_YUV420P) {
481  av_log(avctx, AV_LOG_ERROR, "YUV 4:2:0 not supported in profile %d\n",
482  avctx->profile);
483  return AVERROR_INVALIDDATA;
484  } else if (get_bits1(&s->gb)) {
485  av_log(avctx, AV_LOG_ERROR, "Profile %d color details reserved bit set\n",
486  avctx->profile);
487  return AVERROR_INVALIDDATA;
488  }
489  } else {
490  s->ss_h = s->ss_v = 1;
491  s->pix_fmt = pix_fmt_for_ss[bits][1][1];
492  }
493  }
494 
495  return 0;
496 }
497 
499  const uint8_t *data, int size, int *ref)
500 {
501  VP9Context *s = avctx->priv_data;
502  int c, i, j, k, l, m, n, w, h, max, size2, ret, sharp;
503  int last_invisible;
504  const uint8_t *data2;
505 
506  /* general header */
507  if ((ret = init_get_bits8(&s->gb, data, size)) < 0) {
508  av_log(avctx, AV_LOG_ERROR, "Failed to initialize bitstream reader\n");
509  return ret;
510  }
511  if (get_bits(&s->gb, 2) != 0x2) { // frame marker
512  av_log(avctx, AV_LOG_ERROR, "Invalid frame marker\n");
513  return AVERROR_INVALIDDATA;
514  }
515  avctx->profile = get_bits1(&s->gb);
516  avctx->profile |= get_bits1(&s->gb) << 1;
517  if (avctx->profile == 3) avctx->profile += get_bits1(&s->gb);
518  if (avctx->profile > 3) {
519  av_log(avctx, AV_LOG_ERROR, "Profile %d is not yet supported\n", avctx->profile);
520  return AVERROR_INVALIDDATA;
521  }
522  s->s.h.profile = avctx->profile;
523  if (get_bits1(&s->gb)) {
524  *ref = get_bits(&s->gb, 3);
525  return 0;
526  }
527 
528  s->last_keyframe = s->s.h.keyframe;
529  s->s.h.keyframe = !get_bits1(&s->gb);
530 
531  last_invisible = s->s.h.invisible;
532  s->s.h.invisible = !get_bits1(&s->gb);
533  s->s.h.errorres = get_bits1(&s->gb);
534  s->s.h.use_last_frame_mvs = !s->s.h.errorres && !last_invisible;
535 
536  if (s->s.h.keyframe) {
537  if (get_bits(&s->gb, 24) != VP9_SYNCCODE) { // synccode
538  av_log(avctx, AV_LOG_ERROR, "Invalid sync code\n");
539  return AVERROR_INVALIDDATA;
540  }
541  if ((ret = read_colorspace_details(avctx)) < 0)
542  return ret;
543  // for profile 1, here follows the subsampling bits
544  s->s.h.refreshrefmask = 0xff;
545  w = get_bits(&s->gb, 16) + 1;
546  h = get_bits(&s->gb, 16) + 1;
547  if (get_bits1(&s->gb)) // display size
548  skip_bits(&s->gb, 32);
549  } else {
550  s->s.h.intraonly = s->s.h.invisible ? get_bits1(&s->gb) : 0;
551  s->s.h.resetctx = s->s.h.errorres ? 0 : get_bits(&s->gb, 2);
552  if (s->s.h.intraonly) {
553  if (get_bits(&s->gb, 24) != VP9_SYNCCODE) { // synccode
554  av_log(avctx, AV_LOG_ERROR, "Invalid sync code\n");
555  return AVERROR_INVALIDDATA;
556  }
557  if (avctx->profile >= 1) {
558  if ((ret = read_colorspace_details(avctx)) < 0)
559  return ret;
560  } else {
561  s->ss_h = s->ss_v = 1;
562  s->s.h.bpp = 8;
563  s->bpp_index = 0;
564  s->bytesperpixel = 1;
565  s->pix_fmt = AV_PIX_FMT_YUV420P;
566  avctx->colorspace = AVCOL_SPC_BT470BG;
567  avctx->color_range = AVCOL_RANGE_MPEG;
568  }
569  s->s.h.refreshrefmask = get_bits(&s->gb, 8);
570  w = get_bits(&s->gb, 16) + 1;
571  h = get_bits(&s->gb, 16) + 1;
572  if (get_bits1(&s->gb)) // display size
573  skip_bits(&s->gb, 32);
574  } else {
575  s->s.h.refreshrefmask = get_bits(&s->gb, 8);
576  s->s.h.refidx[0] = get_bits(&s->gb, 3);
577  s->s.h.signbias[0] = get_bits1(&s->gb) && !s->s.h.errorres;
578  s->s.h.refidx[1] = get_bits(&s->gb, 3);
579  s->s.h.signbias[1] = get_bits1(&s->gb) && !s->s.h.errorres;
580  s->s.h.refidx[2] = get_bits(&s->gb, 3);
581  s->s.h.signbias[2] = get_bits1(&s->gb) && !s->s.h.errorres;
582  if (!s->s.refs[s->s.h.refidx[0]].f ||
583  !s->s.refs[s->s.h.refidx[1]].f ||
584  !s->s.refs[s->s.h.refidx[2]].f) {
585  av_log(avctx, AV_LOG_ERROR, "Not all references are available\n");
586  return AVERROR_INVALIDDATA;
587  }
588  if (get_bits1(&s->gb)) {
589  w = s->s.refs[s->s.h.refidx[0]].f->width;
590  h = s->s.refs[s->s.h.refidx[0]].f->height;
591  } else if (get_bits1(&s->gb)) {
592  w = s->s.refs[s->s.h.refidx[1]].f->width;
593  h = s->s.refs[s->s.h.refidx[1]].f->height;
594  } else if (get_bits1(&s->gb)) {
595  w = s->s.refs[s->s.h.refidx[2]].f->width;
596  h = s->s.refs[s->s.h.refidx[2]].f->height;
597  } else {
598  w = get_bits(&s->gb, 16) + 1;
599  h = get_bits(&s->gb, 16) + 1;
600  }
601  // Note that in this code, "CUR_FRAME" is actually before we
602  // have formally allocated a frame, and thus actually represents
603  // the _last_ frame
604  s->s.h.use_last_frame_mvs &= s->s.frames[CUR_FRAME].tf.f &&
605  s->s.frames[CUR_FRAME].tf.f->width == w &&
606  s->s.frames[CUR_FRAME].tf.f->height == h;
607  if (get_bits1(&s->gb)) // display size
608  skip_bits(&s->gb, 32);
609  s->s.h.highprecisionmvs = get_bits1(&s->gb);
610  s->s.h.filtermode = get_bits1(&s->gb) ? FILTER_SWITCHABLE :
611  get_bits(&s->gb, 2);
612  s->s.h.allowcompinter = s->s.h.signbias[0] != s->s.h.signbias[1] ||
613  s->s.h.signbias[0] != s->s.h.signbias[2];
614  if (s->s.h.allowcompinter) {
615  if (s->s.h.signbias[0] == s->s.h.signbias[1]) {
616  s->s.h.fixcompref = 2;
617  s->s.h.varcompref[0] = 0;
618  s->s.h.varcompref[1] = 1;
619  } else if (s->s.h.signbias[0] == s->s.h.signbias[2]) {
620  s->s.h.fixcompref = 1;
621  s->s.h.varcompref[0] = 0;
622  s->s.h.varcompref[1] = 2;
623  } else {
624  s->s.h.fixcompref = 0;
625  s->s.h.varcompref[0] = 1;
626  s->s.h.varcompref[1] = 2;
627  }
628  }
629  }
630  }
631  s->s.h.refreshctx = s->s.h.errorres ? 0 : get_bits1(&s->gb);
632  s->s.h.parallelmode = s->s.h.errorres ? 1 : get_bits1(&s->gb);
633  s->s.h.framectxid = c = get_bits(&s->gb, 2);
634  if (s->s.h.keyframe || s->s.h.intraonly)
635  s->s.h.framectxid = 0; // BUG: libvpx ignores this field in keyframes
636 
637  /* loopfilter header data */
638  if (s->s.h.keyframe || s->s.h.errorres || s->s.h.intraonly) {
639  // reset loopfilter defaults
640  s->s.h.lf_delta.ref[0] = 1;
641  s->s.h.lf_delta.ref[1] = 0;
642  s->s.h.lf_delta.ref[2] = -1;
643  s->s.h.lf_delta.ref[3] = -1;
644  s->s.h.lf_delta.mode[0] = 0;
645  s->s.h.lf_delta.mode[1] = 0;
646  memset(s->s.h.segmentation.feat, 0, sizeof(s->s.h.segmentation.feat));
647  }
648  s->s.h.filter.level = get_bits(&s->gb, 6);
649  sharp = get_bits(&s->gb, 3);
650  // if sharpness changed, reinit lim/mblim LUTs. if it didn't change, keep
651  // the old cache values since they are still valid
652  if (s->s.h.filter.sharpness != sharp) {
653  for (i = 1; i <= 63; i++) {
654  int limit = i;
655 
656  if (sharp > 0) {
657  limit >>= (sharp + 3) >> 2;
658  limit = FFMIN(limit, 9 - sharp);
659  }
660  limit = FFMAX(limit, 1);
661 
662  s->filter_lut.lim_lut[i] = limit;
663  s->filter_lut.mblim_lut[i] = 2 * (i + 2) + limit;
664  }
665  }
666  s->s.h.filter.sharpness = sharp;
667  if ((s->s.h.lf_delta.enabled = get_bits1(&s->gb))) {
668  if ((s->s.h.lf_delta.updated = get_bits1(&s->gb))) {
669  for (i = 0; i < 4; i++)
670  if (get_bits1(&s->gb))
671  s->s.h.lf_delta.ref[i] = get_sbits_inv(&s->gb, 6);
672  for (i = 0; i < 2; i++)
673  if (get_bits1(&s->gb))
674  s->s.h.lf_delta.mode[i] = get_sbits_inv(&s->gb, 6);
675  }
676  }
677 
678  /* quantization header data */
679  s->s.h.yac_qi = get_bits(&s->gb, 8);
680  s->s.h.ydc_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
681  s->s.h.uvdc_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
682  s->s.h.uvac_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
683  s->s.h.lossless = s->s.h.yac_qi == 0 && s->s.h.ydc_qdelta == 0 &&
684  s->s.h.uvdc_qdelta == 0 && s->s.h.uvac_qdelta == 0;
685  if (s->s.h.lossless)
687 
688  /* segmentation header info */
689  if ((s->s.h.segmentation.enabled = get_bits1(&s->gb))) {
690  if ((s->s.h.segmentation.update_map = get_bits1(&s->gb))) {
691  for (i = 0; i < 7; i++)
692  s->s.h.segmentation.prob[i] = get_bits1(&s->gb) ?
693  get_bits(&s->gb, 8) : 255;
694  if ((s->s.h.segmentation.temporal = get_bits1(&s->gb)))
695  for (i = 0; i < 3; i++)
696  s->s.h.segmentation.pred_prob[i] = get_bits1(&s->gb) ?
697  get_bits(&s->gb, 8) : 255;
698  }
699 
700  if (get_bits1(&s->gb)) {
701  s->s.h.segmentation.absolute_vals = get_bits1(&s->gb);
702  for (i = 0; i < 8; i++) {
703  if ((s->s.h.segmentation.feat[i].q_enabled = get_bits1(&s->gb)))
704  s->s.h.segmentation.feat[i].q_val = get_sbits_inv(&s->gb, 8);
705  if ((s->s.h.segmentation.feat[i].lf_enabled = get_bits1(&s->gb)))
706  s->s.h.segmentation.feat[i].lf_val = get_sbits_inv(&s->gb, 6);
707  if ((s->s.h.segmentation.feat[i].ref_enabled = get_bits1(&s->gb)))
708  s->s.h.segmentation.feat[i].ref_val = get_bits(&s->gb, 2);
709  s->s.h.segmentation.feat[i].skip_enabled = get_bits1(&s->gb);
710  }
711  }
712  }
713 
714  // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas
715  for (i = 0; i < (s->s.h.segmentation.enabled ? 8 : 1); i++) {
716  int qyac, qydc, quvac, quvdc, lflvl, sh;
717 
718  if (s->s.h.segmentation.enabled && s->s.h.segmentation.feat[i].q_enabled) {
719  if (s->s.h.segmentation.absolute_vals)
720  qyac = av_clip_uintp2(s->s.h.segmentation.feat[i].q_val, 8);
721  else
722  qyac = av_clip_uintp2(s->s.h.yac_qi + s->s.h.segmentation.feat[i].q_val, 8);
723  } else {
724  qyac = s->s.h.yac_qi;
725  }
726  qydc = av_clip_uintp2(qyac + s->s.h.ydc_qdelta, 8);
727  quvdc = av_clip_uintp2(qyac + s->s.h.uvdc_qdelta, 8);
728  quvac = av_clip_uintp2(qyac + s->s.h.uvac_qdelta, 8);
729  qyac = av_clip_uintp2(qyac, 8);
730 
731  s->s.h.segmentation.feat[i].qmul[0][0] = ff_vp9_dc_qlookup[s->bpp_index][qydc];
732  s->s.h.segmentation.feat[i].qmul[0][1] = ff_vp9_ac_qlookup[s->bpp_index][qyac];
733  s->s.h.segmentation.feat[i].qmul[1][0] = ff_vp9_dc_qlookup[s->bpp_index][quvdc];
734  s->s.h.segmentation.feat[i].qmul[1][1] = ff_vp9_ac_qlookup[s->bpp_index][quvac];
735 
736  sh = s->s.h.filter.level >= 32;
737  if (s->s.h.segmentation.enabled && s->s.h.segmentation.feat[i].lf_enabled) {
738  if (s->s.h.segmentation.absolute_vals)
739  lflvl = av_clip_uintp2(s->s.h.segmentation.feat[i].lf_val, 6);
740  else
741  lflvl = av_clip_uintp2(s->s.h.filter.level + s->s.h.segmentation.feat[i].lf_val, 6);
742  } else {
743  lflvl = s->s.h.filter.level;
744  }
745  if (s->s.h.lf_delta.enabled) {
746  s->s.h.segmentation.feat[i].lflvl[0][0] =
747  s->s.h.segmentation.feat[i].lflvl[0][1] =
748  av_clip_uintp2(lflvl + (s->s.h.lf_delta.ref[0] * (1 << sh)), 6);
749  for (j = 1; j < 4; j++) {
750  s->s.h.segmentation.feat[i].lflvl[j][0] =
751  av_clip_uintp2(lflvl + ((s->s.h.lf_delta.ref[j] +
752  s->s.h.lf_delta.mode[0]) * (1 << sh)), 6);
753  s->s.h.segmentation.feat[i].lflvl[j][1] =
754  av_clip_uintp2(lflvl + ((s->s.h.lf_delta.ref[j] +
755  s->s.h.lf_delta.mode[1]) * (1 << sh)), 6);
756  }
757  } else {
758  memset(s->s.h.segmentation.feat[i].lflvl, lflvl,
759  sizeof(s->s.h.segmentation.feat[i].lflvl));
760  }
761  }
762 
763  /* tiling info */
764  if ((ret = update_size(avctx, w, h)) < 0) {
765  av_log(avctx, AV_LOG_ERROR, "Failed to initialize decoder for %dx%d @ %d\n",
766  w, h, s->pix_fmt);
767  return ret;
768  }
769  for (s->s.h.tiling.log2_tile_cols = 0;
770  s->sb_cols > (64 << s->s.h.tiling.log2_tile_cols);
771  s->s.h.tiling.log2_tile_cols++) ;
772  for (max = 0; (s->sb_cols >> max) >= 4; max++) ;
773  max = FFMAX(0, max - 1);
774  while (max > s->s.h.tiling.log2_tile_cols) {
775  if (get_bits1(&s->gb))
776  s->s.h.tiling.log2_tile_cols++;
777  else
778  break;
779  }
780  s->s.h.tiling.log2_tile_rows = decode012(&s->gb);
781  s->s.h.tiling.tile_rows = 1 << s->s.h.tiling.log2_tile_rows;
782  if (s->s.h.tiling.tile_cols != (1 << s->s.h.tiling.log2_tile_cols)) {
783  int n_range_coders;
784  VPXRangeCoder *rc;
785 
786  if (s->td) {
787  for (i = 0; i < s->active_tile_cols; i++)
788  vp9_tile_data_free(&s->td[i]);
789  av_freep(&s->td);
790  }
791 
792  s->s.h.tiling.tile_cols = 1 << s->s.h.tiling.log2_tile_cols;
793  s->active_tile_cols = avctx->active_thread_type == FF_THREAD_SLICE ?
794  s->s.h.tiling.tile_cols : 1;
795  vp9_alloc_entries(avctx, s->sb_rows);
796  if (avctx->active_thread_type == FF_THREAD_SLICE) {
797  n_range_coders = 4; // max_tile_rows
798  } else {
799  n_range_coders = s->s.h.tiling.tile_cols;
800  }
801  s->td = av_calloc(s->active_tile_cols, sizeof(VP9TileData) +
802  n_range_coders * sizeof(VPXRangeCoder));
803  if (!s->td)
804  return AVERROR(ENOMEM);
805  rc = (VPXRangeCoder *) &s->td[s->active_tile_cols];
806  for (i = 0; i < s->active_tile_cols; i++) {
807  s->td[i].s = s;
808  s->td[i].c_b = rc;
809  rc += n_range_coders;
810  }
811  }
812 
813  /* check reference frames */
814  if (!s->s.h.keyframe && !s->s.h.intraonly) {
815  int valid_ref_frame = 0;
816  for (i = 0; i < 3; i++) {
817  AVFrame *ref = s->s.refs[s->s.h.refidx[i]].f;
818  int refw = ref->width, refh = ref->height;
819 
820  if (ref->format != avctx->pix_fmt) {
821  av_log(avctx, AV_LOG_ERROR,
822  "Ref pixfmt (%s) did not match current frame (%s)",
823  av_get_pix_fmt_name(ref->format),
824  av_get_pix_fmt_name(avctx->pix_fmt));
825  return AVERROR_INVALIDDATA;
826  } else if (refw == w && refh == h) {
827  s->mvscale[i][0] = s->mvscale[i][1] = 0;
828  } else {
829  /* Check to make sure at least one of frames that */
830  /* this frame references has valid dimensions */
831  if (w * 2 < refw || h * 2 < refh || w > 16 * refw || h > 16 * refh) {
832  av_log(avctx, AV_LOG_WARNING,
833  "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
834  refw, refh, w, h);
835  s->mvscale[i][0] = s->mvscale[i][1] = REF_INVALID_SCALE;
836  continue;
837  }
838  s->mvscale[i][0] = (refw << 14) / w;
839  s->mvscale[i][1] = (refh << 14) / h;
840  s->mvstep[i][0] = 16 * s->mvscale[i][0] >> 14;
841  s->mvstep[i][1] = 16 * s->mvscale[i][1] >> 14;
842  }
843  valid_ref_frame++;
844  }
845  if (!valid_ref_frame) {
846  av_log(avctx, AV_LOG_ERROR, "No valid reference frame is found, bitstream not supported\n");
847  return AVERROR_INVALIDDATA;
848  }
849  }
850 
851  if (s->s.h.keyframe || s->s.h.errorres || (s->s.h.intraonly && s->s.h.resetctx == 3)) {
852  s->prob_ctx[0].p = s->prob_ctx[1].p = s->prob_ctx[2].p =
853  s->prob_ctx[3].p = ff_vp9_default_probs;
854  memcpy(s->prob_ctx[0].coef, ff_vp9_default_coef_probs,
855  sizeof(ff_vp9_default_coef_probs));
856  memcpy(s->prob_ctx[1].coef, ff_vp9_default_coef_probs,
857  sizeof(ff_vp9_default_coef_probs));
858  memcpy(s->prob_ctx[2].coef, ff_vp9_default_coef_probs,
859  sizeof(ff_vp9_default_coef_probs));
860  memcpy(s->prob_ctx[3].coef, ff_vp9_default_coef_probs,
861  sizeof(ff_vp9_default_coef_probs));
862  } else if (s->s.h.intraonly && s->s.h.resetctx == 2) {
863  s->prob_ctx[c].p = ff_vp9_default_probs;
864  memcpy(s->prob_ctx[c].coef, ff_vp9_default_coef_probs,
865  sizeof(ff_vp9_default_coef_probs));
866  }
867 
868  // next 16 bits is size of the rest of the header (arith-coded)
869  s->s.h.compressed_header_size = size2 = get_bits(&s->gb, 16);
870  s->s.h.uncompressed_header_size = (get_bits_count(&s->gb) + 7) / 8;
871 
872  data2 = align_get_bits(&s->gb);
873  if (size2 > size - (data2 - data)) {
874  av_log(avctx, AV_LOG_ERROR, "Invalid compressed header size\n");
875  return AVERROR_INVALIDDATA;
876  }
877  ret = ff_vpx_init_range_decoder(&s->c, data2, size2);
878  if (ret < 0)
879  return ret;
880 
881  if (vpx_rac_get_prob_branchy(&s->c, 128)) { // marker bit
882  av_log(avctx, AV_LOG_ERROR, "Marker bit was set\n");
883  return AVERROR_INVALIDDATA;
884  }
885 
886  for (i = 0; i < s->active_tile_cols; i++) {
887  if (s->s.h.keyframe || s->s.h.intraonly) {
888  memset(s->td[i].counts.coef, 0, sizeof(s->td[0].counts.coef));
889  memset(s->td[i].counts.eob, 0, sizeof(s->td[0].counts.eob));
890  } else {
891  memset(&s->td[i].counts, 0, sizeof(s->td[0].counts));
892  }
893  s->td[i].nb_block_structure = 0;
894  }
895 
896  /* FIXME is it faster to not copy here, but do it down in the fw updates
897  * as explicit copies if the fw update is missing (and skip the copy upon
898  * fw update)? */
899  s->prob.p = s->prob_ctx[c].p;
900 
901  // txfm updates
902  if (s->s.h.lossless) {
903  s->s.h.txfmmode = TX_4X4;
904  } else {
905  s->s.h.txfmmode = vp89_rac_get_uint(&s->c, 2);
906  if (s->s.h.txfmmode == 3)
907  s->s.h.txfmmode += vp89_rac_get(&s->c);
908 
909  if (s->s.h.txfmmode == TX_SWITCHABLE) {
910  for (i = 0; i < 2; i++)
911  if (vpx_rac_get_prob_branchy(&s->c, 252))
912  s->prob.p.tx8p[i] = update_prob(&s->c, s->prob.p.tx8p[i]);
913  for (i = 0; i < 2; i++)
914  for (j = 0; j < 2; j++)
915  if (vpx_rac_get_prob_branchy(&s->c, 252))
916  s->prob.p.tx16p[i][j] =
917  update_prob(&s->c, s->prob.p.tx16p[i][j]);
918  for (i = 0; i < 2; i++)
919  for (j = 0; j < 3; j++)
920  if (vpx_rac_get_prob_branchy(&s->c, 252))
921  s->prob.p.tx32p[i][j] =
922  update_prob(&s->c, s->prob.p.tx32p[i][j]);
923  }
924  }
925 
926  // coef updates
927  for (i = 0; i < 4; i++) {
928  uint8_t (*ref)[2][6][6][3] = s->prob_ctx[c].coef[i];
929  if (vp89_rac_get(&s->c)) {
930  for (j = 0; j < 2; j++)
931  for (k = 0; k < 2; k++)
932  for (l = 0; l < 6; l++)
933  for (m = 0; m < 6; m++) {
934  uint8_t *p = s->prob.coef[i][j][k][l][m];
935  uint8_t *r = ref[j][k][l][m];
936  if (m >= 3 && l == 0) // dc only has 3 pt
937  break;
938  for (n = 0; n < 3; n++) {
939  if (vpx_rac_get_prob_branchy(&s->c, 252))
940  p[n] = update_prob(&s->c, r[n]);
941  else
942  p[n] = r[n];
943  }
944  memcpy(&p[3], ff_vp9_model_pareto8[p[2]], 8);
945  }
946  } else {
947  for (j = 0; j < 2; j++)
948  for (k = 0; k < 2; k++)
949  for (l = 0; l < 6; l++)
950  for (m = 0; m < 6; m++) {
951  uint8_t *p = s->prob.coef[i][j][k][l][m];
952  uint8_t *r = ref[j][k][l][m];
953  if (m > 3 && l == 0) // dc only has 3 pt
954  break;
955  memcpy(p, r, 3);
956  memcpy(&p[3], ff_vp9_model_pareto8[p[2]], 8);
957  }
958  }
959  if (s->s.h.txfmmode == i)
960  break;
961  }
962 
963  // mode updates
964  for (i = 0; i < 3; i++)
965  if (vpx_rac_get_prob_branchy(&s->c, 252))
966  s->prob.p.skip[i] = update_prob(&s->c, s->prob.p.skip[i]);
967  if (!s->s.h.keyframe && !s->s.h.intraonly) {
968  for (i = 0; i < 7; i++)
969  for (j = 0; j < 3; j++)
970  if (vpx_rac_get_prob_branchy(&s->c, 252))
971  s->prob.p.mv_mode[i][j] =
972  update_prob(&s->c, s->prob.p.mv_mode[i][j]);
973 
974  if (s->s.h.filtermode == FILTER_SWITCHABLE)
975  for (i = 0; i < 4; i++)
976  for (j = 0; j < 2; j++)
977  if (vpx_rac_get_prob_branchy(&s->c, 252))
978  s->prob.p.filter[i][j] =
979  update_prob(&s->c, s->prob.p.filter[i][j]);
980 
981  for (i = 0; i < 4; i++)
982  if (vpx_rac_get_prob_branchy(&s->c, 252))
983  s->prob.p.intra[i] = update_prob(&s->c, s->prob.p.intra[i]);
984 
985  if (s->s.h.allowcompinter) {
986  s->s.h.comppredmode = vp89_rac_get(&s->c);
987  if (s->s.h.comppredmode)
988  s->s.h.comppredmode += vp89_rac_get(&s->c);
989  if (s->s.h.comppredmode == PRED_SWITCHABLE)
990  for (i = 0; i < 5; i++)
991  if (vpx_rac_get_prob_branchy(&s->c, 252))
992  s->prob.p.comp[i] =
993  update_prob(&s->c, s->prob.p.comp[i]);
994  } else {
995  s->s.h.comppredmode = PRED_SINGLEREF;
996  }
997 
998  if (s->s.h.comppredmode != PRED_COMPREF) {
999  for (i = 0; i < 5; i++) {
1000  if (vpx_rac_get_prob_branchy(&s->c, 252))
1001  s->prob.p.single_ref[i][0] =
1002  update_prob(&s->c, s->prob.p.single_ref[i][0]);
1003  if (vpx_rac_get_prob_branchy(&s->c, 252))
1004  s->prob.p.single_ref[i][1] =
1005  update_prob(&s->c, s->prob.p.single_ref[i][1]);
1006  }
1007  }
1008 
1009  if (s->s.h.comppredmode != PRED_SINGLEREF) {
1010  for (i = 0; i < 5; i++)
1011  if (vpx_rac_get_prob_branchy(&s->c, 252))
1012  s->prob.p.comp_ref[i] =
1013  update_prob(&s->c, s->prob.p.comp_ref[i]);
1014  }
1015 
1016  for (i = 0; i < 4; i++)
1017  for (j = 0; j < 9; j++)
1018  if (vpx_rac_get_prob_branchy(&s->c, 252))
1019  s->prob.p.y_mode[i][j] =
1020  update_prob(&s->c, s->prob.p.y_mode[i][j]);
1021 
1022  for (i = 0; i < 4; i++)
1023  for (j = 0; j < 4; j++)
1024  for (k = 0; k < 3; k++)
1025  if (vpx_rac_get_prob_branchy(&s->c, 252))
1026  s->prob.p.partition[3 - i][j][k] =
1027  update_prob(&s->c,
1028  s->prob.p.partition[3 - i][j][k]);
1029 
1030  // mv fields don't use the update_prob subexp model for some reason
1031  for (i = 0; i < 3; i++)
1032  if (vpx_rac_get_prob_branchy(&s->c, 252))
1033  s->prob.p.mv_joint[i] = (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1034 
1035  for (i = 0; i < 2; i++) {
1036  if (vpx_rac_get_prob_branchy(&s->c, 252))
1037  s->prob.p.mv_comp[i].sign =
1038  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1039 
1040  for (j = 0; j < 10; j++)
1041  if (vpx_rac_get_prob_branchy(&s->c, 252))
1042  s->prob.p.mv_comp[i].classes[j] =
1043  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1044 
1045  if (vpx_rac_get_prob_branchy(&s->c, 252))
1046  s->prob.p.mv_comp[i].class0 =
1047  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1048 
1049  for (j = 0; j < 10; j++)
1050  if (vpx_rac_get_prob_branchy(&s->c, 252))
1051  s->prob.p.mv_comp[i].bits[j] =
1052  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1053  }
1054 
1055  for (i = 0; i < 2; i++) {
1056  for (j = 0; j < 2; j++)
1057  for (k = 0; k < 3; k++)
1058  if (vpx_rac_get_prob_branchy(&s->c, 252))
1059  s->prob.p.mv_comp[i].class0_fp[j][k] =
1060  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1061 
1062  for (j = 0; j < 3; j++)
1063  if (vpx_rac_get_prob_branchy(&s->c, 252))
1064  s->prob.p.mv_comp[i].fp[j] =
1065  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1066  }
1067 
1068  if (s->s.h.highprecisionmvs) {
1069  for (i = 0; i < 2; i++) {
1070  if (vpx_rac_get_prob_branchy(&s->c, 252))
1071  s->prob.p.mv_comp[i].class0_hp =
1072  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1073 
1074  if (vpx_rac_get_prob_branchy(&s->c, 252))
1075  s->prob.p.mv_comp[i].hp =
1076  (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
1077  }
1078  }
1079  }
1080 
1081  return (data2 - data) + size2;
1082 }
1083 
1084 static void decode_sb(VP9TileData *td, int row, int col, VP9Filter *lflvl,
1085  ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
1086 {
1087  const VP9Context *s = td->s;
1088  int c = ((s->above_partition_ctx[col] >> (3 - bl)) & 1) |
1089  (((td->left_partition_ctx[row & 0x7] >> (3 - bl)) & 1) << 1);
1090  const uint8_t *p = s->s.h.keyframe || s->s.h.intraonly ? ff_vp9_default_kf_partition_probs[bl][c] :
1091  s->prob.p.partition[bl][c];
1092  enum BlockPartition bp;
1093  ptrdiff_t hbs = 4 >> bl;
1094  AVFrame *f = s->s.frames[CUR_FRAME].tf.f;
1095  ptrdiff_t y_stride = f->linesize[0], uv_stride = f->linesize[1];
1096  int bytesperpixel = s->bytesperpixel;
1097 
1098  if (bl == BL_8X8) {
1100  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
1101  } else if (col + hbs < s->cols) { // FIXME why not <=?
1102  if (row + hbs < s->rows) { // FIXME why not <=?
1104  switch (bp) {
1105  case PARTITION_NONE:
1106  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
1107  break;
1108  case PARTITION_H:
1109  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
1110  yoff += hbs * 8 * y_stride;
1111  uvoff += hbs * 8 * uv_stride >> s->ss_v;
1112  ff_vp9_decode_block(td, row + hbs, col, lflvl, yoff, uvoff, bl, bp);
1113  break;
1114  case PARTITION_V:
1115  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
1116  yoff += hbs * 8 * bytesperpixel;
1117  uvoff += hbs * 8 * bytesperpixel >> s->ss_h;
1118  ff_vp9_decode_block(td, row, col + hbs, lflvl, yoff, uvoff, bl, bp);
1119  break;
1120  case PARTITION_SPLIT:
1121  decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1122  decode_sb(td, row, col + hbs, lflvl,
1123  yoff + 8 * hbs * bytesperpixel,
1124  uvoff + (8 * hbs * bytesperpixel >> s->ss_h), bl + 1);
1125  yoff += hbs * 8 * y_stride;
1126  uvoff += hbs * 8 * uv_stride >> s->ss_v;
1127  decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1128  decode_sb(td, row + hbs, col + hbs, lflvl,
1129  yoff + 8 * hbs * bytesperpixel,
1130  uvoff + (8 * hbs * bytesperpixel >> s->ss_h), bl + 1);
1131  break;
1132  default:
1133  av_assert0(0);
1134  }
1135  } else if (vpx_rac_get_prob_branchy(td->c, p[1])) {
1136  bp = PARTITION_SPLIT;
1137  decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1138  decode_sb(td, row, col + hbs, lflvl,
1139  yoff + 8 * hbs * bytesperpixel,
1140  uvoff + (8 * hbs * bytesperpixel >> s->ss_h), bl + 1);
1141  } else {
1142  bp = PARTITION_H;
1143  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
1144  }
1145  } else if (row + hbs < s->rows) { // FIXME why not <=?
1146  if (vpx_rac_get_prob_branchy(td->c, p[2])) {
1147  bp = PARTITION_SPLIT;
1148  decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1149  yoff += hbs * 8 * y_stride;
1150  uvoff += hbs * 8 * uv_stride >> s->ss_v;
1151  decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1152  } else {
1153  bp = PARTITION_V;
1154  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
1155  }
1156  } else {
1157  bp = PARTITION_SPLIT;
1158  decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1159  }
1160  td->counts.partition[bl][c][bp]++;
1161 }
1162 
1163 static void decode_sb_mem(VP9TileData *td, int row, int col, VP9Filter *lflvl,
1164  ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
1165 {
1166  const VP9Context *s = td->s;
1167  VP9Block *b = td->b;
1168  ptrdiff_t hbs = 4 >> bl;
1169  AVFrame *f = s->s.frames[CUR_FRAME].tf.f;
1170  ptrdiff_t y_stride = f->linesize[0], uv_stride = f->linesize[1];
1171  int bytesperpixel = s->bytesperpixel;
1172 
1173  if (bl == BL_8X8) {
1174  av_assert2(b->bl == BL_8X8);
1175  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, b->bl, b->bp);
1176  } else if (td->b->bl == bl) {
1177  ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, b->bl, b->bp);
1178  if (b->bp == PARTITION_H && row + hbs < s->rows) {
1179  yoff += hbs * 8 * y_stride;
1180  uvoff += hbs * 8 * uv_stride >> s->ss_v;
1181  ff_vp9_decode_block(td, row + hbs, col, lflvl, yoff, uvoff, b->bl, b->bp);
1182  } else if (b->bp == PARTITION_V && col + hbs < s->cols) {
1183  yoff += hbs * 8 * bytesperpixel;
1184  uvoff += hbs * 8 * bytesperpixel >> s->ss_h;
1185  ff_vp9_decode_block(td, row, col + hbs, lflvl, yoff, uvoff, b->bl, b->bp);
1186  }
1187  } else {
1188  decode_sb_mem(td, row, col, lflvl, yoff, uvoff, bl + 1);
1189  if (col + hbs < s->cols) { // FIXME why not <=?
1190  if (row + hbs < s->rows) {
1191  decode_sb_mem(td, row, col + hbs, lflvl, yoff + 8 * hbs * bytesperpixel,
1192  uvoff + (8 * hbs * bytesperpixel >> s->ss_h), bl + 1);
1193  yoff += hbs * 8 * y_stride;
1194  uvoff += hbs * 8 * uv_stride >> s->ss_v;
1195  decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1196  decode_sb_mem(td, row + hbs, col + hbs, lflvl,
1197  yoff + 8 * hbs * bytesperpixel,
1198  uvoff + (8 * hbs * bytesperpixel >> s->ss_h), bl + 1);
1199  } else {
1200  yoff += hbs * 8 * bytesperpixel;
1201  uvoff += hbs * 8 * bytesperpixel >> s->ss_h;
1202  decode_sb_mem(td, row, col + hbs, lflvl, yoff, uvoff, bl + 1);
1203  }
1204  } else if (row + hbs < s->rows) {
1205  yoff += hbs * 8 * y_stride;
1206  uvoff += hbs * 8 * uv_stride >> s->ss_v;
1207  decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1208  }
1209  }
1210 }
1211 
1212 static void set_tile_offset(int *start, int *end, int idx, int log2_n, int n)
1213 {
1214  int sb_start = ( idx * n) >> log2_n;
1215  int sb_end = ((idx + 1) * n) >> log2_n;
1216  *start = FFMIN(sb_start, n) << 3;
1217  *end = FFMIN(sb_end, n) << 3;
1218 }
1219 
1221 {
1222  int i;
1223 
1224  av_freep(&s->intra_pred_data[0]);
1225  for (i = 0; i < s->active_tile_cols; i++)
1226  vp9_tile_data_free(&s->td[i]);
1227 }
1228 
1230 {
1231  VP9Context *s = avctx->priv_data;
1232  int i;
1233 
1234  for (int i = 0; i < 3; i++)
1235  vp9_frame_unref(&s->s.frames[i]);
1236  ff_refstruct_pool_uninit(&s->frame_extradata_pool);
1237  for (i = 0; i < 8; i++) {
1238  ff_progress_frame_unref(&s->s.refs[i]);
1239  ff_progress_frame_unref(&s->next_refs[i]);
1240  }
1241 
1242  free_buffers(s);
1243 #if HAVE_THREADS
1244  av_freep(&s->entries);
1245  ff_pthread_free(s, vp9_context_offsets);
1246 #endif
1247  av_freep(&s->td);
1248  return 0;
1249 }
1250 
1251 static int decode_tiles(AVCodecContext *avctx,
1252  const uint8_t *data, int size)
1253 {
1254  VP9Context *s = avctx->priv_data;
1255  VP9TileData *td = &s->td[0];
1256  int row, col, tile_row, tile_col, ret;
1257  int bytesperpixel;
1258  int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1259  AVFrame *f;
1260  ptrdiff_t yoff, uvoff, ls_y, ls_uv;
1261 
1262  f = s->s.frames[CUR_FRAME].tf.f;
1263  ls_y = f->linesize[0];
1264  ls_uv =f->linesize[1];
1265  bytesperpixel = s->bytesperpixel;
1266 
1267  yoff = uvoff = 0;
1268  for (tile_row = 0; tile_row < s->s.h.tiling.tile_rows; tile_row++) {
1269  set_tile_offset(&tile_row_start, &tile_row_end,
1270  tile_row, s->s.h.tiling.log2_tile_rows, s->sb_rows);
1271 
1272  for (tile_col = 0; tile_col < s->s.h.tiling.tile_cols; tile_col++) {
1273  int64_t tile_size;
1274 
1275  if (tile_col == s->s.h.tiling.tile_cols - 1 &&
1276  tile_row == s->s.h.tiling.tile_rows - 1) {
1277  tile_size = size;
1278  } else {
1279  tile_size = AV_RB32(data);
1280  data += 4;
1281  size -= 4;
1282  }
1283  if (tile_size > size)
1284  return AVERROR_INVALIDDATA;
1285  ret = ff_vpx_init_range_decoder(&td->c_b[tile_col], data, tile_size);
1286  if (ret < 0)
1287  return ret;
1288  if (vpx_rac_get_prob_branchy(&td->c_b[tile_col], 128)) // marker bit
1289  return AVERROR_INVALIDDATA;
1290  data += tile_size;
1291  size -= tile_size;
1292  }
1293 
1294  for (row = tile_row_start; row < tile_row_end;
1295  row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >> s->ss_v) {
1296  VP9Filter *lflvl_ptr = s->lflvl;
1297  ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1298 
1299  for (tile_col = 0; tile_col < s->s.h.tiling.tile_cols; tile_col++) {
1300  set_tile_offset(&tile_col_start, &tile_col_end,
1301  tile_col, s->s.h.tiling.log2_tile_cols, s->sb_cols);
1302  td->tile_col_start = tile_col_start;
1303  if (s->pass != 2) {
1304  memset(td->left_partition_ctx, 0, 8);
1305  memset(td->left_skip_ctx, 0, 8);
1306  if (s->s.h.keyframe || s->s.h.intraonly) {
1307  memset(td->left_mode_ctx, DC_PRED, 16);
1308  } else {
1309  memset(td->left_mode_ctx, NEARESTMV, 8);
1310  }
1311  memset(td->left_y_nnz_ctx, 0, 16);
1312  memset(td->left_uv_nnz_ctx, 0, 32);
1313  memset(td->left_segpred_ctx, 0, 8);
1314 
1315  td->c = &td->c_b[tile_col];
1316  }
1317 
1318  for (col = tile_col_start;
1319  col < tile_col_end;
1320  col += 8, yoff2 += 64 * bytesperpixel,
1321  uvoff2 += 64 * bytesperpixel >> s->ss_h, lflvl_ptr++) {
1322  // FIXME integrate with lf code (i.e. zero after each
1323  // use, similar to invtxfm coefficients, or similar)
1324  if (s->pass != 1) {
1325  memset(lflvl_ptr->mask, 0, sizeof(lflvl_ptr->mask));
1326  }
1327 
1328  if (s->pass == 2) {
1329  decode_sb_mem(td, row, col, lflvl_ptr,
1330  yoff2, uvoff2, BL_64X64);
1331  } else {
1332  if (vpx_rac_is_end(td->c)) {
1333  return AVERROR_INVALIDDATA;
1334  }
1335  decode_sb(td, row, col, lflvl_ptr,
1336  yoff2, uvoff2, BL_64X64);
1337  }
1338  }
1339  }
1340 
1341  if (s->pass == 1)
1342  continue;
1343 
1344  // backup pre-loopfilter reconstruction data for intra
1345  // prediction of next row of sb64s
1346  if (row + 8 < s->rows) {
1347  memcpy(s->intra_pred_data[0],
1348  f->data[0] + yoff + 63 * ls_y,
1349  8 * s->cols * bytesperpixel);
1350  memcpy(s->intra_pred_data[1],
1351  f->data[1] + uvoff + ((64 >> s->ss_v) - 1) * ls_uv,
1352  8 * s->cols * bytesperpixel >> s->ss_h);
1353  memcpy(s->intra_pred_data[2],
1354  f->data[2] + uvoff + ((64 >> s->ss_v) - 1) * ls_uv,
1355  8 * s->cols * bytesperpixel >> s->ss_h);
1356  }
1357 
1358  // loopfilter one row
1359  if (s->s.h.filter.level) {
1360  yoff2 = yoff;
1361  uvoff2 = uvoff;
1362  lflvl_ptr = s->lflvl;
1363  for (col = 0; col < s->cols;
1364  col += 8, yoff2 += 64 * bytesperpixel,
1365  uvoff2 += 64 * bytesperpixel >> s->ss_h, lflvl_ptr++) {
1366  ff_vp9_loopfilter_sb(avctx, lflvl_ptr, row, col,
1367  yoff2, uvoff2);
1368  }
1369  }
1370 
1371  // FIXME maybe we can make this more finegrained by running the
1372  // loopfilter per-block instead of after each sbrow
1373  // In fact that would also make intra pred left preparation easier?
1374  ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, row >> 3);
1375  }
1376  }
1377  return 0;
1378 }
1379 
1380 #if HAVE_THREADS
1381 static av_always_inline
1382 int decode_tiles_mt(AVCodecContext *avctx, void *tdata, int jobnr,
1383  int threadnr)
1384 {
1385  VP9Context *s = avctx->priv_data;
1386  VP9TileData *td = &s->td[jobnr];
1387  ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1388  int bytesperpixel = s->bytesperpixel, row, col, tile_row;
1389  unsigned tile_cols_len;
1390  int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1391  VP9Filter *lflvl_ptr_base;
1392  AVFrame *f;
1393 
1394  f = s->s.frames[CUR_FRAME].tf.f;
1395  ls_y = f->linesize[0];
1396  ls_uv =f->linesize[1];
1397 
1398  set_tile_offset(&tile_col_start, &tile_col_end,
1399  jobnr, s->s.h.tiling.log2_tile_cols, s->sb_cols);
1400  td->tile_col_start = tile_col_start;
1401  uvoff = (64 * bytesperpixel >> s->ss_h)*(tile_col_start >> 3);
1402  yoff = (64 * bytesperpixel)*(tile_col_start >> 3);
1403  lflvl_ptr_base = s->lflvl+(tile_col_start >> 3);
1404 
1405  for (tile_row = 0; tile_row < s->s.h.tiling.tile_rows; tile_row++) {
1406  set_tile_offset(&tile_row_start, &tile_row_end,
1407  tile_row, s->s.h.tiling.log2_tile_rows, s->sb_rows);
1408 
1409  td->c = &td->c_b[tile_row];
1410  for (row = tile_row_start; row < tile_row_end;
1411  row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >> s->ss_v) {
1412  ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1413  VP9Filter *lflvl_ptr = lflvl_ptr_base+s->sb_cols*(row >> 3);
1414 
1415  memset(td->left_partition_ctx, 0, 8);
1416  memset(td->left_skip_ctx, 0, 8);
1417  if (s->s.h.keyframe || s->s.h.intraonly) {
1418  memset(td->left_mode_ctx, DC_PRED, 16);
1419  } else {
1420  memset(td->left_mode_ctx, NEARESTMV, 8);
1421  }
1422  memset(td->left_y_nnz_ctx, 0, 16);
1423  memset(td->left_uv_nnz_ctx, 0, 32);
1424  memset(td->left_segpred_ctx, 0, 8);
1425 
1426  for (col = tile_col_start;
1427  col < tile_col_end;
1428  col += 8, yoff2 += 64 * bytesperpixel,
1429  uvoff2 += 64 * bytesperpixel >> s->ss_h, lflvl_ptr++) {
1430  // FIXME integrate with lf code (i.e. zero after each
1431  // use, similar to invtxfm coefficients, or similar)
1432  memset(lflvl_ptr->mask, 0, sizeof(lflvl_ptr->mask));
1433  decode_sb(td, row, col, lflvl_ptr,
1434  yoff2, uvoff2, BL_64X64);
1435  }
1436 
1437  // backup pre-loopfilter reconstruction data for intra
1438  // prediction of next row of sb64s
1439  tile_cols_len = tile_col_end - tile_col_start;
1440  if (row + 8 < s->rows) {
1441  memcpy(s->intra_pred_data[0] + (tile_col_start * 8 * bytesperpixel),
1442  f->data[0] + yoff + 63 * ls_y,
1443  8 * tile_cols_len * bytesperpixel);
1444  memcpy(s->intra_pred_data[1] + (tile_col_start * 8 * bytesperpixel >> s->ss_h),
1445  f->data[1] + uvoff + ((64 >> s->ss_v) - 1) * ls_uv,
1446  8 * tile_cols_len * bytesperpixel >> s->ss_h);
1447  memcpy(s->intra_pred_data[2] + (tile_col_start * 8 * bytesperpixel >> s->ss_h),
1448  f->data[2] + uvoff + ((64 >> s->ss_v) - 1) * ls_uv,
1449  8 * tile_cols_len * bytesperpixel >> s->ss_h);
1450  }
1451 
1452  vp9_report_tile_progress(s, row >> 3, 1);
1453  }
1454  }
1455  return 0;
1456 }
1457 
1458 static av_always_inline
1459 int loopfilter_proc(AVCodecContext *avctx)
1460 {
1461  VP9Context *s = avctx->priv_data;
1462  ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1463  VP9Filter *lflvl_ptr;
1464  int bytesperpixel = s->bytesperpixel, col, i;
1465  AVFrame *f;
1466 
1467  f = s->s.frames[CUR_FRAME].tf.f;
1468  ls_y = f->linesize[0];
1469  ls_uv =f->linesize[1];
1470 
1471  for (i = 0; i < s->sb_rows; i++) {
1472  vp9_await_tile_progress(s, i, s->s.h.tiling.tile_cols);
1473 
1474  if (s->s.h.filter.level) {
1475  yoff = (ls_y * 64)*i;
1476  uvoff = (ls_uv * 64 >> s->ss_v)*i;
1477  lflvl_ptr = s->lflvl+s->sb_cols*i;
1478  for (col = 0; col < s->cols;
1479  col += 8, yoff += 64 * bytesperpixel,
1480  uvoff += 64 * bytesperpixel >> s->ss_h, lflvl_ptr++) {
1481  ff_vp9_loopfilter_sb(avctx, lflvl_ptr, i << 3, col,
1482  yoff, uvoff);
1483  }
1484  }
1485  }
1486  return 0;
1487 }
1488 #endif
1489 
1491 {
1492  AVVideoEncParams *par;
1493  unsigned int tile, nb_blocks = 0;
1494 
1495  if (s->s.h.segmentation.enabled) {
1496  for (tile = 0; tile < s->active_tile_cols; tile++)
1497  nb_blocks += s->td[tile].nb_block_structure;
1498  }
1499 
1501  AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
1502  if (!par)
1503  return AVERROR(ENOMEM);
1504 
1505  par->qp = s->s.h.yac_qi;
1506  par->delta_qp[0][0] = s->s.h.ydc_qdelta;
1507  par->delta_qp[1][0] = s->s.h.uvdc_qdelta;
1508  par->delta_qp[2][0] = s->s.h.uvdc_qdelta;
1509  par->delta_qp[1][1] = s->s.h.uvac_qdelta;
1510  par->delta_qp[2][1] = s->s.h.uvac_qdelta;
1511 
1512  if (nb_blocks) {
1513  unsigned int block = 0;
1514  unsigned int tile, block_tile;
1515 
1516  for (tile = 0; tile < s->active_tile_cols; tile++) {
1517  VP9TileData *td = &s->td[tile];
1518 
1519  for (block_tile = 0; block_tile < td->nb_block_structure; block_tile++) {
1521  unsigned int row = td->block_structure[block_tile].row;
1522  unsigned int col = td->block_structure[block_tile].col;
1523  uint8_t seg_id = frame->segmentation_map[row * 8 * s->sb_cols + col];
1524 
1525  b->src_x = col * 8;
1526  b->src_y = row * 8;
1527  b->w = 1 << (3 + td->block_structure[block_tile].block_size_idx_x);
1528  b->h = 1 << (3 + td->block_structure[block_tile].block_size_idx_y);
1529 
1530  if (s->s.h.segmentation.feat[seg_id].q_enabled) {
1531  b->delta_qp = s->s.h.segmentation.feat[seg_id].q_val;
1532  if (s->s.h.segmentation.absolute_vals)
1533  b->delta_qp -= par->qp;
1534  }
1535  }
1536  }
1537  }
1538 
1539  return 0;
1540 }
1541 
1543  int *got_frame, AVPacket *pkt)
1544 {
1545  const uint8_t *data = pkt->data;
1546  int size = pkt->size;
1547  VP9Context *s = avctx->priv_data;
1548  int ret, i, j, ref;
1549  int retain_segmap_ref = s->s.frames[REF_FRAME_SEGMAP].segmentation_map &&
1550  (!s->s.h.segmentation.enabled || !s->s.h.segmentation.update_map);
1551  const VP9Frame *src;
1552  AVFrame *f;
1553 
1554  if ((ret = decode_frame_header(avctx, data, size, &ref)) < 0) {
1555  return ret;
1556  } else if (ret == 0) {
1557  if (!s->s.refs[ref].f) {
1558  av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref);
1559  return AVERROR_INVALIDDATA;
1560  }
1561  for (int i = 0; i < 8; i++)
1562  ff_progress_frame_replace(&s->next_refs[i], &s->s.refs[i]);
1563  ff_thread_finish_setup(avctx);
1564  ff_progress_frame_await(&s->s.refs[ref], INT_MAX);
1565 
1566  if ((ret = av_frame_ref(frame, s->s.refs[ref].f)) < 0)
1567  return ret;
1568  frame->pts = pkt->pts;
1569  frame->pkt_dts = pkt->dts;
1570  *got_frame = 1;
1571  return pkt->size;
1572  }
1573  data += ret;
1574  size -= ret;
1575 
1576  src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ?
1577  &s->s.frames[CUR_FRAME] : &s->s.frames[BLANK_FRAME];
1578  if (!retain_segmap_ref || s->s.h.keyframe || s->s.h.intraonly)
1579  vp9_frame_replace(&s->s.frames[REF_FRAME_SEGMAP], src);
1580  vp9_frame_replace(&s->s.frames[REF_FRAME_MVPAIR], src);
1581  vp9_frame_unref(&s->s.frames[CUR_FRAME]);
1582  if ((ret = vp9_frame_alloc(avctx, &s->s.frames[CUR_FRAME])) < 0)
1583  return ret;
1584  f = s->s.frames[CUR_FRAME].tf.f;
1585  if (s->s.h.keyframe)
1586  f->flags |= AV_FRAME_FLAG_KEY;
1587  else
1588  f->flags &= ~AV_FRAME_FLAG_KEY;
1589  f->pict_type = (s->s.h.keyframe || s->s.h.intraonly) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
1590 
1591  // Non-existent frames have the implicit dimension 0x0 != CUR_FRAME
1592  if (!s->s.frames[REF_FRAME_MVPAIR].tf.f ||
1593  (s->s.frames[REF_FRAME_MVPAIR].tf.f->width != s->s.frames[CUR_FRAME].tf.f->width ||
1594  s->s.frames[REF_FRAME_MVPAIR].tf.f->height != s->s.frames[CUR_FRAME].tf.f->height)) {
1595  vp9_frame_unref(&s->s.frames[REF_FRAME_SEGMAP]);
1596  }
1597 
1598  // ref frame setup
1599  for (i = 0; i < 8; i++) {
1600  ff_progress_frame_replace(&s->next_refs[i],
1601  s->s.h.refreshrefmask & (1 << i) ?
1602  &s->s.frames[CUR_FRAME].tf : &s->s.refs[i]);
1603  }
1604 
1605  if (avctx->hwaccel) {
1606  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1607  ret = hwaccel->start_frame(avctx, NULL, 0);
1608  if (ret < 0)
1609  return ret;
1610  ret = hwaccel->decode_slice(avctx, pkt->data, pkt->size);
1611  if (ret < 0)
1612  return ret;
1613  ret = hwaccel->end_frame(avctx);
1614  if (ret < 0)
1615  return ret;
1616  goto finish;
1617  }
1618 
1619  // main tile decode loop
1620  memset(s->above_partition_ctx, 0, s->cols);
1621  memset(s->above_skip_ctx, 0, s->cols);
1622  if (s->s.h.keyframe || s->s.h.intraonly) {
1623  memset(s->above_mode_ctx, DC_PRED, s->cols * 2);
1624  } else {
1625  memset(s->above_mode_ctx, NEARESTMV, s->cols);
1626  }
1627  memset(s->above_y_nnz_ctx, 0, s->sb_cols * 16);
1628  memset(s->above_uv_nnz_ctx[0], 0, s->sb_cols * 16 >> s->ss_h);
1629  memset(s->above_uv_nnz_ctx[1], 0, s->sb_cols * 16 >> s->ss_h);
1630  memset(s->above_segpred_ctx, 0, s->cols);
1631  s->pass = s->s.frames[CUR_FRAME].uses_2pass =
1632  avctx->active_thread_type == FF_THREAD_FRAME && s->s.h.refreshctx && !s->s.h.parallelmode;
1633  if ((ret = update_block_buffers(avctx)) < 0) {
1634  av_log(avctx, AV_LOG_ERROR,
1635  "Failed to allocate block buffers\n");
1636  return ret;
1637  }
1638  if (s->s.h.refreshctx && s->s.h.parallelmode) {
1639  int j, k, l, m;
1640 
1641  for (i = 0; i < 4; i++) {
1642  for (j = 0; j < 2; j++)
1643  for (k = 0; k < 2; k++)
1644  for (l = 0; l < 6; l++)
1645  for (m = 0; m < 6; m++)
1646  memcpy(s->prob_ctx[s->s.h.framectxid].coef[i][j][k][l][m],
1647  s->prob.coef[i][j][k][l][m], 3);
1648  if (s->s.h.txfmmode == i)
1649  break;
1650  }
1651  s->prob_ctx[s->s.h.framectxid].p = s->prob.p;
1652  ff_thread_finish_setup(avctx);
1653  } else if (!s->s.h.refreshctx) {
1654  ff_thread_finish_setup(avctx);
1655  }
1656 
1657 #if HAVE_THREADS
1658  if (avctx->active_thread_type & FF_THREAD_SLICE) {
1659  for (i = 0; i < s->sb_rows; i++)
1660  atomic_init(&s->entries[i], 0);
1661  }
1662 #endif
1663 
1664  do {
1665  for (i = 0; i < s->active_tile_cols; i++) {
1666  s->td[i].b = s->td[i].b_base;
1667  s->td[i].block = s->td[i].block_base;
1668  s->td[i].uvblock[0] = s->td[i].uvblock_base[0];
1669  s->td[i].uvblock[1] = s->td[i].uvblock_base[1];
1670  s->td[i].eob = s->td[i].eob_base;
1671  s->td[i].uveob[0] = s->td[i].uveob_base[0];
1672  s->td[i].uveob[1] = s->td[i].uveob_base[1];
1673  s->td[i].error_info = 0;
1674  }
1675 
1676 #if HAVE_THREADS
1677  if (avctx->active_thread_type == FF_THREAD_SLICE) {
1678  int tile_row, tile_col;
1679 
1680  av_assert1(!s->pass);
1681 
1682  for (tile_row = 0; tile_row < s->s.h.tiling.tile_rows; tile_row++) {
1683  for (tile_col = 0; tile_col < s->s.h.tiling.tile_cols; tile_col++) {
1684  int64_t tile_size;
1685 
1686  if (tile_col == s->s.h.tiling.tile_cols - 1 &&
1687  tile_row == s->s.h.tiling.tile_rows - 1) {
1688  tile_size = size;
1689  } else {
1690  tile_size = AV_RB32(data);
1691  data += 4;
1692  size -= 4;
1693  }
1694  if (tile_size > size)
1695  return AVERROR_INVALIDDATA;
1696  ret = ff_vpx_init_range_decoder(&s->td[tile_col].c_b[tile_row], data, tile_size);
1697  if (ret < 0)
1698  return ret;
1699  if (vpx_rac_get_prob_branchy(&s->td[tile_col].c_b[tile_row], 128)) // marker bit
1700  return AVERROR_INVALIDDATA;
1701  data += tile_size;
1702  size -= tile_size;
1703  }
1704  }
1705 
1706  ff_slice_thread_execute_with_mainfunc(avctx, decode_tiles_mt, loopfilter_proc, s->td, NULL, s->s.h.tiling.tile_cols);
1707  } else
1708 #endif
1709  {
1710  ret = decode_tiles(avctx, data, size);
1711  if (ret < 0)
1712  goto fail;
1713  }
1714 
1715  // Sum all counts fields into td[0].counts for tile threading
1716  if (avctx->active_thread_type == FF_THREAD_SLICE)
1717  for (i = 1; i < s->s.h.tiling.tile_cols; i++)
1718  for (j = 0; j < sizeof(s->td[i].counts) / sizeof(unsigned); j++)
1719  ((unsigned *)&s->td[0].counts)[j] += ((unsigned *)&s->td[i].counts)[j];
1720 
1721  if (s->pass < 2 && s->s.h.refreshctx && !s->s.h.parallelmode) {
1723  ff_thread_finish_setup(avctx);
1724  }
1725  } while (s->pass++ == 1);
1726 
1727  if (s->td->error_info < 0) {
1728  av_log(avctx, AV_LOG_ERROR, "Failed to decode tile data\n");
1729  s->td->error_info = 0;
1731  goto fail;
1732  }
1734  ret = vp9_export_enc_params(s, &s->s.frames[CUR_FRAME]);
1735  if (ret < 0)
1736  goto fail;
1737  }
1738  ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
1739 
1740 finish:
1741  // ref frame setup
1742  for (int i = 0; i < 8; i++)
1743  ff_progress_frame_replace(&s->s.refs[i], &s->next_refs[i]);
1744 
1745  if (!s->s.h.invisible) {
1746  if ((ret = av_frame_ref(frame, s->s.frames[CUR_FRAME].tf.f)) < 0)
1747  return ret;
1748  *got_frame = 1;
1749  }
1750 
1751  return pkt->size;
1752 fail:
1753  ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
1754  return ret;
1755 }
1756 
1758 {
1759  VP9Context *s = avctx->priv_data;
1760  int i;
1761 
1762  for (i = 0; i < 3; i++)
1763  vp9_frame_unref(&s->s.frames[i]);
1764  for (i = 0; i < 8; i++)
1765  ff_progress_frame_unref(&s->s.refs[i]);
1766 
1767  if (FF_HW_HAS_CB(avctx, flush))
1768  FF_HW_SIMPLE_CALL(avctx, flush);
1769 }
1770 
1772 {
1773  VP9Context *s = avctx->priv_data;
1774  int ret;
1775 
1776  s->last_bpp = 0;
1777  s->s.h.filter.sharpness = -1;
1778 
1779 #if HAVE_THREADS
1780  if (avctx->active_thread_type & FF_THREAD_SLICE) {
1781  ret = ff_pthread_init(s, vp9_context_offsets);
1782  if (ret < 0)
1783  return ret;
1784  }
1785 #endif
1786 
1787  return 0;
1788 }
1789 
1790 #if HAVE_THREADS
1791 static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1792 {
1793  VP9Context *s = dst->priv_data, *ssrc = src->priv_data;
1794 
1795  for (int i = 0; i < 3; i++)
1796  vp9_frame_replace(&s->s.frames[i], &ssrc->s.frames[i]);
1797  for (int i = 0; i < 8; i++)
1798  ff_progress_frame_replace(&s->s.refs[i], &ssrc->next_refs[i]);
1799  ff_refstruct_replace(&s->frame_extradata_pool, ssrc->frame_extradata_pool);
1800  s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size;
1801 
1802  s->s.h.invisible = ssrc->s.h.invisible;
1803  s->s.h.keyframe = ssrc->s.h.keyframe;
1804  s->s.h.intraonly = ssrc->s.h.intraonly;
1805  s->ss_v = ssrc->ss_v;
1806  s->ss_h = ssrc->ss_h;
1807  s->s.h.segmentation.enabled = ssrc->s.h.segmentation.enabled;
1808  s->s.h.segmentation.update_map = ssrc->s.h.segmentation.update_map;
1809  s->s.h.segmentation.absolute_vals = ssrc->s.h.segmentation.absolute_vals;
1810  s->bytesperpixel = ssrc->bytesperpixel;
1811  s->gf_fmt = ssrc->gf_fmt;
1812  s->w = ssrc->w;
1813  s->h = ssrc->h;
1814  s->s.h.bpp = ssrc->s.h.bpp;
1815  s->bpp_index = ssrc->bpp_index;
1816  s->pix_fmt = ssrc->pix_fmt;
1817  memcpy(&s->prob_ctx, &ssrc->prob_ctx, sizeof(s->prob_ctx));
1818  memcpy(&s->s.h.lf_delta, &ssrc->s.h.lf_delta, sizeof(s->s.h.lf_delta));
1819  memcpy(&s->s.h.segmentation.feat, &ssrc->s.h.segmentation.feat,
1820  sizeof(s->s.h.segmentation.feat));
1821 
1822  return 0;
1823 }
1824 #endif
1825 
1827  .p.name = "vp9",
1828  CODEC_LONG_NAME("Google VP9"),
1829  .p.type = AVMEDIA_TYPE_VIDEO,
1830  .p.id = AV_CODEC_ID_VP9,
1831  .priv_data_size = sizeof(VP9Context),
1832  .init = vp9_decode_init,
1833  .close = vp9_decode_free,
1836  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1839  .flush = vp9_decode_flush,
1840  UPDATE_THREAD_CONTEXT(vp9_decode_update_thread_context),
1841  .p.profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
1842  .bsfs = "vp9_superframe_split",
1843  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1844 #if CONFIG_VP9_DXVA2_HWACCEL
1845  HWACCEL_DXVA2(vp9),
1846 #endif
1847 #if CONFIG_VP9_D3D11VA_HWACCEL
1848  HWACCEL_D3D11VA(vp9),
1849 #endif
1850 #if CONFIG_VP9_D3D11VA2_HWACCEL
1851  HWACCEL_D3D11VA2(vp9),
1852 #endif
1853 #if CONFIG_VP9_D3D12VA_HWACCEL
1854  HWACCEL_D3D12VA(vp9),
1855 #endif
1856 #if CONFIG_VP9_NVDEC_HWACCEL
1857  HWACCEL_NVDEC(vp9),
1858 #endif
1859 #if CONFIG_VP9_VAAPI_HWACCEL
1860  HWACCEL_VAAPI(vp9),
1861 #endif
1862 #if CONFIG_VP9_VDPAU_HWACCEL
1863  HWACCEL_VDPAU(vp9),
1864 #endif
1865 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
1866  HWACCEL_VIDEOTOOLBOX(vp9),
1867 #endif
1868  NULL
1869  },
1870 };
HWACCEL_D3D12VA
#define HWACCEL_D3D12VA(codec)
Definition: hwconfig.h:80
AVVideoEncParams::qp
int32_t qp
Base quantisation parameter for the frame.
Definition: video_enc_params.h:103
hwconfig.h
ff_progress_frame_report
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition: decode.c:1740
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1427
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
FF_CODEC_CAP_SLICE_THREAD_HAS_MF
#define FF_CODEC_CAP_SLICE_THREAD_HAS_MF
Codec initializes slice-based threading with a main function.
Definition: codec_internal.h:64
decode_tiles
static int decode_tiles(AVCodecContext *avctx, const uint8_t *data, int size)
Definition: vp9.c:1251
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
vp9_frame_alloc
static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
Definition: vp9.c:105
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
PRED_SWITCHABLE
@ PRED_SWITCHABLE
Definition: vp9shared.h:52
PRED_SINGLEREF
@ PRED_SINGLEREF
Definition: vp9shared.h:50
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1222
ff_refstruct_pool_alloc
FFRefStructPool * ff_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
Definition: refstruct.c:335
VP9Frame::segmentation_map
uint8_t * segmentation_map
Definition: vp9shared.h:68
VP9Frame
Definition: vp9shared.h:65
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:123
ff_vp9_decoder
const FFCodec ff_vp9_decoder
Definition: vp9.c:1826
decode_sb
static void decode_sb(VP9TileData *td, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
Definition: vp9.c:1084
ff_vp9_adapt_probs
void ff_vp9_adapt_probs(VP9Context *s)
Definition: vp9prob.c:44
vp9_decode_flush
static void vp9_decode_flush(AVCodecContext *avctx)
Definition: vp9.c:1757
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
PRED_COMPREF
@ PRED_COMPREF
Definition: vp9shared.h:51
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
HWACCEL_DXVA2
#define HWACCEL_DXVA2(codec)
Definition: hwconfig.h:64
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:686
BlockPartition
BlockPartition
Definition: vp9shared.h:35
AVPacket::data
uint8_t * data
Definition: packet.h:524
DC_PRED
@ DC_PRED
Definition: vp9.h:48
HWACCEL_D3D11VA2
#define HWACCEL_D3D11VA2(codec)
Definition: hwconfig.h:66
b
#define b
Definition: input.c:41
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1698
data
const char data[16]
Definition: mxf.c:148
update_size
static int update_size(AVCodecContext *avctx, int w, int h)
Definition: vp9.c:160
decode_sb_mem
static void decode_sb_mem(VP9TileData *td, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
Definition: vp9.c:1163
REF_FRAME_SEGMAP
#define REF_FRAME_SEGMAP
Definition: vp9shared.h:170
decode_frame_header
static int decode_frame_header(AVCodecContext *avctx, const uint8_t *data, int size, int *ref)
Definition: vp9.c:498
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
atomic_int
intptr_t atomic_int
Definition: stdatomic.h:55
AV_PIX_FMT_D3D11VA_VLD
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
Definition: pixfmt.h:254
FFCodec
Definition: codec_internal.h:126
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:610
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:174
VP9Frame::tf
ProgressFrame tf
Definition: vp9shared.h:66
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
VP9_SYNCCODE
#define VP9_SYNCCODE
Definition: vp9.c:49
vp89_rac.h
VP9Filter
Definition: vp9dec.h:78
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:94
VPXRangeCoder
Definition: vpx_rac.h:35
thread.h
ff_pthread_free
av_cold void ff_pthread_free(void *obj, const unsigned offsets[])
Definition: pthread.c:91
FILTER_SWITCHABLE
@ FILTER_SWITCHABLE
Definition: vp9.h:70
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
VP9Block
Definition: vp9dec.h:84
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:615
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:613
TX_SWITCHABLE
@ TX_SWITCHABLE
Definition: vp9.h:33
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:130
finish
static void finish(void)
Definition: movenc.c:373
FFHWAccel
Definition: hwaccel_internal.h:34
ff_vp9_ac_qlookup
const int16_t ff_vp9_ac_qlookup[3][256]
Definition: vp9data.c:334
AVVideoEncParams::delta_qp
int32_t delta_qp[4][2]
Quantisation parameter offset from the base (per-frame) qp for a given plane (first index) and AC/DC ...
Definition: video_enc_params.h:109
fail
#define fail()
Definition: checkasm.h:179
ff_refstruct_pool_uninit
static void ff_refstruct_pool_uninit(FFRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition: refstruct.h:292
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:494
GetBitContext
Definition: get_bits.h:108
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
HWACCEL_VDPAU
#define HWACCEL_VDPAU(codec)
Definition: hwconfig.h:72
ff_videodsp_init
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:39
PARTITION_NONE
@ PARTITION_NONE
Definition: vp9shared.h:36
vp9_frame_unref
static void vp9_frame_unref(VP9Frame *f)
Definition: vp9.c:97
VP9Frame::hwaccel_picture_private
void * hwaccel_picture_private
RefStruct reference.
Definition: vp9shared.h:72
progressframe.h
refstruct.h
AVVideoEncParams
Video encoding parameters for a given frame.
Definition: video_enc_params.h:73
vp9_decode_free
static av_cold int vp9_decode_free(AVCodecContext *avctx)
Definition: vp9.c:1229
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
avassert.h
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:68
ff_vp9_model_pareto8
const uint8_t ff_vp9_model_pareto8[256][8]
Definition: vp9data.c:1176
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
FF_CODEC_PROPERTY_LOSSLESS
#define FF_CODEC_PROPERTY_LOSSLESS
Definition: avcodec.h:1796
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:625
BL_8X8
@ BL_8X8
Definition: vp9shared.h:79
PARTITION_V
@ PARTITION_V
Definition: vp9shared.h:38
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:286
ff_hwaccel_frame_priv_alloc
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition: decode.c:2085
AV_PIX_FMT_DXVA2_VLD
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:134
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:616
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:425
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
vp9data.h
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
ff_progress_frame_unref
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition: decode.c:1723
ff_progress_frame_await
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_progress_frame_await() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_progress_frame_report() has been called on them. This includes draw_edges(). Porting codecs to frame threading
decode.h
get_bits.h
field
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 field
Definition: writing_filters.txt:78
ff_vp9dsp_init
av_cold void ff_vp9dsp_init(VP9DSPContext *dsp, int bpp, int bitexact)
Definition: vp9dsp.c:88
ff_vp9_partition_tree
const int8_t ff_vp9_partition_tree[3][2]
Definition: vp9data.c:35
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
vp9_decode_frame
static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: vp9.c:1542
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:271
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
hwaccel_internal.h
VP9Context
Definition: vp9dec.h:96
REF_FRAME_MVPAIR
#define REF_FRAME_MVPAIR
Definition: vp9shared.h:169
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:388
vp89_rac_get_uint
static av_unused int vp89_rac_get_uint(VPXRangeCoder *c, int bits)
Definition: vp89_rac.h:41
profiles.h
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:480
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:368
pthread_internal.h
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:280
AV_PIX_FMT_D3D12
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition: pixfmt.h:440
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
VP9mv
Definition: vp9shared.h:55
PARTITION_SPLIT
@ PARTITION_SPLIT
Definition: vp9shared.h:39
FF_HW_HAS_CB
#define FF_HW_HAS_CB(avctx, function)
Definition: hwaccel_internal.h:177
atomic_load_explicit
#define atomic_load_explicit(object, order)
Definition: stdatomic.h:96
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
pthread_mutex_unlock
#define pthread_mutex_unlock(a)
Definition: ffprobe.c:82
vp9_frame_replace
static void vp9_frame_replace(VP9Frame *dst, const VP9Frame *src)
Definition: vp9.c:146
av_video_enc_params_create_side_data
AVVideoEncParams * av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, unsigned int nb_blocks)
Allocates memory for AVEncodeInfoFrame plus an array of.
Definition: video_enc_params.c:58
vp9.h
VP9Frame::uses_2pass
int uses_2pass
Definition: vp9shared.h:70
f
f
Definition: af_crystalizer.c:121
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:525
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
av_frame_ref
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:384
codec_internal.h
pix_fmt_rgb
static enum AVPixelFormat pix_fmt_rgb[3]
Definition: libdav1d.c:68
REF_INVALID_SCALE
#define REF_INVALID_SCALE
Definition: vp9dec.h:42
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
read_colorspace_details
static int read_colorspace_details(AVCodecContext *avctx)
Definition: vp9.c:436
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
size
int size
Definition: twinvq_data.h:10344
vp9_alloc_entries
static int vp9_alloc_entries(AVCodecContext *avctx, int n)
Definition: vp9.c:87
atomic_fetch_add_explicit
#define atomic_fetch_add_explicit(object, operand, order)
Definition: stdatomic.h:149
free_buffers
static void free_buffers(VP9Context *s)
Definition: vp9.c:1220
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
FF_THREAD_SLICE
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:1594
AVCodecHWConfigInternal
Definition: hwconfig.h:25
TX_4X4
@ TX_4X4
Definition: vp9.h:28
update_block_buffers
static int update_block_buffers(AVCodecContext *avctx)
Definition: vp9.c:301
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:523
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
HWACCEL_D3D11VA
#define HWACCEL_D3D11VA(codec)
Definition: hwconfig.h:78
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:336
inv_recenter_nonneg
static av_always_inline int inv_recenter_nonneg(int v, int m)
Definition: vp9.c:368
VP9Frame::extradata
void * extradata
RefStruct reference.
Definition: vp9shared.h:67
HWACCEL_NVDEC
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:68
vpx_rac_is_end
static av_always_inline int vpx_rac_is_end(VPXRangeCoder *c)
returns 1 if the end of the stream has been reached, 0 otherwise.
Definition: vpx_rac.h:51
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1593
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
ff_slice_thread_execute_with_mainfunc
int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx, action_func2 *func2, main_func *mainfunc, void *arg, int *ret, int job_count)
Definition: pthread_slice.c:126
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition: pixfmt.h:617
assign
#define assign(var, type, n)
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
#define FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
If this flag is set, the entries will be zeroed before being returned to the user (after the init or ...
Definition: refstruct.h:221
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
update_prob
static int update_prob(VPXRangeCoder *c, int p)
Definition: vp9.c:378
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:517
DEFINE_OFFSET_ARRAY
#define DEFINE_OFFSET_ARRAY(type, name, cnt_variable, mutexes, conds)
Definition: pthread_internal.h:61
AVCodecContext::properties
unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:1795
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:620
vpx_rac.h
decode012
static int BS_FUNC() decode012(BSCTX *bc)
Return decoded truncated unary code for the values 0, 1, 2.
Definition: bitstream_template.h:436
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:495
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:609
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
vpx_rac_get_prob_branchy
static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob)
Definition: vpx_rac.h:99
AVVideoBlockParams
Data structure for storing block-level encoding information.
Definition: video_enc_params.h:120
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
get_sbits_inv
static av_always_inline int get_sbits_inv(GetBitContext *gb, int n)
Definition: vp9.c:362
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:612
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:669
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
HWACCEL_VIDEOTOOLBOX
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition: hwconfig.h:74
avcodec.h
limit
static double limit(double x)
Definition: vf_pseudocolor.c:142
vp89_rac_get_tree
static av_always_inline int vp89_rac_get_tree(VPXRangeCoder *c, const int8_t(*tree)[2], const uint8_t *probs)
Definition: vp89_rac.h:54
BL_64X64
@ BL_64X64
Definition: vp9shared.h:76
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
vp9_decode_init
static av_cold int vp9_decode_init(AVCodecContext *avctx)
Definition: vp9.c:1771
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:561
hwaccel
static const char * hwaccel
Definition: ffplay.c:353
ff_vpx_init_range_decoder
int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size)
Definition: vpx_rac.c:42
ff_refstruct_replace
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
vp9_tile_data_free
static void vp9_tile_data_free(VP9TileData *td)
Definition: vp9.c:90
ff_thread_finish_setup
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
VP9mvrefPair
Definition: vp9shared.h:60
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
pthread_cond_signal
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
Definition: os2threads.h:152
AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
Decoding only.
Definition: avcodec.h:415
ff_progress_frame_replace
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition: decode.c:1730
VP9TileData
Definition: vp9dec.h:167
vp89_rac_get
static av_always_inline int vp89_rac_get(VPXRangeCoder *c)
Definition: vp89_rac.h:36
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1601
VP9Filter::mask
uint8_t mask[2][2][8][4]
Definition: vp9dec.h:81
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
VP9Frame::mv
VP9mvrefPair * mv
Definition: vp9shared.h:69
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1639
ffhwaccel
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
Definition: hwaccel_internal.h:166
ff_vp9_decode_block
void ff_vp9_decode_block(VP9TileData *td, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl, enum BlockPartition bp)
Definition: vp9block.c:1264
NEARESTMV
@ NEARESTMV
Definition: vp9shared.h:43
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
BlockLevel
BlockLevel
Definition: vp9shared.h:75
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:1926
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
ff_pthread_init
av_cold int ff_pthread_init(void *obj, const unsigned offsets[])
Initialize/destroy a list of mutexes/conditions contained in a structure.
Definition: pthread.c:104
pthread_cond_wait
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Definition: os2threads.h:192
vp9dec.h
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_vp9_default_kf_partition_probs
const uint8_t ff_vp9_default_kf_partition_probs[4][4][3]
Definition: vp9data.c:41
AV_VIDEO_ENC_PARAMS_VP9
@ AV_VIDEO_ENC_PARAMS_VP9
VP9 stores:
Definition: video_enc_params.h:44
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
ff_vp9_default_probs
const ProbContext ff_vp9_default_probs
Definition: vp9data.c:1435
CUR_FRAME
#define CUR_FRAME
Definition: vp9shared.h:168
ff_vp9_loopfilter_sb
void ff_vp9_loopfilter_sb(struct AVCodecContext *avctx, VP9Filter *lflvl, int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff)
Definition: vp9lpf.c:179
vp9_export_enc_params
static int vp9_export_enc_params(VP9Context *s, VP9Frame *frame)
Definition: vp9.c:1490
AVPacket
This structure stores compressed data.
Definition: packet.h:501
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
PARTITION_H
@ PARTITION_H
Definition: vp9shared.h:37
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
videodsp.h
BLANK_FRAME
#define BLANK_FRAME
Definition: vp9shared.h:171
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:70
d
d
Definition: ffmpeg_filter.c:424
HWACCEL_MAX
#define HWACCEL_MAX
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
av_video_enc_params_block
static av_always_inline AVVideoBlockParams * av_video_enc_params_block(AVVideoEncParams *par, unsigned int idx)
Get the block at the specified.
Definition: video_enc_params.h:143
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:484
h
h
Definition: vp9dsp_template.c:2038
atomic_init
#define atomic_init(obj, value)
Definition: stdatomic.h:33
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:611
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
ff_vp9_profiles
const AVProfile ff_vp9_profiles[]
Definition: profiles.c:153
ff_refstruct_pool_get
void * ff_refstruct_pool_get(FFRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
Definition: refstruct.c:297
video_enc_params.h
set_tile_offset
static void set_tile_offset(int *start, int *end, int idx, int log2_n, int n)
Definition: vp9.c:1212
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2885
ff_vp9_dc_qlookup
const int16_t ff_vp9_dc_qlookup[3][256]
Definition: vp9data.c:231
pthread_mutex_lock
#define pthread_mutex_lock(a)
Definition: ffprobe.c:78
ff_vp9_default_coef_probs
const uint8_t ff_vp9_default_coef_probs[4][2][2][6][6][3]
Definition: vp9data.c:1540