FFmpeg
rv60dec.c
Go to the documentation of this file.
1 /*
2  * RV60 decoder
3  * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
4  * Copyright (C) 2023 Peter Ross
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avcodec.h"
24 #include "codec_internal.h"
25 #include "decode.h"
26 #include "get_bits.h"
27 #include "golomb.h"
28 #include "libavutil/mem.h"
29 #include "rv60data.h"
30 #include "rv60dsp.h"
31 #include "rv60vlcs.h"
32 #include "threadprogress.h"
33 #include "unary.h"
34 #include "videodsp.h"
35 
36 #include "libavutil/attributes.h"
37 
39 
40 enum CUType {
41  CU_INTRA = 0,
45 };
46 
47 enum PUType {
48  PU_FULL = 0,
56 };
57 
58 enum IntraMode {
63 };
64 
65 enum MVRefEnum {
75 };
76 
78 
79 enum {
84 };
85 
86 static const VLCElem * cbp8_vlc[7][4];
87 static const VLCElem * cbp16_vlc[7][4][4];
88 
89 typedef struct {
90  const VLCElem * l0[2];
91  const VLCElem * l12[2];
92  const VLCElem * l3[2];
93  const VLCElem * esc;
94 } CoeffVLCs;
95 
98 
99 #define MAX_VLC_SIZE 864
100 static VLCElem table_data[129148];
101 
102 /* 32-bit version of rv34_gen_vlc */
103 static const VLCElem * gen_vlc(const uint8_t * bits, int size, VLCInitState * state)
104 {
105  int counts[17] = {0};
106  uint32_t codes[18];
107  uint32_t cw[MAX_VLC_SIZE];
108 
109  for (int i = 0; i < size; i++)
110  counts[bits[i]]++;
111 
112  codes[0] = counts[0] = 0;
113  for (int i = 0; i < 17; i++)
114  codes[i+1] = (codes[i] + counts[i]) << 1;
115 
116  for (int i = 0; i < size; i++)
117  cw[i] = codes[bits[i]]++;
118 
119  return ff_vlc_init_tables(state, 9, size,
120  bits, 1, 1,
121  cw, 4, 4, 0);
122 }
123 
124 static void build_coeff_vlc(const CoeffLens * lens, CoeffVLCs * vlc, int count, VLCInitState * state)
125 {
126  for (int i = 0; i < count; i++) {
127  for (int j = 0; j < 2; j++) {
128  vlc[i].l0[j] = gen_vlc(lens[i].l0[j], 864, state);
129  vlc[i].l12[j] = gen_vlc(lens[i].l12[j], 108, state);
130  vlc[i].l3[j] = gen_vlc(lens[i].l3[j], 108, state);
131  }
132  vlc[i].esc = gen_vlc(lens[i].esc, 32, state);
133  }
134 }
135 
137 {
139 
140  for (int i = 0; i < 7; i++)
141  for (int j = 0; j < 4; j++)
142  cbp16_vlc[i][0][j] = cbp8_vlc[i][j] = gen_vlc(rv60_cbp8_lens[i][j], 64, &state);
143 
144  for (int i = 0; i < 7; i++)
145  for (int j = 0; j < 3; j++)
146  for (int k = 0; k < 4; k++)
147  cbp16_vlc[i][j + 1][k] = gen_vlc(rv60_cbp16_lens[i][j][k], 64, &state);
148 
151 }
152 
153 typedef struct {
154  int sign;
155  int size;
156  const uint8_t * data;
158 } Slice;
159 
160 typedef struct {
162  uint8_t cu_split[1+4+16+64];
163 
164  uint8_t coded_blk[64];
165 
166  uint8_t avg_buffer[64*64 + 32*32*2];
167  uint8_t * avg_data[3];
168  int avg_linesize[3];
169 } ThreadContext;
170 
171 typedef struct {
172  int16_t x;
173  int16_t y;
174 } MV;
175 
176 typedef struct {
177  enum MVRefEnum mvref;
180 } MVInfo;
181 
182 typedef struct {
183  enum IntraMode imode;
185 } BlockInfo;
186 
187 typedef struct {
188  enum CUType cu_type;
189  enum PUType pu_type;
190 } PUInfo;
191 
192 typedef struct RV60Context {
195 
196 #define CUR_PIC 0
197 #define LAST_PIC 1
198 #define NEXT_PIC 2
200 
202  int qp;
203  int osvquant;
204  int ts;
207  int deblock;
209  int awidth;
210  int aheight;
211  int cu_width;
213 
215 
218 
221 
223  uint8_t * left_str;
224  uint8_t * top_str;
225 
226  uint64_t ref_pts[2], ts_scale;
227  uint32_t ref_ts[2];
228 
230  unsigned nb_progress;
231 } RV60Context;
232 
233 static int progress_init(RV60Context *s, unsigned count)
234 {
235  if (s->nb_progress < count) {
236  void *tmp = av_realloc_array(s->progress, count, sizeof(*s->progress));
237  if (!tmp)
238  return AVERROR(ENOMEM);
239  s->progress = tmp;
240  memset(s->progress + s->nb_progress, 0, (count - s->nb_progress) * sizeof(*s->progress));
241  for (int i = s->nb_progress; i < count; i++) {
242  int ret = ff_thread_progress_init(&s->progress[i], 1);
243  if (ret < 0)
244  return ret;
245  s->nb_progress = i + 1;
246  }
247  }
248 
249  for (int i = 0; i < count; i++)
250  ff_thread_progress_reset(&s->progress[i]);
251 
252  return 0;
253 }
254 
256 {
257  static AVOnce init_static_once = AV_ONCE_INIT;
258  RV60Context *s = avctx->priv_data;
259 
260  s->avctx = avctx;
261 
262  ff_videodsp_init(&s->vdsp, 8);
263 
264  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
265 
266  for (int i = 0; i < 3; i++) {
267  s->last_frame[i] = av_frame_alloc();
268  if (!s->last_frame[i])
269  return AVERROR(ENOMEM);
270  }
271 
272  ff_thread_once(&init_static_once, rv60_init_static_data);
273 
274  return 0;
275 }
276 
278 {
279  int ret;
280 
281  if (width != s->avctx->width || height != s->avctx->height) {
282 
283  av_log(s->avctx, AV_LOG_INFO, "changing dimensions to %dx%d\n", width, height);
284 
285  for (int i = 0; i < 3; i++)
286  av_frame_unref(s->last_frame[i]);
287 
288  if ((ret = ff_set_dimensions(s->avctx, width, height)) < 0)
289  return ret;
290 
291  if (s->avctx->width <= 64 || s->avctx->height <= 64)
292  av_log(s->avctx, AV_LOG_WARNING, "unable to faithfully reproduce emulated edges; expect visual artefacts\n");
293  }
294 
295  s->awidth = FFALIGN(width, 16);
296  s->aheight = FFALIGN(height, 16);
297 
298  s->cu_width = (width + 63) >> 6;
299  s->cu_height = (height + 63) >> 6;
300 
301  s->pu_stride = s->cu_width << 3;
302  s->blk_stride = s->cu_width << 4;
303 
304  if ((ret = av_reallocp_array(&s->slice, s->cu_height, sizeof(s->slice[0]))) < 0)
305  return ret;
306 
307  if ((ret = av_reallocp_array(&s->pu_info, s->pu_stride * (s->cu_height << 3), sizeof(s->pu_info[0]))) < 0)
308  return ret;
309 
310  if ((ret = av_reallocp_array(&s->blk_info, s->blk_stride * (s->cu_height << 4), sizeof(s->blk_info[0]))) < 0)
311  return ret;
312 
313  memset(s->pu_info, 0, s->pu_stride * (s->cu_height << 3) * sizeof(s->pu_info[0]));
314  memset(s->blk_info, 0, s->blk_stride * (s->cu_height << 4) * sizeof(s->blk_info[0]));
315 
316  for (int j = 0; j < s->cu_height << 4; j++)
317  for (int i = 0; i < s->cu_width << 4; i++)
318  s->blk_info[j*s->blk_stride + i].mv.mvref = MVREF_NONE;
319 
320  if (s->deblock) {
321  int size;
322 
323  s->dblk_stride = s->awidth >> 2;
324 
325  size = s->dblk_stride * (s->aheight >> 2);
326 
327  if ((ret = av_reallocp_array(&s->top_str, size, sizeof(s->top_str[0]))) < 0)
328  return ret;
329 
330  if ((ret = av_reallocp_array(&s->left_str, size, sizeof(s->left_str[0]))) < 0)
331  return ret;
332 
333  memset(s->top_str, 0, size);
334  memset(s->left_str, 0, size);
335  }
336 
337  return 0;
338 }
339 
340 static int read_code012(GetBitContext * gb)
341 {
342  if (!get_bits1(gb))
343  return 0;
344  return get_bits1(gb) + 1;
345 }
346 
347 static int read_frame_header(RV60Context *s, GetBitContext *gb, int * width, int * height)
348 {
349  if (get_bits(gb, 2) != 3)
350  return AVERROR_INVALIDDATA;
351 
352  skip_bits(gb, 2);
353  skip_bits(gb, 4);
354 
355  s->pict_type = frame_types[get_bits(gb, 2)];
356  if (s->pict_type == AV_PICTURE_TYPE_NONE)
357  return AVERROR_INVALIDDATA;
358 
359  s->qp = get_bits(gb, 6);
360  skip_bits1(gb);
361  skip_bits(gb, 2);
362  s->osvquant = get_bits(gb, 2);
363  skip_bits1(gb);
364  skip_bits(gb, 2);
365  s->ts = get_bits(gb, 24);
366  *width = (get_bits(gb, 11) + 1) * 4;
367  *height = get_bits(gb, 11) * 4;
368  skip_bits1(gb);
369  if (s->pict_type == AV_PICTURE_TYPE_I) {
370  s->two_f_refs = 0;
371  } else {
372  if (get_bits1(gb))
373  skip_bits(gb, 3);
374  s->two_f_refs = get_bits1(gb);
375  }
376  read_code012(gb);
377  read_code012(gb);
378  s->qp_off_type = read_code012(gb);
379  s->deblock = get_bits1(gb);
380  s->deblock_chroma = s->deblock && !get_bits1(gb);
381 
382  if (get_bits1(gb)) {
383  int count = get_bits(gb, 2);
384  if (count) {
385  skip_bits(gb, 2);
386  for (int i = 0; i < count; i++)
387  for (int j = 0; j < 2 << i; j++)
388  skip_bits(gb, 8);
389  }
390  }
391 
392  return 0;
393 }
394 
396 {
397  int nbits = get_bits(gb, 5) + 1;
398  int last_size;
399 
400  for (int i = 0; i < s->cu_height; i++)
401  s->slice[i].sign = get_bits1(gb);
402 
403  s->slice[0].size = last_size = get_bits_long(gb, nbits);
404 
405  if (last_size < 0)
406  return AVERROR_INVALIDDATA;
407 
408  for (int i = 1; i < s->cu_height; i++) {
409  int diff = get_bits_long(gb, nbits);
410  if (s->slice[i].sign)
411  last_size += diff;
412  else
413  last_size -= diff;
414  if (last_size <= 0)
415  return AVERROR_INVALIDDATA;
416  s->slice[i].size = last_size;
417  }
418 
419  align_get_bits(gb);
420  return 0;
421 }
422 
423 static int read_intra_mode(GetBitContext * gb, int * param)
424 {
425  if (get_bits1(gb)) {
426  *param = read_code012(gb);
427  return INTRAMODE_INDEX;
428  } else {
429  *param = get_bits(gb, 5);
430  return INTRAMODE_MODE;
431  }
432 }
433 
434 static int has_top_block(const RV60Context * s, int xpos, int ypos, int dx, int dy, int size)
435 {
436  return ypos + dy && xpos + dx + size <= s->awidth;
437 }
438 
439 static int has_left_block(const RV60Context * s, int xpos, int ypos, int dx, int dy, int size)
440 {
441  return xpos + dx && ypos + dy + size <= s->aheight;
442 }
443 
444 static int has_top_right_block(const RV60Context * s, int xpos, int ypos, int dx, int dy, int size)
445 {
446  if (has_top_block(s, xpos, ypos, dx, dy, size * 2)) {
447  int cxpos = ((xpos + dx) & 63) >> ff_log2(size);
448  int cypos = ((ypos + dy) & 63) >> ff_log2(size);
449  return !(rv60_avail_mask[cxpos] & cypos);
450  }
451  return 0;
452 }
453 
454 static int has_left_down_block(const RV60Context * s, int xpos, int ypos, int dx, int dy, int size)
455 {
456  if (has_left_block(s, xpos, ypos, dx, dy, size * 2)) {
457  int cxpos = (~(xpos + dx) & 63) >> ff_log2(size);
458  int cypos = (~(ypos + dy) & 63) >> ff_log2(size);
459  return rv60_avail_mask[cxpos] & cypos;
460  }
461  return 0;
462 }
463 
464 typedef struct {
465  uint8_t t[129];
466  uint8_t l[129];
467  int has_t;
468  int has_tr;
469  int has_l;
470  int has_ld;
472 
473 typedef struct {
474  int xpos;
475  int ypos;
476  int pu_pos;
477  int blk_pos;
478 
479  enum CUType cu_type;
480  enum PUType pu_type;
481  enum IntraMode imode[4];
482  int imode_param[4];
483  MVInfo mv[4];
484 
486 } CUContext;
487 
489 {
490  memset(i->t, 0x80, sizeof(i->t));
491  memset(i->l, 0x80, sizeof(i->l));
492  i->has_t = i->has_tr = i->has_l = i->has_ld = 0;
493 }
494 
495 static void populate_ipred(const RV60Context * s, CUContext * cu, const uint8_t * src, int stride, int xoff, int yoff, int size, int is_luma)
496 {
497  if (is_luma)
498  src += (cu->ypos + yoff) * stride + cu->xpos + xoff;
499  else
500  src += (cu->ypos >> 1) * stride + (cu->xpos >> 1);
501 
502  ipred_init(&cu->ipred);
503 
504  if (cu->ypos + yoff > 0) {
505  cu->ipred.has_t = 1;
506 
507  memcpy(cu->ipred.t + 1, src - stride, size);
508 
509  if ((is_luma && has_top_right_block(s, cu->xpos, cu->ypos, xoff, yoff, size)) ||
510  (!is_luma && has_top_right_block(s, cu->xpos, cu->ypos, 0, 0, size << 1))) {
511  cu->ipred.has_tr = 1;
512  memcpy(cu->ipred.t + size + 1, src - stride + size, size);
513  } else
514  memset(cu->ipred.t + size + 1, cu->ipred.t[size], size);
515 
516  if (cu->xpos + xoff > 0)
517  cu->ipred.t[0] = src[-stride - 1];
518  }
519 
520  if (cu->xpos + xoff > 0) {
521  cu->ipred.has_l = 1;
522 
523  for (int y = 0; y < size; y++)
524  cu->ipred.l[y + 1] = src[y*stride - 1];
525 
526  if ((is_luma && has_left_down_block(s, cu->xpos, cu->ypos, xoff, yoff, size)) ||
527  (!is_luma && has_left_down_block(s, cu->xpos, cu->ypos, 0, 0, size << 1))) {
528  cu->ipred.has_ld = 1;
529  for (int y = size; y < size * 2; y++)
530  cu->ipred.l[y + 1] = src[y*stride - 1];
531  } else
532  memset(cu->ipred.l + size + 1, cu->ipred.l[size], size);
533 
534  if (cu->ypos + yoff > 0)
535  cu->ipred.l[0] = src[-stride - 1];
536  }
537 }
538 
539 static void pred_plane(const IntraPredContext * p, uint8_t * dst, int stride, int size)
540 {
541  int lastl = p->l[size + 1];
542  int lastt = p->t[size + 1];
543  int tmp1[64], tmp2[64];
544  int top_ref[64], left_ref[64];
545  int shift;
546 
547  for (int i = 0; i < size; i++) {
548  tmp1[i] = lastl - p->t[i + 1];
549  tmp2[i] = lastt - p->l[i + 1];
550  }
551 
552  shift = ff_log2(size) + 1;
553  for (int i = 0; i < size; i++) {
554  top_ref[i] = p->t[i + 1] << (shift - 1);
555  left_ref[i] = p->l[i + 1] << (shift - 1);
556  }
557 
558  for (int y = 0; y < size; y++) {
559  int add = tmp2[y];
560  int sum = left_ref[y] + size;
561  for (int x = 0; x < size; x++) {
562  int v = tmp1[x] + top_ref[x];
563  sum += add;
564  top_ref[x] = v;
565  dst[y*stride + x] = (sum + v) >> shift;
566  }
567  }
568 }
569 
570 static void pred_dc(const IntraPredContext * p, uint8_t * dst, int stride, int size, int filter)
571 {
572  int dc;
573 
574  if (!p->has_t && !p->has_l)
575  dc = 0x80;
576  else {
577  int sum = 0;
578  if (p->has_t)
579  for (int x = 0; x < size; x++)
580  sum += p->t[x + 1];
581  if (p->has_l)
582  for (int y = 0; y < size; y++)
583  sum += p->l[y + 1];
584  if (p->has_t && p->has_l)
585  dc = (sum + size) / (size * 2);
586  else
587  dc = (sum + size / 2) / size;
588  }
589 
590  for (int y = 0; y < size; y++)
591  memset(dst + y*stride, dc, size);
592 
593  if (filter && p->has_t && p->has_l) {
594  dst[0] = (p->t[1] + p->l[1] + 2 * dst[0] + 2) >> 2;
595  for (int x = 1; x < size; x++)
596  dst[x] = (p->t[x + 1] + 3 * dst[x] + 2) >> 2;
597  for (int y = 1; y < size; y++)
598  dst[y*stride] = (p->l[y + 1] + 3 * dst[y*stride] + 2) >> 2;
599  }
600 }
601 
602 static void filter_weak(uint8_t * dst, const uint8_t * src, int size)
603 {
604  dst[0] = src[0];
605  for (int i = 1; i < size - 1; i++)
606  dst[i] = (src[i - 1] + 2*src[i] + src[i + 1] + 2) >> 2;
607  dst[size - 1] = src[size - 1];
608 }
609 
610 static void filter_bilin32(uint8_t * dst, int v0, int v1, int size)
611 {
612  int diff = v1 - v0;
613  int sum = (v0 << 5) + (1 << (5 - 1));
614  for (int i = 0; i < size; i++) {
615  dst[i] = sum >> 5;
616  sum += diff;
617  }
618 }
619 
620 static void pred_hor_angle(uint8_t * dst, int stride, int size, int weight, const uint8_t * src)
621 {
622  int sum = 0;
623  for (int x = 0; x < size; x++) {
624  int off, frac;
625  sum += weight;
626  off = (sum >> 5) + 32;
627  frac = sum & 0x1F;
628  if (!frac)
629  for (int y = 0; y < size; y++)
630  dst[y*stride + x] = src[off + y];
631  else {
632  for (int y = 0; y < size; y++) {
633  int a = src[off + y];
634  int b = src[off + y + 1];
635  dst[y*stride + x] = ((32 - frac) * a + frac * b + 16) >> 5;
636  }
637  }
638  }
639 }
640 
641 static void pred_ver_angle(uint8_t * dst, int stride, int size, int weight, const uint8_t * src)
642 {
643  int sum = 0;
644  for (int y = 0; y < size; y++) {
645  int off, frac;
646  sum += weight;
647  off = (sum >> 5) + 32;
648  frac = sum & 0x1F;
649  if (!frac)
650  memcpy(dst + y*stride, src + off, size);
651  else {
652  for (int x = 0; x < size; x++) {
653  int a = src[off + x];
654  int b = src[off + x + 1];
655  dst[y*stride + x] = ((32 - frac) * a + frac * b + 16) >> 5;
656  }
657  }
658  }
659 }
660 
661 static int pred_angle(const IntraPredContext * p, uint8_t * dst, int stride, int size, int imode, int filter)
662 {
663  uint8_t filtered1[96], filtered2[96];
664 
665  if (!imode) {
666  pred_plane(p, dst, stride, size);
667  } else if (imode == 1) {
668  pred_dc(p, dst, stride, size, filter);
669  } else if (imode <= 9) {
670  int ang_weight = rv60_ipred_angle[10 - imode];
671  int add_size = (size * ang_weight + 31) >> 5;
672  if (size <= 16) {
673  filter_weak(filtered1 + 32, &p->l[1], size + add_size);
674  } else {
675  filter_bilin32(filtered1 + 32, p->l[1], p->l[33], 32);
676  filter_bilin32(filtered1 + 64, p->l[32], p->l[64], add_size);
677  }
678  pred_hor_angle(dst, stride, size, ang_weight, filtered1);
679  } else if (imode == 10) {
680  if (size <= 16)
681  filter_weak(filtered1 + 32, &p->l[1], size);
682  else
683  filter_bilin32(filtered1 + 32, p->l[1], p->l[33], 32);
684  for (int y = 0; y < size; y++)
685  for (int x = 0; x < size; x++)
686  dst[y*stride + x] = filtered1[32 + y];
687  if (filter) {
688  int tl = p->t[0];
689  for (int x = 0; x < size; x++)
690  dst[x] = av_clip_uint8(dst[x] + ((p->t[x + 1] - tl) >> 1));
691  }
692  } else if (imode <= 17) {
693  int ang_weight = rv60_ipred_angle[imode - 10];
694  int inv_angle = rv60_ipred_inv_angle[imode - 10];
695  int add_size = (size * ang_weight + 31) >> 5;
696  if (size <= 16) {
697  memcpy(filtered1 + 32 - 1, p->l, size + 1);
698  memcpy(filtered2 + 32 - 1, p->t, size + 1);
699  } else {
700  filtered1[32 - 1] = p->l[0];
701  filter_bilin32(filtered1 + 32, p->l[0], p->l[32], 32);
702  filtered2[32 - 1] = p->t[0];
703  filter_bilin32(filtered2 + 32, p->t[0], p->t[32], 32);
704  }
705  if (add_size > 1) {
706  int sum = 0x80;
707  for (int i = 1; i < add_size; i++) {
708  sum += inv_angle;
709  filtered1[32 - 1 - i] = filtered2[32 - 1 + (sum >> 8)];
710  }
711  }
712  pred_hor_angle(dst, stride, size, -ang_weight, filtered1);
713  } else if (imode <= 25) {
714  int ang_weight = rv60_ipred_angle[26 - imode];
715  int inv_angle = rv60_ipred_inv_angle[26 - imode];
716  int add_size = (size * ang_weight + 31) >> 5;
717  if (size <= 16) {
718  memcpy(filtered1 + 32 - 1, p->t, size + 1);
719  memcpy(filtered2 + 32 - 1, p->l, size + 1);
720  } else {
721  filtered1[32 - 1] = p->t[0];
722  filter_bilin32(filtered1 + 32, p->t[0], p->t[32], 32);
723  filtered2[32 - 1] = p->l[0];
724  filter_bilin32(filtered2 + 32, p->l[0], p->l[32], 32);
725  }
726  if (add_size > 1) {
727  int sum = 0x80;
728  for (int i = 1; i < add_size; i++) {
729  sum += inv_angle;
730  filtered1[32 - 1 - i] = filtered2[32 - 1 + (sum >> 8)];
731  }
732  }
733  pred_ver_angle(dst, stride, size, -ang_weight, filtered1);
734  } else if (imode == 26) {
735  if (size <= 16)
736  filter_weak(&filtered1[32], &p->t[1], size);
737  else
738  filter_bilin32(filtered1 + 32, p->t[1], p->t[33], 32);
739  for (int i = 0; i < size; i++)
740  memcpy(dst + i*stride, filtered1 + 32, size);
741  if (filter) {
742  int tl = p->l[0];
743  for (int y = 0; y < size; y++)
744  dst[y*stride] = av_clip_uint8(dst[y*stride] + ((p->l[y+1] - tl) >> 1));
745  }
746  } else if (imode <= 34) {
747  int ang_weight = rv60_ipred_angle[imode - 26];
748  int add_size = (size * ang_weight + 31) >> 5;
749  if (size <= 16)
750  filter_weak(&filtered1[32], &p->t[1], size + add_size);
751  else {
752  filter_bilin32(filtered1 + 32, p->t[1], p->t[33], 32);
753  filter_bilin32(filtered1 + 64, p->t[32], p->t[64], add_size);
754  }
755  pred_ver_angle(dst, stride, size, ang_weight, filtered1);
756  } else
757  return AVERROR_INVALIDDATA;
758  return 0;
759 }
760 
761 static int pu_is_intra(const PUInfo * pu)
762 {
763  return pu->cu_type == CU_INTRA;
764 }
765 
766 static int ipm_compar(const void * a, const void * b)
767 {
768  return *(const enum IntraMode *)a - *(const enum IntraMode *)b;
769 }
770 
771 #define MK_UNIQUELIST(name, type, max_size) \
772 typedef struct { \
773  type list[max_size]; \
774  int size; \
775 } unique_list_##name; \
776 \
777 static void unique_list_##name##_init(unique_list_##name * s) \
778 { \
779  memset(s->list, 0, sizeof(s->list)); \
780  s->size = 0; \
781 } \
782 \
783 static void unique_list_##name##_add(unique_list_##name * s, type cand) \
784 { \
785  if (s->size == max_size) \
786  return; \
787  \
788  for (int i = 0; i < s->size; i++) { \
789  if (!memcmp(&s->list[i], &cand, sizeof(type))) { \
790  return; \
791  } \
792  } \
793  s->list[s->size++] = cand; \
794 }
795 
796 MK_UNIQUELIST(intramode, enum IntraMode, 3)
797 MK_UNIQUELIST(mvinfo, MVInfo, 4)
798 
799 static int reconstruct_intra(const RV60Context * s, const CUContext * cu, int size, int sub)
800 {
801  int blk_pos, tl_x, tl_y;
802  unique_list_intramode ipm_cand;
803 
804  if (cu->imode[0] == INTRAMODE_DC64)
805  return 1;
806 
807  if (cu->imode[0] == INTRAMODE_PLANE64)
808  return 0;
809 
810  unique_list_intramode_init(&ipm_cand);
811 
812  if (has_top_block(s, cu->xpos, cu->ypos, (sub & 1) * 4, 0, size)) {
813  const PUInfo * pu = &s->pu_info[cu->pu_pos - s->pu_stride];
814  if (pu_is_intra(pu))
815  unique_list_intramode_add(&ipm_cand, s->blk_info[cu->blk_pos - s->blk_stride + (sub & 1)].imode);
816  }
817 
818  blk_pos = cu->blk_pos + (sub >> 1) * s->blk_stride + (sub & 1);
819 
820  if (has_left_block(s, cu->xpos, cu->ypos, 0, (sub & 2) * 2, size)) {
821  const PUInfo * pu = &s->pu_info[cu->pu_pos - 1];
822  if (pu_is_intra(pu))
823  unique_list_intramode_add(&ipm_cand, s->blk_info[blk_pos - 1 - (sub & 1)].imode);
824  }
825 
826  tl_x = !(sub & 2) ? (cu->xpos + (sub & 1) * 4) : cu->xpos;
827  tl_y = cu->ypos + (sub & 2) * 4;
828  if (tl_x > 0 && tl_y > 0) {
829  const PUInfo * pu;
830  switch (sub) {
831  case 0: pu = &s->pu_info[cu->pu_pos - s->pu_stride - 1]; break;
832  case 1: pu = &s->pu_info[cu->pu_pos - s->pu_stride]; break;
833  default: pu = &s->pu_info[cu->pu_pos - 1];
834  }
835  if (pu_is_intra(pu)) {
836  if (sub != 3)
837  unique_list_intramode_add(&ipm_cand, s->blk_info[blk_pos - s->blk_stride - 1].imode);
838  else
839  unique_list_intramode_add(&ipm_cand, s->blk_info[blk_pos - s->blk_stride - 2].imode);
840  }
841  }
842 
843  for (int i = 0; i < FF_ARRAY_ELEMS(rv60_candidate_intra_angles); i++)
844  unique_list_intramode_add(&ipm_cand, rv60_candidate_intra_angles[i]);
845 
846  if (cu->imode[sub] == INTRAMODE_INDEX)
847  return ipm_cand.list[cu->imode_param[sub]];
848 
849  if (cu->imode[sub] == INTRAMODE_MODE) {
850  enum IntraMode imode = cu->imode_param[sub];
851  qsort(ipm_cand.list, 3, sizeof(ipm_cand.list[0]), ipm_compar);
852  for (int i = 0; i < 3; i++)
853  if (imode >= ipm_cand.list[i])
854  imode++;
855  return imode;
856  }
857 
858  av_assert0(0); // should never reach here
859  return 0;
860 }
861 
862 static int get_skip_mv_index(enum MVRefEnum mvref)
863 {
864  switch (mvref) {
865  case MVREF_SKIP1: return 1;
866  case MVREF_SKIP2: return 2;
867  case MVREF_SKIP3: return 3;
868  default: return 0;
869  }
870 }
871 
872 static void add_if_valid(unique_list_mvinfo * skip_cand, const MVInfo * mvi)
873 {
874  if (mvi->mvref != MVREF_NONE)
875  unique_list_mvinfo_add(skip_cand, *mvi);
876 }
877 
878 static void fill_mv_skip_cand(RV60Context * s, const CUContext * cu, unique_list_mvinfo * skip_cand, int size)
879 {
880  int mv_size = size >> 2;
881 
882  if (cu->xpos)
883  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos - 1].mv);
884  if (cu->ypos)
885  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos - s->blk_stride].mv);
886  if (cu->ypos && cu->xpos + size < s->awidth)
887  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos - s->blk_stride + mv_size].mv);
888  if (cu->xpos && cu->ypos + size < s->aheight)
889  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos + s->blk_stride * mv_size - 1].mv);
890  if (cu->xpos)
891  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos + s->blk_stride * (mv_size - 1) - 1].mv);
892  if (cu->ypos)
893  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos - s->blk_stride + mv_size - 1].mv);
894  if (cu->xpos && cu->ypos)
895  add_if_valid(skip_cand, &s->blk_info[cu->blk_pos - s->blk_stride - 1].mv);
896 
897  for (int i = skip_cand->size; i < 4; i++)
898  skip_cand->list[i] = (MVInfo){.mvref=MVREF_REF0,.f_mv={0,0},.b_mv={0,0}};
899 }
900 
901 typedef struct {
902  int w, h;
903 } Dimensions;
904 
905 static void get_mv_dimensions(Dimensions * dim, enum PUType pu_type, int part_no, int size)
906 {
907  int mv_size = size >> 2;
908  switch (pu_type) {
909  case PU_FULL:
910  dim->w = dim->h = mv_size;
911  break;
912  case PU_N2HOR:
913  dim->w = mv_size;
914  dim->h = mv_size >> 1;
915  break;
916  case PU_N2VER:
917  dim->w = mv_size >> 1;
918  dim->h = mv_size;
919  break;
920  case PU_QUARTERS:
921  dim->w = dim->h = mv_size >> 1;
922  break;
923  case PU_N4HOR:
924  dim->w = mv_size;
925  dim->h = !part_no ? (mv_size >> 2) : ((3 * mv_size) >> 2);
926  break;
927  case PU_N34HOR:
928  dim->w = mv_size;
929  dim->h = !part_no ? ((3 * mv_size) >> 2) : (mv_size >> 2);
930  break;
931  case PU_N4VER:
932  dim->w = !part_no ? (mv_size >> 2) : ((3 * mv_size) >> 2);
933  dim->h = mv_size;
934  break;
935  case PU_N34VER:
936  dim->w = !part_no ? ((3 * mv_size) >> 2) : (mv_size >> 2);
937  dim->h = mv_size;
938  break;
939  }
940 }
941 
942 static int has_hor_split(enum PUType pu_type)
943 {
944  return pu_type == PU_N2HOR || pu_type == PU_N4HOR || pu_type == PU_N34HOR || pu_type == PU_QUARTERS;
945 }
946 
947 static int has_ver_split(enum PUType pu_type)
948 {
949  return pu_type == PU_N2VER || pu_type == PU_N4VER || pu_type == PU_N34VER || pu_type == PU_QUARTERS;
950 }
951 
952 static int pu_type_num_parts(enum PUType pu_type)
953 {
954  switch (pu_type) {
955  case PU_FULL: return 1;
956  case PU_QUARTERS: return 4;
957  default: return 2;
958  }
959 }
960 
961 static void get_next_mv(const RV60Context * s, const Dimensions * dim, enum PUType pu_type, int part_no, int * mv_pos, int * mv_x, int * mv_y)
962 {
963  if (pu_type == PU_QUARTERS) {
964  if (part_no != 1) {
965  *mv_pos += dim->w;
966  *mv_x += dim->w;
967  } else {
968  *mv_pos += dim->h*s->blk_stride - dim->w;
969  *mv_x -= dim->w;
970  *mv_y += dim->h;
971  }
972  } else if (has_hor_split(pu_type)) {
973  *mv_pos += dim->h * s->blk_stride;
974  *mv_y += dim->h;
975  } else if (has_ver_split(pu_type)) {
976  *mv_pos += dim->w;
977  *mv_x += dim->w;
978  }
979 }
980 
981 static int mv_is_ref0(enum MVRefEnum mvref)
982 {
983  return mvref == MVREF_REF0 || mvref == MVREF_REF0ANDBREF;
984 }
985 
986 static int mv_is_forward(enum MVRefEnum mvref)
987 {
988  return mvref == MVREF_REF0 || mvref == MVREF_REF1 || mvref == MVREF_REF0ANDBREF;
989 }
990 
991 static int mv_is_backward(enum MVRefEnum mvref)
992 {
993  return mvref == MVREF_BREF || mvref == MVREF_REF0ANDBREF;
994 }
995 
996 static int mvinfo_matches_forward(const MVInfo * a, const MVInfo * b)
997 {
998  return a->mvref == b->mvref || (mv_is_ref0(a->mvref) && mv_is_ref0(b->mvref));
999 }
1000 
1001 static int mvinfo_matches_backward(const MVInfo * a, const MVInfo * b)
1002 {
1003  return mv_is_backward(a->mvref) && mv_is_backward(b->mvref);
1004 }
1005 
1006 static int mvinfo_is_deblock_cand(const MVInfo * a, const MVInfo * b)
1007 {
1008  int diff;
1009 
1010  if (a->mvref != b->mvref)
1011  return 1;
1012 
1013  diff = 0;
1014  if (mv_is_forward(a->mvref)) {
1015  int dx = a->f_mv.x - b->f_mv.x;
1016  int dy = a->f_mv.y - b->f_mv.y;
1017  diff += FFABS(dx) + FFABS(dy);
1018  }
1019  if (mv_is_backward(a->mvref)) {
1020  int dx = a->b_mv.x - b->b_mv.x;
1021  int dy = a->b_mv.y - b->b_mv.y;
1022  diff += FFABS(dx) + FFABS(dy);
1023  }
1024  return diff > 4;
1025 }
1026 
1027 static void mv_pred(MV * ret, MV a, MV b, MV c)
1028 {
1029 #define MEDIAN(x) \
1030  if (a.x < b.x) \
1031  if (b.x < c.x) \
1032  ret->x = b.x; \
1033  else \
1034  ret->x = a.x < c.x ? c.x : a.x; \
1035  else \
1036  if (b.x < c.x) \
1037  ret->x = a.x < c.x ? a.x : c.x; \
1038  else \
1039  ret->x = b.x; \
1040 
1041  MEDIAN(x)
1042  MEDIAN(y)
1043 }
1044 
1045 static void predict_mv(const RV60Context * s, MVInfo * dst, int mv_x, int mv_y, int mv_w, const MVInfo * src)
1046 {
1047  int mv_pos = mv_y * s->blk_stride + mv_x;
1048  MV f_mv, b_mv;
1049 
1050  dst->mvref = src->mvref;
1051 
1052  if (mv_is_forward(src->mvref)) {
1053  MV cand[3] = {0};
1054  int cand_size = 0;
1055  if (mv_x > 0) {
1056  const MVInfo * mv = &s->blk_info[mv_pos - 1].mv;
1058  cand[cand_size++] = mv->f_mv;
1059  }
1060  if (mv_y > 0) {
1061  const MVInfo * mv = &s->blk_info[mv_pos - s->blk_stride].mv;
1063  cand[cand_size++] = mv->f_mv;
1064  }
1065  if (has_top_block(s, mv_x << 2, mv_y << 2, mv_w << 2, 0, 4)) {
1066  const MVInfo * mv = &s->blk_info[mv_pos - s->blk_stride + mv_w].mv;
1068  cand[cand_size++] = mv->f_mv;
1069  }
1070 
1071  switch (cand_size) {
1072  case 1:
1073  f_mv.x = cand[0].x;
1074  f_mv.y = cand[0].y;
1075  break;
1076  case 2:
1077  f_mv.x = (cand[0].x + cand[1].x) >> 1;
1078  f_mv.y = (cand[0].y + cand[1].y) >> 1;
1079  break;
1080  case 3:
1081  mv_pred(&f_mv, cand[0], cand[1], cand[2]);
1082  break;
1083  default:
1084  f_mv = (MV){0,0};
1085  break;
1086  }
1087  } else {
1088  f_mv = (MV){0,0};
1089  }
1090 
1091  dst->f_mv.x = src->f_mv.x + f_mv.x;
1092  dst->f_mv.y = src->f_mv.y + f_mv.y;
1093 
1094  if (mv_is_backward(src->mvref)) {
1095  MV cand[3] = {0};
1096  int cand_size = 0;
1097  if (mv_x > 0) {
1098  const MVInfo * mv = &s->blk_info[mv_pos - 1].mv;
1100  cand[cand_size++] = mv->b_mv;
1101  }
1102  if (mv_y > 0) {
1103  const MVInfo * mv = &s->blk_info[mv_pos - s->blk_stride].mv;
1105  cand[cand_size++] = mv->b_mv;
1106  }
1107  if (has_top_block(s, mv_x << 2, mv_y << 2, mv_w << 2, 0, 4)) {
1108  const MVInfo * mv = &s->blk_info[mv_pos - s->blk_stride + mv_w].mv;
1110  cand[cand_size++] = mv->b_mv;
1111  }
1112 
1113  switch (cand_size) {
1114  case 1:
1115  b_mv.x = cand[0].x;
1116  b_mv.y = cand[0].y;
1117  break;
1118  case 2:
1119  b_mv.x = (cand[0].x + cand[1].x) >> 1;
1120  b_mv.y = (cand[0].y + cand[1].y) >> 1;
1121  break;
1122  case 3:
1123  mv_pred(&b_mv, cand[0], cand[1], cand[2]);
1124  break;
1125  default:
1126  b_mv = (MV){0,0};
1127  break;
1128  }
1129  } else {
1130  b_mv = (MV){0,0};
1131  }
1132 
1133  dst->b_mv.x = src->b_mv.x + b_mv.x;
1134  dst->b_mv.y = src->b_mv.y + b_mv.y;
1135 }
1136 
1137 static void reconstruct(RV60Context * s, const CUContext * cu, int size)
1138 {
1139  int pu_size = size >> 3;
1140  PUInfo pui;
1141  int imode, mv_x, mv_y, mv_pos, count, mv_size;
1142  unique_list_mvinfo skip_cand;
1143  Dimensions dim;
1144  MVInfo mv;
1145 
1146  pui.cu_type = cu->cu_type;
1147  pui.pu_type = cu->pu_type;
1148 
1149  if (cu->cu_type == CU_INTRA && cu->pu_type == PU_QUARTERS) {
1150  s->pu_info[cu->pu_pos] = pui;
1151  for (int y = 0; y < 2; y++)
1152  for (int x = 0; x < 2; x++)
1153  s->blk_info[cu->blk_pos + y*s->blk_stride + x].imode =
1154  reconstruct_intra(s, cu, 4, y*2 + x);
1155  return;
1156  }
1157 
1158  switch (cu->cu_type) {
1159  case CU_INTRA:
1160  imode = reconstruct_intra(s, cu, size, 0);
1161  for (int y = 0; y < size >> 2; y++)
1162  for (int x = 0; x < size >> 2; x++)
1163  s->blk_info[cu->blk_pos + y*s->blk_stride + x].imode = imode;
1164  break;
1165  case CU_INTER_MV:
1166  mv_x = cu->xpos >> 2;
1167  mv_y = cu->ypos >> 2;
1168  mv_pos = cu->blk_pos;
1169  count = pu_type_num_parts(cu->pu_type);
1170  for (int part_no = 0; part_no < count; part_no++) {
1171  MVInfo mv;
1172  get_mv_dimensions(&dim, cu->pu_type, part_no, size);
1173  predict_mv(s, &mv, mv_x, mv_y, dim.w, &cu->mv[part_no]);
1174  for (int y = 0; y < dim.h; y++)
1175  for (int x = 0; x < dim.w; x++)
1176  s->blk_info[mv_pos + y*s->blk_stride + x].mv = mv;
1177  get_next_mv(s, &dim, cu->pu_type, part_no, &mv_pos, &mv_x, &mv_y);
1178  }
1179  break;
1180  default:
1181  unique_list_mvinfo_init(&skip_cand);
1182  fill_mv_skip_cand(s, cu, &skip_cand, size);
1183  mv = skip_cand.list[get_skip_mv_index(cu->mv[0].mvref)];
1184  mv_size = size >> 2;
1185  for (int y = 0; y < mv_size; y++)
1186  for (int x = 0; x < mv_size; x++)
1187  s->blk_info[cu->blk_pos + y*s->blk_stride + x].mv = mv;
1188  }
1189 
1190  for (int y = 0; y < pu_size; y++)
1191  for (int x = 0; x < pu_size; x++)
1192  s->pu_info[cu->pu_pos + y*s->pu_stride + x] = pui;
1193 }
1194 
1195 static void read_mv(GetBitContext * gb, MV * mv)
1196 {
1197  mv->x = get_interleaved_se_golomb(gb);
1198  mv->y = get_interleaved_se_golomb(gb);
1199 }
1200 
1201 static void read_mv_info(RV60Context *s, GetBitContext * gb, MVInfo * mvinfo, int size, enum PUType pu_type)
1202 {
1203  if (s->pict_type != AV_PICTURE_TYPE_B) {
1204  if (s->two_f_refs && get_bits1(gb))
1205  mvinfo->mvref = MVREF_REF1;
1206  else
1207  mvinfo->mvref = MVREF_REF0;
1208  read_mv(gb, &mvinfo->f_mv);
1209  mvinfo->b_mv.x = mvinfo->b_mv.y = 0;
1210  } else {
1211  if ((size <= 8 && (size != 8 || pu_type != PU_FULL)) || get_bits1(gb)) {
1212  if (!get_bits1(gb)) {
1213  mvinfo->mvref = MVREF_REF0;
1214  read_mv(gb, &mvinfo->f_mv);
1215  mvinfo->b_mv.x = mvinfo->b_mv.y = 0;
1216  } else {
1217  mvinfo->mvref = MVREF_BREF;
1218  mvinfo->f_mv.x = mvinfo->f_mv.y = 0;
1219  read_mv(gb, &mvinfo->b_mv);
1220  }
1221  } else {
1222  mvinfo->mvref = MVREF_REF0ANDBREF;
1223  read_mv(gb, &mvinfo->f_mv);
1224  read_mv(gb, &mvinfo->b_mv);
1225  }
1226  }
1227 }
1228 
1229 #define FILTER1(src, src_stride, src_y_ofs, step) \
1230  ( (src)[(y + src_y_ofs)*(src_stride) + x - 2*step] \
1231  - 5 * (src)[(y + src_y_ofs)*(src_stride) + x - 1*step] \
1232  +52 * (src)[(y + src_y_ofs)*(src_stride) + x ] \
1233  +20 * (src)[(y + src_y_ofs)*(src_stride) + x + 1*step] \
1234  - 5 * (src)[(y + src_y_ofs)*(src_stride) + x + 2*step] \
1235  + (src)[(y + src_y_ofs)*(src_stride) + x + 3*step] + 32) >> 6
1236 
1237 #define FILTER2(src, src_stride, src_y_ofs, step) \
1238  ( (src)[(y + src_y_ofs)*(src_stride) + x - 2*step] \
1239  - 5 * (src)[(y + src_y_ofs)*(src_stride) + x - 1*step] \
1240  +20 * (src)[(y + src_y_ofs)*(src_stride) + x ] \
1241  +20 * (src)[(y + src_y_ofs)*(src_stride) + x + 1*step] \
1242  - 5 * (src)[(y + src_y_ofs)*(src_stride) + x + 2*step] \
1243  + (src)[(y + src_y_ofs)*(src_stride) + x + 3*step] + 16) >> 5
1244 
1245 #define FILTER3(src, src_stride, src_y_ofs, step) \
1246  ( (src)[(y + src_y_ofs)*(src_stride) + x - 2*step] \
1247  - 5 * (src)[(y + src_y_ofs)*(src_stride) + x - 1*step] \
1248  +20 * (src)[(y + src_y_ofs)*(src_stride) + x ] \
1249  +52 * (src)[(y + src_y_ofs)*(src_stride) + x + 1*step] \
1250  - 5 * (src)[(y + src_y_ofs)*(src_stride) + x + 2*step] \
1251  + (src)[(y + src_y_ofs)*(src_stride) + x + 3*step] + 32) >> 6
1252 
1253 #define FILTER_CASE(idx, dst, dst_stride, filter, w, h) \
1254  case idx: \
1255  for (int y = 0; y < h; y++) \
1256  for (int x = 0; x < w; x++) \
1257  (dst)[y*dst_stride + x] = av_clip_uint8(filter); \
1258  break;
1259 
1260 #define FILTER_BLOCK(dst, dst_stride, src, src_stride, src_y_ofs, w, h, cond, step) \
1261  switch (cond) { \
1262  FILTER_CASE(1, dst, dst_stride, FILTER1(src, src_stride, src_y_ofs, step), w, h) \
1263  FILTER_CASE(2, dst, dst_stride, FILTER2(src, src_stride, src_y_ofs, step), w, h) \
1264  FILTER_CASE(3, dst, dst_stride, FILTER3(src, src_stride, src_y_ofs, step), w, h) \
1265  }
1266 
1267 static void luma_mc(uint8_t * dst, int dst_stride, const uint8_t * src, int src_stride, int w, int h, int cx, int cy)
1268 {
1269  if (!cx && !cy) {
1270  for (int y = 0; y < h; y++)
1271  memcpy(dst + y*dst_stride, src + y*src_stride, w);
1272  } else if (!cy) {
1273  FILTER_BLOCK(dst, dst_stride, src, src_stride, 0, w, h, cx, 1)
1274  } else if (!cx) {
1275  FILTER_BLOCK(dst, dst_stride, src, src_stride, 0, w, h, cy, src_stride)
1276  } else if (cx != 3 || cy != 3) {
1277  uint8_t tmp[70 * 64];
1278  FILTER_BLOCK(tmp, 64, src - src_stride * 2, src_stride, 0, w, h + 5, cx, 1)
1279  FILTER_BLOCK(dst, dst_stride, tmp + 2*64, 64, 0, w, h, cy, 64)
1280  } else {
1281  for (int j = 0; j < h; j++)
1282  for (int i = 0; i < w; i++)
1283  dst[j*dst_stride + i] = (
1284  src[j*src_stride + i] +
1285  src[j*src_stride + i + 1] +
1286  src[(j + 1)*src_stride + i] +
1287  src[(j + 1)*src_stride + i + 1] + 2) >> 2;
1288  }
1289 }
1290 
1291 static void chroma_mc(uint8_t * dst, int dst_stride, const uint8_t * src, int src_stride, int w, int h, int x, int y)
1292 {
1293  if (!x && !y) {
1294  for (int j = 0; j < h; j++)
1295  memcpy(dst + j*dst_stride, src + j*src_stride, w);
1296  } else if (x > 0 && y > 0) {
1297  int a, b, c, d;
1298 
1299  if (x == 3 && y == 3)
1300  y = 2; //reproduce bug in rv60 decoder. tested with realplayer version 18.1.7.344 and 22.0.0.321
1301 
1302  a = (4 - x) * (4 - y);
1303  b = x * (4 - y);
1304  c = (4 - x) * y;
1305  d = x * y;
1306  for (int j = 0; j < h; j++)
1307  for (int i = 0; i < w; i++)
1308  dst[j*dst_stride + i] =
1309  (a * src[j*src_stride + i] +
1310  b * src[j*src_stride + i + 1] +
1311  c * src[(j + 1)*src_stride + i] +
1312  d * src[(j + 1)*src_stride + i + 1] + 8) >> 4;
1313  } else {
1314  int a = (4 - x) * (4 - y);
1315  int e = x * (4 - y) + (4 - x) * y;
1316  int step = y > 0 ? src_stride : 1;
1317  for (int j = 0; j < h; j++)
1318  for (int i = 0; i < w; i++)
1319  dst[j*dst_stride + i] =
1320  (a * src[j*src_stride + i] +
1321  e * src[j*src_stride + i + step] + 8) >> 4;
1322  }
1323 }
1324 
1325 static int check_pos(int x, int y, int cw, int ch, int w, int h, int dx, int dy, int e0, int e1, int e2, int e3)
1326 {
1327  int x2 = x + dx;
1328  int y2 = y + dy;
1329  return x2 - e0 >= 0 && x2 + cw + e1 <= w && y2 - e2 >= 0 && y2 + ch + e3 <= h;
1330 }
1331 
1332 static void mc(RV60Context * s, uint8_t * frame_data[3], int frame_linesize[3], const AVFrame * ref, int x, int y, int w, int h, MV mv, int avg)
1333 {
1334  {
1335  int off = !avg ? y * frame_linesize[0] + x : 0;
1336  int fw = s->awidth;
1337  int fh = s->aheight;
1338  int dx = mv.x >> 2;
1339  int cx = mv.x & 3;
1340  int dy = mv.y >> 2;
1341  int cy = mv.y & 3;
1342 
1343  if (check_pos(x, y, w, h, fw, fh, dx, dy, rv60_edge1[cx], rv60_edge2[cx], rv60_edge1[cy], rv60_edge2[cy])) {
1344  luma_mc(
1345  frame_data[0] + off,
1346  frame_linesize[0],
1347  ref->data[0] + (y + dy) * ref->linesize[0] + x + dx,
1348  ref->linesize[0],
1349  w, h, cx, cy);
1350  } else {
1351  uint8_t buf[70*70];
1352  int xoff = x + dx - 2;
1353  int yoff = y + dy - 2;
1354  s->vdsp.emulated_edge_mc(buf,
1355  ref->data[0] + yoff * ref->linesize[0] + xoff,
1356  70, ref->linesize[0],
1357  w + 5, h + 5,
1358  xoff, yoff,
1359  fw, fh);
1360 
1361  luma_mc(frame_data[0] + off, frame_linesize[0],
1362  buf + 70 * 2 + 2, 70, w, h, cx, cy);
1363  }
1364  }
1365  {
1366  int fw = s->awidth >> 1;
1367  int fh = s->aheight >> 1;
1368  int mvx = mv.x / 2;
1369  int mvy = mv.y / 2;
1370  int dx = mvx >> 2;
1371  int cx = mvx & 3;
1372  int dy = mvy >> 2;
1373  int cy = mvy & 3;
1374  int cw = w >> 1;
1375  int ch = h >> 1;
1376 
1377  for (int plane = 1; plane < 3; plane++) {
1378  int off = !avg ? (y >> 1) * frame_linesize[plane] + (x >> 1) : 0;
1379  if (check_pos(x >> 1, y >> 1, cw, ch, fw, fh, dx, dy, 0, 1, 0, 1)) {
1380  chroma_mc(
1381  frame_data[plane] + off,
1382  frame_linesize[plane],
1383  ref->data[plane] + ((y >> 1) + dy) * ref->linesize[plane] + (x >> 1) + dx,
1384  ref->linesize[plane],
1385  cw, ch, cx, cy);
1386  } else {
1387  uint8_t buf[40*40];
1388  s->vdsp.emulated_edge_mc(buf,
1389  ref->data[plane] + ((y >> 1) + dy) * ref->linesize[plane] + (x >> 1) + dx,
1390  40, ref->linesize[plane],
1391  cw + 1, ch + 1,
1392  (x >> 1) + dx, (y >> 1) + dy,
1393  fw, fh);
1394  chroma_mc(frame_data[plane] + off, frame_linesize[plane], buf, 40, cw, ch, cx, cy);
1395  }
1396  }
1397  }
1398 }
1399 
1400 static void avg_plane(uint8_t * dst, int dst_stride, const uint8_t * src, int src_stride, int w, int h)
1401 {
1402  for (int j = 0; j < h; j++)
1403  for (int i = 0; i < w; i++)
1404  dst[j*dst_stride + i] = (dst[j*dst_stride + i] + src[j*src_stride + i]) >> 1;
1405 }
1406 
1407 static void avg(AVFrame * frame, uint8_t * prev_frame_data[3], int prev_frame_linesize[3], int x, int y, int w, int h)
1408 {
1409  for (int plane = 0; plane < 3; plane++) {
1410  int shift = !plane ? 0 : 1;
1411  avg_plane(frame->data[plane] + (y >> shift) * frame->linesize[plane] + (x >> shift), frame->linesize[plane],
1412  prev_frame_data[plane], prev_frame_linesize[plane],
1413  w >> shift, h >> shift);
1414  }
1415 }
1416 
1417 static int get_c4x4_set(int qp, int is_intra)
1418 {
1419  if (is_intra)
1420  return rv60_qp_to_idx[qp + 32];
1421  else
1422  return rv60_qp_to_idx[qp];
1423 }
1424 
1425 static int quant(int v, int q)
1426 {
1427  return (v * q + 8) >> 4;
1428 }
1429 
1430 static int decode_coeff(GetBitContext * gb, const CoeffVLCs * vlcs, int inval, int val)
1431 {
1432  int esc_sym;
1433 
1434  if (inval != val)
1435  return inval && get_bits1(gb) ? -inval : inval;
1436 
1437  esc_sym = get_vlc2(gb, vlcs->esc, 9, 2);
1438  if (esc_sym > 23) {
1439  int esc_bits = esc_sym - 23;
1440  val += (1 << esc_bits) + get_bits(gb, esc_bits) + 22;
1441  } else
1442  val += esc_sym;
1443 
1444  return get_bits1(gb) ? -val : val;
1445 }
1446 
1447 static void decode_2x2_dc(GetBitContext * gb, const CoeffVLCs * vlcs, int16_t * coeffs, int stride, int block2, int dsc, int q_dc, int q_ac)
1448 {
1449  const uint8_t * lx;
1450  if (!dsc)
1451  return;
1452 
1453  lx = rv60_dsc_to_lx[dsc - 1];
1454 
1455  coeffs[0] = quant(decode_coeff(gb, vlcs, lx[0], 3), q_dc);
1456  if (!block2) {
1457  coeffs[1] = quant(decode_coeff(gb, vlcs, lx[1], 2), q_ac);
1458  coeffs[stride] = quant(decode_coeff(gb, vlcs, lx[2], 2), q_ac);
1459  } else {
1460  coeffs[stride] = quant(decode_coeff(gb, vlcs, lx[1], 2), q_ac);
1461  coeffs[1] = quant(decode_coeff(gb, vlcs, lx[2], 2), q_ac);
1462  }
1463  coeffs[stride + 1] = quant(decode_coeff(gb, vlcs, lx[3], 2), q_ac);
1464 }
1465 
1466 static void decode_2x2(GetBitContext * gb, const CoeffVLCs * vlcs, int16_t * coeffs, int stride, int block2, int dsc, int q_ac)
1467 {
1468  const uint8_t * lx;
1469  if (!dsc)
1470  return;
1471 
1472  lx = rv60_dsc_to_lx[dsc - 1];
1473 
1474  coeffs[0] = quant(decode_coeff(gb, vlcs, lx[0], 3), q_ac);
1475  if (!block2) {
1476  coeffs[1] = quant(decode_coeff(gb, vlcs, lx[1], 2), q_ac);
1477  coeffs[stride] = quant(decode_coeff(gb, vlcs, lx[2], 2), q_ac);
1478  } else {
1479  coeffs[stride] = quant(decode_coeff(gb, vlcs, lx[1], 2), q_ac);
1480  coeffs[1] = quant(decode_coeff(gb, vlcs, lx[2], 2), q_ac);
1481  }
1482  coeffs[stride + 1] = quant(decode_coeff(gb, vlcs, lx[3], 2), q_ac);
1483 }
1484 
1485 static void decode_4x4_block_dc(GetBitContext * gb, const CoeffVLCs * vlcs, int is_luma, int16_t * coeffs, int stride, int q_dc, int q_ac)
1486 {
1487  int sym0 = get_vlc2(gb, vlcs->l0[!is_luma], 9, 2);
1488  int grp0 = sym0 >> 3;
1489 
1490  if (grp0)
1491  decode_2x2_dc(gb, vlcs, coeffs, stride, 0, grp0, q_dc, q_ac);
1492 
1493  if (sym0 & 4) {
1494  int grp = get_vlc2(gb, vlcs->l12[!is_luma], 9, 2);
1495  decode_2x2(gb, vlcs, coeffs + 2, stride, 0, grp, q_ac);
1496  }
1497  if (sym0 & 2) {
1498  int grp = get_vlc2(gb, vlcs->l12[!is_luma], 9, 2);
1499  decode_2x2(gb, vlcs, coeffs + 2*stride, stride, 1, grp, q_ac);
1500  }
1501  if (sym0 & 1) {
1502  int grp = get_vlc2(gb, vlcs->l3[!is_luma], 9, 2);
1503  decode_2x2(gb, vlcs, coeffs + 2*stride + 2, stride, 0, grp, q_ac);
1504  }
1505 }
1506 
1507 static void decode_4x4_block(GetBitContext * gb, const CoeffVLCs * vlcs, int is_luma, int16_t * coeffs, int stride, int q_ac)
1508 {
1509  int sym0 = get_vlc2(gb, vlcs->l0[!is_luma], 9, 2);
1510  int grp0 = (sym0 >> 3);
1511 
1512  if (grp0)
1513  decode_2x2(gb, vlcs, coeffs, stride, 0, grp0, q_ac);
1514 
1515  if (sym0 & 4) {
1516  int grp = get_vlc2(gb, vlcs->l12[!is_luma], 9, 2);
1517  decode_2x2(gb, vlcs, coeffs + 2, stride, 0, grp, q_ac);
1518  }
1519  if (sym0 & 2) {
1520  int grp = get_vlc2(gb, vlcs->l12[!is_luma], 9, 2);
1521  decode_2x2(gb, vlcs, coeffs + 2*stride, stride, 1, grp, q_ac);
1522  }
1523  if (sym0 & 1) {
1524  int grp = get_vlc2(gb, vlcs->l3[!is_luma], 9, 2);
1525  decode_2x2(gb, vlcs, coeffs + 2*stride + 2, stride, 0, grp, q_ac);
1526  }
1527 }
1528 
1529 static void decode_cu_4x4in16x16(GetBitContext * gb, int is_intra, int qp, int sel_qp, int16_t * y_coeffs, int16_t * u_coeffs, int16_t * v_coeffs, int cbp)
1530 {
1531  int cb_set = get_c4x4_set(sel_qp, is_intra);
1532  const CoeffVLCs * vlc = is_intra ? &intra_coeff_vlc[cb_set] : &inter_coeff_vlc[cb_set];
1533  int q_y = rv60_quants_b[qp];
1534  int q_c_dc = rv60_quants_b[rv60_chroma_quant_dc[qp]];
1535  int q_c_ac = rv60_quants_b[rv60_chroma_quant_ac[qp]];
1536 
1537  memset(y_coeffs, 0, sizeof(y_coeffs[0])*256);
1538  for (int i = 0; i < 16; i++)
1539  if ((cbp >> i) & 1)
1540  decode_4x4_block(gb, vlc, 1, y_coeffs + i * 16 , 4, q_y);
1541 
1542  memset(u_coeffs, 0, sizeof(u_coeffs[0])*64);
1543  for (int i = 0; i < 4; i++)
1544  if ((cbp >> (16 + i)) & 1)
1545  decode_4x4_block_dc(gb, vlc, 0, u_coeffs + i * 16, 4, q_c_dc, q_c_ac);
1546 
1547  memset(v_coeffs, 0, sizeof(v_coeffs[0])*64);
1548  for (int i = 0; i < 4; i++)
1549  if ((cbp >> (20 + i)) & 1)
1550  decode_4x4_block_dc(gb, vlc, 0, v_coeffs + i * 16, 4, q_c_dc, q_c_ac);
1551 }
1552 
1553 static int decode_cbp8(GetBitContext * gb, int subset, int qp)
1554 {
1555  int cb_set = rv60_qp_to_idx[qp];
1556  return get_vlc2(gb, cbp8_vlc[cb_set][subset], 9, 2);
1557 }
1558 
1559 static void decode_cu_8x8(GetBitContext * gb, int is_intra, int qp, int sel_qp, int16_t * y_coeffs, int16_t * u_coeffs, int16_t * v_coeffs, int ccbp, int mode4x4)
1560 {
1561  int cb_set = get_c4x4_set(sel_qp, is_intra);
1562  const CoeffVLCs * vlc = is_intra ? &intra_coeff_vlc[cb_set] : &inter_coeff_vlc[cb_set];
1563  int q_y = rv60_quants_b[qp];
1564  int q_c_dc = rv60_quants_b[rv60_chroma_quant_dc[qp]];
1565  int q_c_ac = rv60_quants_b[rv60_chroma_quant_ac[qp]];
1566 
1567  memset(y_coeffs, 0, sizeof(y_coeffs[0])*64);
1568  for (int i = 0; i < 4; i++) {
1569  if ((ccbp >> i) & 1) {
1570  int offset, stride;
1571  if (mode4x4) {
1572  offset = i*16;
1573  stride = 4;
1574  } else {
1575  offset = (i & 1) * 4 + (i & 2) * 2 * 8;
1576  stride = 8;
1577  }
1578  decode_4x4_block(gb, vlc, 1, y_coeffs + offset, stride, q_y);
1579  }
1580  }
1581 
1582  if ((ccbp >> 4) & 1) {
1583  memset(u_coeffs, 0, sizeof(u_coeffs[0])*16);
1584  decode_4x4_block_dc(gb, vlc, 0, u_coeffs, 4, q_c_dc, q_c_ac);
1585  }
1586 
1587  if ((ccbp >> 5) & 1) {
1588  memset(v_coeffs, 0, sizeof(u_coeffs[0])*16);
1589  decode_4x4_block_dc(gb, vlc, 0, v_coeffs, 4, q_c_dc, q_c_ac);
1590  }
1591 }
1592 
1593 static void decode_cu_16x16(GetBitContext * gb, int is_intra, int qp, int sel_qp, int16_t * y_coeffs, int16_t * u_coeffs, int16_t * v_coeffs, int ccbp)
1594 {
1595  int cb_set = get_c4x4_set(sel_qp, is_intra);
1596  const CoeffVLCs * vlc = is_intra ? &intra_coeff_vlc[cb_set] : &inter_coeff_vlc[cb_set];
1597  int q_y = rv60_quants_b[qp];
1598  int q_c_dc = rv60_quants_b[rv60_chroma_quant_dc[qp]];
1599  int q_c_ac = rv60_quants_b[rv60_chroma_quant_ac[qp]];
1600 
1601  memset(y_coeffs, 0, sizeof(y_coeffs[0])*256);
1602  for (int i = 0; i < 16; i++)
1603  if ((ccbp >> i) & 1) {
1604  int off = (i & 3) * 4 + (i >> 2) * 4 * 16;
1605  decode_4x4_block(gb, vlc, 1, y_coeffs + off, 16, q_y);
1606  }
1607 
1608  memset(u_coeffs, 0, sizeof(u_coeffs[0])*64);
1609  for (int i = 0; i < 4; i++)
1610  if ((ccbp >> (16 + i)) & 1) {
1611  int off = (i & 1) * 4 + (i & 2) * 2 * 8;
1612  if (!i)
1613  decode_4x4_block_dc(gb, vlc, 0, u_coeffs + off, 8, q_c_dc, q_c_ac);
1614  else
1615  decode_4x4_block(gb, vlc, 0, u_coeffs + off, 8, q_c_ac);
1616  }
1617 
1618  memset(v_coeffs, 0, sizeof(v_coeffs[0])*64);
1619  for (int i = 0; i < 4; i++)
1620  if ((ccbp >> (20 + i)) & 1) {
1621  int off = (i & 1) * 4 + (i & 2) * 2 * 8;
1622  if (!i)
1623  decode_4x4_block_dc(gb, vlc, 0, v_coeffs + off, 8, q_c_dc, q_c_ac);
1624  else
1625  decode_4x4_block(gb, vlc, 0, v_coeffs + off, 8, q_c_ac);
1626  }
1627 }
1628 
1629 static int decode_super_cbp(GetBitContext * gb, const VLCElem * vlc[4])
1630 {
1631  int sym0 = get_vlc2(gb, vlc[0], 9, 2);
1632  int sym1 = get_vlc2(gb, vlc[1], 9, 2);
1633  int sym2 = get_vlc2(gb, vlc[2], 9, 2);
1634  int sym3 = get_vlc2(gb, vlc[3], 9, 2);
1635  return 0
1636  + ((sym0 & 0x03) << 0)
1637  + ((sym0 & 0x0C) << 2)
1638  + ((sym0 & 0x10) << 12)
1639  + ((sym0 & 0x20) << 15)
1640  + ((sym1 & 0x03) << 2)
1641  + ((sym1 & 0x0C) << 4)
1642  + ((sym1 & 0x10) << 13)
1643  + ((sym1 & 0x20) << 16)
1644  + ((sym2 & 0x03) << 8)
1645  + ((sym2 & 0x0C) << 10)
1646  + ((sym2 & 0x10) << 14)
1647  + ((sym2 & 0x20) << 17)
1648  + ((sym3 & 0x03) << 10)
1649  + ((sym3 & 0x0C) << 12)
1650  + ((sym3 & 0x10) << 15)
1651  + ((sym3 & 0x20) << 18);
1652 }
1653 
1654 static int decode_cbp16(GetBitContext * gb, int subset, int qp)
1655 {
1656  int cb_set = rv60_qp_to_idx[qp];
1657  return decode_super_cbp(gb, cbp16_vlc[cb_set][subset]);
1658 }
1659 
1660 static int decode_cu_r(RV60Context * s, AVFrame * frame, ThreadContext * thread, GetBitContext * gb, int xpos, int ypos, int log_size, int qp, int sel_qp)
1661 {
1662  int size = 1 << log_size;
1663  int split, ret, ttype, count, is_intra, cu_pos, subset, cbp8, imode, split_i4x4, num_clusters, cl_cbp, super_cbp, mv_x, mv_y, mv_pos;
1664  int16_t y_coeffs[16*16], u_coeffs[8*8], v_coeffs[8*8];
1665  CUContext cu;
1666 
1667  if (xpos >= s->awidth || ypos >= s->aheight)
1668  return 0;
1669 
1670  split = xpos + size > s->awidth || ypos + size > s->aheight || (size > 8 && get_bits1(gb));
1671  thread->cu_split[thread->cu_split_pos++] = split;
1672  if (split) {
1673  size >>= 1;
1674  log_size -= 1;
1675  if ((ret = decode_cu_r(s, frame, thread, gb, xpos, ypos, log_size, qp, sel_qp)) < 0 ||
1676  (ret = decode_cu_r(s, frame, thread, gb, xpos + size, ypos, log_size, qp, sel_qp)) < 0 ||
1677  (ret = decode_cu_r(s, frame, thread, gb, xpos, ypos + size, log_size, qp, sel_qp)) < 0 ||
1678  (ret = decode_cu_r(s, frame, thread, gb, xpos + size, ypos + size, log_size, qp, sel_qp)) < 0)
1679  return ret;
1680  return 0;
1681  }
1682 
1683  cu.xpos = xpos;
1684  cu.ypos = ypos;
1685  cu.pu_pos = (xpos >> 3) + (ypos >> 3) * s->pu_stride;
1686  cu.blk_pos = (xpos >> 2) + (ypos >> 2) * s->blk_stride;
1687  cu.cu_type = s->pict_type != AV_PICTURE_TYPE_I ? get_bits(gb, 2) : CU_INTRA;
1688 
1689  switch (cu.cu_type) {
1690  case CU_INTRA:
1691  cu.pu_type = size == 8 && get_bits1(gb) ? PU_QUARTERS : PU_FULL;
1692  if (cu.pu_type == PU_QUARTERS)
1693  for (int i = 0; i < 4; i++)
1694  cu.imode[i] = read_intra_mode(gb, &cu.imode_param[i]);
1695  else if (size <= 32)
1696  cu.imode[0] = read_intra_mode(gb, &cu.imode_param[0]);
1697  else
1699  break;
1700  case CU_INTER_MV:
1701  cu.pu_type = get_bits(gb, size == 8 ? 2 : 3);
1702  count = pu_type_num_parts(cu.pu_type);
1703  for (int i = 0; i < count; i++)
1704  read_mv_info(s, gb, &cu.mv[i], size, cu.pu_type);
1705  break;
1706  default:
1707  cu.pu_type = PU_FULL;
1708  cu.mv[0].mvref = skip_mv_ref[get_unary(gb, 0, 3)];
1709  break;
1710  }
1711 
1712  reconstruct(s, &cu, size);
1713 
1714  split_i4x4 = cu.cu_type == CU_INTRA && size == 8 && cu.pu_type == PU_QUARTERS;
1715 
1716  switch (cu.cu_type) {
1717  case CU_INTRA:
1718  imode = s->blk_info[cu.blk_pos].imode;
1719  if (!split_i4x4) {
1720  int off = ypos * frame->linesize[0] + xpos;
1721  populate_ipred(s, &cu, frame->data[0], frame->linesize[0], 0, 0, size, 1);
1722  if (pred_angle(&cu.ipred, frame->data[0] + off, frame->linesize[0], size, imode, 1) < 0)
1723  return AVERROR_INVALIDDATA;
1724  }
1725  for (int plane = 1; plane < 3; plane++) {
1726  int off = (ypos >> 1) * frame->linesize[plane] + (xpos >> 1);
1727  populate_ipred(s, &cu, frame->data[plane], frame->linesize[plane], 0, 0, size >> 1, 0);
1728  if (pred_angle(&cu.ipred, frame->data[plane] + off, frame->linesize[plane], size >> 1, imode, 0) < 0)
1729  return AVERROR_INVALIDDATA;
1730  }
1731  break;
1732  default:
1733  mv_x = xpos >> 2;
1734  mv_y = ypos >> 2;
1735  mv_pos = mv_y * s->blk_stride + mv_x;
1736  count = pu_type_num_parts(cu.pu_type);
1737  for (int part_no = 0; part_no < count; part_no++) {
1738  MVInfo mv;
1739  Dimensions dim;
1740  int bw, bh, bx, by;
1741 
1742  mv = s->blk_info[mv_pos].mv;
1743  get_mv_dimensions(&dim, cu.pu_type, part_no, size);
1744  bw = dim.w << 2;
1745  bh = dim.h << 2;
1746  bx = mv_x << 2;
1747  by = mv_y << 2;
1748 
1749  if (!(mv.mvref & 2)) {
1750  if (!s->last_frame[LAST_PIC]->data[0]) {
1751  av_log(s->avctx, AV_LOG_ERROR, "missing reference frame\n");
1752  return AVERROR_INVALIDDATA;
1753  }
1754  }
1755  if (mv.mvref & 6) {
1756  if (!s->last_frame[NEXT_PIC]->data[0]) {
1757  av_log(s->avctx, AV_LOG_ERROR, "missing reference frame\n");
1758  return AVERROR_INVALIDDATA;
1759  }
1760  }
1761 
1762  switch (mv.mvref) {
1763  case MVREF_REF0:
1764  mc(s, frame->data, frame->linesize, s->last_frame[LAST_PIC], bx, by, bw, bh, mv.f_mv, 0);
1765  break;
1766  case MVREF_REF1:
1767  mc(s, frame->data, frame->linesize, s->last_frame[NEXT_PIC], bx, by, bw, bh, mv.f_mv, 0);
1768  break;
1769  case MVREF_BREF:
1770  mc(s, frame->data, frame->linesize, s->last_frame[NEXT_PIC], bx, by, bw, bh, mv.b_mv, 0);
1771  break;
1772  case MVREF_REF0ANDBREF:
1773  mc(s, frame->data, frame->linesize, s->last_frame[LAST_PIC], bx, by, bw, bh, mv.f_mv, 0);
1774  mc(s, thread->avg_data, thread->avg_linesize, s->last_frame[NEXT_PIC], bx, by, bw, bh, mv.b_mv, 1);
1775  avg(frame, thread->avg_data, thread->avg_linesize, bx, by, bw, bh);
1776  break;
1777  default:
1778  av_assert0(0); //should never reach here
1779  }
1780  get_next_mv(s, &dim, cu.pu_type, part_no, &mv_pos, &mv_x, &mv_y);
1781  }
1782  break;
1783  }
1784 
1785  if (cu.cu_type == CU_SKIP)
1786  ttype = TRANSFORM_NONE;
1787  else if (size >= 32)
1788  ttype = TRANSFORM_16X16;
1789  else if (size == 16)
1790  ttype = cu.cu_type == CU_INTRA || cu.pu_type == PU_FULL ? TRANSFORM_16X16 : TRANSFORM_4X4;
1791  else
1792  ttype = cu.pu_type == PU_FULL ? TRANSFORM_8X8 : TRANSFORM_4X4;
1793 
1794  is_intra = cu.cu_type == CU_INTRA;
1795  if (qp >= 32)
1796  return AVERROR_INVALIDDATA;
1797  cu_pos = ((xpos & 63) >> 3) + ((ypos & 63) >> 3) * 8;
1798 
1799  switch (ttype) {
1800  case TRANSFORM_4X4:
1801  subset = is_intra ? 0 : 2;
1802  if (size == 16) {
1803  int cbp16 = get_bits1(gb) ? decode_cbp16(gb, subset, sel_qp) : 0;
1804  if (cbp16) {
1805  decode_cu_4x4in16x16(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, cbp16);
1806  for (int y = 0; y < 4; y++)
1807  for (int x = 0; x < 4; x++) {
1808  int i = y*4 + x;
1809  if ((cbp16 >> i) & 1) {
1810  int off = (ypos + y * 4)*frame->linesize[0] + xpos + x * 4;
1811  ff_rv60_idct4x4_add(y_coeffs + i*16, frame->data[0] + off, frame->linesize[0]);
1812  thread->coded_blk[cu_pos + (y/2)*8 + (x/2)] = 1;
1813  }
1814  }
1815  for (int y = 0; y < 2; y++)
1816  for (int x = 0; x < 2; x++) {
1817  int i = y * 2 + x;
1818  int xoff = (xpos >> 1) + x * 4;
1819  int yoff = (ypos >> 1) + y * 4;
1820  if ((cbp16 >> (16 + i)) & 1) {
1821  int off = yoff * frame->linesize[1] + xoff;
1822  ff_rv60_idct4x4_add(u_coeffs + i * 16, frame->data[1] + off, frame->linesize[1]);
1823  thread->coded_blk[cu_pos + y*8 + x] = 1;
1824  }
1825  if ((cbp16 >> (20 + i)) & 1) {
1826  int off = yoff * frame->linesize[2] + xoff;
1827  ff_rv60_idct4x4_add(v_coeffs + i * 16, frame->data[2] + off, frame->linesize[2]);
1828  thread->coded_blk[cu_pos + y*8 + x] = 1;
1829  }
1830  }
1831  }
1832  } else {
1833  cbp8 = decode_cbp8(gb, subset, sel_qp);
1834  if (cbp8) {
1835  thread->coded_blk[cu_pos] = 1;
1836  decode_cu_8x8(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, cbp8, 1);
1837  }
1838  for (int i = 0; i < 4; i++) {
1839  int xoff = (i & 1) << 2;
1840  int yoff = (i & 2) << 1;
1841  if (split_i4x4) {
1842  int off = (ypos + yoff) * frame->linesize[0] + xpos + xoff;
1843  int imode = s->blk_info[cu.blk_pos + (i >> 1) * s->blk_stride + (i & 1)].imode;
1844  populate_ipred(s, &cu, frame->data[0], frame->linesize[0], xoff, yoff, 4, 1);
1845  if (pred_angle(&cu.ipred, frame->data[0] + off, frame->linesize[0], 4, imode, 1) < 0)
1846  return AVERROR_INVALIDDATA;
1847  }
1848  if ((cbp8 >> i) & 1) {
1849  int off = (ypos + yoff) * frame->linesize[0] + xpos + xoff;
1850  ff_rv60_idct4x4_add(y_coeffs + i * 16, frame->data[0] + off, frame->linesize[0]);
1851  }
1852  }
1853  if ((cbp8 >> 4) & 1) {
1854  int off = (ypos >> 1) * frame->linesize[1] + (xpos >> 1);
1855  ff_rv60_idct4x4_add(u_coeffs, frame->data[1] + off, frame->linesize[1]);
1856  }
1857  if ((cbp8 >> 5) & 1) {
1858  int off = (ypos >> 1) * frame->linesize[2] + (xpos >> 1);
1859  ff_rv60_idct4x4_add(v_coeffs, frame->data[2] + off, frame->linesize[2]);
1860  }
1861  }
1862  break;
1863  case TRANSFORM_8X8:
1864  subset = is_intra ? 1 : 3;
1865  cbp8 = decode_cbp8(gb, subset, sel_qp);
1866  if (cbp8) {
1867  thread->coded_blk[cu_pos] = 1;
1868  decode_cu_8x8(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, cbp8, 0);
1869  if (cbp8 & 0xF) {
1870  int off = ypos * frame->linesize[0] + xpos;
1871  ff_rv60_idct8x8_add(y_coeffs, frame->data[0] + off, frame->linesize[0]);
1872  }
1873  if ((cbp8 >> 4) & 1) {
1874  int off = (ypos >> 1) * frame->linesize[1] + (xpos >> 1);
1875  ff_rv60_idct4x4_add(u_coeffs, frame->data[1] + off, frame->linesize[1]);
1876  }
1877  if ((cbp8 >> 5) & 1) {
1878  int off = (ypos >> 1) * frame->linesize[2] + (xpos >> 1);
1879  ff_rv60_idct4x4_add(v_coeffs, frame->data[2] + off, frame->linesize[2]);
1880  }
1881  }
1882  break;
1883  case TRANSFORM_16X16:
1884  subset = is_intra ? 1 : 3;
1885  num_clusters = size >> 4;
1886  cl_cbp = get_bits(gb, num_clusters * num_clusters);
1887  for (int y = 0; y < num_clusters; y++) {
1888  for (int x = 0; x < num_clusters; x++) {
1889  if (!((cl_cbp >> (y*num_clusters + x)) & 1))
1890  continue;
1891  thread->coded_blk[cu_pos + y*2*8 + x*2 + 0] = 1;
1892  thread->coded_blk[cu_pos + y*2*8 + x*2 + 1] = 1;
1893  thread->coded_blk[cu_pos + y*2*8 + x*2 + 8] = 1;
1894  thread->coded_blk[cu_pos + y*2*8 + x*2 + 9] = 1;
1895  super_cbp = decode_cbp16(gb, subset, sel_qp);
1896  if (super_cbp) {
1897  decode_cu_16x16(gb, is_intra, qp, sel_qp, y_coeffs, u_coeffs, v_coeffs, super_cbp);
1898  if (super_cbp & 0xFFFF) {
1899  int off = (ypos + y * 16) * frame->linesize[0] + xpos + x * 16;
1900  ff_rv60_idct16x16_add(y_coeffs, frame->data[0] + off, frame->linesize[0]);
1901  }
1902  if ((super_cbp >> 16) & 0xF) {
1903  int off = ((ypos >> 1) + y * 8) * frame->linesize[1] + (xpos >> 1) + x * 8;
1904  ff_rv60_idct8x8_add(u_coeffs, frame->data[1] + off, frame->linesize[1]);
1905  }
1906  if ((super_cbp >> 20) & 0xF) {
1907  int off = ((ypos >> 1) + y * 8) * frame->linesize[2] + (xpos >> 1) + x * 8;
1908  ff_rv60_idct8x8_add(v_coeffs, frame->data[2] + off, frame->linesize[2]);
1909  }
1910  }
1911  }
1912  }
1913  break;
1914  }
1915 
1916  return 0;
1917 }
1918 
1919 static int deblock_get_pos(RV60Context * s, int xpos, int ypos)
1920 {
1921  return (ypos >> 2) * s->dblk_stride + (xpos >> 2);
1922 }
1923 
1924 static void deblock_set_strength(RV60Context * s, int xpos, int ypos, int size, int q, int strength)
1925 {
1926  int pos = deblock_get_pos(s, xpos, ypos);
1927  int dsize = size >> 2;
1928  int dval = (q << 2) + strength;
1929 
1930  for (int x = 0; x < dsize; x++) {
1931  s->top_str[pos + x] = dval;
1932  s->top_str[pos + (dsize - 1)*s->dblk_stride + x] = dval;
1933  }
1934 
1935  for (int y = 0; y < dsize; y++) {
1936  s->left_str[pos + y*s->dblk_stride] = dval;
1937  s->left_str[pos + y*s->dblk_stride + dsize - 1] = dval;
1938  }
1939 }
1940 
1941 static int deblock_get_top_strength(const RV60Context * s, int pos)
1942 {
1943  return s->top_str[pos] & 3;
1944 }
1945 
1946 static int deblock_get_left_strength(const RV60Context * s, int pos)
1947 {
1948  return s->left_str[pos] & 3;
1949 }
1950 
1951 static void deblock_set_top_strength(RV60Context * s, int pos, int strength)
1952 {
1953  s->top_str[pos] |= strength;
1954 }
1955 
1956 static void deblock_set_left_strength(RV60Context * s, int pos, int strength)
1957 {
1958  s->left_str[pos] |= strength;
1959 }
1960 
1961 static void derive_deblock_strength(RV60Context * s, int xpos, int ypos, int size)
1962 {
1963  int blk_pos = (ypos >> 2) * s->blk_stride + (xpos >> 2);
1964  int dblk_pos = deblock_get_pos(s, xpos, ypos);
1965  if (ypos > 0)
1966  for (int i = 0; i < size; i++)
1967  if (!deblock_get_top_strength(s, dblk_pos - s->dblk_stride + i) && mvinfo_is_deblock_cand(&s->blk_info[blk_pos + i].mv, &s->blk_info[blk_pos - s->blk_stride + i].mv))
1968  deblock_set_top_strength(s, dblk_pos + i, 1);
1969  if (xpos > 0)
1970  for (int i = 0; i < size; i++)
1971  if (!deblock_get_left_strength(s, dblk_pos + i *s->dblk_stride - 1) && mvinfo_is_deblock_cand(&s->blk_info[blk_pos + i*s->blk_stride].mv, &s->blk_info[blk_pos + i*s->blk_stride - 1].mv))
1972  deblock_set_left_strength(s, dblk_pos + i *s->dblk_stride, 1);
1973 }
1974 
1975 #define STRENGTH(el, lim) (FFABS(el) < (lim) ? 3 : 1)
1976 #define CLIP_SYMM(a, b) av_clip(a, -(b), b)
1977 
1978 static void filter_luma_edge(uint8_t * dst, int step, int stride, int mode1, int mode2, int lim1, int lim2)
1979 {
1980  int16_t diff_q1q0[4];
1981  int16_t diff_p1p0[4];
1982  int str_p, str_q, msum, maxprod, weak;
1983 
1984  for (int i = 0; i < 4; i++) {
1985  diff_q1q0[i] = dst[i * stride - 2*step] - dst[i*stride - step];
1986  diff_p1p0[i] = dst[i * stride + step] - dst[i*stride];
1987  }
1988 
1989  str_p = STRENGTH(diff_q1q0[0] + diff_q1q0[1] + diff_q1q0[2] + diff_q1q0[3], lim2);
1990  str_q = STRENGTH(diff_p1p0[0] + diff_p1p0[1] + diff_p1p0[2] + diff_p1p0[3], lim2);
1991 
1992  if (str_p + str_q <= 2)
1993  return;
1994 
1995  msum = (mode1 + mode2 + str_q + str_p) >> 1;
1996  if (str_q == 1 || str_p == 1) {
1997  maxprod = 384;
1998  weak = 1;
1999  } else {
2000  maxprod = 256;
2001  weak = 0;
2002  }
2003 
2004  for (int y = 0; y < 4; y++) {
2005  int diff_p0q0 = dst[0] - dst[-step];
2006  int result = (lim1 * FFABS(diff_p0q0)) & -128;
2007  if (diff_p0q0 && result <= maxprod) {
2008  int diff_q1q2 = dst[-2*step] - dst[-3*step];
2009  int diff_p1p2 = dst[step] - dst[2*step];
2010  int delta;
2011  if (weak) {
2012  delta = CLIP_SYMM((diff_p0q0 + 1) >> 1, msum >> 1);
2013  } else {
2014  int diff_strg = (dst[-2*step] - dst[step] + 4 * diff_p0q0 + 4) >> 3;
2015  delta = CLIP_SYMM(diff_strg, msum);
2016  }
2017  dst[-step] = av_clip_uint8(dst[-step] + delta);
2018  dst[0] = av_clip_uint8(dst[0] - delta);
2019  if (str_p != 1 && FFABS(diff_q1q2) <= (lim2 >> 2)) {
2020  int diff = (diff_q1q0[y] + diff_q1q2 - delta) >> 1;
2021  int delta_q1 = weak ? CLIP_SYMM(diff, mode1 >> 1) : CLIP_SYMM(diff, mode1);
2022  dst[-2 * step] = av_clip_uint8(dst[-2*step] - delta_q1);
2023  }
2024  if (str_q != 1 && FFABS(diff_p1p2) <= (lim2 >> 2)) {
2025  int diff = (diff_p1p0[y] + diff_p1p2 + delta) >> 1;
2026  int delta_p1 = weak ? CLIP_SYMM(diff, mode2 >> 1) : CLIP_SYMM(diff, mode2);
2027  dst[step] = av_clip_uint8(dst[step] - delta_p1);
2028  }
2029  }
2030  dst += stride;
2031  }
2032 }
2033 
2034 static void filter_chroma_edge(uint8_t * dst, int step, int stride, int mode1, int mode2, int lim1, int lim2)
2035 {
2036  int diff_q = 4 * FFABS(dst[-2*step] - dst[-step]);
2037  int diff_p = 4 * FFABS(dst[ step] - dst[0]);
2038  int str_q = STRENGTH(diff_q, lim2);
2039  int str_p = STRENGTH(diff_p, lim2);
2040  int msum, maxprod, weak;
2041 
2042  if (str_p + str_q <= 2)
2043  return;
2044 
2045  msum = (mode1 + mode2 + str_q + str_p) >> 1;
2046  if (str_q == 1 || str_p == 1) {
2047  maxprod = 384;
2048  weak = 1;
2049  } else {
2050  maxprod = 256;
2051  weak = 0;
2052  }
2053 
2054  for (int y = 0; y < 2; y++) {
2055  int diff_pq = dst[0] - dst[-step];
2056  int result = (lim1 * FFABS(diff_pq)) & -128;
2057  if (diff_pq && result <= maxprod) {
2058  int delta;
2059  if (weak) {
2060  delta = CLIP_SYMM((diff_pq + 1) >> 1, msum >> 1);
2061  } else {
2062  int diff_strg = (dst[-2*step] - dst[step] + 4 * diff_pq + 4) >> 3;
2063  delta = CLIP_SYMM(diff_strg, msum);
2064  }
2065  dst[-step] = av_clip_uint8(dst[-step] + delta);
2066  dst[ 0 ] = av_clip_uint8(dst[ 0 ] - delta);
2067  }
2068  dst += stride;
2069  }
2070 }
2071 
2072 static void deblock_edge_ver(AVFrame * frame, int xpos, int ypos, int dblk_l, int dblk_r, int deblock_chroma)
2073 {
2074  int qp_l = dblk_l >> 2;
2075  int str_l = dblk_l & 3;
2076  int qp_r = dblk_r >> 2;
2077  int str_r = dblk_r & 3;
2078  const uint8_t * dl_l = rv60_deblock_limits[qp_l];
2079  const uint8_t * dl_r = rv60_deblock_limits[qp_r];
2080  int mode_l = str_l ? dl_l[str_l - 1] : 0;
2081  int mode_r = str_r ? dl_r[str_r - 1] : 0;
2082  int lim1 = dl_r[2];
2083  int lim2 = dl_r[3] * 4;
2084 
2085  filter_luma_edge(frame->data[0] + ypos * frame->linesize[0] + xpos, 1, frame->linesize[0], mode_l, mode_r, lim1, lim2);
2086  if ((str_l | str_r) >= 2 && deblock_chroma)
2087  for (int plane = 1; plane < 3; plane++)
2088  filter_chroma_edge(frame->data[plane] + (ypos >> 1) * frame->linesize[plane] + (xpos >> 1), 1, frame->linesize[plane], mode_l, mode_r, lim1, lim2);
2089 }
2090 
2091 static void deblock_edge_hor(AVFrame * frame, int xpos, int ypos, int dblk_t, int dblk_d, int deblock_chroma)
2092 {
2093  int qp_t = dblk_t >> 2;
2094  int str_t = dblk_t & 3;
2095  int qp_d = dblk_d >> 2;
2096  int str_d = dblk_d & 3;
2097  const uint8_t * dl_t = rv60_deblock_limits[qp_t];
2098  const uint8_t * dl_d = rv60_deblock_limits[qp_d];
2099  int mode_t = str_t ? dl_t[str_t - 1] : 0;
2100  int mode_d = str_d ? dl_d[str_d - 1] : 0;
2101  int lim1 = dl_d[2];
2102  int lim2 = dl_d[3] * 4;
2103 
2104  filter_luma_edge(frame->data[0] + ypos * frame->linesize[0] + xpos, frame->linesize[0], 1, mode_t, mode_d, lim1, lim2);
2105  if ((str_t | str_d) >= 2 && deblock_chroma)
2106  for (int plane = 1; plane < 3; plane++)
2107  filter_chroma_edge(frame->data[plane] + (ypos >> 1) * frame->linesize[plane] + (xpos >> 1), frame->linesize[plane], 1, mode_t, mode_d, lim1, lim2);
2108 }
2109 
2110 static void deblock8x8(const RV60Context * s, AVFrame * frame, int xpos, int ypos, int dblkpos)
2111 {
2112  if (xpos > 0) {
2113  if (ypos > 0) {
2114  int str_l = s->left_str[dblkpos - s->dblk_stride - 1];
2115  int str_r = s->left_str[dblkpos - s->dblk_stride];
2116  if ((str_l | str_r) & 3)
2117  deblock_edge_ver(frame, xpos, ypos - 4, str_l, str_r, s->deblock_chroma);
2118  }
2119  {
2120  int str_l = s->left_str[dblkpos - 1];
2121  int str_r = s->left_str[dblkpos];
2122  if ((str_l | str_r) & 3)
2123  deblock_edge_ver(frame, xpos, ypos, str_l, str_r, s->deblock_chroma);
2124  }
2125  if (ypos + 8 >= s->aheight) {
2126  int str_l = s->left_str[dblkpos + s->dblk_stride - 1];
2127  int str_r = s->left_str[dblkpos + s->dblk_stride];
2128  if ((str_l | str_r) & 3)
2129  deblock_edge_ver(frame, xpos, ypos + 4, str_l, str_r, s->deblock_chroma);
2130  }
2131  }
2132  if (ypos > 0) {
2133  if (xpos > 0) {
2134  int str_t = s->top_str[dblkpos - s->dblk_stride - 1];
2135  int str_d = s->top_str[dblkpos - 1];
2136  if ((str_t | str_d) & 3)
2137  deblock_edge_hor(frame, xpos - 4, ypos, str_t, str_d, s->deblock_chroma);
2138  }
2139  {
2140  int str_t = s->top_str[dblkpos - s->dblk_stride];
2141  int str_d = s->top_str[dblkpos];
2142  if ((str_t | str_d) & 3)
2143  deblock_edge_hor(frame, xpos, ypos, str_t, str_d, s->deblock_chroma);
2144  }
2145  if (xpos + 8 >= s->awidth) {
2146  int str_t = s->top_str[dblkpos - s->dblk_stride + 1];
2147  int str_d = s->top_str[dblkpos + 1];
2148  if ((str_t | str_d) & 3)
2149  deblock_edge_hor(frame, xpos + 4, ypos, str_t, str_d, s->deblock_chroma);
2150  }
2151  }
2152 }
2153 
2154 static void deblock(const RV60Context * s, AVFrame * frame, int xpos, int ypos, int size, int dpos)
2155 {
2156  for (int x = 0; x < size >> 3; x++)
2157  deblock8x8(s, frame, xpos + x * 8, ypos, dpos + x * 2);
2158 
2159  for (int y = 1; y < size >> 3; y++)
2160  deblock8x8(s, frame, xpos, ypos + y * 8, dpos + y * 2 * s->dblk_stride);
2161 }
2162 
2163 static void deblock_cu_r(RV60Context * s, AVFrame * frame, ThreadContext * thread, int xpos, int ypos, int log_size, int qp)
2164 {
2165  int pu_pos, tsize, ntiles;
2166  enum CUType cu_type;
2167 
2168  if (xpos >= s->awidth || ypos >= s->aheight)
2169  return;
2170 
2171  if (thread->cu_split[thread->cu_split_pos++]) {
2172  int hsize = 1 << (log_size - 1);
2173  log_size--;
2174  deblock_cu_r(s, frame, thread, xpos, ypos, log_size, qp);
2175  deblock_cu_r(s, frame, thread, xpos + hsize, ypos, log_size, qp);
2176  deblock_cu_r(s, frame, thread, xpos, ypos + hsize, log_size, qp);
2177  deblock_cu_r(s, frame, thread, xpos + hsize, ypos + hsize, log_size, qp);
2178  return;
2179  }
2180 
2181  pu_pos = (ypos >> 3) * s->pu_stride + (xpos >> 3);
2182  cu_type = s->pu_info[pu_pos].cu_type;
2183  switch (log_size) {
2184  case 3: tsize = 3; break;
2185  case 4: tsize = cu_type && s->pu_info[pu_pos].pu_type ? 3 : 4; break;
2186  case 5:
2187  case 6: tsize = 4; break;
2188  }
2189  ntiles = 1 << (log_size - tsize);
2190 
2191  for (int ty = 0; ty < ntiles; ty++)
2192  for (int tx = 0; tx < ntiles; tx++) {
2193  int x = xpos + (tx << tsize);
2194  int y = ypos + (ty << tsize);
2195  int cu_pos = ((y & 63) >> 3) * 8 + ((x & 63) >> 3);
2196 
2197  if (cu_type == CU_INTRA)
2198  deblock_set_strength(s, x, y, 1 << tsize, qp, 2);
2199  else if (cu_type != CU_SKIP && thread->coded_blk[cu_pos])
2200  deblock_set_strength(s, x, y, 1 << tsize, qp, 1);
2201  else {
2202  deblock_set_strength(s, x, y, 1 << tsize, qp, 0);
2203  derive_deblock_strength(s, x, y, 1 << (tsize - 2));
2204  }
2205 
2206  deblock(s, frame, x, y, 1 << tsize, deblock_get_pos(s, x, y));
2207  }
2208 }
2209 
2210 static int read_qp_offset(GetBitContext *gb, int qp_off_type)
2211 {
2212  int val;
2213 
2214  switch (qp_off_type) {
2215  case 0:
2216  return 0;
2217  case 1:
2218  val = read_code012(gb);
2219  return val != 2 ? val : -1;
2220  default:
2221  if (!get_bits1(gb))
2222  return 0;
2223  val = get_bits(gb, 2);
2224  if (!(val & 2))
2225  return val + 1;
2226  else
2227  return -((val & 1) + 1);
2228  }
2229 }
2230 
2231 static int calc_sel_qp(int osvquant, int qp)
2232 {
2233  switch (osvquant) {
2234  case 0: return qp;
2235  case 1: return qp <= 25 ? qp + 5 : qp;
2236  default:
2237  if (qp <= 18)
2238  return qp + 10;
2239  else if (qp <= 25)
2240  return qp + 5;
2241  else
2242  return qp;
2243  }
2244 }
2245 
2246 static int decode_slice(AVCodecContext *avctx, void *tdata, int cu_y, int threadnr)
2247 {
2248  RV60Context *s = avctx->priv_data;
2249  AVFrame * frame = tdata;
2250  ThreadContext thread;
2251  GetBitContext gb;
2252  int qp, sel_qp, ret;
2253 
2254  thread.avg_data[0] = thread.avg_buffer;
2255  thread.avg_data[1] = thread.avg_buffer + 64*64;
2256  thread.avg_data[2] = thread.avg_buffer + 64*64 + 32*32;
2257  thread.avg_linesize[0] = 64;
2258  thread.avg_linesize[1] = 32;
2259  thread.avg_linesize[2] = 32;
2260 
2261  if ((ret = init_get_bits8(&gb, s->slice[cu_y].data, s->slice[cu_y].data_size)) < 0)
2262  return ret;
2263 
2264  for (int cu_x = 0; cu_x < s->cu_width; cu_x++) {
2265  if ((s->avctx->active_thread_type & FF_THREAD_SLICE) && cu_y)
2266  ff_thread_progress_await(&s->progress[cu_y - 1], cu_x + 2);
2267 
2268  qp = s->qp + read_qp_offset(&gb, s->qp_off_type);
2269  if (qp < 0 || qp >= 64) {
2271  break;
2272  }
2273  sel_qp = calc_sel_qp(s->osvquant, qp);
2274 
2275  memset(thread.coded_blk, 0, sizeof(thread.coded_blk));
2276  thread.cu_split_pos = 0;
2277 
2278  if ((ret = decode_cu_r(s, frame, &thread, &gb, cu_x << 6, cu_y << 6, 6, qp, sel_qp)) < 0)
2279  break;
2280 
2281  if (s->deblock) {
2282  thread.cu_split_pos = 0;
2283  deblock_cu_r(s, frame, &thread, cu_x << 6, cu_y << 6, 6, qp);
2284  }
2285 
2286  if (s->avctx->active_thread_type & FF_THREAD_SLICE)
2287  ff_thread_progress_report(&s->progress[cu_y], cu_x + 1);
2288  }
2289 
2290  if (s->avctx->active_thread_type & FF_THREAD_SLICE)
2291  ff_thread_progress_report(&s->progress[cu_y], INT_MAX);
2292 
2293  return ret;
2294 }
2295 
2297  int * got_frame, AVPacket * avpkt)
2298 {
2299  RV60Context *s = avctx->priv_data;
2300  GetBitContext gb;
2301  int ret, header_size, width, height, ofs;
2302 
2303  if (avpkt->size == 0) {
2304  if (s->last_frame[NEXT_PIC]->data[0]) {
2305  av_frame_move_ref(frame, s->last_frame[NEXT_PIC]);
2306  *got_frame = 1;
2307  }
2308  return 0;
2309  }
2310 
2311  if (avpkt->size < 9)
2312  return AVERROR_INVALIDDATA;
2313 
2314  header_size = avpkt->data[0] * 8 + 9;
2315  if (avpkt->size < header_size)
2316  return AVERROR_INVALIDDATA;
2317 
2318  if ((ret = init_get_bits8(&gb, avpkt->data + header_size, avpkt->size - header_size)) < 0)
2319  return ret;
2320 
2321  if ((ret = read_frame_header(s, &gb, &width, &height)) < 0)
2322  return ret;
2323 
2324  if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
2325  avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
2326  avctx->skip_frame >= AVDISCARD_ALL)
2327  return avpkt->size;
2328 
2329  if (s->pict_type != AV_PICTURE_TYPE_B)
2330  FFSWAP(AVFrame *, s->last_frame[NEXT_PIC], s->last_frame[LAST_PIC]);
2331 
2332  if ((s->pict_type == AV_PICTURE_TYPE_P && !s->last_frame[LAST_PIC]->data[0]) ||
2333  (s->pict_type == AV_PICTURE_TYPE_B && (!s->last_frame[LAST_PIC]->data[0] || !s->last_frame[NEXT_PIC]->data[0]))) {
2334  av_log(s->avctx, AV_LOG_ERROR, "missing reference frame\n");
2335  return AVERROR_INVALIDDATA;
2336  }
2337 
2338  s->last_frame[CUR_PIC]->pict_type = s->pict_type;
2339  if (s->pict_type == AV_PICTURE_TYPE_I)
2340  s->last_frame[CUR_PIC]->flags |= AV_FRAME_FLAG_KEY;
2341 
2343  return ret;
2344 
2345  if (!s->last_frame[CUR_PIC]->data[0])
2346  if ((ret = ff_get_buffer(avctx, s->last_frame[CUR_PIC], 0)) < 0)
2347  return ret;
2348 
2349  if ((ret = read_slice_sizes(s, &gb)) < 0)
2350  return ret;
2351 
2352  ofs = get_bits_count(&gb) / 8;
2353 
2354  for (int i = 0; i < s->cu_height; i++) {
2355  if (ofs >= avpkt->size - header_size)
2356  return AVERROR_INVALIDDATA;
2357  s->slice[i].data = avpkt->data + header_size + ofs;
2358  s->slice[i].data_size = FFMIN(s->slice[i].size, avpkt->size - header_size - ofs);
2359  if (s->slice[i].size > INT32_MAX - ofs)
2360  return AVERROR_INVALIDDATA;
2361  ofs += s->slice[i].size;
2362  }
2363 
2364  ret = progress_init(s, s->cu_height);
2365  if (ret < 0)
2366  return ret;
2367 
2368  s->avctx->execute2(s->avctx, decode_slice, s->last_frame[CUR_PIC], NULL, s->cu_height);
2369 
2370  ret = 0;
2371  if (s->pict_type == AV_PICTURE_TYPE_B)
2372  av_frame_move_ref(frame, s->last_frame[CUR_PIC]);
2373  else if (s->last_frame[LAST_PIC]->data[0])
2374  ret = av_frame_ref(frame, s->last_frame[LAST_PIC]);
2375  if (ret < 0)
2376  return ret;
2377 
2378  if (frame->data[0])
2379  *got_frame = 1;
2380 
2381  if (s->pict_type != AV_PICTURE_TYPE_B) {
2382  av_frame_unref(s->last_frame[NEXT_PIC]);
2383  FFSWAP(AVFrame *, s->last_frame[CUR_PIC], s->last_frame[NEXT_PIC]);
2384  }
2385 
2386  if (s->pict_type != AV_PICTURE_TYPE_B) {
2387  s->ref_pts[0] = s->ref_pts[1];
2388  s->ref_pts[1] = avpkt->pts;
2389 
2390  s->ref_ts[0] = s->ref_ts[1];
2391  s->ref_ts[1] = s->ts;
2392 
2393  if (s->ref_pts[1] > s->ref_pts[0] && s->ref_ts[1] > s->ref_ts[0])
2394  s->ts_scale = (s->ref_pts[1] - s->ref_pts[0]) / (s->ref_ts[1] - s->ref_ts[0]);
2395  } else {
2396  frame->pts = s->ref_pts[0] + (s->ts - s->ref_ts[0]) * s->ts_scale;
2397  }
2398 
2399  return avpkt->size;
2400 }
2401 
2402 static av_cold void rv60_flush(AVCodecContext *avctx)
2403 {
2404  RV60Context *s = avctx->priv_data;
2405 
2406  for (int i = 0; i < 3; i++)
2407  av_frame_unref(s->last_frame[i]);
2408 }
2409 
2411 {
2412  RV60Context *s = avctx->priv_data;
2413 
2414  for (int i = 0; i < 3; i++)
2415  av_frame_free(&s->last_frame[i]);
2416 
2417  av_freep(&s->slice);
2418  av_freep(&s->pu_info);
2419  av_freep(&s->blk_info);
2420  av_freep(&s->top_str);
2421  av_freep(&s->left_str);
2422 
2423  for (int i = 0; i < s->nb_progress; i++)
2424  ff_thread_progress_destroy(&s->progress[i]);
2425  av_freep(&s->progress);
2426 
2427  return 0;
2428 }
2429 
2431  .p.name = "rv60",
2432  CODEC_LONG_NAME("RealVideo 6.0"),
2433  .p.type = AVMEDIA_TYPE_VIDEO,
2434  .p.id = AV_CODEC_ID_RV60,
2435  .priv_data_size = sizeof(RV60Context),
2439  .flush = rv60_flush,
2441  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
2442 };
fill_mv_skip_cand
static void fill_mv_skip_cand(RV60Context *s, const CUContext *cu, unique_list_mvinfo *skip_cand, int size)
Definition: rv60dec.c:878
filter_luma_edge
static void filter_luma_edge(uint8_t *dst, int step, int stride, int mode1, int mode2, int lim1, int lim2)
Definition: rv60dec.c:1978
skip_mv_ref
static const uint8_t skip_mv_ref[4]
Definition: rv60dec.c:77
ThreadContext::coded_blk
uint8_t coded_blk[64]
Definition: rv60dec.c:164
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
decode_2x2_dc
static void decode_2x2_dc(GetBitContext *gb, const CoeffVLCs *vlcs, int16_t *coeffs, int stride, int block2, int dsc, int q_dc, int q_ac)
Definition: rv60dec.c:1447
IntraMode
IntraMode
Definition: rv60dec.c:58
ff_thread_progress_report
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
Definition: threadprogress.c:53
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
CoeffVLCs::l12
const VLCElem * l12[2]
Definition: rv60dec.c:91
IntraPredContext::l
uint8_t l[129]
Definition: rv60dec.c:466
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
pu_is_intra
static int pu_is_intra(const PUInfo *pu)
Definition: rv60dec.c:761
threadprogress.h
PUInfo::pu_type
enum PUType pu_type
Definition: rv60dec.c:189
RV60Context::deblock
int deblock
Definition: rv60dec.c:207
ThreadProgress
ThreadProgress is an API to easily notify other threads about progress of any kind as long as it can ...
Definition: threadprogress.h:43
RV60Context::deblock_chroma
int deblock_chroma
Definition: rv60dec.c:208
deblock_get_top_strength
static int deblock_get_top_strength(const RV60Context *s, int pos)
Definition: rv60dec.c:1941
MVREF_SKIP1
@ MVREF_SKIP1
Definition: rv60dec.c:72
AV_CODEC_ID_RV60
@ AV_CODEC_ID_RV60
Definition: codec_id.h:330
deblock
static void deblock(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int size, int dpos)
Definition: rv60dec.c:2154
CUContext::xpos
int xpos
Definition: rv60dec.c:474
CU_INTRA
@ CU_INTRA
Definition: rv60dec.c:41
RV60Context::osvquant
int osvquant
Definition: rv60dec.c:203
RV60Context::cu_width
int cu_width
Definition: rv60dec.c:211
pred_angle
static int pred_angle(const IntraPredContext *p, uint8_t *dst, int stride, int size, int imode, int filter)
Definition: rv60dec.c:661
IntraPredContext::has_t
int has_t
Definition: rv60dec.c:467
ff_rv60_idct8x8_add
void ff_rv60_idct8x8_add(const int16_t *block, uint8_t *dst, int dst_stride)
Definition: rv60dsp.c:50
read_mv
static void read_mv(GetBitContext *gb, MV *mv)
Definition: rv60dec.c:1195
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:424
decode_cu_16x16
static void decode_cu_16x16(GetBitContext *gb, int is_intra, int qp, int sel_qp, int16_t *y_coeffs, int16_t *u_coeffs, int16_t *v_coeffs, int ccbp)
Definition: rv60dec.c:1593
RV60Context::qp
int qp
Definition: rv60dec.c:202
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
FILTER_BLOCK
#define FILTER_BLOCK(dst, dst_stride, src, src_stride, src_y_ofs, w, h, cond, step)
Definition: rv60dec.c:1260
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:254
deblock_edge_ver
static void deblock_edge_ver(AVFrame *frame, int xpos, int ypos, int dblk_l, int dblk_r, int deblock_chroma)
Definition: rv60dec.c:2072
cbp8_vlc
static const VLCElem * cbp8_vlc[7][4]
Definition: rv60dec.c:86
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
MV::y
int16_t y
Definition: clearvideo.c:49
rv60_init_static_data
static av_cold void rv60_init_static_data(void)
Definition: rv60dec.c:136
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
INTRAMODE_PLANE64
@ INTRAMODE_PLANE64
Definition: rv60dec.c:61
IntraPredContext::has_tr
int has_tr
Definition: rv60dec.c:468
mvinfo_matches_forward
static int mvinfo_matches_forward(const MVInfo *a, const MVInfo *b)
Definition: rv60dec.c:996
RV60Context::dblk_stride
int dblk_stride
Definition: rv60dec.c:222
w
uint8_t w
Definition: llviddspenc.c:38
mc
static void mc(RV60Context *s, uint8_t *frame_data[3], int frame_linesize[3], const AVFrame *ref, int x, int y, int w, int h, MV mv, int avg)
Definition: rv60dec.c:1332
AVPacket::data
uint8_t * data
Definition: packet.h:588
filter_weak
static void filter_weak(uint8_t *dst, const uint8_t *src, int size)
Definition: rv60dec.c:602
rv60_flush
static av_cold void rv60_flush(AVCodecContext *avctx)
Definition: rv60dec.c:2402
b
#define b
Definition: input.c:42
ff_rv60_decoder
const FFCodec ff_rv60_decoder
Definition: rv60dec.c:2430
FFCodec
Definition: codec_internal.h:127
TRANSFORM_8X8
@ TRANSFORM_8X8
Definition: rv60dec.c:82
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
rv60_cbp8_lens
static const uint8_t rv60_cbp8_lens[7][4][64]
Definition: rv60vlcs.h:26
PU_N4VER
@ PU_N4VER
Definition: rv60dec.c:54
update_dimensions_clear_info
static int update_dimensions_clear_info(RV60Context *s, int width, int height)
Definition: rv60dec.c:277
CUContext
Definition: rv60dec.c:473
decode_4x4_block
static void decode_4x4_block(GetBitContext *gb, const CoeffVLCs *vlcs, int is_luma, int16_t *coeffs, int stride, int q_ac)
Definition: rv60dec.c:1507
rv60dsp.h
decode_cu_4x4in16x16
static void decode_cu_4x4in16x16(GetBitContext *gb, int is_intra, int qp, int sel_qp, int16_t *y_coeffs, int16_t *u_coeffs, int16_t *v_coeffs, int cbp)
Definition: rv60dec.c:1529
ipm_compar
static int ipm_compar(const void *a, const void *b)
Definition: rv60dec.c:766
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:91
PU_FULL
@ PU_FULL
Definition: rv60dec.c:48
deblock_get_pos
static int deblock_get_pos(RV60Context *s, int xpos, int ypos)
Definition: rv60dec.c:1919
IntraPredContext::has_l
int has_l
Definition: rv60dec.c:469
CUContext::pu_pos
int pu_pos
Definition: rv60dec.c:476
deblock_get_left_strength
static int deblock_get_left_strength(const RV60Context *s, int pos)
Definition: rv60dec.c:1946
populate_ipred
static void populate_ipred(const RV60Context *s, CUContext *cu, const uint8_t *src, int stride, int xoff, int yoff, int size, int is_luma)
Definition: rv60dec.c:495
ThreadContext::avg_buffer
uint8_t avg_buffer[64 *64+32 *32 *2]
Definition: rv60dec.c:166
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:383
golomb.h
exp golomb vlc stuff
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:136
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:337
Slice::data_size
int data_size
Definition: rv60dec.c:157
IntraPredContext::has_ld
int has_ld
Definition: rv60dec.c:470
MVREF_REF0ANDBREF
@ MVREF_REF0ANDBREF
Definition: rv60dec.c:70
has_left_block
static int has_left_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
Definition: rv60dec.c:439
CU_INTER_MV
@ CU_INTER_MV
Definition: rv60dec.c:42
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
CoeffVLCs::esc
const VLCElem * esc
Definition: rv60dec.c:93
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1662
RV60Context::left_str
uint8_t * left_str
Definition: rv60dec.c:223
RV60Context::qp_off_type
int qp_off_type
Definition: rv60dec.c:206
CoeffVLCs
Definition: rv60dec.c:89
GetBitContext
Definition: get_bits.h:109
deblock_set_top_strength
static void deblock_set_top_strength(RV60Context *s, int pos, int strength)
Definition: rv60dec.c:1951
get_skip_mv_index
static int get_skip_mv_index(enum MVRefEnum mvref)
Definition: rv60dec.c:862
state
static struct @545 state
deblock_edge_hor
static void deblock_edge_hor(AVFrame *frame, int xpos, int ypos, int dblk_t, int dblk_d, int deblock_chroma)
Definition: rv60dec.c:2091
weight
const h264_weight_func weight
Definition: h264dsp_init.c:33
val
static double val(void *priv, double ch)
Definition: aeval.c:77
ff_videodsp_init
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:39
get_mv_dimensions
static void get_mv_dimensions(Dimensions *dim, enum PUType pu_type, int part_no, int size)
Definition: rv60dec.c:905
LAST_PIC
#define LAST_PIC
Definition: rv60dec.c:197
CoeffLens
Definition: rv60vlcs.h:550
pred_plane
static void pred_plane(const IntraPredContext *p, uint8_t *dst, int stride, int size)
Definition: rv60dec.c:539
PU_N2VER
@ PU_N2VER
Definition: rv60dec.c:50
CU_SKIP
@ CU_SKIP
Definition: rv60dec.c:43
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
derive_deblock_strength
static void derive_deblock_strength(RV60Context *s, int xpos, int ypos, int size)
Definition: rv60dec.c:1961
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
CUContext::blk_pos
int blk_pos
Definition: rv60dec.c:477
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:106
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
quant
static int quant(int v, int q)
Definition: rv60dec.c:1425
MVREF_SKIP3
@ MVREF_SKIP3
Definition: rv60dec.c:74
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:642
VLCInitState
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
Definition: vlc.h:220
RV60Context::last_frame
AVFrame * last_frame[3]
Definition: rv60dec.c:199
decode_slice
static int decode_slice(AVCodecContext *avctx, void *tdata, int cu_y, int threadnr)
Definition: rv60dec.c:2246
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:347
s
#define s(width, name)
Definition: cbs_vp9.c:198
PU_QUARTERS
@ PU_QUARTERS
Definition: rv60dec.c:51
rv60_deblock_limits
static const uint8_t rv60_deblock_limits[32][4]
Definition: rv60data.h:107
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
rv60_edge2
static const uint8_t rv60_edge2[4]
Definition: rv60data.h:49
CoeffVLCs::l3
const VLCElem * l3[2]
Definition: rv60dec.c:92
PU_N2HOR
@ PU_N2HOR
Definition: rv60dec.c:49
ThreadContext::cu_split
uint8_t cu_split[1+4+16+64]
Definition: rv60dec.c:162
MK_UNIQUELIST
#define MK_UNIQUELIST(name, type, max_size)
Definition: rv60dec.c:771
Dimensions::w
int w
Definition: rv60dec.c:902
bits
uint8_t bits
Definition: vp3data.h:128
MEDIAN
#define MEDIAN(x)
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
rv60_cbp16_lens
static const uint8_t rv60_cbp16_lens[7][3][4][64]
Definition: rv60vlcs.h:155
MVREF_NONE
@ MVREF_NONE
Definition: rv60dec.c:66
predict_mv
static void predict_mv(const RV60Context *s, MVInfo *dst, int mv_x, int mv_y, int mv_w, const MVInfo *src)
Definition: rv60dec.c:1045
mv_is_forward
static int mv_is_forward(enum MVRefEnum mvref)
Definition: rv60dec.c:986
rv60_ipred_angle
static const uint8_t rv60_ipred_angle[9]
Definition: rv60data.h:30
decode.h
RV60Context::nb_progress
unsigned nb_progress
Definition: rv60dec.c:230
get_bits.h
MV::x
int16_t x
Definition: clearvideo.c:49
Slice
Definition: magicyuv.c:40
mv_is_ref0
static int mv_is_ref0(enum MVRefEnum mvref)
Definition: rv60dec.c:981
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
mv_pred
static void mv_pred(MV *ret, MV a, MV b, MV c)
Definition: rv60dec.c:1027
deblock8x8
static void deblock8x8(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int dblkpos)
Definition: rv60dec.c:2110
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
read_frame_header
static int read_frame_header(RV60Context *s, GetBitContext *gb, int *width, int *height)
Definition: rv60dec.c:347
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
if
if(ret)
Definition: filter_design.txt:179
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
MVREF_REF1
@ MVREF_REF1
Definition: rv60dec.c:68
decode_4x4_block_dc
static void decode_4x4_block_dc(GetBitContext *gb, const CoeffVLCs *vlcs, int is_luma, int16_t *coeffs, int stride, int q_dc, int q_ac)
Definition: rv60dec.c:1485
ipred_init
static void ipred_init(IntraPredContext *i)
Definition: rv60dec.c:488
ff_thread_progress_await
void ff_thread_progress_await(const ThreadProgress *pro_c, int n)
This function is a no-op in no-op mode; otherwise it waits until other threads have reached a certain...
Definition: threadprogress.c:64
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
mvinfo_is_deblock_cand
static int mvinfo_is_deblock_cand(const MVInfo *a, const MVInfo *b)
Definition: rv60dec.c:1006
PUInfo
Definition: rv60dec.c:187
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
decode_cu_r
static int decode_cu_r(RV60Context *s, AVFrame *frame, ThreadContext *thread, GetBitContext *gb, int xpos, int ypos, int log_size, int qp, int sel_qp)
Definition: rv60dec.c:1660
NULL
#define NULL
Definition: coverity.c:32
CUContext::ypos
int ypos
Definition: rv60dec.c:475
PU_N4HOR
@ PU_N4HOR
Definition: rv60dec.c:52
rv60_chroma_quant_ac
static const uint8_t rv60_chroma_quant_ac[32]
Definition: rv60data.h:72
has_ver_split
static int has_ver_split(enum PUType pu_type)
Definition: rv60dec.c:947
RV60Context::pu_info
PUInfo * pu_info
Definition: rv60dec.c:217
table_data
static VLCElem table_data[129148]
Definition: rv60dec.c:100
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:391
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
read_slice_sizes
static int read_slice_sizes(RV60Context *s, GetBitContext *gb)
Definition: rv60dec.c:395
RV60Context::pu_stride
int pu_stride
Definition: rv60dec.c:216
has_hor_split
static int has_hor_split(enum PUType pu_type)
Definition: rv60dec.c:942
decode_2x2
static void decode_2x2(GetBitContext *gb, const CoeffVLCs *vlcs, int16_t *coeffs, int stride, int block2, int dsc, int q_ac)
Definition: rv60dec.c:1466
has_top_block
static int has_top_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
Definition: rv60dec.c:434
rv60_dsc_to_lx
static const uint8_t rv60_dsc_to_lx[][4]
Definition: rv60data.h:77
CUContext::mv
MVInfo mv[4]
Definition: rv60dec.c:483
IntraPredContext::t
uint8_t t[129]
Definition: rv60dec.c:465
cbp16_vlc
static const VLCElem * cbp16_vlc[7][4][4]
Definition: rv60dec.c:87
ff_log2
#define ff_log2
Definition: intmath.h:51
rv60data.h
Slice::data
const uint8_t * data
Definition: rv60dec.c:156
MVInfo
Definition: clearvideo.c:54
TRANSFORM_4X4
@ TRANSFORM_4X4
Definition: rv60dec.c:83
gen_vlc
static const VLCElem * gen_vlc(const uint8_t *bits, int size, VLCInitState *state)
Definition: rv60dec.c:103
TRANSFORM_NONE
@ TRANSFORM_NONE
Definition: rv60dec.c:80
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:651
RV60Context
Definition: rv60dec.c:192
rv60_intra_lens
static const CoeffLens rv60_intra_lens[5]
Definition: rv60vlcs.h:557
luma_mc
static void luma_mc(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h, int cx, int cy)
Definition: rv60dec.c:1267
AVOnce
#define AVOnce
Definition: thread.h:202
ThreadContext::avg_data
uint8_t * avg_data[3]
Definition: rv60dec.c:167
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
RV60Context::vdsp
VideoDSPContext vdsp
Definition: rv60dec.c:194
pred_dc
static void pred_dc(const IntraPredContext *p, uint8_t *dst, int stride, int size, int filter)
Definition: rv60dec.c:570
get_unary
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
BlockInfo
Definition: dvdec.c:56
RV60Context::slice
Slice * slice
Definition: rv60dec.c:214
MVInfo::f_mv
MV f_mv
Definition: rv60dec.c:178
NEXT_PIC
#define NEXT_PIC
Definition: rv60dec.c:198
read_mv_info
static void read_mv_info(RV60Context *s, GetBitContext *gb, MVInfo *mvinfo, int size, enum PUType pu_type)
Definition: rv60dec.c:1201
CUContext::imode_param
int imode_param[4]
Definition: rv60dec.c:482
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:231
PUInfo::cu_type
enum CUType cu_type
Definition: rv60dec.c:188
MAX_VLC_SIZE
#define MAX_VLC_SIZE
Definition: rv60dec.c:99
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1728
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
RV60Context::ref_pts
uint64_t ref_pts[2]
Definition: rv60dec.c:226
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
rv60_avail_mask
static const uint8_t rv60_avail_mask[64]
Definition: rv60data.h:38
AVPacket::size
int size
Definition: packet.h:589
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
rv60_ipred_inv_angle
static const uint16_t rv60_ipred_inv_angle[9]
Definition: rv60data.h:34
height
#define height
Definition: dsp.h:89
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
filter_bilin32
static void filter_bilin32(uint8_t *dst, int v0, int v1, int size)
Definition: rv60dec.c:610
codec_internal.h
build_coeff_vlc
static void build_coeff_vlc(const CoeffLens *lens, CoeffVLCs *vlc, int count, VLCInitState *state)
Definition: rv60dec.c:124
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
rv60_decode_frame
static int rv60_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: rv60dec.c:2296
pu_type_num_parts
static int pu_type_num_parts(enum PUType pu_type)
Definition: rv60dec.c:952
add_if_valid
static void add_if_valid(unique_list_mvinfo *skip_cand, const MVInfo *mvi)
Definition: rv60dec.c:872
MV
Definition: clearvideo.c:48
INTRAMODE_INDEX
@ INTRAMODE_INDEX
Definition: rv60dec.c:59
get_interleaved_se_golomb
static int get_interleaved_se_golomb(GetBitContext *gb)
Definition: golomb.h:301
size
int size
Definition: twinvq_data.h:10344
VLCElem
Definition: vlc.h:32
rv60_inter_lens
static const CoeffLens rv60_inter_lens[7]
Definition: rv60vlcs.h:1290
CU_INTER
@ CU_INTER
Definition: rv60dec.c:44
chroma_mc
static void chroma_mc(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h, int x, int y)
Definition: rv60dec.c:1291
FF_THREAD_SLICE
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:1573
CoeffVLCs::l0
const VLCElem * l0[2]
Definition: rv60dec.c:90
filter_chroma_edge
static void filter_chroma_edge(uint8_t *dst, int step, int stride, int mode1, int mode2, int lim1, int lim2)
Definition: rv60dec.c:2034
RV60Context::cu_height
int cu_height
Definition: rv60dec.c:212
PUType
PUType
Definition: rv60dec.c:47
rv60_decode_end
static av_cold int rv60_decode_end(AVCodecContext *avctx)
Definition: rv60dec.c:2410
AV_PICTURE_TYPE_NONE
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition: avutil.h:277
RV60Context::ts_scale
uint64_t ts_scale
Definition: rv60dec.c:226
ThreadContext::avg_linesize
int avg_linesize[3]
Definition: rv60dec.c:168
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:476
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:89
RV60Context::pict_type
int pict_type
Definition: rv60dec.c:201
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:225
intra_coeff_vlc
static CoeffVLCs intra_coeff_vlc[5]
Definition: rv60dec.c:96
CUContext::imode
enum IntraMode imode[4]
Definition: rv60dec.c:481
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:99
MVREF_REF0
@ MVREF_REF0
Definition: rv60dec.c:67
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
pred_hor_angle
static void pred_hor_angle(uint8_t *dst, int stride, int size, int weight, const uint8_t *src)
Definition: rv60dec.c:620
RV60Context::progress
struct ThreadProgress * progress
Definition: rv60dec.c:229
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:416
deblock_cu_r
static void deblock_cu_r(RV60Context *s, AVFrame *frame, ThreadContext *thread, int xpos, int ypos, int log_size, int qp)
Definition: rv60dec.c:2163
calc_sel_qp
static int calc_sel_qp(int osvquant, int qp)
Definition: rv60dec.c:2231
unary.h
read_intra_mode
static int read_intra_mode(GetBitContext *gb, int *param)
Definition: rv60dec.c:423
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
RV60Context::ref_ts
uint32_t ref_ts[2]
Definition: rv60dec.c:227
decode_super_cbp
static int decode_super_cbp(GetBitContext *gb, const VLCElem *vlc[4])
Definition: rv60dec.c:1629
STRENGTH
#define STRENGTH(el, lim)
Definition: rv60dec.c:1975
rv60_candidate_intra_angles
static const uint8_t rv60_candidate_intra_angles[6]
Definition: rv60data.h:26
PU_N34VER
@ PU_N34VER
Definition: rv60dec.c:55
decode_cbp8
static int decode_cbp8(GetBitContext *gb, int subset, int qp)
Definition: rv60dec.c:1553
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:581
INTRAMODE_MODE
@ INTRAMODE_MODE
Definition: rv60dec.c:62
has_left_down_block
static int has_left_down_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
Definition: rv60dec.c:454
INTRAMODE_DC64
@ INTRAMODE_DC64
Definition: rv60dec.c:60
delta
float delta
Definition: vorbis_enc_data.h:430
ff_thread_progress_init
av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode)
Initialize a ThreadProgress.
Definition: threadprogress.c:33
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:523
MVREF_BREF
@ MVREF_BREF
Definition: rv60dec.c:69
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
has_top_right_block
static int has_top_right_block(const RV60Context *s, int xpos, int ypos, int dx, int dy, int size)
Definition: rv60dec.c:444
avg
static void avg(AVFrame *frame, uint8_t *prev_frame_data[3], int prev_frame_linesize[3], int x, int y, int w, int h)
Definition: rv60dec.c:1407
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
ff_rv60_idct4x4_add
void ff_rv60_idct4x4_add(const int16_t *block, uint8_t *dst, int dst_stride)
Definition: rv60dsp.c:24
pred_ver_angle
static void pred_ver_angle(uint8_t *dst, int stride, int size, int weight, const uint8_t *src)
Definition: rv60dec.c:641
rv60_decode_init
static av_cold int rv60_decode_init(AVCodecContext *avctx)
Definition: rv60dec.c:255
decode_coeff
static int decode_coeff(GetBitContext *gb, const CoeffVLCs *vlcs, int inval, int val)
Definition: rv60dec.c:1430
CUContext::cu_type
enum CUType cu_type
Definition: rv60dec.c:479
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:631
ThreadContext::cu_split_pos
int cu_split_pos
Definition: rv60dec.c:161
mv_is_backward
static int mv_is_backward(enum MVRefEnum mvref)
Definition: rv60dec.c:991
reconstruct_intra
static int reconstruct_intra(const RV60Context *s, const CUContext *cu, int size, int sub)
Definition: rv60dec.c:799
avcodec.h
dim
int dim
Definition: vorbis_enc_data.h:425
BlockInfo::mv
MVInfo mv
Definition: rv60dec.c:184
CUContext::ipred
IntraPredContext ipred
Definition: rv60dec.c:485
mvinfo_matches_backward
static int mvinfo_matches_backward(const MVInfo *a, const MVInfo *b)
Definition: rv60dec.c:1001
ret
ret
Definition: filter_design.txt:187
PU_N34HOR
@ PU_N34HOR
Definition: rv60dec.c:53
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
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
RV60Context::awidth
int awidth
Definition: rv60dec.c:209
MVInfo::mvref
enum MVRefEnum mvref
Definition: rv60dec.c:177
progress_init
static int progress_init(RV60Context *s, unsigned count)
Definition: rv60dec.c:233
MVRefEnum
MVRefEnum
Definition: rv60dec.c:65
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:560
RV60Context::avctx
AVCodecContext * avctx
Definition: rv60dec.c:193
inter_coeff_vlc
static CoeffVLCs inter_coeff_vlc[7]
Definition: rv60dec.c:97
pos
unsigned int pos
Definition: spdifenc.c:414
ff_thread_progress_destroy
av_cold void ff_thread_progress_destroy(ThreadProgress *pro)
Destroy a ThreadProgress.
Definition: threadprogress.c:44
decode_cbp16
static int decode_cbp16(GetBitContext *gb, int subset, int qp)
Definition: rv60dec.c:1654
AVCodecContext
main external API structure.
Definition: avcodec.h:431
ThreadContext
Definition: frame_thread_encoder.c:52
CLIP_SYMM
#define CLIP_SYMM(a, b)
Definition: rv60dec.c:1976
rv60vlcs.h
RV60Context::blk_stride
int blk_stride
Definition: rv60dec.c:219
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:280
CUR_PIC
#define CUR_PIC
Definition: rv60dec.c:196
CUType
CUType
Definition: rv60dec.c:40
RV60Context::ts
int ts
Definition: rv60dec.c:204
get_next_mv
static void get_next_mv(const RV60Context *s, const Dimensions *dim, enum PUType pu_type, int part_no, int *mv_pos, int *mv_x, int *mv_y)
Definition: rv60dec.c:961
RV60Context::aheight
int aheight
Definition: rv60dec.c:210
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
ff_thread_progress_reset
static void ff_thread_progress_reset(ThreadProgress *pro)
Reset the ThreadProgress.progress counter; must only be called if the ThreadProgress is not in use in...
Definition: threadprogress.h:72
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
Slice::sign
int sign
Definition: rv60dec.c:154
MVREF_SKIP2
@ MVREF_SKIP2
Definition: rv60dec.c:73
deblock_set_strength
static void deblock_set_strength(RV60Context *s, int xpos, int ypos, int size, int q, int strength)
Definition: rv60dec.c:1924
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
VideoDSPContext
Definition: videodsp.h:40
TRANSFORM_16X16
@ TRANSFORM_16X16
Definition: rv60dec.c:81
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ff_vlc_init_tables
static const VLCElem * ff_vlc_init_tables(VLCInitState *state, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, int flags)
Definition: vlc.h:254
deblock_set_left_strength
static void deblock_set_left_strength(RV60Context *s, int pos, int strength)
Definition: rv60dec.c:1956
mem.h
rv60_chroma_quant_dc
static const uint8_t rv60_chroma_quant_dc[32]
Definition: rv60data.h:67
read_qp_offset
static int read_qp_offset(GetBitContext *gb, int qp_off_type)
Definition: rv60dec.c:2210
read_code012
static int read_code012(GetBitContext *gb)
Definition: rv60dec.c:340
check_pos
static int check_pos(int x, int y, int cw, int ch, int w, int h, int dx, int dy, int e0, int e1, int e2, int e3)
Definition: rv60dec.c:1325
rv60_qp_to_idx
static const uint8_t rv60_qp_to_idx[64]
Definition: rv60data.h:53
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
VLC_INIT_STATE
#define VLC_INIT_STATE(_table)
Definition: vlc.h:225
get_c4x4_set
static int get_c4x4_set(int qp, int is_intra)
Definition: rv60dec.c:1417
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
MVInfo::b_mv
MV b_mv
Definition: rv60dec.c:179
videodsp.h
avg_plane
static void avg_plane(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
Definition: rv60dec.c:1400
IntraPredContext
Definition: rv60dec.c:464
ff_rv60_idct16x16_add
void ff_rv60_idct16x16_add(const int16_t *block, uint8_t *dst, int dst_stride)
Definition: rv60dsp.c:92
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
RV60Context::top_str
uint8_t * top_str
Definition: rv60dec.c:224
h
h
Definition: vp9dsp_template.c:2070
stride
#define stride
Definition: h264pred_template.c:536
decode_cu_8x8
static void decode_cu_8x8(GetBitContext *gb, int is_intra, int qp, int sel_qp, int16_t *y_coeffs, int16_t *u_coeffs, int16_t *v_coeffs, int ccbp, int mode4x4)
Definition: rv60dec.c:1559
width
#define width
Definition: dsp.h:89
CUContext::pu_type
enum PUType pu_type
Definition: rv60dec.c:480
MVREF_SKIP0
@ MVREF_SKIP0
Definition: rv60dec.c:71
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:228
rv60_edge1
static const uint8_t rv60_edge1[4]
Definition: rv60data.h:45
RV60Context::two_f_refs
int two_f_refs
Definition: rv60dec.c:205
reconstruct
static void reconstruct(RV60Context *s, const CUContext *cu, int size)
Definition: rv60dec.c:1137
src
#define src
Definition: vp8dsp.c:248
Dimensions
Definition: rv60dec.c:901
frame_types
static const int8_t frame_types[4]
Definition: rv60dec.c:38
rv60_quants_b
static const uint16_t rv60_quants_b[32]
Definition: rv60data.h:60
Slice::size
int size
Definition: rv60dec.c:155
RV60Context::blk_info
BlockInfo * blk_info
Definition: rv60dec.c:220