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