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