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