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