FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vp8.c
Date: 2026-09-26 20:14:34
Exec Total Coverage
Lines: 1377 1610 85.5%
Functions: 79 86 91.9%
Branches: 816 1163 70.2%

Line Branch Exec Source
1 /*
2 * VP7/VP8 compatible video decoder
3 *
4 * Copyright (C) 2010 David Conrad
5 * Copyright (C) 2010 Ronald S. Bultje
6 * Copyright (C) 2010 Fiona Glaser
7 * Copyright (C) 2012 Daniel Kang
8 * Copyright (C) 2014 Peter Ross
9 *
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include "config_components.h"
28
29 #include "libavutil/attributes.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/mem_internal.h"
33
34 #include "avcodec.h"
35 #include "codec_internal.h"
36 #include "decode.h"
37 #include "hwaccel_internal.h"
38 #include "hwconfig.h"
39 #include "mathops.h"
40 #include "progressframe.h"
41 #include "libavutil/refstruct.h"
42 #include "thread.h"
43 #include "vp8.h"
44 #include "vp89_rac.h"
45 #include "vp8data.h"
46 #include "vpx_rac.h"
47
48 #if ARCH_ARM
49 # include "arm/vp8.h"
50 #endif
51
52 // fixme: add 1 bit to all the calls to this?
53 6678 static int vp8_rac_get_sint(VPXRangeCoder *c, int bits)
54 {
55 int v;
56
57
2/2
✓ Branch 1 taken 5593 times.
✓ Branch 2 taken 1085 times.
6678 if (!vp89_rac_get(c))
58 5593 return 0;
59
60 1085 v = vp89_rac_get_uint(c, bits);
61
62
2/2
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 935 times.
1085 if (vp89_rac_get(c))
63 150 v = -v;
64
65 1085 return v;
66 }
67
68 306 static int vp8_rac_get_nn(VPXRangeCoder *c)
69 {
70 306 int v = vp89_rac_get_uint(c, 7) << 1;
71 306 return v + !v;
72 }
73
74 // DCTextra
75 49481 static int vp8_rac_get_coeff(VPXRangeCoder *c, const uint8_t *prob)
76 {
77 49481 int v = 0;
78
79 do {
80 185407 v = (v<<1) + vpx_rac_get_prob(c, *prob++);
81
2/2
✓ Branch 0 taken 135926 times.
✓ Branch 1 taken 49481 times.
185407 } while (*prob);
82
83 49481 return v;
84 }
85
86 115 static void free_buffers(VP8Context *s)
87 {
88 int i;
89
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 40 times.
115 if (s->thread_data)
90
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 75 times.
675 for (i = 0; i < MAX_THREADS; i++) {
91 #if HAVE_THREADS
92 600 pthread_cond_destroy(&s->thread_data[i].cond);
93 600 pthread_mutex_destroy(&s->thread_data[i].lock);
94 #endif
95 600 av_freep(&s->thread_data[i].filter_strength);
96 }
97 115 av_freep(&s->thread_data);
98 115 av_freep(&s->macroblocks_base);
99 115 av_freep(&s->intra4x4_pred_mode_top);
100 115 av_freep(&s->top_nnz);
101 115 av_freep(&s->top_border);
102
103 115 s->macroblocks = NULL;
104 115 }
105
106 1190 static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref)
107 {
108 1190 int ret = ff_progress_frame_get_buffer(s->avctx, &f->tf,
109 ref ? AV_GET_BUFFER_FLAG_REF : 0);
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (ret < 0)
111 ✗ return ret;
112 1190 f->seg_map = av_refstruct_allocz(s->mb_width * s->mb_height);
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (!f->seg_map) {
114 ✗ ret = AVERROR(ENOMEM);
115 ✗ goto fail;
116 }
117 1190 ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private);
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (ret < 0)
119 ✗ goto fail;
120
121 1190 return 0;
122
123 ✗ fail:
124 ✗ av_refstruct_unref(&f->seg_map);
125 ✗ ff_progress_frame_unref(&f->tf);
126 ✗ return ret;
127 }
128
129 1612 static void vp8_release_frame(VP8Frame *f)
130 {
131 1612 av_refstruct_unref(&f->seg_map);
132 1612 av_refstruct_unref(&f->hwaccel_picture_private);
133 1612 ff_progress_frame_unref(&f->tf);
134 1612 }
135
136 115 static av_cold void vp8_decode_flush_impl(AVCodecContext *avctx, int free_mem)
137 {
138 115 VP8Context *s = avctx->priv_data;
139 int i;
140
141
2/2
✓ Branch 0 taken 575 times.
✓ Branch 1 taken 115 times.
690 for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++)
142 575 vp8_release_frame(&s->frames[i]);
143 115 memset(s->framep, 0, sizeof(s->framep));
144
145
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 if (free_mem)
146 115 free_buffers(s);
147
148
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
115 if (FF_HW_HAS_CB(avctx, flush))
149 ✗ FF_HW_SIMPLE_CALL(avctx, flush);
150 115 }
151
152 ✗ static av_cold void vp8_decode_flush(AVCodecContext *avctx)
153 {
154 ✗ vp8_decode_flush_impl(avctx, 0);
155 ✗ }
156
157 1190 static VP8Frame *vp8_find_free_buffer(VP8Context *s)
158 {
159 1190 VP8Frame *frame = NULL;
160 int i;
161
162 // find a free buffer
163
1/2
✓ Branch 0 taken 2849 times.
✗ Branch 1 not taken.
2849 for (i = 0; i < 5; i++)
164
2/2
✓ Branch 0 taken 2252 times.
✓ Branch 1 taken 597 times.
2849 if (&s->frames[i] != s->framep[VP8_FRAME_CURRENT] &&
165
2/2
✓ Branch 0 taken 2251 times.
✓ Branch 1 taken 1 times.
2252 &s->frames[i] != s->framep[VP8_FRAME_PREVIOUS] &&
166
2/2
✓ Branch 0 taken 1648 times.
✓ Branch 1 taken 603 times.
2251 &s->frames[i] != s->framep[VP8_FRAME_GOLDEN] &&
167
2/2
✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 458 times.
1648 &s->frames[i] != s->framep[VP8_FRAME_ALTREF]) {
168 1190 frame = &s->frames[i];
169 1190 break;
170 }
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (i == 5) {
172 ✗ av_log(s->avctx, AV_LOG_FATAL, "Ran out of free frames!\n");
173 ✗ abort();
174 }
175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (frame->tf.f)
176 ✗ vp8_release_frame(frame);
177
178 1190 return frame;
179 }
180
181 21 static enum AVPixelFormat get_pixel_format(VP8Context *s)
182 {
183 21 enum AVPixelFormat pix_fmts[] = {
184 #if CONFIG_VP8_VAAPI_HWACCEL
185 AV_PIX_FMT_VAAPI,
186 #endif
187 #if CONFIG_VP8_NVDEC_HWACCEL
188 AV_PIX_FMT_CUDA,
189 #endif
190 #if CONFIG_VP8_NVDEC_CUARRAY_HWACCEL
191 AV_PIX_FMT_CUARRAY,
192 #endif
193 AV_PIX_FMT_YUV420P,
194 AV_PIX_FMT_NONE,
195 };
196
197 21 return ff_get_format(s->avctx, pix_fmts);
198 }
199
200 static av_always_inline
201 75 int update_dimensions(VP8Context *s, int width, int height, int is_vp7)
202 {
203 75 AVCodecContext *avctx = s->avctx;
204 75 int i, ret, dim_reset = 0;
205
206
7/8
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 26 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 25 times.
✓ Branch 7 taken 7 times.
75 if (width != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||
207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 height != s->avctx->height) {
208 50 vp8_decode_flush_impl(s->avctx, 1);
209
210 50 ret = ff_set_dimensions(s->avctx, width, height);
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
212 ✗ return ret;
213
214 50 dim_reset = (s->macroblocks_base != NULL);
215 }
216
217
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
75 if ((s->pix_fmt == AV_PIX_FMT_NONE || dim_reset) &&
218
4/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 1 times.
65 !s->actually_webp && !is_vp7) {
219 21 s->pix_fmt = get_pixel_format(s);
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (s->pix_fmt < 0)
221 ✗ return AVERROR(EINVAL);
222 21 avctx->pix_fmt = s->pix_fmt;
223 }
224
225 75 s->mb_width = (s->avctx->coded_width + 15) / 16;
226 75 s->mb_height = (s->avctx->coded_height + 15) / 16;
227
228
3/4
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 74 times.
75 s->mb_layout = is_vp7 || avctx->active_thread_type == FF_THREAD_SLICE &&
229 ✗ avctx->thread_count > 1;
230
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 1 times.
75 if (!s->mb_layout) { // Frame threading and one thread
231 74 s->macroblocks_base = av_mallocz((s->mb_width + s->mb_height * 2 + 1) *
232 sizeof(*s->macroblocks));
233 74 s->intra4x4_pred_mode_top = av_mallocz(s->mb_width * 4);
234 } else // Sliced threading
235 1 s->macroblocks_base = av_mallocz((s->mb_width + 2) * (s->mb_height + 2) *
236 sizeof(*s->macroblocks));
237 75 s->top_nnz = av_mallocz(s->mb_width * sizeof(*s->top_nnz));
238 75 s->top_border = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));
239 75 s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));
240
241
3/6
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✗ Branch 5 not taken.
75 if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
242
4/6
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 74 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
75 !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {
243 ✗ free_buffers(s);
244 ✗ return AVERROR(ENOMEM);
245 }
246
247
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 75 times.
675 for (i = 0; i < MAX_THREADS; i++) {
248 1200 s->thread_data[i].filter_strength =
249 600 av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));
250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 if (!s->thread_data[i].filter_strength) {
251 ✗ free_buffers(s);
252 ✗ return AVERROR(ENOMEM);
253 }
254 #if HAVE_THREADS
255 600 ret = pthread_mutex_init(&s->thread_data[i].lock, NULL);
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 if (ret) {
257 ✗ free_buffers(s);
258 ✗ return AVERROR(ret);
259 }
260 600 ret = pthread_cond_init(&s->thread_data[i].cond, NULL);
261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 if (ret) {
262 ✗ free_buffers(s);
263 ✗ return AVERROR(ret);
264 }
265 #endif
266 }
267
268 75 s->macroblocks = s->macroblocks_base + 1;
269
270 75 return 0;
271 }
272
273 1 static int vp7_update_dimensions(VP8Context *s, int width, int height)
274 {
275 1 return update_dimensions(s, width, height, IS_VP7);
276 }
277
278 74 static int vp8_update_dimensions(VP8Context *s, int width, int height)
279 {
280 74 return update_dimensions(s, width, height, IS_VP8);
281 }
282
283
284 476 static void parse_segment_info(VP8Context *s)
285 {
286 476 VPXRangeCoder *c = &s->c;
287 int i;
288
289 476 s->segmentation.update_map = vp89_rac_get(c);
290 476 s->segmentation.update_feature_data = vp89_rac_get(c);
291
292
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 365 times.
476 if (s->segmentation.update_feature_data) {
293 111 s->segmentation.absolute_vals = vp89_rac_get(c);
294
295
2/2
✓ Branch 0 taken 444 times.
✓ Branch 1 taken 111 times.
555 for (i = 0; i < 4; i++)
296 444 s->segmentation.base_quant[i] = vp8_rac_get_sint(c, 7);
297
298
2/2
✓ Branch 0 taken 444 times.
✓ Branch 1 taken 111 times.
555 for (i = 0; i < 4; i++)
299 444 s->segmentation.filter_level[i] = vp8_rac_get_sint(c, 6);
300 }
301
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 365 times.
476 if (s->segmentation.update_map)
302
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 111 times.
444 for (i = 0; i < 3; i++)
303
2/2
✓ Branch 1 taken 149 times.
✓ Branch 2 taken 184 times.
333 s->prob->segmentid[i] = vp89_rac_get(c) ? vp89_rac_get_uint(c, 8) : 255;
304 476 }
305
306 43 static void update_lf_deltas(VP8Context *s)
307 {
308 43 VPXRangeCoder *c = &s->c;
309 int i;
310
311
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 43 times.
215 for (i = 0; i < 4; i++) {
312
2/2
✓ Branch 1 taken 129 times.
✓ Branch 2 taken 43 times.
172 if (vp89_rac_get(c)) {
313 129 s->lf_delta.ref[i] = vp89_rac_get_uint(c, 6);
314
315
2/2
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 43 times.
129 if (vp89_rac_get(c))
316 86 s->lf_delta.ref[i] = -s->lf_delta.ref[i];
317 }
318 }
319
320
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 43 times.
215 for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) {
321
1/2
✓ Branch 1 taken 172 times.
✗ Branch 2 not taken.
172 if (vp89_rac_get(c)) {
322 172 s->lf_delta.mode[i] = vp89_rac_get_uint(c, 6);
323
324
2/2
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 129 times.
172 if (vp89_rac_get(c))
325 43 s->lf_delta.mode[i] = -s->lf_delta.mode[i];
326 }
327 }
328 43 }
329
330 1158 static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
331 {
332 1158 const uint8_t *sizes = buf;
333 int i;
334 int ret;
335
336 1158 s->num_coeff_partitions = 1 << vp89_rac_get_uint(&s->c, 2);
337
338 1158 buf += 3 * (s->num_coeff_partitions - 1);
339 1158 buf_size -= 3 * (s->num_coeff_partitions - 1);
340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1158 times.
1158 if (buf_size < 0)
341 ✗ return -1;
342
343
2/2
✓ Branch 0 taken 339 times.
✓ Branch 1 taken 1158 times.
1497 for (i = 0; i < s->num_coeff_partitions - 1; i++) {
344 339 int size = AV_RL24(sizes + 3 * i);
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if (buf_size - size < 0)
346 ✗ return -1;
347 339 s->coeff_partition_size[i] = size;
348
349 339 ret = ff_vpx_init_range_decoder(&s->coeff_partition[i], buf, size);
350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if (ret < 0)
351 ✗ return ret;
352 339 buf += size;
353 339 buf_size -= size;
354 }
355
356 1158 s->coeff_partition_size[i] = buf_size;
357
358 1158 return ff_vpx_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
359 }
360
361 32 static void vp7_get_quants(VP8Context *s)
362 {
363 32 VPXRangeCoder *c = &s->c;
364
365 32 int yac_qi = vp89_rac_get_uint(c, 7);
366
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 int ydc_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
367
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 int y2dc_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
368
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 int y2ac_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
369
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 int uvdc_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
370
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 int uvac_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
371
372 32 s->qmat[0].luma_qmul[0] = vp7_ydc_qlookup[ydc_qi];
373 32 s->qmat[0].luma_qmul[1] = vp7_yac_qlookup[yac_qi];
374 32 s->qmat[0].luma_dc_qmul[0] = vp7_y2dc_qlookup[y2dc_qi];
375 32 s->qmat[0].luma_dc_qmul[1] = vp7_y2ac_qlookup[y2ac_qi];
376 32 s->qmat[0].chroma_qmul[0] = FFMIN(vp7_ydc_qlookup[uvdc_qi], 132);
377 32 s->qmat[0].chroma_qmul[1] = vp7_yac_qlookup[uvac_qi];
378 32 }
379
380 1158 static void vp8_get_quants(VP8Context *s)
381 {
382 1158 VPXRangeCoder *c = &s->c;
383 int i, base_qi;
384
385 1158 s->quant.yac_qi = vp89_rac_get_uint(c, 7);
386 1158 s->quant.ydc_delta = vp8_rac_get_sint(c, 4);
387 1158 s->quant.y2dc_delta = vp8_rac_get_sint(c, 4);
388 1158 s->quant.y2ac_delta = vp8_rac_get_sint(c, 4);
389 1158 s->quant.uvdc_delta = vp8_rac_get_sint(c, 4);
390 1158 s->quant.uvac_delta = vp8_rac_get_sint(c, 4);
391
392
2/2
✓ Branch 0 taken 4632 times.
✓ Branch 1 taken 1158 times.
5790 for (i = 0; i < 4; i++) {
393
2/2
✓ Branch 0 taken 1904 times.
✓ Branch 1 taken 2728 times.
4632 if (s->segmentation.enabled) {
394 1904 base_qi = s->segmentation.base_quant[i];
395
2/2
✓ Branch 0 taken 1608 times.
✓ Branch 1 taken 296 times.
1904 if (!s->segmentation.absolute_vals)
396 1608 base_qi += s->quant.yac_qi;
397 } else
398 2728 base_qi = s->quant.yac_qi;
399
400 4632 s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + s->quant.ydc_delta, 7)];
401 4632 s->qmat[i].luma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi, 7)];
402 4632 s->qmat[i].luma_dc_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + s->quant.y2dc_delta, 7)] * 2;
403 /* 101581>>16 is equivalent to 155/100 */
404 4632 s->qmat[i].luma_dc_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + s->quant.y2ac_delta, 7)] * 101581 >> 16;
405 4632 s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + s->quant.uvdc_delta, 7)];
406 4632 s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + s->quant.uvac_delta, 7)];
407
408 4632 s->qmat[i].luma_dc_qmul[1] = FFMAX(s->qmat[i].luma_dc_qmul[1], 8);
409 4632 s->qmat[i].chroma_qmul[0] = FFMIN(s->qmat[i].chroma_qmul[0], 132);
410 }
411 1158 }
412
413 /**
414 * Determine which buffers golden and altref should be updated with after this frame.
415 * The spec isn't clear here, so I'm going by my understanding of what libvpx does
416 *
417 * Intra frames update all 3 references
418 * Inter frames update VP8_FRAME_PREVIOUS if the update_last flag is set
419 * If the update (golden|altref) flag is set, it's updated with the current frame
420 * if update_last is set, and VP8_FRAME_PREVIOUS otherwise.
421 * If the flag is not set, the number read means:
422 * 0: no update
423 * 1: VP8_FRAME_PREVIOUS
424 * 2: update golden with altref, or update altref with golden
425 */
426 2132 static VP8FrameType ref_to_update(VP8Context *s, int update, VP8FrameType ref)
427 {
428 2132 VPXRangeCoder *c = &s->c;
429
430
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 2042 times.
2132 if (update)
431 90 return VP8_FRAME_CURRENT;
432
433
3/3
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 1927 times.
2042 switch (vp89_rac_get_uint(c, 2)) {
434 31 case 1:
435 31 return VP8_FRAME_PREVIOUS;
436 84 case 2:
437
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 81 times.
84 return (ref == VP8_FRAME_GOLDEN) ? VP8_FRAME_ALTREF : VP8_FRAME_GOLDEN;
438 }
439 1927 return VP8_FRAME_NONE;
440 }
441
442 93 static void vp78_reset_probability_tables(VP8Context *s)
443 {
444 int i, j;
445
2/2
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 93 times.
465 for (i = 0; i < 4; i++)
446
2/2
✓ Branch 0 taken 5952 times.
✓ Branch 1 taken 372 times.
6324 for (j = 0; j < 16; j++)
447 5952 memcpy(s->prob->token[i][j], vp8_token_default_probs[i][vp8_coeff_band[j]],
448 sizeof(s->prob->token[i][j]));
449 93 }
450
451 1190 static void vp78_update_probability_tables(VP8Context *s)
452 {
453 1190 VPXRangeCoder *c = &s->c;
454 int i, j, k, l, m;
455
456
2/2
✓ Branch 0 taken 4760 times.
✓ Branch 1 taken 1190 times.
5950 for (i = 0; i < 4; i++)
457
2/2
✓ Branch 0 taken 38080 times.
✓ Branch 1 taken 4760 times.
42840 for (j = 0; j < 8; j++)
458
2/2
✓ Branch 0 taken 114240 times.
✓ Branch 1 taken 38080 times.
152320 for (k = 0; k < 3; k++)
459
2/2
✓ Branch 0 taken 1256640 times.
✓ Branch 1 taken 114240 times.
1370880 for (l = 0; l < NUM_DCT_TOKENS-1; l++)
460
2/2
✓ Branch 1 taken 10427 times.
✓ Branch 2 taken 1246213 times.
1256640 if (vpx_rac_get_prob_branchy(c, ff_vp8_token_update_probs[i][j][k][l])) {
461 10427 int prob = vp89_rac_get_uint(c, 8);
462
2/2
✓ Branch 0 taken 23139 times.
✓ Branch 1 taken 10427 times.
33566 for (m = 0; vp8_coeff_band_indexes[j][m] >= 0; m++)
463 23139 s->prob->token[i][vp8_coeff_band_indexes[j][m]][k][l] = prob;
464 }
465 1190 }
466
467 #define VP7_MVC_SIZE 17
468 #define VP8_MVC_SIZE 19
469
470 1097 static void vp78_update_pred16x16_pred8x8_mvc_probabilities(VP8Context *s,
471 int mvc_size)
472 {
473 1097 VPXRangeCoder *c = &s->c;
474 int i, j;
475
476
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1095 times.
1097 if (vp89_rac_get(c))
477
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 for (i = 0; i < 4; i++)
478 8 s->prob->pred16x16[i] = vp89_rac_get_uint(c, 8);
479
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1096 times.
1097 if (vp89_rac_get(c))
480
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (i = 0; i < 3; i++)
481 3 s->prob->pred8x8c[i] = vp89_rac_get_uint(c, 8);
482
483 // 17.2 MV probability update
484
2/2
✓ Branch 0 taken 2194 times.
✓ Branch 1 taken 1097 times.
3291 for (i = 0; i < 2; i++)
485
2/2
✓ Branch 0 taken 41562 times.
✓ Branch 1 taken 2194 times.
43756 for (j = 0; j < mvc_size; j++)
486
2/2
✓ Branch 1 taken 306 times.
✓ Branch 2 taken 41256 times.
41562 if (vpx_rac_get_prob_branchy(c, vp8_mv_update_prob[i][j]))
487 306 s->prob->mvc[i][j] = vp8_rac_get_nn(c);
488 1097 }
489
490 1066 static void update_refs(VP8Context *s)
491 {
492 1066 VPXRangeCoder *c = &s->c;
493
494 1066 int update_golden = vp89_rac_get(c);
495 1066 int update_altref = vp89_rac_get(c);
496
497 1066 s->update_golden = ref_to_update(s, update_golden, VP8_FRAME_GOLDEN);
498 1066 s->update_altref = ref_to_update(s, update_altref, VP8_FRAME_ALTREF);
499 1066 }
500
501 ✗ static void copy_chroma(AVFrame *dst, const AVFrame *src, int width, int height)
502 {
503 int i, j;
504
505 ✗ for (j = 1; j < 3; j++) {
506 ✗ for (i = 0; i < height / 2; i++)
507 ✗ memcpy(dst->data[j] + i * dst->linesize[j],
508 ✗ src->data[j] + i * src->linesize[j], width / 2);
509 }
510 ✗ }
511
512 ✗ static void fade(uint8_t *dst, ptrdiff_t dst_linesize,
513 const uint8_t *src, ptrdiff_t src_linesize,
514 int width, int height,
515 int alpha, int beta)
516 {
517 int i, j;
518 ✗ for (j = 0; j < height; j++) {
519 ✗ const uint8_t *src2 = src + j * src_linesize;
520 ✗ uint8_t *dst2 = dst + j * dst_linesize;
521 ✗ for (i = 0; i < width; i++) {
522 ✗ uint8_t y = src2[i];
523 ✗ dst2[i] = av_clip_uint8(y + ((y * beta) >> 8) + alpha);
524 }
525 }
526 ✗ }
527
528 32 static int vp7_fade_frame(VP8Context *s, int alpha, int beta)
529 {
530 int ret;
531
532
4/6
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 31 times.
32 if (!s->keyframe && (alpha || beta)) {
533 ✗ int width = s->mb_width * 16;
534 ✗ int height = s->mb_height * 16;
535 const AVFrame *src;
536 AVFrame *dst;
537
538 ✗ if (!s->framep[VP8_FRAME_PREVIOUS] ||
539 ✗ !s->framep[VP8_FRAME_GOLDEN]) {
540 ✗ av_log(s->avctx, AV_LOG_WARNING, "Discarding interframe without a prior keyframe!\n");
541 ✗ return AVERROR_INVALIDDATA;
542 }
543
544 ✗ src =
545 ✗ dst = s->framep[VP8_FRAME_PREVIOUS]->tf.f;
546
547 /* preserve the golden frame, write a new previous frame */
548 ✗ if (s->framep[VP8_FRAME_GOLDEN] == s->framep[VP8_FRAME_PREVIOUS]) {
549 ✗ VP8Frame *prev_frame = vp8_find_free_buffer(s);
550
551 ✗ ret = vp8_alloc_frame(s, prev_frame, 1);
552 ✗ if (ret < 0)
553 ✗ return ret;
554 ✗ s->framep[VP8_FRAME_PREVIOUS] = prev_frame;
555
556 ✗ dst = s->framep[VP8_FRAME_PREVIOUS]->tf.f;
557
558 ✗ copy_chroma(dst, src, width, height);
559 }
560
561 ✗ fade(dst->data[0], dst->linesize[0],
562 ✗ src->data[0], src->linesize[0],
563 width, height, alpha, beta);
564 }
565
566 32 return 0;
567 }
568
569 32 static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
570 {
571 32 VPXRangeCoder *c = &s->c;
572 int part1_size, hscale, vscale, i, j, ret;
573 32 int width = s->avctx->width;
574 32 int height = s->avctx->height;
575 32 int alpha = 0;
576 32 int beta = 0;
577 32 int fade_present = 1;
578
579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (buf_size < 4) {
580 ✗ return AVERROR_INVALIDDATA;
581 }
582
583 32 s->profile = (buf[0] >> 1) & 7;
584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (s->profile > 1) {
585 ✗ avpriv_request_sample(s->avctx, "Unknown profile %d", s->profile);
586 ✗ return AVERROR_INVALIDDATA;
587 }
588
589 32 s->keyframe = !(buf[0] & 1);
590 32 s->invisible = 0;
591 32 part1_size = AV_RL24(buf) >> 4;
592
593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (buf_size < 4 - s->profile + part1_size) {
594 ✗ av_log(s->avctx, AV_LOG_ERROR, "Buffer size %d is too small, needed : %d\n", buf_size, 4 - s->profile + part1_size);
595 ✗ return AVERROR_INVALIDDATA;
596 }
597
598 32 buf += 4 - s->profile;
599 32 buf_size -= 4 - s->profile;
600
601 32 memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));
602
603 32 ret = ff_vpx_init_range_decoder(c, buf, part1_size);
604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
605 ✗ return ret;
606 32 buf += part1_size;
607 32 buf_size -= part1_size;
608
609 /* A. Dimension information (keyframes only) */
610
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 31 times.
32 if (s->keyframe) {
611 1 width = vp89_rac_get_uint(c, 12);
612 1 height = vp89_rac_get_uint(c, 12);
613 1 hscale = vp89_rac_get_uint(c, 2);
614 1 vscale = vp89_rac_get_uint(c, 2);
615
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (hscale || vscale)
616 ✗ avpriv_request_sample(s->avctx, "Upscaling");
617
618 1 s->update_golden = s->update_altref = VP8_FRAME_CURRENT;
619 1 vp78_reset_probability_tables(s);
620 1 memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter,
621 sizeof(s->prob->pred16x16));
622 1 memcpy(s->prob->pred8x8c, vp8_pred8x8c_prob_inter,
623 sizeof(s->prob->pred8x8c));
624
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (i = 0; i < 2; i++)
625 2 memcpy(s->prob->mvc[i], vp7_mv_default_prob[i],
626 sizeof(vp7_mv_default_prob[i]));
627 1 memset(&s->segmentation, 0, sizeof(s->segmentation));
628 1 memset(&s->lf_delta, 0, sizeof(s->lf_delta));
629 1 memcpy(s->prob[0].scan, ff_zigzag_scan, sizeof(s->prob[0].scan));
630 }
631
632
3/4
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
32 if (s->keyframe || s->profile > 0)
633 1 memset(s->inter_dc_pred, 0 , sizeof(s->inter_dc_pred));
634
635 /* B. Decoding information for all four macroblock-level features */
636
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 32 times.
160 for (i = 0; i < 4; i++) {
637 128 s->feature_enabled[i] = vp89_rac_get(c);
638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
128 if (s->feature_enabled[i]) {
639 ✗ s->feature_present_prob[i] = vp89_rac_get_uint(c, 8);
640
641 ✗ for (j = 0; j < 3; j++)
642 ✗ s->feature_index_prob[i][j] =
643 ✗ vp89_rac_get(c) ? vp89_rac_get_uint(c, 8) : 255;
644
645 ✗ if (vp7_feature_value_size[s->profile][i])
646 ✗ for (j = 0; j < 4; j++)
647 ✗ s->feature_value[i][j] =
648 ✗ vp89_rac_get(c) ? vp89_rac_get_uint(c, vp7_feature_value_size[s->profile][i]) : 0;
649 }
650 }
651
652 32 s->segmentation.enabled = 0;
653 32 s->segmentation.update_map = 0;
654 32 s->lf_delta.enabled = 0;
655
656 32 s->num_coeff_partitions = 1;
657 32 ret = ff_vpx_init_range_decoder(&s->coeff_partition[0], buf, buf_size);
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
659 ✗ return ret;
660
661
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
32 if (!s->macroblocks_base || /* first frame */
662
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 width != s->avctx->width || height != s->avctx->height ||
663
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 (width + 15) / 16 != s->mb_width || (height + 15) / 16 != s->mb_height) {
664
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if ((ret = vp7_update_dimensions(s, width, height)) < 0)
665 ✗ return ret;
666 }
667
668 /* C. Dequantization indices */
669 32 vp7_get_quants(s);
670
671 /* D. Golden frame update flag (a Flag) for interframes only */
672
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
32 if (!s->keyframe) {
673
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 28 times.
31 s->update_golden = vp89_rac_get(c) ? VP8_FRAME_CURRENT : VP8_FRAME_NONE;
674 31 s->sign_bias[VP8_FRAME_GOLDEN] = 0;
675 }
676
677 32 s->update_last = 1;
678 32 s->update_probabilities = 1;
679
680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (s->profile > 0) {
681 ✗ s->update_probabilities = vp89_rac_get(c);
682 ✗ if (!s->update_probabilities)
683 ✗ s->prob[1] = s->prob[0];
684
685 ✗ if (!s->keyframe)
686 ✗ fade_present = vp89_rac_get(c);
687 }
688
689
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 if (vpx_rac_is_end(c))
690 ✗ return AVERROR_INVALIDDATA;
691 /* E. Fading information for previous frame */
692
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
32 if (fade_present && vp89_rac_get(c)) {
693 ✗ alpha = (int8_t) vp89_rac_get_uint(c, 8);
694 ✗ beta = (int8_t) vp89_rac_get_uint(c, 8);
695 }
696
697 /* F. Loop filter type */
698
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (!s->profile)
699 32 s->filter.simple = vp89_rac_get(c);
700
701 /* G. DCT coefficient ordering specification */
702
2/2
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 19 times.
32 if (vp89_rac_get(c))
703
2/2
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 13 times.
208 for (i = 1; i < 16; i++)
704 195 s->prob[0].scan[i] = ff_zigzag_scan[vp89_rac_get_uint(c, 4)];
705
706 /* H. Loop filter levels */
707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (s->profile > 0)
708 ✗ s->filter.simple = vp89_rac_get(c);
709 32 s->filter.level = vp89_rac_get_uint(c, 6);
710 32 s->filter.sharpness = vp89_rac_get_uint(c, 3);
711
712 /* I. DCT coefficient probability update; 13.3 Token Probability Updates */
713 32 vp78_update_probability_tables(s);
714
715 32 s->mbskip_enabled = 0;
716
717 /* J. The remaining frame header data occurs ONLY FOR INTERFRAMES */
718
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
32 if (!s->keyframe) {
719 31 s->prob->intra = vp89_rac_get_uint(c, 8);
720 31 s->prob->last = vp89_rac_get_uint(c, 8);
721 31 vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP7_MVC_SIZE);
722 }
723
724
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 if (vpx_rac_is_end(c))
725 ✗ return AVERROR_INVALIDDATA;
726
727
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 if ((ret = vp7_fade_frame(s, alpha, beta)) < 0)
728 ✗ return ret;
729
730 32 return 0;
731 }
732
733 1158 static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
734 {
735 1158 VPXRangeCoder *c = &s->c;
736 int header_size, hscale, vscale, ret;
737 1158 int width = s->avctx->width;
738 1158 int height = s->avctx->height;
739
740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1158 times.
1158 if (buf_size < 3) {
741 ✗ av_log(s->avctx, AV_LOG_ERROR, "Insufficient data (%d) for header\n", buf_size);
742 ✗ return AVERROR_INVALIDDATA;
743 }
744
745 1158 s->keyframe = !(buf[0] & 1);
746 1158 s->profile = (buf[0]>>1) & 7;
747 1158 s->invisible = !(buf[0] & 0x10);
748 1158 header_size = AV_RL24(buf) >> 5;
749 1158 buf += 3;
750 1158 buf_size -= 3;
751
752 1158 s->header_partition_size = header_size;
753
754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1158 times.
1158 if (s->profile > 3)
755 ✗ av_log(s->avctx, AV_LOG_WARNING, "Unknown profile %d\n", s->profile);
756
757
2/2
✓ Branch 0 taken 980 times.
✓ Branch 1 taken 178 times.
1158 if (!s->profile)
758 980 memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab,
759 sizeof(s->put_pixels_tab));
760 else // profile 1-3 use bilinear, 4+ aren't defined so whatever
761 178 memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_bilinear_pixels_tab,
762 sizeof(s->put_pixels_tab));
763
764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1158 times.
1158 if (header_size > buf_size - 7 * s->keyframe) {
765 ✗ av_log(s->avctx, AV_LOG_ERROR, "Header size larger than data provided\n");
766 ✗ return AVERROR_INVALIDDATA;
767 }
768
769
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 1066 times.
1158 if (s->keyframe) {
770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (AV_RL24(buf) != 0x2a019d) {
771 ✗ av_log(s->avctx, AV_LOG_ERROR,
772 ✗ "Invalid start code 0x%x\n", AV_RL24(buf));
773 ✗ return AVERROR_INVALIDDATA;
774 }
775 92 width = AV_RL16(buf + 3) & 0x3fff;
776 92 height = AV_RL16(buf + 5) & 0x3fff;
777 92 hscale = buf[4] >> 6;
778 92 vscale = buf[6] >> 6;
779 92 buf += 7;
780 92 buf_size -= 7;
781
782
2/4
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 92 times.
92 if (hscale || vscale)
783 ✗ avpriv_request_sample(s->avctx, "Upscaling");
784
785 92 s->update_golden = s->update_altref = VP8_FRAME_CURRENT;
786 92 vp78_reset_probability_tables(s);
787 92 memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter,
788 sizeof(s->prob->pred16x16));
789 92 memcpy(s->prob->pred8x8c, vp8_pred8x8c_prob_inter,
790 sizeof(s->prob->pred8x8c));
791 92 memcpy(s->prob->mvc, vp8_mv_default_prob,
792 sizeof(s->prob->mvc));
793 92 memset(&s->segmentation, 0, sizeof(s->segmentation));
794 92 memset(&s->lf_delta, 0, sizeof(s->lf_delta));
795 }
796
797 1158 ret = ff_vpx_init_range_decoder(c, buf, header_size);
798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1158 times.
1158 if (ret < 0)
799 ✗ return ret;
800 1158 buf += header_size;
801 1158 buf_size -= header_size;
802
803
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 1066 times.
1158 if (s->keyframe) {
804 92 s->colorspace = vp89_rac_get(c);
805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (s->colorspace)
806 ✗ av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");
807 92 s->fullrange = vp89_rac_get(c);
808 }
809
810
2/2
✓ Branch 1 taken 476 times.
✓ Branch 2 taken 682 times.
1158 if ((s->segmentation.enabled = vp89_rac_get(c)))
811 476 parse_segment_info(s);
812 else
813 682 s->segmentation.update_map = 0; // FIXME: move this to some init function?
814
815 1158 s->filter.simple = vp89_rac_get(c);
816 1158 s->filter.level = vp89_rac_get_uint(c, 6);
817 1158 s->filter.sharpness = vp89_rac_get_uint(c, 3);
818
819
2/2
✓ Branch 1 taken 1109 times.
✓ Branch 2 taken 49 times.
1158 if ((s->lf_delta.enabled = vp89_rac_get(c))) {
820 1109 s->lf_delta.update = vp89_rac_get(c);
821
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 1066 times.
1109 if (s->lf_delta.update)
822 43 update_lf_deltas(s);
823 }
824
825
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1158 times.
1158 if (setup_partitions(s, buf, buf_size)) {
826 ✗ av_log(s->avctx, AV_LOG_ERROR, "Invalid partitions\n");
827 ✗ return AVERROR_INVALIDDATA;
828 }
829
830
2/2
✓ Branch 0 taken 1129 times.
✓ Branch 1 taken 29 times.
1158 if (!s->macroblocks_base || /* first frame */
831
4/4
✓ Branch 0 taken 1091 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 1084 times.
✓ Branch 3 taken 7 times.
1129 width != s->avctx->width || height != s->avctx->height ||
832
2/4
✓ Branch 0 taken 1084 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1084 times.
1084 (width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height)
833
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 74 times.
74 if ((ret = vp8_update_dimensions(s, width, height)) < 0)
834 ✗ return ret;
835
836 1158 vp8_get_quants(s);
837
838
2/2
✓ Branch 0 taken 1066 times.
✓ Branch 1 taken 92 times.
1158 if (!s->keyframe) {
839 1066 update_refs(s);
840 1066 s->sign_bias[VP8_FRAME_GOLDEN] = vp89_rac_get(c);
841 1066 s->sign_bias[VP8_FRAME_ALTREF] = vp89_rac_get(c);
842 }
843
844 // if we aren't saving this frame's probabilities for future frames,
845 // make a copy of the current probabilities
846
2/2
✓ Branch 1 taken 107 times.
✓ Branch 2 taken 1051 times.
1158 if (!(s->update_probabilities = vp89_rac_get(c)))
847 107 s->prob[1] = s->prob[0];
848
849
4/4
✓ Branch 0 taken 1066 times.
✓ Branch 1 taken 92 times.
✓ Branch 3 taken 1055 times.
✓ Branch 4 taken 11 times.
1158 s->update_last = s->keyframe || vp89_rac_get(c);
850
851 1158 vp78_update_probability_tables(s);
852
853
2/2
✓ Branch 1 taken 1109 times.
✓ Branch 2 taken 49 times.
1158 if ((s->mbskip_enabled = vp89_rac_get(c)))
854 1109 s->prob->mbskip = vp89_rac_get_uint(c, 8);
855
856
2/2
✓ Branch 0 taken 1066 times.
✓ Branch 1 taken 92 times.
1158 if (!s->keyframe) {
857 1066 s->prob->intra = vp89_rac_get_uint(c, 8);
858 1066 s->prob->last = vp89_rac_get_uint(c, 8);
859 1066 s->prob->golden = vp89_rac_get_uint(c, 8);
860 1066 vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP8_MVC_SIZE);
861 }
862
863 // Record the entropy coder state here so that hwaccels can use it.
864 1158 s->c.code_word = vpx_rac_renorm(&s->c);
865 1158 s->coder_state_at_header_end.input = s->c.buffer - (-s->c.bits / 8);
866 1158 s->coder_state_at_header_end.range = s->c.high;
867 1158 s->coder_state_at_header_end.value = s->c.code_word >> 16;
868 1158 s->coder_state_at_header_end.bit_count = -s->c.bits % 8;
869
870 1158 return 0;
871 }
872
873 static av_always_inline
874 57182 void clamp_mv(const VP8mvbounds *s, VP8mv *dst, const VP8mv *src)
875 {
876 57182 dst->x = av_clip(src->x, av_clip(s->mv_min.x, INT16_MIN, INT16_MAX),
877 57182 av_clip(s->mv_max.x, INT16_MIN, INT16_MAX));
878 57182 dst->y = av_clip(src->y, av_clip(s->mv_min.y, INT16_MIN, INT16_MAX),
879 57182 av_clip(s->mv_max.y, INT16_MIN, INT16_MAX));
880 57182 }
881
882 /**
883 * Motion vector coding, 17.1.
884 */
885 84910 static av_always_inline int read_mv_component(VPXRangeCoder *c, const uint8_t *p, int vp7)
886 {
887 84910 int bit, x = 0;
888
889
2/2
✓ Branch 1 taken 19966 times.
✓ Branch 2 taken 64944 times.
84910 if (vpx_rac_get_prob_branchy(c, p[0])) {
890 int i;
891
892
2/2
✓ Branch 0 taken 59898 times.
✓ Branch 1 taken 19966 times.
79864 for (i = 0; i < 3; i++)
893 59898 x += vpx_rac_get_prob(c, p[9 + i]) << i;
894
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19966 times.
✓ Branch 2 taken 119796 times.
✓ Branch 3 taken 19966 times.
139762 for (i = (vp7 ? 7 : 9); i > 3; i--)
895 119796 x += vpx_rac_get_prob(c, p[9 + i]) << i;
896
5/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19966 times.
✓ Branch 2 taken 12222 times.
✓ Branch 3 taken 7744 times.
✓ Branch 5 taken 5564 times.
✓ Branch 6 taken 6658 times.
19966 if (!(x & (vp7 ? 0xF0 : 0xFFF0)) || vpx_rac_get_prob(c, p[12]))
897 13308 x += 8;
898 } else {
899 // small_mvtree
900 64944 const uint8_t *ps = p + 2;
901 64944 bit = vpx_rac_get_prob(c, *ps);
902 64944 ps += 1 + 3 * bit;
903 64944 x += 4 * bit;
904 64944 bit = vpx_rac_get_prob(c, *ps);
905 64944 ps += 1 + bit;
906 64944 x += 2 * bit;
907 64944 x += vpx_rac_get_prob(c, *ps);
908 }
909
910
4/4
✓ Branch 0 taken 66588 times.
✓ Branch 1 taken 18322 times.
✓ Branch 3 taken 34958 times.
✓ Branch 4 taken 31630 times.
84910 return (x && vpx_rac_get_prob(c, p[1])) ? -x : x;
911 }
912
913 ✗ static int vp7_read_mv_component(VPXRangeCoder *c, const uint8_t *p)
914 {
915 ✗ return read_mv_component(c, p, 1);
916 }
917
918 28394 static int vp8_read_mv_component(VPXRangeCoder *c, const uint8_t *p)
919 {
920 28394 return read_mv_component(c, p, 0);
921 }
922
923 static av_always_inline
924 136610 const uint8_t *get_submv_prob(uint32_t left, uint32_t top, int is_vp7)
925 {
926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136610 times.
136610 if (is_vp7)
927 ✗ return vp7_submv_prob;
928
929
2/2
✓ Branch 0 taken 58719 times.
✓ Branch 1 taken 77891 times.
136610 if (left == top)
930
2/2
✓ Branch 0 taken 23422 times.
✓ Branch 1 taken 35297 times.
58719 return vp8_submv_prob[4 - !!left];
931
2/2
✓ Branch 0 taken 18934 times.
✓ Branch 1 taken 58957 times.
77891 if (!top)
932 18934 return vp8_submv_prob[2];
933 58957 return vp8_submv_prob[1 - !!left];
934 }
935
936 /**
937 * Split motion vector prediction, 16.4.
938 * @returns the number of motion vectors parsed (2, 4 or 16)
939 */
940 static av_always_inline
941 18330 int decode_splitmvs(const VP8Context *s, VPXRangeCoder *c, VP8Macroblock *mb,
942 int layout, int is_vp7)
943 {
944 int part_idx;
945 int n, num;
946 const VP8Macroblock *top_mb;
947 18330 const VP8Macroblock *left_mb = &mb[-1];
948 18330 const uint8_t *mbsplits_left = vp8_mbsplits[left_mb->partitioning];
949 const uint8_t *mbsplits_top, *mbsplits_cur, *firstidx;
950 const VP8mv *top_mv;
951 18330 const VP8mv *left_mv = left_mb->bmv;
952 18330 const VP8mv *cur_mv = mb->bmv;
953
954
1/2
✓ Branch 0 taken 18330 times.
✗ Branch 1 not taken.
18330 if (!layout) // layout is inlined, s->mb_layout is not
955 18330 top_mb = &mb[2];
956 else
957 ✗ top_mb = &mb[-s->mb_width - 1];
958 18330 mbsplits_top = vp8_mbsplits[top_mb->partitioning];
959 18330 top_mv = top_mb->bmv;
960
961
2/2
✓ Branch 1 taken 11715 times.
✓ Branch 2 taken 6615 times.
18330 if (vpx_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {
962
2/2
✓ Branch 1 taken 8045 times.
✓ Branch 2 taken 3670 times.
11715 if (vpx_rac_get_prob_branchy(c, vp8_mbsplit_prob[1]))
963 8045 part_idx = VP8_SPLITMVMODE_16x8 + vpx_rac_get_prob(c, vp8_mbsplit_prob[2]);
964 else
965 3670 part_idx = VP8_SPLITMVMODE_8x8;
966 } else {
967 6615 part_idx = VP8_SPLITMVMODE_4x4;
968 }
969
970 18330 num = vp8_mbsplit_count[part_idx];
971 18330 mbsplits_cur = vp8_mbsplits[part_idx],
972 18330 firstidx = vp8_mbfirstidx[part_idx];
973 18330 mb->partitioning = part_idx;
974
975
2/2
✓ Branch 0 taken 136610 times.
✓ Branch 1 taken 18330 times.
154940 for (n = 0; n < num; n++) {
976 136610 int k = firstidx[n];
977 uint32_t left, above;
978 const uint8_t *submv_prob;
979
980
2/2
✓ Branch 0 taken 46755 times.
✓ Branch 1 taken 89855 times.
136610 if (!(k & 3))
981 46755 left = AV_RN32A(&left_mv[mbsplits_left[k + 3]]);
982 else
983 89855 left = AV_RN32A(&cur_mv[mbsplits_cur[k - 1]]);
984
2/2
✓ Branch 0 taken 44980 times.
✓ Branch 1 taken 91630 times.
136610 if (k <= 3)
985 44980 above = AV_RN32A(&top_mv[mbsplits_top[k + 12]]);
986 else
987 91630 above = AV_RN32A(&cur_mv[mbsplits_cur[k - 4]]);
988
989 136610 submv_prob = get_submv_prob(left, above, is_vp7);
990
991
2/2
✓ Branch 1 taken 50617 times.
✓ Branch 2 taken 85993 times.
136610 if (vpx_rac_get_prob_branchy(c, submv_prob[0])) {
992
2/2
✓ Branch 1 taken 31746 times.
✓ Branch 2 taken 18871 times.
50617 if (vpx_rac_get_prob_branchy(c, submv_prob[1])) {
993
2/2
✓ Branch 1 taken 28258 times.
✓ Branch 2 taken 3488 times.
31746 if (vpx_rac_get_prob_branchy(c, submv_prob[2])) {
994 56516 mb->bmv[n].y = mb->mv.y +
995 28258 read_mv_component(c, s->prob->mvc[0], is_vp7);
996 28258 mb->bmv[n].x = mb->mv.x +
997 28258 read_mv_component(c, s->prob->mvc[1], is_vp7);
998 } else {
999 3488 AV_ZERO32(&mb->bmv[n]);
1000 }
1001 } else {
1002 18871 AV_WN32A(&mb->bmv[n], above);
1003 }
1004 } else {
1005 85993 AV_WN32A(&mb->bmv[n], left);
1006 }
1007 }
1008
1009 18330 return num;
1010 }
1011
1012 /**
1013 * The vp7 reference decoder uses a padding macroblock column (added to right
1014 * edge of the frame) to guard against illegal macroblock offsets. The
1015 * algorithm has bugs that permit offsets to straddle the padding column.
1016 * This function replicates those bugs.
1017 *
1018 * @param[out] edge_x macroblock x address
1019 * @param[out] edge_y macroblock y address
1020 *
1021 * @return macroblock offset legal (boolean)
1022 */
1023 81840 static int vp7_calculate_mb_offset(int mb_x, int mb_y, int mb_width,
1024 int xoffset, int yoffset, int boundary,
1025 int *edge_x, int *edge_y)
1026 {
1027 81840 int vwidth = mb_width + 1;
1028 81840 int new = (mb_y + yoffset) * vwidth + mb_x + xoffset;
1029
4/4
✓ Branch 0 taken 72013 times.
✓ Branch 1 taken 9827 times.
✓ Branch 2 taken 2852 times.
✓ Branch 3 taken 69161 times.
81840 if (new < boundary || new % vwidth == vwidth - 1)
1030 12679 return 0;
1031 69161 *edge_y = new / vwidth;
1032 69161 *edge_x = new % vwidth;
1033 69161 return 1;
1034 }
1035
1036 69161 static const VP8mv *get_bmv_ptr(const VP8Macroblock *mb, int subblock)
1037 {
1038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69161 times.
69161 return &mb->bmv[mb->mode == VP8_MVMODE_SPLIT ? vp8_mbsplits[mb->partitioning][subblock] : 0];
1039 }
1040
1041 static av_always_inline
1042 6820 void vp7_decode_mvs(VP8Context *s, VP8Macroblock *mb,
1043 int mb_x, int mb_y, int layout)
1044 {
1045 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR };
1046 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
1047 6820 int idx = CNT_ZERO;
1048 VP8mv near_mv[3];
1049 6820 uint8_t cnt[3] = { 0 };
1050 6820 VPXRangeCoder *c = &s->c;
1051 int i;
1052
1053 6820 AV_ZERO32(&near_mv[0]);
1054 6820 AV_ZERO32(&near_mv[1]);
1055 6820 AV_ZERO32(&near_mv[2]);
1056
1057
2/2
✓ Branch 0 taken 81840 times.
✓ Branch 1 taken 6820 times.
88660 for (i = 0; i < VP7_MV_PRED_COUNT; i++) {
1058 81840 const VP7MVPred * pred = &vp7_mv_pred[i];
1059 int edge_x, edge_y;
1060
1061
2/2
✓ Branch 0 taken 69161 times.
✓ Branch 1 taken 12679 times.
81840 if (vp7_calculate_mb_offset(mb_x, mb_y, s->mb_width, pred->xoffset,
1062 81840 pred->yoffset, !s->profile, &edge_x, &edge_y)) {
1063
1/2
✓ Branch 0 taken 69161 times.
✗ Branch 1 not taken.
69161 const VP8Macroblock *edge = (s->mb_layout == 1)
1064 69161 ? s->macroblocks_base + 1 + edge_x +
1065 69161 (s->mb_width + 1) * (edge_y + 1)
1066 ✗ : s->macroblocks + edge_x +
1067 ✗ (s->mb_height - edge_y - 1) * 2;
1068 69161 uint32_t mv = AV_RN32A(get_bmv_ptr(edge, vp7_mv_pred[i].subblock));
1069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69161 times.
69161 if (mv) {
1070 ✗ if (AV_RN32A(&near_mv[CNT_NEAREST])) {
1071 ✗ if (mv == AV_RN32A(&near_mv[CNT_NEAREST])) {
1072 ✗ idx = CNT_NEAREST;
1073 ✗ } else if (AV_RN32A(&near_mv[CNT_NEAR])) {
1074 ✗ if (mv != AV_RN32A(&near_mv[CNT_NEAR]))
1075 ✗ continue;
1076 ✗ idx = CNT_NEAR;
1077 } else {
1078 ✗ AV_WN32A(&near_mv[CNT_NEAR], mv);
1079 ✗ idx = CNT_NEAR;
1080 }
1081 } else {
1082 ✗ AV_WN32A(&near_mv[CNT_NEAREST], mv);
1083 ✗ idx = CNT_NEAREST;
1084 }
1085 } else {
1086 69161 idx = CNT_ZERO;
1087 }
1088 } else {
1089 12679 idx = CNT_ZERO;
1090 }
1091 81840 cnt[idx] += vp7_mv_pred[i].score;
1092 }
1093
1094 6820 mb->partitioning = VP8_SPLITMVMODE_NONE;
1095
1096
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6820 times.
6820 if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_ZERO]][0])) {
1097 ✗ mb->mode = VP8_MVMODE_MV;
1098
1099 ✗ if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAREST]][1])) {
1100
1101 ✗ if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAR]][2])) {
1102
1103 ✗ if (cnt[CNT_NEAREST] > cnt[CNT_NEAR])
1104 ✗ AV_WN32A(&mb->mv, cnt[CNT_ZERO] > cnt[CNT_NEAREST] ? 0 : AV_RN32A(&near_mv[CNT_NEAREST]));
1105 else
1106 ✗ AV_WN32A(&mb->mv, cnt[CNT_ZERO] > cnt[CNT_NEAR] ? 0 : AV_RN32A(&near_mv[CNT_NEAR]));
1107
1108 ✗ if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAR]][3])) {
1109 ✗ mb->mode = VP8_MVMODE_SPLIT;
1110 ✗ mb->mv = mb->bmv[decode_splitmvs(s, c, mb, layout, IS_VP7) - 1];
1111 } else {
1112 ✗ mb->mv.y += vp7_read_mv_component(c, s->prob->mvc[0]);
1113 ✗ mb->mv.x += vp7_read_mv_component(c, s->prob->mvc[1]);
1114 ✗ mb->bmv[0] = mb->mv;
1115 }
1116 } else {
1117 ✗ mb->mv = near_mv[CNT_NEAR];
1118 ✗ mb->bmv[0] = mb->mv;
1119 }
1120 } else {
1121 ✗ mb->mv = near_mv[CNT_NEAREST];
1122 ✗ mb->bmv[0] = mb->mv;
1123 }
1124 } else {
1125 6820 mb->mode = VP8_MVMODE_ZERO;
1126 6820 AV_ZERO32(&mb->mv);
1127 6820 mb->bmv[0] = mb->mv;
1128 }
1129 6820 }
1130
1131 static av_always_inline
1132 379559 void vp8_decode_mvs(VP8Context *s, const VP8mvbounds *mv_bounds, VP8Macroblock *mb,
1133 int mb_x, int mb_y, int layout)
1134 {
1135 379559 VP8Macroblock *mb_edge[3] = { 0 /* top */,
1136 379559 mb - 1 /* left */,
1137 0 /* top-left */ };
1138 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
1139 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
1140 379559 int idx = CNT_ZERO;
1141 379559 int cur_sign_bias = s->sign_bias[mb->ref_frame];
1142 379559 const int8_t *sign_bias = s->sign_bias;
1143 VP8mv near_mv[4];
1144 379559 uint8_t cnt[4] = { 0 };
1145 379559 VPXRangeCoder *c = &s->c;
1146
1147
1/2
✓ Branch 0 taken 379559 times.
✗ Branch 1 not taken.
379559 if (!layout) { // layout is inlined (s->mb_layout is not)
1148 379559 mb_edge[0] = mb + 2;
1149 379559 mb_edge[2] = mb + 1;
1150 } else {
1151 ✗ mb_edge[0] = mb - s->mb_width - 1;
1152 ✗ mb_edge[2] = mb - s->mb_width - 2;
1153 }
1154
1155 379559 AV_ZERO32(&near_mv[0]);
1156 379559 AV_ZERO32(&near_mv[1]);
1157 379559 AV_ZERO32(&near_mv[2]);
1158
1159 /* Process MB on top, left and top-left */
1160 #define MV_EDGE_CHECK(n) \
1161 { \
1162 const VP8Macroblock *edge = mb_edge[n]; \
1163 int edge_ref = edge->ref_frame; \
1164 if (edge_ref != VP8_FRAME_CURRENT) { \
1165 uint32_t mv = AV_RN32A(&edge->mv); \
1166 if (mv) { \
1167 if (cur_sign_bias != sign_bias[edge_ref]) { \
1168 /* SWAR negate of the values in mv. */ \
1169 mv = ~mv; \
1170 mv = ((mv & 0x7fff7fff) + \
1171 0x00010001) ^ (mv & 0x80008000); \
1172 } \
1173 if (!n || mv != AV_RN32A(&near_mv[idx])) \
1174 AV_WN32A(&near_mv[++idx], mv); \
1175 cnt[idx] += 1 + (n != 2); \
1176 } else \
1177 cnt[CNT_ZERO] += 1 + (n != 2); \
1178 } \
1179 }
1180
1181
6/6
✓ Branch 0 taken 352727 times.
✓ Branch 1 taken 26832 times.
✓ Branch 2 taken 44594 times.
✓ Branch 3 taken 308133 times.
✓ Branch 4 taken 109 times.
✓ Branch 5 taken 44485 times.
379559 MV_EDGE_CHECK(0)
1182
8/8
✓ Branch 0 taken 360687 times.
✓ Branch 1 taken 18872 times.
✓ Branch 2 taken 44761 times.
✓ Branch 3 taken 315926 times.
✓ Branch 4 taken 87 times.
✓ Branch 5 taken 44674 times.
✓ Branch 6 taken 36130 times.
✓ Branch 7 taken 8631 times.
379559 MV_EDGE_CHECK(1)
1183
8/8
✓ Branch 0 taken 339544 times.
✓ Branch 1 taken 40015 times.
✓ Branch 2 taken 41903 times.
✓ Branch 3 taken 297641 times.
✓ Branch 4 taken 123 times.
✓ Branch 5 taken 41780 times.
✓ Branch 6 taken 24718 times.
✓ Branch 7 taken 17185 times.
379559 MV_EDGE_CHECK(2)
1184
1185 379559 mb->partitioning = VP8_SPLITMVMODE_NONE;
1186
2/2
✓ Branch 1 taken 57182 times.
✓ Branch 2 taken 322377 times.
379559 if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_ZERO]][0])) {
1187 57182 mb->mode = VP8_MVMODE_MV;
1188
1189 /* If we have three distinct MVs, merge first and last if they're the same */
1190
2/2
✓ Branch 0 taken 12759 times.
✓ Branch 1 taken 44423 times.
57182 if (cnt[CNT_SPLITMV] &&
1191
2/2
✓ Branch 0 taken 5465 times.
✓ Branch 1 taken 7294 times.
12759 AV_RN32A(&near_mv[1 + VP8_EDGE_TOP]) == AV_RN32A(&near_mv[1 + VP8_EDGE_TOPLEFT]))
1192 5465 cnt[CNT_NEAREST] += 1;
1193
1194 /* Swap near and nearest if necessary */
1195
2/2
✓ Branch 0 taken 4482 times.
✓ Branch 1 taken 52700 times.
57182 if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
1196 4482 FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]);
1197 4482 FFSWAP(VP8mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
1198 }
1199
1200
2/2
✓ Branch 1 taken 37615 times.
✓ Branch 2 taken 19567 times.
57182 if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) {
1201
2/2
✓ Branch 1 taken 32527 times.
✓ Branch 2 taken 5088 times.
37615 if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAR]][2])) {
1202 /* Choose the best mv out of 0,0 and the nearest mv */
1203 32527 clamp_mv(mv_bounds, &mb->mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]);
1204 32527 cnt[CNT_SPLITMV] = ((mb_edge[VP8_EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) +
1205 32527 (mb_edge[VP8_EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 +
1206 32527 (mb_edge[VP8_EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT);
1207
1208
2/2
✓ Branch 1 taken 18330 times.
✓ Branch 2 taken 14197 times.
32527 if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
1209 18330 mb->mode = VP8_MVMODE_SPLIT;
1210 18330 mb->mv = mb->bmv[decode_splitmvs(s, c, mb, layout, IS_VP8) - 1];
1211 } else {
1212 14197 mb->mv.y += vp8_read_mv_component(c, s->prob->mvc[0]);
1213 14197 mb->mv.x += vp8_read_mv_component(c, s->prob->mvc[1]);
1214 14197 mb->bmv[0] = mb->mv;
1215 }
1216 } else {
1217 5088 clamp_mv(mv_bounds, &mb->mv, &near_mv[CNT_NEAR]);
1218 5088 mb->bmv[0] = mb->mv;
1219 }
1220 } else {
1221 19567 clamp_mv(mv_bounds, &mb->mv, &near_mv[CNT_NEAREST]);
1222 19567 mb->bmv[0] = mb->mv;
1223 }
1224 } else {
1225 322377 mb->mode = VP8_MVMODE_ZERO;
1226 322377 AV_ZERO32(&mb->mv);
1227 322377 mb->bmv[0] = mb->mv;
1228 }
1229 379559 }
1230
1231 static av_always_inline
1232 22267 void decode_intra4x4_modes(VP8Context *s, VPXRangeCoder *c, VP8Macroblock *mb,
1233 int mb_x, int keyframe, int layout)
1234 {
1235 22267 uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb;
1236
1237
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 22234 times.
22267 if (layout) {
1238 33 VP8Macroblock *mb_top = mb - s->mb_width - 1;
1239 33 memcpy(mb->intra4x4_pred_mode_top, mb_top->intra4x4_pred_mode_top, 4);
1240 }
1241
2/2
✓ Branch 0 taken 15397 times.
✓ Branch 1 taken 6870 times.
22267 if (keyframe) {
1242 int x, y;
1243 uint8_t *top;
1244 15397 uint8_t *const left = s->intra4x4_pred_mode_left;
1245
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 15364 times.
15397 if (layout)
1246 33 top = mb->intra4x4_pred_mode_top;
1247 else
1248 15364 top = s->intra4x4_pred_mode_top + 4 * mb_x;
1249
2/2
✓ Branch 0 taken 61588 times.
✓ Branch 1 taken 15397 times.
76985 for (y = 0; y < 4; y++) {
1250
2/2
✓ Branch 0 taken 246352 times.
✓ Branch 1 taken 61588 times.
307940 for (x = 0; x < 4; x++) {
1251 const uint8_t *ctx;
1252 246352 ctx = vp8_pred4x4_prob_intra[top[x]][left[y]];
1253 246352 *intra4x4 = vp89_rac_get_tree(c, vp8_pred4x4_tree, ctx);
1254 246352 left[y] = top[x] = *intra4x4;
1255 246352 intra4x4++;
1256 }
1257 }
1258 } else {
1259 int i;
1260
2/2
✓ Branch 0 taken 109920 times.
✓ Branch 1 taken 6870 times.
116790 for (i = 0; i < 16; i++)
1261 109920 intra4x4[i] = vp89_rac_get_tree(c, vp8_pred4x4_tree,
1262 vp8_pred4x4_prob_inter);
1263 }
1264 22267 }
1265
1266 static av_always_inline
1267 453515 void decode_mb_mode(VP8Context *s, const VP8mvbounds *mv_bounds,
1268 VP8Macroblock *mb, int mb_x, int mb_y,
1269 uint8_t *segment, const uint8_t *ref, int layout, int is_vp7)
1270 {
1271 453515 VPXRangeCoder *c = &s->c;
1272 static const char * const vp7_feature_name[] = { "q-index",
1273 "lf-delta",
1274 "partial-golden-update",
1275 "blit-pitch" };
1276
2/2
✓ Branch 0 taken 7040 times.
✓ Branch 1 taken 446475 times.
453515 if (is_vp7) {
1277 int i;
1278 7040 *segment = 0;
1279
2/2
✓ Branch 0 taken 28160 times.
✓ Branch 1 taken 7040 times.
35200 for (i = 0; i < 4; i++) {
1280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28160 times.
28160 if (s->feature_enabled[i]) {
1281 ✗ if (vpx_rac_get_prob_branchy(c, s->feature_present_prob[i])) {
1282 ✗ int index = vp89_rac_get_tree(c, vp7_feature_index_tree,
1283 ✗ s->feature_index_prob[i]);
1284 ✗ av_log(s->avctx, AV_LOG_WARNING,
1285 "Feature %s present in macroblock (value 0x%x)\n",
1286 ✗ vp7_feature_name[i], s->feature_value[i][index]);
1287 }
1288 }
1289 }
1290
2/2
✓ Branch 0 taken 17915 times.
✓ Branch 1 taken 428560 times.
446475 } else if (s->segmentation.update_map) {
1291 17915 int bit = vpx_rac_get_prob(c, s->prob->segmentid[0]);
1292 17915 *segment = vpx_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
1293
2/2
✓ Branch 0 taken 94425 times.
✓ Branch 1 taken 334135 times.
428560 } else if (s->segmentation.enabled)
1294
1/2
✓ Branch 0 taken 94425 times.
✗ Branch 1 not taken.
94425 *segment = ref ? *ref : *segment;
1295 453515 mb->segment = *segment;
1296
1297
2/2
✓ Branch 0 taken 436095 times.
✓ Branch 1 taken 17420 times.
453515 mb->skip = s->mbskip_enabled ? vpx_rac_get_prob(c, s->prob->mbskip) : 0;
1298
1299
2/2
✓ Branch 0 taken 42578 times.
✓ Branch 1 taken 410937 times.
453515 if (s->keyframe) {
1300 42578 mb->mode = vp89_rac_get_tree(c, vp8_pred16x16_tree_intra,
1301 vp8_pred16x16_prob_intra);
1302
1303
2/2
✓ Branch 0 taken 15397 times.
✓ Branch 1 taken 27181 times.
42578 if (mb->mode == MODE_I4x4) {
1304 15397 decode_intra4x4_modes(s, c, mb, mb_x, 1, layout);
1305 } else {
1306 27181 const uint32_t modes = (is_vp7 ? vp7_pred4x4_mode
1307
2/2
✓ Branch 0 taken 187 times.
✓ Branch 1 taken 26994 times.
27181 : vp8_pred4x4_mode)[mb->mode] * 0x01010101u;
1308
2/2
✓ Branch 0 taken 187 times.
✓ Branch 1 taken 26994 times.
27181 if (s->mb_layout)
1309 187 AV_WN32A(mb->intra4x4_pred_mode_top, modes);
1310 else
1311 26994 AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);
1312 27181 AV_WN32A(s->intra4x4_pred_mode_left, modes);
1313 }
1314
1315 42578 mb->chroma_pred_mode = vp89_rac_get_tree(c, vp8_pred8x8c_tree,
1316 vp8_pred8x8c_prob_intra);
1317 42578 mb->ref_frame = VP8_FRAME_CURRENT;
1318
2/2
✓ Branch 1 taken 386379 times.
✓ Branch 2 taken 24558 times.
410937 } else if (vpx_rac_get_prob_branchy(c, s->prob->intra)) {
1319 // inter MB, 16.2
1320
2/2
✓ Branch 1 taken 17280 times.
✓ Branch 2 taken 369099 times.
386379 if (vpx_rac_get_prob_branchy(c, s->prob->last))
1321
2/2
✓ Branch 0 taken 17248 times.
✓ Branch 1 taken 32 times.
34528 mb->ref_frame =
1322
2/2
✓ Branch 1 taken 8904 times.
✓ Branch 2 taken 8344 times.
17248 (!is_vp7 && vpx_rac_get_prob(c, s->prob->golden)) ? VP8_FRAME_ALTREF
1323 : VP8_FRAME_GOLDEN;
1324 else
1325 369099 mb->ref_frame = VP8_FRAME_PREVIOUS;
1326 386379 s->ref_count[mb->ref_frame - 1]++;
1327
1328 // motion vectors, 16.3
1329
2/2
✓ Branch 0 taken 6820 times.
✓ Branch 1 taken 379559 times.
386379 if (is_vp7)
1330 6820 vp7_decode_mvs(s, mb, mb_x, mb_y, layout);
1331 else
1332 379559 vp8_decode_mvs(s, mv_bounds, mb, mb_x, mb_y, layout);
1333 } else {
1334 // intra MB, 16.1
1335 49116 mb->mode = vp89_rac_get_tree(c, vp8_pred16x16_tree_inter,
1336 24558 s->prob->pred16x16);
1337
1338
2/2
✓ Branch 0 taken 6870 times.
✓ Branch 1 taken 17688 times.
24558 if (mb->mode == MODE_I4x4)
1339 6870 decode_intra4x4_modes(s, c, mb, mb_x, 0, layout);
1340
1341 49116 mb->chroma_pred_mode = vp89_rac_get_tree(c, vp8_pred8x8c_tree,
1342 24558 s->prob->pred8x8c);
1343 24558 mb->ref_frame = VP8_FRAME_CURRENT;
1344 24558 mb->partitioning = VP8_SPLITMVMODE_NONE;
1345 24558 AV_ZERO32(&mb->bmv[0]);
1346 }
1347 453515 }
1348
1349 /**
1350 * @param r arithmetic bitstream reader context
1351 * @param block destination for block coefficients
1352 * @param probs probabilities to use when reading trees from the bitstream
1353 * @param i initial coeff index, 0 unless a separate DC block is coded
1354 * @param qmul array holding the dc/ac dequant factor at position 0/1
1355 *
1356 * @return 0 if no coeffs were decoded
1357 * otherwise, the index of the last coeff decoded plus one
1358 */
1359 static av_always_inline
1360 449150 int decode_block_coeffs_internal(VPXRangeCoder *r, int16_t block[16],
1361 uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
1362 int i, const uint8_t *token_prob, const int16_t qmul[2],
1363 const uint8_t scan[16], int vp7)
1364 {
1365 449150 VPXRangeCoder c = *r;
1366 449150 goto skip_eob;
1367 do {
1368 int coeff;
1369 1370694 restart:
1370
2/2
✓ Branch 1 taken 423989 times.
✓ Branch 2 taken 948824 times.
1372813 if (!vpx_rac_get_prob_branchy(&c, token_prob[0])) // DCT_EOB
1371 423989 break;
1372
1373 1987171 skip_eob:
1374
2/2
✓ Branch 1 taken 1040466 times.
✓ Branch 2 taken 1395855 times.
2436321 if (!vpx_rac_get_prob_branchy(&c, token_prob[1])) { // DCT_0
1375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1040466 times.
1040466 if (++i == 16)
1376 ✗ break; // invalid input; blocks should end with EOB
1377 1040466 token_prob = probs[i][0];
1378
2/2
✓ Branch 0 taken 2119 times.
✓ Branch 1 taken 1038347 times.
1040466 if (vp7)
1379 2119 goto restart;
1380 1038347 goto skip_eob;
1381 }
1382
1383
2/2
✓ Branch 1 taken 898694 times.
✓ Branch 2 taken 497161 times.
1395855 if (!vpx_rac_get_prob_branchy(&c, token_prob[2])) { // DCT_1
1384 898694 coeff = 1;
1385 898694 token_prob = probs[i + 1][1];
1386 } else {
1387
2/2
✓ Branch 1 taken 349934 times.
✓ Branch 2 taken 147227 times.
497161 if (!vpx_rac_get_prob_branchy(&c, token_prob[3])) { // DCT 2,3,4
1388 349934 coeff = vpx_rac_get_prob_branchy(&c, token_prob[4]);
1389
2/2
✓ Branch 0 taken 140904 times.
✓ Branch 1 taken 209030 times.
349934 if (coeff)
1390 140904 coeff += vpx_rac_get_prob(&c, token_prob[5]);
1391 349934 coeff += 2;
1392 } else {
1393 // DCT_CAT*
1394
2/2
✓ Branch 1 taken 97746 times.
✓ Branch 2 taken 49481 times.
147227 if (!vpx_rac_get_prob_branchy(&c, token_prob[6])) {
1395
2/2
✓ Branch 1 taken 52974 times.
✓ Branch 2 taken 44772 times.
97746 if (!vpx_rac_get_prob_branchy(&c, token_prob[7])) { // DCT_CAT1
1396 52974 coeff = 5 + vpx_rac_get_prob(&c, vp8_dct_cat1_prob[0]);
1397 } else { // DCT_CAT2
1398 44772 coeff = 7;
1399 44772 coeff += vpx_rac_get_prob(&c, vp8_dct_cat2_prob[0]) << 1;
1400 44772 coeff += vpx_rac_get_prob(&c, vp8_dct_cat2_prob[1]);
1401 }
1402 } else { // DCT_CAT3 and up
1403 49481 int a = vpx_rac_get_prob(&c, token_prob[8]);
1404 49481 int b = vpx_rac_get_prob(&c, token_prob[9 + a]);
1405 49481 int cat = (a << 1) + b;
1406 49481 coeff = 3 + (8 << cat);
1407 49481 coeff += vp8_rac_get_coeff(&c, ff_vp8_dct_cat_prob[cat]);
1408 }
1409 }
1410 497161 token_prob = probs[i + 1][2];
1411 }
1412
4/4
✓ Branch 1 taken 703048 times.
✓ Branch 2 taken 692807 times.
✓ Branch 3 taken 1049893 times.
✓ Branch 4 taken 345962 times.
1395855 block[scan[i]] = (vp89_rac_get(&c) ? -coeff : coeff) * qmul[!!i];
1413
2/2
✓ Branch 0 taken 1370694 times.
✓ Branch 1 taken 25161 times.
1395855 } while (++i < 16);
1414
1415 449150 *r = c;
1416 449150 return i;
1417 }
1418
1419 static av_always_inline
1420 6820 int inter_predict_dc(int16_t block[16], int16_t pred[2])
1421 {
1422 6820 int16_t dc = block[0];
1423 6820 int ret = 0;
1424
1425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6820 times.
6820 if (pred[1] > 3) {
1426 ✗ dc += pred[0];
1427 ✗ ret = 1;
1428 }
1429
1430
1/2
✓ Branch 0 taken 6820 times.
✗ Branch 1 not taken.
6820 if (!pred[0] | !dc | ((int32_t)pred[0] ^ (int32_t)dc) >> 31) {
1431 6820 block[0] = pred[0] = dc;
1432 6820 pred[1] = 0;
1433 } else {
1434 ✗ if (pred[0] == dc)
1435 ✗ pred[1]++;
1436 ✗ block[0] = pred[0] = dc;
1437 }
1438
1439 6820 return ret;
1440 }
1441
1442 736 static int vp7_decode_block_coeffs_internal(VPXRangeCoder *r,
1443 int16_t block[16],
1444 uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
1445 int i, const uint8_t *token_prob,
1446 const int16_t qmul[2],
1447 const uint8_t scan[16])
1448 {
1449 736 return decode_block_coeffs_internal(r, block, probs, i,
1450 token_prob, qmul, scan, IS_VP7);
1451 }
1452
1453 #ifndef vp8_decode_block_coeffs_internal
1454 448414 static int vp8_decode_block_coeffs_internal(VPXRangeCoder *r,
1455 int16_t block[16],
1456 uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
1457 int i, const uint8_t *token_prob,
1458 const int16_t qmul[2])
1459 {
1460 448414 return decode_block_coeffs_internal(r, block, probs, i,
1461 token_prob, qmul, ff_zigzag_scan, IS_VP8);
1462 }
1463 #endif
1464
1465 /**
1466 * @param c arithmetic bitstream reader context
1467 * @param block destination for block coefficients
1468 * @param probs probabilities to use when reading trees from the bitstream
1469 * @param i initial coeff index, 0 unless a separate DC block is coded
1470 * @param zero_nhood the initial prediction context for number of surrounding
1471 * all-zero blocks (only left/top, so 0-2)
1472 * @param qmul array holding the dc/ac dequant factor at position 0/1
1473 * @param scan scan pattern (VP7 only)
1474 *
1475 * @return 0 if no coeffs were decoded
1476 * otherwise, the index of the last coeff decoded plus one
1477 */
1478 static av_always_inline
1479 2300257 int decode_block_coeffs(VPXRangeCoder *c, int16_t block[16],
1480 uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
1481 int i, int zero_nhood, const int16_t qmul[2],
1482 const uint8_t scan[16], int vp7)
1483 {
1484 2300257 const uint8_t *token_prob = probs[i][zero_nhood];
1485
2/2
✓ Branch 1 taken 1851107 times.
✓ Branch 2 taken 449150 times.
2300257 if (!vpx_rac_get_prob_branchy(c, token_prob[0])) // DCT_EOB
1486 1851107 return 0;
1487 736 return vp7 ? vp7_decode_block_coeffs_internal(c, block, probs, i,
1488 token_prob, qmul, scan)
1489
2/2
✓ Branch 0 taken 736 times.
✓ Branch 1 taken 448414 times.
449886 : vp8_decode_block_coeffs_internal(c, block, probs, i,
1490 token_prob, qmul);
1491 }
1492
1493 static av_always_inline
1494 93485 void decode_mb_coeffs(VP8Context *s, VP8ThreadData *td, VPXRangeCoder *c,
1495 VP8Macroblock *mb, uint8_t t_nnz[9], uint8_t l_nnz[9],
1496 int is_vp7)
1497 {
1498 93485 int i, x, y, luma_start = 0, luma_ctx = 3;
1499 93485 int nnz_pred, nnz, nnz_total = 0;
1500 93485 int segment = mb->segment;
1501 93485 int block_dc = 0;
1502
1503
6/6
✓ Branch 0 taken 71680 times.
✓ Branch 1 taken 21805 times.
✓ Branch 2 taken 64673 times.
✓ Branch 3 taken 7007 times.
✓ Branch 4 taken 49610 times.
✓ Branch 5 taken 15063 times.
93485 if (mb->mode != MODE_I4x4 && (is_vp7 || mb->mode != VP8_MVMODE_SPLIT)) {
1504 56617 nnz_pred = t_nnz[8] + l_nnz[8];
1505
1506 // decode DC values and do hadamard
1507 56617 nnz = decode_block_coeffs(c, td->block_dc, s->prob->token[1], 0,
1508 56617 nnz_pred, s->qmat[segment].luma_dc_qmul,
1509 ff_zigzag_scan, is_vp7);
1510 56617 l_nnz[8] = t_nnz[8] = !!nnz;
1511
1512
4/4
✓ Branch 0 taken 7007 times.
✓ Branch 1 taken 49610 times.
✓ Branch 2 taken 6820 times.
✓ Branch 3 taken 187 times.
56617 if (is_vp7 && mb->mode > MODE_I4x4) {
1513 6820 nnz |= inter_predict_dc(td->block_dc,
1514 6820 s->inter_dc_pred[mb->ref_frame - 1]);
1515 }
1516
1517
2/2
✓ Branch 0 taken 35379 times.
✓ Branch 1 taken 21238 times.
56617 if (nnz) {
1518 35379 nnz_total += nnz;
1519 35379 block_dc = 1;
1520
2/2
✓ Branch 0 taken 10745 times.
✓ Branch 1 taken 24634 times.
35379 if (nnz == 1)
1521 10745 s->vp8dsp.vp8_luma_dc_wht_dc(td->block, td->block_dc);
1522 else
1523 24634 s->vp8dsp.vp8_luma_dc_wht(td->block, td->block_dc);
1524 }
1525 56617 luma_start = 1;
1526 56617 luma_ctx = 0;
1527 }
1528
1529 // luma blocks
1530
2/2
✓ Branch 0 taken 373940 times.
✓ Branch 1 taken 93485 times.
467425 for (y = 0; y < 4; y++)
1531
2/2
✓ Branch 0 taken 1495760 times.
✓ Branch 1 taken 373940 times.
1869700 for (x = 0; x < 4; x++) {
1532 1495760 nnz_pred = l_nnz[y] + t_nnz[x];
1533 1495760 nnz = decode_block_coeffs(c, td->block[y][x],
1534 1495760 s->prob->token[luma_ctx],
1535 luma_start, nnz_pred,
1536 1495760 s->qmat[segment].luma_qmul,
1537 1495760 s->prob[0].scan, is_vp7);
1538 /* nnz+block_dc may be one more than the actual last index,
1539 * but we don't care */
1540 1495760 td->non_zero_count_cache[y][x] = nnz + block_dc;
1541 1495760 t_nnz[x] = l_nnz[y] = !!nnz;
1542 1495760 nnz_total += nnz;
1543 }
1544
1545 // chroma blocks
1546 // TODO: what to do about dimensions? 2nd dim for luma is x,
1547 // but for chroma it's (y<<1)|x
1548
2/2
✓ Branch 0 taken 186970 times.
✓ Branch 1 taken 93485 times.
280455 for (i = 4; i < 6; i++)
1549
2/2
✓ Branch 0 taken 373940 times.
✓ Branch 1 taken 186970 times.
560910 for (y = 0; y < 2; y++)
1550
2/2
✓ Branch 0 taken 747880 times.
✓ Branch 1 taken 373940 times.
1121820 for (x = 0; x < 2; x++) {
1551 747880 nnz_pred = l_nnz[i + 2 * y] + t_nnz[i + 2 * x];
1552 747880 nnz = decode_block_coeffs(c, td->block[i][(y << 1) + x],
1553 747880 s->prob->token[2], 0, nnz_pred,
1554 747880 s->qmat[segment].chroma_qmul,
1555 747880 s->prob[0].scan, is_vp7);
1556 747880 td->non_zero_count_cache[i][(y << 1) + x] = nnz;
1557 747880 t_nnz[i + 2 * x] = l_nnz[i + 2 * y] = !!nnz;
1558 747880 nnz_total += nnz;
1559 }
1560
1561 // if there were no coded coeffs despite the macroblock not being marked skip,
1562 // we MUST not do the inner loop filter and should not do IDCT
1563 // Since skip isn't used for bitstream prediction, just manually set it.
1564
2/2
✓ Branch 0 taken 11111 times.
✓ Branch 1 taken 82374 times.
93485 if (!nnz_total)
1565 11111 mb->skip = 1;
1566 93485 }
1567
1568 static av_always_inline
1569 431129 void backup_mb_border(uint8_t *top_border, const uint8_t *src_y,
1570 const uint8_t *src_cb, const uint8_t *src_cr,
1571 ptrdiff_t linesize, ptrdiff_t uvlinesize, int simple)
1572 {
1573 431129 AV_COPY128(top_border, src_y + 15 * linesize);
1574
2/2
✓ Branch 0 taken 423407 times.
✓ Branch 1 taken 7722 times.
431129 if (!simple) {
1575 423407 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
1576 423407 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
1577 }
1578 431129 }
1579
1580 static av_always_inline
1581 96048 void xchg_mb_border(uint8_t *top_border, uint8_t *src_y, uint8_t *src_cb,
1582 uint8_t *src_cr, ptrdiff_t linesize, ptrdiff_t uvlinesize, int mb_x,
1583 int mb_y, int mb_width, int simple, int xchg)
1584 {
1585 96048 uint8_t *top_border_m1 = top_border - 32; // for TL prediction
1586 96048 src_y -= linesize;
1587 96048 src_cb -= uvlinesize;
1588 96048 src_cr -= uvlinesize;
1589
1590 #define XCHG(a, b, xchg) \
1591 do { \
1592 if (xchg) \
1593 AV_SWAP64(b, a); \
1594 else \
1595 AV_COPY64(b, a); \
1596 } while (0)
1597
1598
2/2
✓ Branch 0 taken 48024 times.
✓ Branch 1 taken 48024 times.
96048 XCHG(top_border_m1 + 8, src_y - 8, xchg);
1599
2/2
✓ Branch 0 taken 48024 times.
✓ Branch 1 taken 48024 times.
96048 XCHG(top_border, src_y, xchg);
1600 96048 XCHG(top_border + 8, src_y + 8, 1);
1601
2/2
✓ Branch 0 taken 92012 times.
✓ Branch 1 taken 4036 times.
96048 if (mb_x < mb_width - 1)
1602 92012 XCHG(top_border + 32, src_y + 16, 1);
1603
1604 // only copy chroma for normal loop filter
1605 // or to initialize the top row to 127
1606
3/4
✓ Branch 0 taken 3082 times.
✓ Branch 1 taken 92966 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3082 times.
96048 if (!simple || !mb_y) {
1607
2/2
✓ Branch 0 taken 46483 times.
✓ Branch 1 taken 46483 times.
92966 XCHG(top_border_m1 + 16, src_cb - 8, xchg);
1608
2/2
✓ Branch 0 taken 46483 times.
✓ Branch 1 taken 46483 times.
92966 XCHG(top_border_m1 + 24, src_cr - 8, xchg);
1609 92966 XCHG(top_border + 16, src_cb, 1);
1610 92966 XCHG(top_border + 24, src_cr, 1);
1611 }
1612 96048 }
1613
1614 static av_always_inline
1615 84850 int check_dc_pred8x8_mode(int mode, int mb_x, int mb_y)
1616 {
1617
2/2
✓ Branch 0 taken 3934 times.
✓ Branch 1 taken 80916 times.
84850 if (!mb_x)
1618
2/2
✓ Branch 0 taken 3656 times.
✓ Branch 1 taken 278 times.
3934 return mb_y ? TOP_DC_PRED8x8 : DC_128_PRED8x8;
1619 else
1620
2/2
✓ Branch 0 taken 74505 times.
✓ Branch 1 taken 6411 times.
80916 return mb_y ? mode : LEFT_DC_PRED8x8;
1621 }
1622
1623 static av_always_inline
1624 2089 int check_tm_pred8x8_mode(int mode, int mb_x, int mb_y, int vp7)
1625 {
1626
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2088 times.
2089 if (!mb_x)
1627
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 return mb_y ? VERT_PRED8x8 : (vp7 ? DC_128_PRED8x8 : DC_129_PRED8x8);
1628 else
1629
2/2
✓ Branch 0 taken 2083 times.
✓ Branch 1 taken 5 times.
2088 return mb_y ? mode : HOR_PRED8x8;
1630 }
1631
1632 static av_always_inline
1633 112005 int check_intra_pred8x8_mode_emuedge(int mode, int mb_x, int mb_y, int vp7)
1634 {
1635
4/5
✓ Branch 0 taken 84850 times.
✓ Branch 1 taken 6931 times.
✓ Branch 2 taken 18135 times.
✓ Branch 3 taken 2089 times.
✗ Branch 4 not taken.
112005 switch (mode) {
1636 84850 case DC_PRED8x8:
1637 84850 return check_dc_pred8x8_mode(mode, mb_x, mb_y);
1638 6931 case VERT_PRED8x8:
1639
3/4
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 6810 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 121 times.
6931 return !mb_y ? (vp7 ? DC_128_PRED8x8 : DC_127_PRED8x8) : mode;
1640 18135 case HOR_PRED8x8:
1641
3/4
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 17961 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 174 times.
18135 return !mb_x ? (vp7 ? DC_128_PRED8x8 : DC_129_PRED8x8) : mode;
1642 2089 case PLANE_PRED8x8: /* TM */
1643 2089 return check_tm_pred8x8_mode(mode, mb_x, mb_y, vp7);
1644 }
1645 ✗ return mode;
1646 }
1647
1648 static av_always_inline
1649 56229 int check_tm_pred4x4_mode(int mode, int mb_x, int mb_y, int vp7)
1650 {
1651
2/2
✓ Branch 0 taken 1669 times.
✓ Branch 1 taken 54560 times.
56229 if (!mb_x) {
1652
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1668 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1669 return mb_y ? VERT_VP8_PRED : (vp7 ? DC_128_PRED : DC_129_PRED);
1653 } else {
1654
2/2
✓ Branch 0 taken 52551 times.
✓ Branch 1 taken 2009 times.
54560 return mb_y ? mode : HOR_VP8_PRED;
1655 }
1656 }
1657
1658 static av_always_inline
1659 356272 int check_intra_pred4x4_mode_emuedge(int mode, int mb_x, int mb_y,
1660 int *copy_buf, int vp7)
1661 {
1662
6/7
✓ Branch 0 taken 15143 times.
✓ Branch 1 taken 26909 times.
✓ Branch 2 taken 22944 times.
✓ Branch 3 taken 16504 times.
✓ Branch 4 taken 56229 times.
✓ Branch 5 taken 218543 times.
✗ Branch 6 not taken.
356272 switch (mode) {
1663 15143 case VERT_PRED:
1664
3/4
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 15026 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
15143 if (!mb_x && mb_y) {
1665 117 *copy_buf = 1;
1666 117 return mode;
1667 }
1668 av_fallthrough;
1669 case DIAG_DOWN_LEFT_PRED:
1670 case VERT_LEFT_PRED:
1671
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 41911 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
41935 return !mb_y ? (vp7 ? DC_128_PRED : DC_127_PRED) : mode;
1672 22944 case HOR_PRED:
1673
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 22806 times.
22944 if (!mb_y) {
1674 138 *copy_buf = 1;
1675 138 return mode;
1676 }
1677 av_fallthrough;
1678 case HOR_UP_PRED:
1679
3/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 39262 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
39310 return !mb_x ? (vp7 ? DC_128_PRED : DC_129_PRED) : mode;
1680 56229 case TM_VP8_PRED:
1681 56229 return check_tm_pred4x4_mode(mode, mb_x, mb_y, vp7);
1682 218543 case DC_PRED: /* 4x4 DC doesn't use the same "H.264-style" exceptions
1683 * as 16x16/8x8 DC */
1684 case DIAG_DOWN_RIGHT_PRED:
1685 case VERT_RIGHT_PRED:
1686 case HOR_DOWN_PRED:
1687
4/4
✓ Branch 0 taken 217892 times.
✓ Branch 1 taken 651 times.
✓ Branch 2 taken 666 times.
✓ Branch 3 taken 217226 times.
218543 if (!mb_y || !mb_x)
1688 1317 *copy_buf = 1;
1689 218543 return mode;
1690 }
1691 ✗ return mode;
1692 }
1693
1694 static av_always_inline
1695 67136 void intra_predict(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3],
1696 VP8Macroblock *mb, int mb_x, int mb_y, int is_vp7)
1697 {
1698 int x, y, mode, nnz;
1699 uint32_t tr;
1700
1701 /* for the first row, we need to run xchg_mb_border to init the top edge
1702 * to 127 otherwise, skip it if we aren't going to deblock */
1703
6/8
✓ Branch 0 taken 63023 times.
✓ Branch 1 taken 4113 times.
✓ Branch 2 taken 14999 times.
✓ Branch 3 taken 48024 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14999 times.
✓ Branch 6 taken 48024 times.
✗ Branch 7 not taken.
67136 if (mb_y && (s->deblock_filter || !mb_y) && td->thread_nr == 0)
1704 48024 xchg_mb_border(s->top_border[mb_x + 1], dst[0], dst[1], dst[2],
1705 48024 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
1706 48024 s->filter.simple, 1);
1707
1708
2/2
✓ Branch 0 taken 44869 times.
✓ Branch 1 taken 22267 times.
67136 if (mb->mode < MODE_I4x4) {
1709 44869 mode = check_intra_pred8x8_mode_emuedge(mb->mode, mb_x, mb_y, is_vp7);
1710 44869 s->hpc.pred16x16[mode](dst[0], s->linesize);
1711 } else {
1712 22267 uint8_t *ptr = dst[0];
1713 22267 const uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb;
1714
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 22234 times.
22267 const uint8_t lo = is_vp7 ? 128 : 127;
1715
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 22234 times.
22267 const uint8_t hi = is_vp7 ? 128 : 129;
1716 22267 const uint8_t tr_top[4] = { lo, lo, lo, lo };
1717
1718 // all blocks on the right edge of the macroblock use bottom edge
1719 // the top macroblock for their topright edge
1720 22267 const uint8_t *tr_right = ptr - s->linesize + 16;
1721
1722 // if we're on the right edge of the frame, said edge is extended
1723 // from the top macroblock
1724
4/4
✓ Branch 0 taken 21454 times.
✓ Branch 1 taken 813 times.
✓ Branch 2 taken 743 times.
✓ Branch 3 taken 20711 times.
22267 if (mb_y && mb_x == s->mb_width - 1) {
1725 743 tr = tr_right[-1] * 0x01010101u;
1726 743 tr_right = (uint8_t *) &tr;
1727 }
1728
1729
2/2
✓ Branch 0 taken 491 times.
✓ Branch 1 taken 21776 times.
22267 if (mb->skip)
1730 491 AV_ZERO128(td->non_zero_count_cache);
1731
1732
2/2
✓ Branch 0 taken 89068 times.
✓ Branch 1 taken 22267 times.
111335 for (y = 0; y < 4; y++) {
1733 89068 const uint8_t *topright = ptr + 4 - s->linesize;
1734
2/2
✓ Branch 0 taken 356272 times.
✓ Branch 1 taken 89068 times.
445340 for (x = 0; x < 4; x++) {
1735 356272 int copy = 0;
1736 356272 ptrdiff_t linesize = s->linesize;
1737 356272 uint8_t *dst = ptr + 4 * x;
1738 356272 LOCAL_ALIGNED(4, uint8_t, copy_dst, [5 * 8]);
1739
1740
6/6
✓ Branch 0 taken 267204 times.
✓ Branch 1 taken 89068 times.
✓ Branch 2 taken 66801 times.
✓ Branch 3 taken 200403 times.
✓ Branch 4 taken 5691 times.
✓ Branch 5 taken 150178 times.
356272 if ((y == 0 || x == 3) && mb_y == 0) {
1741 5691 topright = tr_top;
1742
2/2
✓ Branch 0 taken 85816 times.
✓ Branch 1 taken 264765 times.
350581 } else if (x == 3)
1743 85816 topright = tr_right;
1744
1745 356272 mode = check_intra_pred4x4_mode_emuedge(intra4x4[x], mb_x + x,
1746 mb_y + y, &copy, is_vp7);
1747
2/2
✓ Branch 0 taken 1572 times.
✓ Branch 1 taken 354700 times.
356272 if (copy) {
1748 1572 dst = copy_dst + 12;
1749 1572 linesize = 8;
1750
2/2
✓ Branch 0 taken 789 times.
✓ Branch 1 taken 783 times.
1572 if (!(mb_y + y)) {
1751 789 copy_dst[3] = lo;
1752 789 AV_WN32A(copy_dst + 4, lo * 0x01010101U);
1753 } else {
1754 783 AV_COPY32(copy_dst + 4, ptr + 4 * x - s->linesize);
1755
1/2
✓ Branch 0 taken 783 times.
✗ Branch 1 not taken.
783 if (!(mb_x + x)) {
1756 783 copy_dst[3] = hi;
1757 } else {
1758 ✗ copy_dst[3] = ptr[4 * x - s->linesize - 1];
1759 }
1760 }
1761
2/2
✓ Branch 0 taken 829 times.
✓ Branch 1 taken 743 times.
1572 if (!(mb_x + x)) {
1762 829 copy_dst[11] =
1763 829 copy_dst[19] =
1764 829 copy_dst[27] =
1765 829 copy_dst[35] = hi;
1766 } else {
1767 743 copy_dst[11] = ptr[4 * x - 1];
1768 743 copy_dst[19] = ptr[4 * x + s->linesize - 1];
1769 743 copy_dst[27] = ptr[4 * x + s->linesize * 2 - 1];
1770 743 copy_dst[35] = ptr[4 * x + s->linesize * 3 - 1];
1771 }
1772 }
1773 356272 s->hpc.pred4x4[mode](dst, topright, linesize);
1774
2/2
✓ Branch 0 taken 1572 times.
✓ Branch 1 taken 354700 times.
356272 if (copy) {
1775 1572 AV_COPY32(ptr + 4 * x, copy_dst + 12);
1776 1572 AV_COPY32(ptr + 4 * x + s->linesize, copy_dst + 20);
1777 1572 AV_COPY32(ptr + 4 * x + s->linesize * 2, copy_dst + 28);
1778 1572 AV_COPY32(ptr + 4 * x + s->linesize * 3, copy_dst + 36);
1779 }
1780
1781 356272 nnz = td->non_zero_count_cache[y][x];
1782
2/2
✓ Branch 0 taken 151777 times.
✓ Branch 1 taken 204495 times.
356272 if (nnz) {
1783
2/2
✓ Branch 0 taken 38846 times.
✓ Branch 1 taken 112931 times.
151777 if (nnz == 1)
1784 38846 s->vp8dsp.vp8_idct_dc_add(ptr + 4 * x,
1785 38846 td->block[y][x], s->linesize);
1786 else
1787 112931 s->vp8dsp.vp8_idct_add(ptr + 4 * x,
1788 112931 td->block[y][x], s->linesize);
1789 }
1790 356272 topright += 4;
1791 }
1792
1793 89068 ptr += 4 * s->linesize;
1794 89068 intra4x4 += 4;
1795 }
1796 }
1797
1798 67136 mode = check_intra_pred8x8_mode_emuedge(mb->chroma_pred_mode,
1799 mb_x, mb_y, is_vp7);
1800 67136 s->hpc.pred8x8[mode](dst[1], s->uvlinesize);
1801 67136 s->hpc.pred8x8[mode](dst[2], s->uvlinesize);
1802
1803
6/8
✓ Branch 0 taken 63023 times.
✓ Branch 1 taken 4113 times.
✓ Branch 2 taken 14999 times.
✓ Branch 3 taken 48024 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14999 times.
✓ Branch 6 taken 48024 times.
✗ Branch 7 not taken.
67136 if (mb_y && (s->deblock_filter || !mb_y) && td->thread_nr == 0)
1804 48024 xchg_mb_border(s->top_border[mb_x + 1], dst[0], dst[1], dst[2],
1805 48024 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
1806 48024 s->filter.simple, 0);
1807 67136 }
1808
1809 static const uint8_t subpel_idx[3][8] = {
1810 { 0, 1, 2, 1, 2, 1, 2, 1 }, // nr. of left extra pixels,
1811 // also function pointer index
1812 { 0, 3, 5, 3, 5, 3, 5, 3 }, // nr. of extra pixels required
1813 { 0, 2, 3, 2, 3, 2, 3, 2 }, // nr. of right extra pixels
1814 };
1815
1816 /**
1817 * luma MC function
1818 *
1819 * @param s VP8 decoding context
1820 * @param dst target buffer for block data at block position
1821 * @param ref reference picture buffer at origin (0, 0)
1822 * @param mv motion vector (relative to block position) to get pixel data from
1823 * @param x_off horizontal position of block from origin (0, 0)
1824 * @param y_off vertical position of block from origin (0, 0)
1825 * @param block_w width of block (16, 8 or 4)
1826 * @param block_h height of block (always same as block_w)
1827 * @param width width of src/dst plane data
1828 * @param height height of src/dst plane data
1829 * @param linesize size of a single line of plane data, including padding
1830 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
1831 */
1832 static av_always_inline
1833 504659 void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst,
1834 const ProgressFrame *ref, const VP8mv *mv,
1835 int x_off, int y_off, int block_w, int block_h,
1836 int width, int height, ptrdiff_t linesize,
1837 vp8_mc_func mc_func[3][3])
1838 {
1839 504659 const uint8_t *src = ref->f->data[0];
1840
1841
2/2
✓ Branch 0 taken 124899 times.
✓ Branch 1 taken 379760 times.
504659 if (AV_RN32A(mv)) {
1842 124899 ptrdiff_t src_linesize = linesize;
1843
1844 124899 int mx = (mv->x * 2) & 7, mx_idx = subpel_idx[0][mx];
1845 124899 int my = (mv->y * 2) & 7, my_idx = subpel_idx[0][my];
1846
1847 124899 x_off += mv->x >> 2;
1848 124899 y_off += mv->y >> 2;
1849
1850 // edge emulation
1851 124899 ff_progress_frame_await(ref, FFMAX((3 + y_off + block_h + subpel_idx[2][my]) >> 4, 0));
1852 124899 src += y_off * linesize + x_off;
1853
6/6
✓ Branch 0 taken 123700 times.
✓ Branch 1 taken 1199 times.
✓ Branch 2 taken 120199 times.
✓ Branch 3 taken 3501 times.
✓ Branch 4 taken 118706 times.
✓ Branch 5 taken 1493 times.
124899 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
1854
2/2
✓ Branch 0 taken 3043 times.
✓ Branch 1 taken 115663 times.
118706 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
1855 9236 s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
1856 9236 src - my_idx * linesize - mx_idx,
1857 EDGE_EMU_LINESIZE, linesize,
1858 9236 block_w + subpel_idx[1][mx],
1859 9236 block_h + subpel_idx[1][my],
1860 x_off - mx_idx, y_off - my_idx,
1861 width, height);
1862 9236 src = td->edge_emu_buffer + mx_idx + EDGE_EMU_LINESIZE * my_idx;
1863 9236 src_linesize = EDGE_EMU_LINESIZE;
1864 }
1865 124899 mc_func[my_idx][mx_idx](dst, linesize, src, src_linesize, block_h, mx, my);
1866 } else {
1867 379760 ff_progress_frame_await(ref, (3 + y_off + block_h) >> 4);
1868 379760 mc_func[0][0](dst, linesize, src + y_off * linesize + x_off,
1869 linesize, block_h, 0, 0);
1870 }
1871 504659 }
1872
1873 /**
1874 * chroma MC function
1875 *
1876 * @param s VP8 decoding context
1877 * @param dst1 target buffer for block data at block position (U plane)
1878 * @param dst2 target buffer for block data at block position (V plane)
1879 * @param ref reference picture buffer at origin (0, 0)
1880 * @param mv motion vector (relative to block position) to get pixel data from
1881 * @param x_off horizontal position of block from origin (0, 0)
1882 * @param y_off vertical position of block from origin (0, 0)
1883 * @param block_w width of block (16, 8 or 4)
1884 * @param block_h height of block (always same as block_w)
1885 * @param width width of src/dst plane data
1886 * @param height height of src/dst plane data
1887 * @param linesize size of a single line of plane data, including padding
1888 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
1889 */
1890 static av_always_inline
1891 425279 void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1,
1892 uint8_t *dst2, const ProgressFrame *ref, const VP8mv *mv,
1893 int x_off, int y_off, int block_w, int block_h,
1894 int width, int height, ptrdiff_t linesize,
1895 vp8_mc_func mc_func[3][3])
1896 {
1897 425279 const uint8_t *src1 = ref->f->data[1], *src2 = ref->f->data[2];
1898
1899
2/2
✓ Branch 0 taken 79190 times.
✓ Branch 1 taken 346089 times.
425279 if (AV_RN32A(mv)) {
1900 79190 int mx = mv->x & 7, mx_idx = subpel_idx[0][mx];
1901 79190 int my = mv->y & 7, my_idx = subpel_idx[0][my];
1902
1903 79190 x_off += mv->x >> 3;
1904 79190 y_off += mv->y >> 3;
1905
1906 // edge emulation
1907 79190 src1 += y_off * linesize + x_off;
1908 79190 src2 += y_off * linesize + x_off;
1909 79190 ff_progress_frame_await(ref, FFMAX((3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0));
1910
6/6
✓ Branch 0 taken 77874 times.
✓ Branch 1 taken 1316 times.
✓ Branch 2 taken 74583 times.
✓ Branch 3 taken 3291 times.
✓ Branch 4 taken 73050 times.
✓ Branch 5 taken 1533 times.
79190 if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
1911
2/2
✓ Branch 0 taken 3017 times.
✓ Branch 1 taken 70033 times.
73050 y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
1912 9157 s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
1913 9157 src1 - my_idx * linesize - mx_idx,
1914 EDGE_EMU_LINESIZE, linesize,
1915 9157 block_w + subpel_idx[1][mx],
1916 9157 block_h + subpel_idx[1][my],
1917 x_off - mx_idx, y_off - my_idx, width, height);
1918 9157 src1 = td->edge_emu_buffer + mx_idx + EDGE_EMU_LINESIZE * my_idx;
1919 9157 mc_func[my_idx][mx_idx](dst1, linesize, src1, EDGE_EMU_LINESIZE, block_h, mx, my);
1920
1921 9157 s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
1922 9157 src2 - my_idx * linesize - mx_idx,
1923 EDGE_EMU_LINESIZE, linesize,
1924 9157 block_w + subpel_idx[1][mx],
1925 9157 block_h + subpel_idx[1][my],
1926 x_off - mx_idx, y_off - my_idx, width, height);
1927 9157 src2 = td->edge_emu_buffer + mx_idx + EDGE_EMU_LINESIZE * my_idx;
1928 9157 mc_func[my_idx][mx_idx](dst2, linesize, src2, EDGE_EMU_LINESIZE, block_h, mx, my);
1929 } else {
1930 70033 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1931 70033 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1932 }
1933 } else {
1934 346089 ff_progress_frame_await(ref, (3 + y_off + block_h) >> 3);
1935 346089 mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1936 346089 mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1937 }
1938 425279 }
1939
1940 static av_always_inline
1941 398819 void vp8_mc_part(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3],
1942 const ProgressFrame *ref_frame, int x_off, int y_off,
1943 int bx_off, int by_off, int block_w, int block_h,
1944 int width, int height, const VP8mv *mv)
1945 {
1946 398819 VP8mv uvmv = *mv;
1947
1948 /* Y */
1949 398819 vp8_mc_luma(s, td, dst[0] + by_off * s->linesize + bx_off,
1950 ref_frame, mv, x_off + bx_off, y_off + by_off,
1951 block_w, block_h, width, height, s->linesize,
1952 398819 s->put_pixels_tab[block_w == 8]);
1953
1954 /* U/V */
1955
2/2
✓ Branch 0 taken 4775 times.
✓ Branch 1 taken 394044 times.
398819 if (s->profile == 3) {
1956 /* this block only applies VP8; it is safe to check
1957 * only the profile, as VP7 profile <= 1 */
1958 4775 uvmv.x &= ~7;
1959 4775 uvmv.y &= ~7;
1960 }
1961 398819 x_off >>= 1;
1962 398819 y_off >>= 1;
1963 398819 bx_off >>= 1;
1964 398819 by_off >>= 1;
1965 398819 width >>= 1;
1966 398819 height >>= 1;
1967 398819 block_w >>= 1;
1968 398819 block_h >>= 1;
1969 398819 vp8_mc_chroma(s, td, dst[1] + by_off * s->uvlinesize + bx_off,
1970 398819 dst[2] + by_off * s->uvlinesize + bx_off, ref_frame,
1971 &uvmv, x_off + bx_off, y_off + by_off,
1972 block_w, block_h, width, height, s->uvlinesize,
1973
2/2
✓ Branch 0 taken 20950 times.
✓ Branch 1 taken 377869 times.
398819 s->put_pixels_tab[1 + (block_w == 4)]);
1974 398819 }
1975
1976 /* Fetch pixels for estimated mv 4 macroblocks ahead.
1977 * Optimized for 64-byte cache lines. Inspired by ffh264 prefetch_motion. */
1978 static av_always_inline
1979 1360545 void prefetch_motion(const VP8Context *s, const VP8Macroblock *mb,
1980 int mb_x, int mb_y, int mb_xy, int ref)
1981 {
1982 /* Don't prefetch refs that haven't been used very often this frame. */
1983
2/2
✓ Branch 0 taken 479331 times.
✓ Branch 1 taken 881214 times.
1360545 if (s->ref_count[ref - 1] > (mb_xy >> 5)) {
1984 479331 int x_off = mb_x << 4, y_off = mb_y << 4;
1985 479331 int mx = (mb->mv.x >> 2) + x_off + 8;
1986 479331 int my = (mb->mv.y >> 2) + y_off;
1987 479331 uint8_t **src = s->framep[ref]->tf.f->data;
1988 479331 int off = mx + (my + (mb_x & 3) * 4) * s->linesize + 64;
1989 /* For threading, a ff_thread_await_progress here might be useful, but
1990 * it actually slows down the decoder. Since a bad prefetch doesn't
1991 * generate bad decoder output, we don't run it here. */
1992 479331 s->vdsp.prefetch(src[0] + off, s->linesize, 4);
1993 479331 off = (mx >> 1) + ((my >> 1) + (mb_x & 7)) * s->uvlinesize + 64;
1994 479331 s->vdsp.prefetch(src[1] + off, src[2] - src[1], 2);
1995 }
1996 1360545 }
1997
1998 /**
1999 * Apply motion vectors to prediction buffer, chapter 18.
2000 */
2001 static av_always_inline
2002 386379 void inter_predict(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3],
2003 VP8Macroblock *mb, int mb_x, int mb_y)
2004 {
2005 386379 int x_off = mb_x << 4, y_off = mb_y << 4;
2006 386379 int width = 16 * s->mb_width, height = 16 * s->mb_height;
2007 386379 const ProgressFrame *ref = &s->framep[mb->ref_frame]->tf;
2008 386379 const VP8mv *bmv = mb->bmv;
2009
2010
5/6
✓ Branch 0 taken 368049 times.
✓ Branch 1 taken 6615 times.
✓ Branch 2 taken 4910 times.
✓ Branch 3 taken 3135 times.
✓ Branch 4 taken 3670 times.
✗ Branch 5 not taken.
386379 switch (mb->partitioning) {
2011 368049 case VP8_SPLITMVMODE_NONE:
2012 368049 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2013 368049 0, 0, 16, 16, width, height, &mb->mv);
2014 368049 break;
2015 6615 case VP8_SPLITMVMODE_4x4: {
2016 int x, y;
2017 VP8mv uvmv;
2018
2019 /* Y */
2020
2/2
✓ Branch 0 taken 26460 times.
✓ Branch 1 taken 6615 times.
33075 for (y = 0; y < 4; y++) {
2021
2/2
✓ Branch 0 taken 105840 times.
✓ Branch 1 taken 26460 times.
132300 for (x = 0; x < 4; x++) {
2022 105840 vp8_mc_luma(s, td, dst[0] + 4 * y * s->linesize + x * 4,
2023 105840 ref, &bmv[4 * y + x],
2024 105840 4 * x + x_off, 4 * y + y_off, 4, 4,
2025 width, height, s->linesize,
2026 105840 s->put_pixels_tab[2]);
2027 }
2028 }
2029
2030 /* U/V */
2031 6615 x_off >>= 1;
2032 6615 y_off >>= 1;
2033 6615 width >>= 1;
2034 6615 height >>= 1;
2035
2/2
✓ Branch 0 taken 13230 times.
✓ Branch 1 taken 6615 times.
19845 for (y = 0; y < 2; y++) {
2036
2/2
✓ Branch 0 taken 26460 times.
✓ Branch 1 taken 13230 times.
39690 for (x = 0; x < 2; x++) {
2037 26460 uvmv.x = mb->bmv[2 * y * 4 + 2 * x ].x +
2038 26460 mb->bmv[2 * y * 4 + 2 * x + 1].x +
2039 26460 mb->bmv[(2 * y + 1) * 4 + 2 * x ].x +
2040 26460 mb->bmv[(2 * y + 1) * 4 + 2 * x + 1].x;
2041 26460 uvmv.y = mb->bmv[2 * y * 4 + 2 * x ].y +
2042 26460 mb->bmv[2 * y * 4 + 2 * x + 1].y +
2043 26460 mb->bmv[(2 * y + 1) * 4 + 2 * x ].y +
2044 26460 mb->bmv[(2 * y + 1) * 4 + 2 * x + 1].y;
2045 26460 uvmv.x = (uvmv.x + 2 + FF_SIGNBIT(uvmv.x)) >> 2;
2046 26460 uvmv.y = (uvmv.y + 2 + FF_SIGNBIT(uvmv.y)) >> 2;
2047
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 25968 times.
26460 if (s->profile == 3) {
2048 492 uvmv.x &= ~7;
2049 492 uvmv.y &= ~7;
2050 }
2051 26460 vp8_mc_chroma(s, td, dst[1] + 4 * y * s->uvlinesize + x * 4,
2052 26460 dst[2] + 4 * y * s->uvlinesize + x * 4, ref,
2053 26460 &uvmv, 4 * x + x_off, 4 * y + y_off, 4, 4,
2054 width, height, s->uvlinesize,
2055 26460 s->put_pixels_tab[2]);
2056 }
2057 }
2058 6615 break;
2059 }
2060 4910 case VP8_SPLITMVMODE_16x8:
2061 4910 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2062 0, 0, 16, 8, width, height, &bmv[0]);
2063 4910 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2064 0, 8, 16, 8, width, height, &bmv[1]);
2065 4910 break;
2066 3135 case VP8_SPLITMVMODE_8x16:
2067 3135 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2068 0, 0, 8, 16, width, height, &bmv[0]);
2069 3135 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2070 8, 0, 8, 16, width, height, &bmv[1]);
2071 3135 break;
2072 3670 case VP8_SPLITMVMODE_8x8:
2073 3670 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2074 0, 0, 8, 8, width, height, &bmv[0]);
2075 3670 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2076 8, 0, 8, 8, width, height, &bmv[1]);
2077 3670 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2078 0, 8, 8, 8, width, height, &bmv[2]);
2079 3670 vp8_mc_part(s, td, dst, ref, x_off, y_off,
2080 8, 8, 8, 8, width, height, &bmv[3]);
2081 3670 break;
2082 }
2083 386379 }
2084
2085 static av_always_inline
2086 82374 void idct_mb(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3],
2087 const VP8Macroblock *mb)
2088 {
2089 int x, y, ch;
2090
2091
2/2
✓ Branch 0 taken 60598 times.
✓ Branch 1 taken 21776 times.
82374 if (mb->mode != MODE_I4x4) {
2092 60598 uint8_t *y_dst = dst[0];
2093
2/2
✓ Branch 0 taken 242392 times.
✓ Branch 1 taken 60598 times.
302990 for (y = 0; y < 4; y++) {
2094 242392 uint32_t nnz4 = AV_RL32(td->non_zero_count_cache[y]);
2095
2/2
✓ Branch 0 taken 178464 times.
✓ Branch 1 taken 63928 times.
242392 if (nnz4) {
2096
2/2
✓ Branch 0 taken 45187 times.
✓ Branch 1 taken 133277 times.
178464 if (nnz4 & ~0x01010101) {
2097
1/2
✓ Branch 0 taken 157052 times.
✗ Branch 1 not taken.
157052 for (x = 0; x < 4; x++) {
2098
2/2
✓ Branch 0 taken 54457 times.
✓ Branch 1 taken 102595 times.
157052 if ((uint8_t) nnz4 == 1)
2099 54457 s->vp8dsp.vp8_idct_dc_add(y_dst + 4 * x,
2100 54457 td->block[y][x],
2101 s->linesize);
2102
2/2
✓ Branch 0 taken 75043 times.
✓ Branch 1 taken 27552 times.
102595 else if ((uint8_t) nnz4 > 1)
2103 75043 s->vp8dsp.vp8_idct_add(y_dst + 4 * x,
2104 75043 td->block[y][x],
2105 s->linesize);
2106 157052 nnz4 >>= 8;
2107
2/2
✓ Branch 0 taken 45187 times.
✓ Branch 1 taken 111865 times.
157052 if (!nnz4)
2108 45187 break;
2109 }
2110 } else {
2111 133277 s->vp8dsp.vp8_idct_dc_add4y(y_dst, td->block[y], s->linesize);
2112 }
2113 }
2114 242392 y_dst += 4 * s->linesize;
2115 }
2116 }
2117
2118
2/2
✓ Branch 0 taken 164748 times.
✓ Branch 1 taken 82374 times.
247122 for (ch = 0; ch < 2; ch++) {
2119 164748 uint32_t nnz4 = AV_RL32(td->non_zero_count_cache[4 + ch]);
2120
2/2
✓ Branch 0 taken 96081 times.
✓ Branch 1 taken 68667 times.
164748 if (nnz4) {
2121 68667 uint8_t *ch_dst = dst[1 + ch];
2122
2/2
✓ Branch 0 taken 37407 times.
✓ Branch 1 taken 31260 times.
68667 if (nnz4 & ~0x01010101) {
2123
1/2
✓ Branch 0 taken 69665 times.
✗ Branch 1 not taken.
69665 for (y = 0; y < 2; y++) {
2124
2/2
✓ Branch 0 taken 134125 times.
✓ Branch 1 taken 32258 times.
166383 for (x = 0; x < 2; x++) {
2125
2/2
✓ Branch 0 taken 21507 times.
✓ Branch 1 taken 112618 times.
134125 if ((uint8_t) nnz4 == 1)
2126 21507 s->vp8dsp.vp8_idct_dc_add(ch_dst + 4 * x,
2127 21507 td->block[4 + ch][(y << 1) + x],
2128 s->uvlinesize);
2129
2/2
✓ Branch 0 taken 83822 times.
✓ Branch 1 taken 28796 times.
112618 else if ((uint8_t) nnz4 > 1)
2130 83822 s->vp8dsp.vp8_idct_add(ch_dst + 4 * x,
2131 83822 td->block[4 + ch][(y << 1) + x],
2132 s->uvlinesize);
2133 134125 nnz4 >>= 8;
2134
2/2
✓ Branch 0 taken 37407 times.
✓ Branch 1 taken 96718 times.
134125 if (!nnz4)
2135 37407 goto chroma_idct_end;
2136 }
2137 32258 ch_dst += 4 * s->uvlinesize;
2138 }
2139 } else {
2140 31260 s->vp8dsp.vp8_idct_dc_add4uv(ch_dst, td->block[4 + ch], s->uvlinesize);
2141 }
2142 }
2143 164748 chroma_idct_end:
2144 ;
2145 }
2146 82374 }
2147
2148 static av_always_inline
2149 431129 void filter_level_for_mb(const VP8Context *s, const VP8Macroblock *mb,
2150 VP8FilterStrength *f, int is_vp7)
2151 {
2152 int interior_limit, filter_level;
2153
2154
2/2
✓ Branch 0 taken 108519 times.
✓ Branch 1 taken 322610 times.
431129 if (s->segmentation.enabled) {
2155 108519 filter_level = s->segmentation.filter_level[mb->segment];
2156
2/2
✓ Branch 0 taken 98895 times.
✓ Branch 1 taken 9624 times.
108519 if (!s->segmentation.absolute_vals)
2157 98895 filter_level += s->filter.level;
2158 } else
2159 322610 filter_level = s->filter.level;
2160
2161
2/2
✓ Branch 0 taken 417035 times.
✓ Branch 1 taken 14094 times.
431129 if (s->lf_delta.enabled) {
2162 417035 filter_level += s->lf_delta.ref[mb->ref_frame];
2163 417035 filter_level += s->lf_delta.mode[mb->mode];
2164 }
2165
2166 431129 filter_level = av_clip_uintp2(filter_level, 6);
2167
2168 431129 interior_limit = filter_level;
2169
2/2
✓ Branch 0 taken 2772 times.
✓ Branch 1 taken 428357 times.
431129 if (s->filter.sharpness) {
2170 2772 interior_limit >>= (s->filter.sharpness + 3) >> 2;
2171 2772 interior_limit = FFMIN(interior_limit, 9 - s->filter.sharpness);
2172 }
2173 431129 interior_limit = FFMAX(interior_limit, 1);
2174
2175 431129 f->filter_level = filter_level;
2176 431129 f->inner_limit = interior_limit;
2177
6/6
✓ Branch 0 taken 424089 times.
✓ Branch 1 taken 7040 times.
✓ Branch 2 taken 356169 times.
✓ Branch 3 taken 67920 times.
✓ Branch 4 taken 355873 times.
✓ Branch 5 taken 296 times.
787002 f->inner_filter = is_vp7 || !mb->skip || mb->mode == MODE_I4x4 ||
2178
2/2
✓ Branch 0 taken 3237 times.
✓ Branch 1 taken 352636 times.
355873 mb->mode == VP8_MVMODE_SPLIT;
2179 431129 }
2180
2181 static av_always_inline
2182 423407 void filter_mb(const VP8Context *s, uint8_t *const dst[3], const VP8FilterStrength *f,
2183 int mb_x, int mb_y, int is_vp7)
2184 {
2185 int mbedge_lim, bedge_lim_y, bedge_lim_uv, hev_thresh;
2186 423407 int filter_level = f->filter_level;
2187 423407 int inner_limit = f->inner_limit;
2188 423407 int inner_filter = f->inner_filter;
2189 423407 ptrdiff_t linesize = s->linesize;
2190 423407 ptrdiff_t uvlinesize = s->uvlinesize;
2191 static const uint8_t hev_thresh_lut[2][64] = {
2192 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
2193 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2194 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2195 3, 3, 3, 3 },
2196 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
2197 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2198 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2199 2, 2, 2, 2 }
2200 };
2201
2202
2/2
✓ Branch 0 taken 5876 times.
✓ Branch 1 taken 417531 times.
423407 if (!filter_level)
2203 5876 return;
2204
2205
2/2
✓ Branch 0 taken 7040 times.
✓ Branch 1 taken 410491 times.
417531 if (is_vp7) {
2206 7040 bedge_lim_y = filter_level;
2207 7040 bedge_lim_uv = filter_level * 2;
2208 7040 mbedge_lim = filter_level + 2;
2209 } else {
2210 410491 bedge_lim_y =
2211 410491 bedge_lim_uv = filter_level * 2 + inner_limit;
2212 410491 mbedge_lim = bedge_lim_y + 4;
2213 }
2214
2215 417531 hev_thresh = hev_thresh_lut[s->keyframe][filter_level];
2216
2217
2/2
✓ Branch 0 taken 403073 times.
✓ Branch 1 taken 14458 times.
417531 if (mb_x) {
2218 403073 s->vp8dsp.vp8_h_loop_filter16y(dst[0], linesize,
2219 mbedge_lim, inner_limit, hev_thresh);
2220 403073 s->vp8dsp.vp8_h_loop_filter8uv(dst[1], dst[2], uvlinesize,
2221 mbedge_lim, inner_limit, hev_thresh);
2222 }
2223
2224 #define H_LOOP_FILTER_16Y_INNER(cond) \
2225 if (cond && inner_filter) { \
2226 s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0] + 4, linesize, \
2227 bedge_lim_y, inner_limit, \
2228 hev_thresh); \
2229 s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0] + 8, linesize, \
2230 bedge_lim_y, inner_limit, \
2231 hev_thresh); \
2232 s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0] + 12, linesize, \
2233 bedge_lim_y, inner_limit, \
2234 hev_thresh); \
2235 s->vp8dsp.vp8_h_loop_filter8uv_inner(dst[1] + 4, dst[2] + 4, \
2236 uvlinesize, bedge_lim_uv, \
2237 inner_limit, hev_thresh); \
2238 }
2239
2240
4/4
✓ Branch 0 taken 410491 times.
✓ Branch 1 taken 7040 times.
✓ Branch 2 taken 66204 times.
✓ Branch 3 taken 344287 times.
417531 H_LOOP_FILTER_16Y_INNER(!is_vp7)
2241
2242
2/2
✓ Branch 0 taken 396037 times.
✓ Branch 1 taken 21494 times.
417531 if (mb_y) {
2243 396037 s->vp8dsp.vp8_v_loop_filter16y(dst[0], linesize,
2244 mbedge_lim, inner_limit, hev_thresh);
2245 396037 s->vp8dsp.vp8_v_loop_filter8uv(dst[1], dst[2], uvlinesize,
2246 mbedge_lim, inner_limit, hev_thresh);
2247 }
2248
2249
2/2
✓ Branch 0 taken 73244 times.
✓ Branch 1 taken 344287 times.
417531 if (inner_filter) {
2250 73244 s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0] + 4 * linesize,
2251 linesize, bedge_lim_y,
2252 inner_limit, hev_thresh);
2253 73244 s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0] + 8 * linesize,
2254 linesize, bedge_lim_y,
2255 inner_limit, hev_thresh);
2256 73244 s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0] + 12 * linesize,
2257 linesize, bedge_lim_y,
2258 inner_limit, hev_thresh);
2259 73244 s->vp8dsp.vp8_v_loop_filter8uv_inner(dst[1] + 4 * uvlinesize,
2260 73244 dst[2] + 4 * uvlinesize,
2261 uvlinesize, bedge_lim_uv,
2262 inner_limit, hev_thresh);
2263 }
2264
2265
3/4
✓ Branch 0 taken 7040 times.
✓ Branch 1 taken 410491 times.
✓ Branch 2 taken 7040 times.
✗ Branch 3 not taken.
417531 H_LOOP_FILTER_16Y_INNER(is_vp7)
2266 }
2267
2268 static av_always_inline
2269 7722 void filter_mb_simple(const VP8Context *s, uint8_t *dst, const VP8FilterStrength *f,
2270 int mb_x, int mb_y)
2271 {
2272 int mbedge_lim, bedge_lim;
2273 7722 int filter_level = f->filter_level;
2274 7722 int inner_limit = f->inner_limit;
2275 7722 int inner_filter = f->inner_filter;
2276 7722 ptrdiff_t linesize = s->linesize;
2277
2278
2/2
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 7390 times.
7722 if (!filter_level)
2279 332 return;
2280
2281 7390 bedge_lim = 2 * filter_level + inner_limit;
2282 7390 mbedge_lim = bedge_lim + 4;
2283
2284
2/2
✓ Branch 0 taken 6713 times.
✓ Branch 1 taken 677 times.
7390 if (mb_x)
2285 6713 s->vp8dsp.vp8_h_loop_filter_simple(dst, linesize, mbedge_lim);
2286
2/2
✓ Branch 0 taken 3523 times.
✓ Branch 1 taken 3867 times.
7390 if (inner_filter) {
2287 3523 s->vp8dsp.vp8_h_loop_filter_simple(dst + 4, linesize, bedge_lim);
2288 3523 s->vp8dsp.vp8_h_loop_filter_simple(dst + 8, linesize, bedge_lim);
2289 3523 s->vp8dsp.vp8_h_loop_filter_simple(dst + 12, linesize, bedge_lim);
2290 }
2291
2292
2/2
✓ Branch 0 taken 6609 times.
✓ Branch 1 taken 781 times.
7390 if (mb_y)
2293 6609 s->vp8dsp.vp8_v_loop_filter_simple(dst, linesize, mbedge_lim);
2294
2/2
✓ Branch 0 taken 3523 times.
✓ Branch 1 taken 3867 times.
7390 if (inner_filter) {
2295 3523 s->vp8dsp.vp8_v_loop_filter_simple(dst + 4 * linesize, linesize, bedge_lim);
2296 3523 s->vp8dsp.vp8_v_loop_filter_simple(dst + 8 * linesize, linesize, bedge_lim);
2297 3523 s->vp8dsp.vp8_v_loop_filter_simple(dst + 12 * linesize, linesize, bedge_lim);
2298 }
2299 }
2300
2301 #define MARGIN (16 << 2)
2302 static av_always_inline
2303 32 int vp78_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe,
2304 const VP8Frame *prev_frame, int is_vp7)
2305 {
2306 32 VP8Context *s = avctx->priv_data;
2307 int mb_x, mb_y;
2308
2309 32 s->mv_bounds.mv_min.y = -MARGIN;
2310 32 s->mv_bounds.mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
2311
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 32 times.
384 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
2312 352 VP8Macroblock *mb = s->macroblocks_base +
2313 352 ((s->mb_width + 1) * (mb_y + 1) + 1);
2314 352 int mb_xy = mb_y * s->mb_width;
2315
2316 352 AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED * 0x01010101);
2317
2318 352 s->mv_bounds.mv_min.x = -MARGIN;
2319 352 s->mv_bounds.mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
2320
2321
2/2
✓ Branch 0 taken 7040 times.
✓ Branch 1 taken 352 times.
7392 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
2322
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7040 times.
7040 if (vpx_rac_is_end(&s->c)) {
2323 ✗ return AVERROR_INVALIDDATA;
2324 }
2325
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 6400 times.
7040 if (mb_y == 0)
2326 640 AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top,
2327 DC_PRED * 0x01010101);
2328
2/2
✓ Branch 0 taken 6820 times.
✓ Branch 1 taken 220 times.
13860 decode_mb_mode(s, &s->mv_bounds, mb, mb_x, mb_y, curframe->seg_map + mb_xy,
2329
1/2
✓ Branch 0 taken 6820 times.
✗ Branch 1 not taken.
6820 prev_frame && prev_frame->seg_map ?
2330 6820 prev_frame->seg_map + mb_xy : NULL, 1, is_vp7);
2331 7040 s->mv_bounds.mv_min.x -= 64;
2332 7040 s->mv_bounds.mv_max.x -= 64;
2333 }
2334 352 s->mv_bounds.mv_min.y -= 64;
2335 352 s->mv_bounds.mv_max.y -= 64;
2336 }
2337 32 return 0;
2338 }
2339
2340 32 static int vp7_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *cur_frame,
2341 const VP8Frame *prev_frame)
2342 {
2343 32 return vp78_decode_mv_mb_modes(avctx, cur_frame, prev_frame, IS_VP7);
2344 }
2345
2346 ✗ static int vp8_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *cur_frame,
2347 const VP8Frame *prev_frame)
2348 {
2349 ✗ return vp78_decode_mv_mb_modes(avctx, cur_frame, prev_frame, IS_VP8);
2350 }
2351
2352 #if HAVE_THREADS
2353 #define check_thread_pos(td, otd, mb_x_check, mb_y_check) \
2354 do { \
2355 int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF); \
2356 if (atomic_load(&otd->thread_mb_pos) < tmp) { \
2357 pthread_mutex_lock(&otd->lock); \
2358 atomic_store(&td->wait_mb_pos, tmp); \
2359 do { \
2360 if (atomic_load(&otd->thread_mb_pos) >= tmp) \
2361 break; \
2362 pthread_cond_wait(&otd->cond, &otd->lock); \
2363 } while (1); \
2364 atomic_store(&td->wait_mb_pos, INT_MAX); \
2365 pthread_mutex_unlock(&otd->lock); \
2366 } \
2367 } while (0)
2368
2369 #define update_pos(td, mb_y, mb_x) \
2370 do { \
2371 int pos = (mb_y << 16) | (mb_x & 0xFFFF); \
2372 int sliced_threading = (avctx->active_thread_type == FF_THREAD_SLICE) && \
2373 (num_jobs > 1); \
2374 int is_null = !next_td || !prev_td; \
2375 int pos_check = (is_null) ? 1 : \
2376 (next_td != td && pos >= atomic_load(&next_td->wait_mb_pos)) || \
2377 (prev_td != td && pos >= atomic_load(&prev_td->wait_mb_pos)); \
2378 atomic_store(&td->thread_mb_pos, pos); \
2379 if (sliced_threading && pos_check) { \
2380 pthread_mutex_lock(&td->lock); \
2381 pthread_cond_broadcast(&td->cond); \
2382 pthread_mutex_unlock(&td->lock); \
2383 } \
2384 } while (0)
2385 #else
2386 #define check_thread_pos(td, otd, mb_x_check, mb_y_check) while(0)
2387 #define update_pos(td, mb_y, mb_x) while(0)
2388 #endif
2389
2390 16744 static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
2391 int jobnr, int threadnr, int is_vp7)
2392 {
2393 16744 VP8Context *s = avctx->priv_data;
2394 16744 VP8ThreadData *prev_td, *next_td, *td = &s->thread_data[threadnr];
2395 16744 int mb_y = atomic_load(&td->thread_mb_pos) >> 16;
2396 16744 int mb_x, mb_xy = mb_y * s->mb_width;
2397 16744 int num_jobs = s->num_jobs;
2398 16744 const VP8Frame *prev_frame = s->prev_frame;
2399 16744 VP8Frame *curframe = s->curframe;
2400 16744 VPXRangeCoder *coeff_c = &s->coeff_partition[mb_y & (s->num_coeff_partitions - 1)];
2401
2402 VP8Macroblock *mb;
2403 16744 uint8_t *dst[3] = {
2404 16744 curframe->tf.f->data[0] + 16 * mb_y * s->linesize,
2405 16744 curframe->tf.f->data[1] + 8 * mb_y * s->uvlinesize,
2406 16744 curframe->tf.f->data[2] + 8 * mb_y * s->uvlinesize
2407 };
2408
2409
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16744 times.
16744 if (vpx_rac_is_end(&s->c))
2410 ✗ return AVERROR_INVALIDDATA;
2411
2412
2/2
✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 15554 times.
16744 if (mb_y == 0)
2413 1190 prev_td = td;
2414 else
2415 15554 prev_td = &s->thread_data[(jobnr + num_jobs - 1) % num_jobs];
2416
2/2
✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 15554 times.
16744 if (mb_y == s->mb_height - 1)
2417 1190 next_td = td;
2418 else
2419 15554 next_td = &s->thread_data[(jobnr + 1) % num_jobs];
2420
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 16392 times.
16744 if (s->mb_layout == 1)
2421 352 mb = s->macroblocks_base + ((s->mb_width + 1) * (mb_y + 1) + 1);
2422 else {
2423 // Make sure the previous frame has read its segmentation map,
2424 // if we reuse the same map.
2425
4/4
✓ Branch 0 taken 15334 times.
✓ Branch 1 taken 1058 times.
✓ Branch 2 taken 5660 times.
✓ Branch 3 taken 9674 times.
16392 if (prev_frame && s->segmentation.enabled &&
2426
2/2
✓ Branch 0 taken 5025 times.
✓ Branch 1 taken 635 times.
5660 !s->segmentation.update_map)
2427 5025 ff_progress_frame_await(&prev_frame->tf, mb_y);
2428 16392 mb = s->macroblocks + (s->mb_height - mb_y - 1) * 2;
2429 16392 memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock
2430 16392 AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED * 0x01010101);
2431 }
2432
2433
4/4
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 16392 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 320 times.
16744 if (!is_vp7 || mb_y == 0)
2434 16424 memset(td->left_nnz, 0, sizeof(td->left_nnz));
2435
2436 16744 td->mv_bounds.mv_min.x = -MARGIN;
2437 16744 td->mv_bounds.mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
2438
2439
2/2
✓ Branch 0 taken 453515 times.
✓ Branch 1 taken 16744 times.
470259 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
2440
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 453515 times.
453515 if (vpx_rac_is_end(&s->c))
2441 ✗ return AVERROR_INVALIDDATA;
2442 // Wait for previous thread to read mb_x+2, and reach mb_y-1.
2443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 453515 times.
453515 if (prev_td != td) {
2444 ✗ if (threadnr != 0) {
2445 ✗ check_thread_pos(td, prev_td,
2446 mb_x + (is_vp7 ? 2 : 1),
2447 mb_y - (is_vp7 ? 2 : 1));
2448 } else {
2449 ✗ check_thread_pos(td, prev_td,
2450 mb_x + (is_vp7 ? 2 : 1) + s->mb_width + 3,
2451 mb_y - (is_vp7 ? 2 : 1));
2452 }
2453 }
2454
2455 453515 s->vdsp.prefetch(dst[0] + (mb_x & 3) * 4 * s->linesize + 64,
2456 s->linesize, 4);
2457 453515 s->vdsp.prefetch(dst[1] + (mb_x & 7) * s->uvlinesize + 64,
2458 453515 dst[2] - dst[1], 2);
2459
2460
2/2
✓ Branch 0 taken 446475 times.
✓ Branch 1 taken 7040 times.
453515 if (!s->mb_layout)
2461
2/2
✓ Branch 0 taken 407187 times.
✓ Branch 1 taken 39288 times.
853662 decode_mb_mode(s, &td->mv_bounds, mb, mb_x, mb_y, curframe->seg_map + mb_xy,
2462
1/2
✓ Branch 0 taken 407187 times.
✗ Branch 1 not taken.
407187 prev_frame && prev_frame->seg_map ?
2463 407187 prev_frame->seg_map + mb_xy : NULL, 0, is_vp7);
2464
2465 453515 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS);
2466
2467
2/2
✓ Branch 0 taken 93485 times.
✓ Branch 1 taken 360030 times.
453515 if (!mb->skip) {
2468
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 93485 times.
93485 if (vpx_rac_is_end(coeff_c))
2469 ✗ return AVERROR_INVALIDDATA;
2470 93485 decode_mb_coeffs(s, td, coeff_c, mb, s->top_nnz[mb_x], td->left_nnz, is_vp7);
2471 }
2472
2473
2/2
✓ Branch 0 taken 67136 times.
✓ Branch 1 taken 386379 times.
453515 if (mb->mode <= MODE_I4x4)
2474 67136 intra_predict(s, td, dst, mb, mb_x, mb_y, is_vp7);
2475 else
2476 386379 inter_predict(s, td, dst, mb, mb_x, mb_y);
2477
2478 453515 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_GOLDEN);
2479
2480
2/2
✓ Branch 0 taken 82374 times.
✓ Branch 1 taken 371141 times.
453515 if (!mb->skip) {
2481 82374 idct_mb(s, td, dst, mb);
2482 } else {
2483 371141 AV_ZERO64(td->left_nnz);
2484 371141 AV_WN64(s->top_nnz[mb_x], 0); // array of 9, so unaligned
2485
2486 /* Reset DC block predictors if they would exist
2487 * if the mb had coefficients */
2488
4/4
✓ Branch 0 taken 370650 times.
✓ Branch 1 taken 491 times.
✓ Branch 2 taken 367383 times.
✓ Branch 3 taken 3267 times.
371141 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
2489 367383 td->left_nnz[8] = 0;
2490 367383 s->top_nnz[mb_x][8] = 0;
2491 }
2492 }
2493
2494
2/2
✓ Branch 0 taken 431129 times.
✓ Branch 1 taken 22386 times.
453515 if (s->deblock_filter)
2495 431129 filter_level_for_mb(s, mb, &td->filter_strength[mb_x], is_vp7);
2496
2497
3/6
✓ Branch 0 taken 431129 times.
✓ Branch 1 taken 22386 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 431129 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
453515 if (s->deblock_filter && num_jobs != 1 && threadnr == num_jobs - 1) {
2498 ✗ if (s->filter.simple)
2499 ✗ backup_mb_border(s->top_border[mb_x + 1], dst[0],
2500 NULL, NULL, s->linesize, 0, 1);
2501 else
2502 ✗ backup_mb_border(s->top_border[mb_x + 1], dst[0],
2503 ✗ dst[1], dst[2], s->linesize, s->uvlinesize, 0);
2504 }
2505
2506 453515 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_ALTREF);
2507
2508 453515 dst[0] += 16;
2509 453515 dst[1] += 8;
2510 453515 dst[2] += 8;
2511 453515 td->mv_bounds.mv_min.x -= 64;
2512 453515 td->mv_bounds.mv_max.x -= 64;
2513
2514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 453515 times.
453515 if (mb_x == s->mb_width + 1) {
2515 ✗ update_pos(td, mb_y, s->mb_width + 3);
2516 } else {
2517
7/22
✗ Branch 0 not taken.
✓ Branch 1 taken 453515 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 453515 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 453515 times.
✓ Branch 8 taken 453515 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 453515 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 453515 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 453515 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
453515 update_pos(td, mb_y, mb_x);
2518 }
2519 }
2520 16744 return 0;
2521 }
2522
2523 15468 static av_always_inline void filter_mb_row(AVCodecContext *avctx, void *tdata,
2524 int jobnr, int threadnr, int is_vp7)
2525 {
2526 15468 VP8Context *s = avctx->priv_data;
2527 15468 VP8ThreadData *td = &s->thread_data[threadnr];
2528 15468 int mb_x, mb_y = atomic_load(&td->thread_mb_pos) >> 16, num_jobs = s->num_jobs;
2529 15468 AVFrame *curframe = s->curframe->tf.f;
2530 VP8ThreadData *prev_td, *next_td;
2531 15468 uint8_t *dst[3] = {
2532 15468 curframe->data[0] + 16 * mb_y * s->linesize,
2533 15468 curframe->data[1] + 8 * mb_y * s->uvlinesize,
2534 15468 curframe->data[2] + 8 * mb_y * s->uvlinesize
2535 };
2536
2537
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 14409 times.
15468 if (mb_y == 0)
2538 1059 prev_td = td;
2539 else
2540 14409 prev_td = &s->thread_data[(jobnr + num_jobs - 1) % num_jobs];
2541
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 14409 times.
15468 if (mb_y == s->mb_height - 1)
2542 1059 next_td = td;
2543 else
2544 14409 next_td = &s->thread_data[(jobnr + 1) % num_jobs];
2545
2546
2/2
✓ Branch 0 taken 431129 times.
✓ Branch 1 taken 15468 times.
446597 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
2547 431129 const VP8FilterStrength *f = &td->filter_strength[mb_x];
2548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 431129 times.
431129 if (prev_td != td)
2549 ✗ check_thread_pos(td, prev_td,
2550 (mb_x + 1) + (s->mb_width + 3), mb_y - 1);
2551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 431129 times.
431129 if (next_td != td)
2552 ✗ if (next_td != &s->thread_data[0])
2553 ✗ check_thread_pos(td, next_td, mb_x + 1, mb_y + 1);
2554
2555
1/2
✓ Branch 0 taken 431129 times.
✗ Branch 1 not taken.
431129 if (num_jobs == 1) {
2556
2/2
✓ Branch 0 taken 7722 times.
✓ Branch 1 taken 423407 times.
431129 if (s->filter.simple)
2557 7722 backup_mb_border(s->top_border[mb_x + 1], dst[0],
2558 NULL, NULL, s->linesize, 0, 1);
2559 else
2560 423407 backup_mb_border(s->top_border[mb_x + 1], dst[0],
2561 423407 dst[1], dst[2], s->linesize, s->uvlinesize, 0);
2562 }
2563
2564
2/2
✓ Branch 0 taken 7722 times.
✓ Branch 1 taken 423407 times.
431129 if (s->filter.simple)
2565 7722 filter_mb_simple(s, dst[0], f, mb_x, mb_y);
2566 else
2567 423407 filter_mb(s, dst, f, mb_x, mb_y, is_vp7);
2568 431129 dst[0] += 16;
2569 431129 dst[1] += 8;
2570 431129 dst[2] += 8;
2571
2572
7/22
✗ Branch 0 not taken.
✓ Branch 1 taken 431129 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 431129 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 431129 times.
✓ Branch 8 taken 431129 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 431129 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 431129 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 431129 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
431129 update_pos(td, mb_y, (s->mb_width + 3) + mb_x);
2573 }
2574 15468 }
2575
2576 static av_always_inline
2577 1190 int vp78_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, int jobnr,
2578 int threadnr, int is_vp7)
2579 {
2580 1190 const VP8Context *s = avctx->priv_data;
2581 1190 VP8ThreadData *td = &s->thread_data[jobnr];
2582 1190 VP8ThreadData *next_td = NULL, *prev_td = NULL;
2583 1190 VP8Frame *curframe = s->curframe;
2584 1190 int mb_y, num_jobs = s->num_jobs;
2585 int ret;
2586
2587 1190 td->thread_nr = threadnr;
2588 1190 td->mv_bounds.mv_min.y = -MARGIN - 64 * threadnr;
2589 1190 td->mv_bounds.mv_max.y = ((s->mb_height - 1) << 6) + MARGIN - 64 * threadnr;
2590
2/2
✓ Branch 0 taken 16744 times.
✓ Branch 1 taken 1190 times.
17934 for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) {
2591 16744 atomic_store(&td->thread_mb_pos, mb_y << 16);
2592 16744 ret = s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
2593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16744 times.
16744 if (ret < 0) {
2594 ✗ update_pos(td, s->mb_height, INT_MAX & 0xFFFF);
2595 ✗ return ret;
2596 }
2597
2/2
✓ Branch 0 taken 15468 times.
✓ Branch 1 taken 1276 times.
16744 if (s->deblock_filter)
2598 15468 s->filter_mb_row(avctx, tdata, jobnr, threadnr);
2599
4/22
✗ Branch 0 not taken.
✓ Branch 1 taken 16744 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 16744 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 16744 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 16744 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
16744 update_pos(td, mb_y, INT_MAX & 0xFFFF);
2600
2601 16744 td->mv_bounds.mv_min.y -= 64 * num_jobs;
2602 16744 td->mv_bounds.mv_max.y -= 64 * num_jobs;
2603
2604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16744 times.
16744 if (avctx->active_thread_type == FF_THREAD_FRAME)
2605 ✗ ff_progress_frame_report(&curframe->tf, mb_y);
2606 }
2607
2608 1190 return 0;
2609 }
2610
2611 32 static int vp7_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata,
2612 int jobnr, int threadnr)
2613 {
2614 32 return vp78_decode_mb_row_sliced(avctx, tdata, jobnr, threadnr, IS_VP7);
2615 }
2616
2617 1158 static int vp8_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata,
2618 int jobnr, int threadnr)
2619 {
2620 1158 return vp78_decode_mb_row_sliced(avctx, tdata, jobnr, threadnr, IS_VP8);
2621 }
2622
2623 static av_always_inline
2624 1190 int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame,
2625 const AVPacket *avpkt, int is_vp7)
2626 {
2627 1190 VP8Context *s = avctx->priv_data;
2628 int ret, i, referenced, num_jobs;
2629 enum AVDiscard skip_thresh;
2630 1190 VP8Frame *av_uninit(curframe), *prev_frame;
2631
2632
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1158 times.
1190 if (is_vp7)
2633 32 ret = vp7_decode_frame_header(s, avpkt->data, avpkt->size);
2634 else
2635 1158 ret = vp8_decode_frame_header(s, avpkt->data, avpkt->size);
2636
2637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (ret < 0)
2638 ✗ goto err;
2639
2640
4/4
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 1109 times.
1190 if (!is_vp7 && s->actually_webp) {
2641 // VP8 in WebP is supposed to be intra-only. Enforce this here
2642 // to ensure that output is reproducible with frame-threading.
2643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (!s->keyframe)
2644 ✗ return AVERROR_INVALIDDATA;
2645 // avctx->pix_fmt already set in caller.
2646
3/4
✓ Branch 0 taken 1109 times.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1109 times.
1141 } else if (!is_vp7 && s->pix_fmt == AV_PIX_FMT_NONE) {
2647 ✗ s->pix_fmt = get_pixel_format(s);
2648 ✗ if (s->pix_fmt < 0) {
2649 ✗ ret = AVERROR(EINVAL);
2650 ✗ goto err;
2651 }
2652 ✗ avctx->pix_fmt = s->pix_fmt;
2653 }
2654
2655 1190 prev_frame = s->framep[VP8_FRAME_CURRENT];
2656
2657
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1179 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
1201 referenced = s->update_last || s->update_golden == VP8_FRAME_CURRENT ||
2658
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 s->update_altref == VP8_FRAME_CURRENT;
2659
2660 1190 skip_thresh = !referenced ? AVDISCARD_NONREF
2661
4/4
✓ Branch 0 taken 1188 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1095 times.
✓ Branch 3 taken 93 times.
1190 : !s->keyframe ? AVDISCARD_NONKEY
2662 : AVDISCARD_ALL;
2663
2664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (avctx->skip_frame >= skip_thresh) {
2665 ✗ s->invisible = 1;
2666 ✗ memcpy(&s->next_framep[0], &s->framep[0], sizeof(s->framep[0]) * 4);
2667 ✗ goto skip_decode;
2668 }
2669
3/4
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 131 times.
✓ Branch 2 taken 1059 times.
✗ Branch 3 not taken.
1190 s->deblock_filter = s->filter.level && avctx->skip_loop_filter < skip_thresh;
2670
2671 // release no longer referenced frames
2672
2/2
✓ Branch 0 taken 5950 times.
✓ Branch 1 taken 1190 times.
7140 for (i = 0; i < 5; i++)
2673
2/2
✓ Branch 0 taken 3843 times.
✓ Branch 1 taken 2107 times.
5950 if (s->frames[i].tf.f &&
2674
2/2
✓ Branch 0 taken 2728 times.
✓ Branch 1 taken 1115 times.
3843 &s->frames[i] != prev_frame &&
2675
2/2
✓ Branch 0 taken 2717 times.
✓ Branch 1 taken 11 times.
2728 &s->frames[i] != s->framep[VP8_FRAME_PREVIOUS] &&
2676
2/2
✓ Branch 0 taken 1745 times.
✓ Branch 1 taken 972 times.
2717 &s->frames[i] != s->framep[VP8_FRAME_GOLDEN] &&
2677
2/2
✓ Branch 0 taken 1037 times.
✓ Branch 1 taken 708 times.
1745 &s->frames[i] != s->framep[VP8_FRAME_ALTREF])
2678 1037 vp8_release_frame(&s->frames[i]);
2679
2680
1/2
✓ Branch 0 taken 1190 times.
✗ Branch 1 not taken.
1190 if (!s->colorspace)
2681 1190 avctx->colorspace = AVCOL_SPC_BT470BG;
2682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (s->fullrange)
2683 ✗ avctx->color_range = AVCOL_RANGE_JPEG;
2684 else
2685 1190 avctx->color_range = AVCOL_RANGE_MPEG;
2686
2687 /* Given that arithmetic probabilities are updated every frame, it's quite
2688 * likely that the values we have on a random interframe are complete
2689 * junk if we didn't start decode on a keyframe. So just don't display
2690 * anything rather than junk. */
2691
3/4
✓ Branch 0 taken 1097 times.
✓ Branch 1 taken 93 times.
✓ Branch 2 taken 1097 times.
✗ Branch 3 not taken.
1190 if (!s->keyframe && (!s->framep[VP8_FRAME_PREVIOUS] ||
2692
1/2
✓ Branch 0 taken 1097 times.
✗ Branch 1 not taken.
1097 !s->framep[VP8_FRAME_GOLDEN] ||
2693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1097 times.
1097 !s->framep[VP8_FRAME_ALTREF])) {
2694 ✗ av_log(avctx, AV_LOG_WARNING,
2695 "Discarding interframe without a prior keyframe!\n");
2696 ✗ ret = AVERROR_INVALIDDATA;
2697 ✗ goto err;
2698 }
2699
2700 1190 curframe = vp8_find_free_buffer(s);
2701
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1190 times.
1190 if ((ret = vp8_alloc_frame(s, curframe, referenced)) < 0)
2702 ✗ goto err;
2703 1190 s->framep[VP8_FRAME_CURRENT] = curframe;
2704
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1097 times.
1190 if (s->keyframe)
2705 93 curframe->tf.f->flags |= AV_FRAME_FLAG_KEY;
2706 else
2707 1097 curframe->tf.f->flags &= ~AV_FRAME_FLAG_KEY;
2708 2380 curframe->tf.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I
2709
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1097 times.
1190 : AV_PICTURE_TYPE_P;
2710
2711 // check if golden and altref are swapped
2712
2/2
✓ Branch 0 taken 242 times.
✓ Branch 1 taken 948 times.
1190 if (s->update_altref != VP8_FRAME_NONE)
2713 242 s->next_framep[VP8_FRAME_ALTREF] = s->framep[s->update_altref];
2714 else
2715 948 s->next_framep[VP8_FRAME_ALTREF] = s->framep[VP8_FRAME_ALTREF];
2716
2717
2/2
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 1007 times.
1190 if (s->update_golden != VP8_FRAME_NONE)
2718 183 s->next_framep[VP8_FRAME_GOLDEN] = s->framep[s->update_golden];
2719 else
2720 1007 s->next_framep[VP8_FRAME_GOLDEN] = s->framep[VP8_FRAME_GOLDEN];
2721
2722
2/2
✓ Branch 0 taken 1179 times.
✓ Branch 1 taken 11 times.
1190 if (s->update_last)
2723 1179 s->next_framep[VP8_FRAME_PREVIOUS] = curframe;
2724 else
2725 11 s->next_framep[VP8_FRAME_PREVIOUS] = s->framep[VP8_FRAME_PREVIOUS];
2726
2727 1190 s->next_framep[VP8_FRAME_CURRENT] = curframe;
2728
2729
4/4
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 1109 times.
✓ Branch 3 taken 49 times.
1190 if (!is_vp7 && !s->actually_webp)
2730 1109 ff_thread_finish_setup(avctx);
2731
2732
3/4
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1158 times.
1190 if (!is_vp7 && avctx->hwaccel) {
2733 ✗ const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
2734 ✗ ret = hwaccel->start_frame(avctx, avpkt->buf, avpkt->data, avpkt->size);
2735 ✗ if (ret < 0)
2736 ✗ goto err;
2737
2738 ✗ ret = hwaccel->decode_slice(avctx, avpkt->data, avpkt->size);
2739 ✗ if (ret < 0)
2740 ✗ goto err;
2741
2742 ✗ ret = hwaccel->end_frame(avctx);
2743 ✗ if (ret < 0)
2744 ✗ goto err;
2745
2746 } else {
2747 1190 s->linesize = curframe->tf.f->linesize[0];
2748 1190 s->uvlinesize = curframe->tf.f->linesize[1];
2749
2750 1190 memset(s->top_nnz, 0, s->mb_width * sizeof(*s->top_nnz));
2751 /* Zero macroblock structures for top/top-left prediction
2752 * from outside the frame. */
2753
2/2
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 32 times.
1190 if (!s->mb_layout)
2754 1158 memset(s->macroblocks + s->mb_height * 2 - 1, 0,
2755 1158 (s->mb_width + 1) * sizeof(*s->macroblocks));
2756
4/4
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 1066 times.
1190 if (!s->mb_layout && s->keyframe)
2757 92 memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width * 4);
2758
2759 1190 memset(s->ref_count, 0, sizeof(s->ref_count));
2760
2761
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1158 times.
1190 if (s->mb_layout == 1) {
2762 // Make sure the previous frame has read its segmentation map,
2763 // if we reuse the same map.
2764
3/4
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
32 if (prev_frame && s->segmentation.enabled &&
2765 ✗ !s->segmentation.update_map)
2766 ✗ ff_progress_frame_await(&prev_frame->tf, 1);
2767
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (is_vp7)
2768 32 ret = vp7_decode_mv_mb_modes(avctx, curframe, prev_frame);
2769 else
2770 ✗ ret = vp8_decode_mv_mb_modes(avctx, curframe, prev_frame);
2771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
2772 ✗ goto err;
2773 }
2774
2775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1190 times.
1190 if (avctx->active_thread_type == FF_THREAD_FRAME)
2776 ✗ num_jobs = 1;
2777 else
2778 1190 num_jobs = FFMIN(s->num_coeff_partitions, avctx->thread_count);
2779 1190 s->num_jobs = num_jobs;
2780 1190 s->curframe = curframe;
2781 1190 s->prev_frame = prev_frame;
2782 1190 s->mv_bounds.mv_min.y = -MARGIN;
2783 1190 s->mv_bounds.mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;
2784
2/2
✓ Branch 0 taken 9520 times.
✓ Branch 1 taken 1190 times.
10710 for (i = 0; i < MAX_THREADS; i++) {
2785 9520 VP8ThreadData *td = &s->thread_data[i];
2786 9520 atomic_init(&td->thread_mb_pos, 0);
2787 9520 atomic_init(&td->wait_mb_pos, INT_MAX);
2788 }
2789
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1158 times.
1190 if (is_vp7)
2790 32 avctx->execute2(avctx, vp7_decode_mb_row_sliced, s->thread_data, NULL,
2791 num_jobs);
2792 else
2793 1158 avctx->execute2(avctx, vp8_decode_mb_row_sliced, s->thread_data, NULL,
2794 num_jobs);
2795 }
2796
2797 1190 ff_progress_frame_report(&curframe->tf, INT_MAX);
2798 1190 memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4);
2799
2800 1190 skip_decode:
2801 // if future frames don't use the updated probabilities,
2802 // reset them to the values we saved
2803
2/2
✓ Branch 0 taken 107 times.
✓ Branch 1 taken 1083 times.
1190 if (!s->update_probabilities)
2804 107 s->prob[0] = s->prob[1];
2805
2806
2/2
✓ Branch 0 taken 1181 times.
✓ Branch 1 taken 9 times.
1190 if (!s->invisible) {
2807
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1181 times.
1181 if ((ret = av_frame_ref(rframe, curframe->tf.f)) < 0)
2808 ✗ return ret;
2809 1181 *got_frame = 1;
2810 }
2811
2812 1190 return avpkt->size;
2813 ✗ err:
2814 ✗ memcpy(&s->next_framep[0], &s->framep[0], sizeof(s->framep[0]) * 4);
2815 ✗ return ret;
2816 }
2817
2818 65 av_cold int ff_vp8_decode_free(AVCodecContext *avctx)
2819 {
2820 65 vp8_decode_flush_impl(avctx, 1);
2821
2822 65 return 0;
2823 }
2824
2825 65 static av_cold void vp78_decode_init(AVCodecContext *avctx)
2826 {
2827 65 VP8Context *s = avctx->priv_data;
2828
2829 65 s->avctx = avctx;
2830 65 s->pix_fmt = AV_PIX_FMT_NONE;
2831 65 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
2832
2833 65 ff_videodsp_init(&s->vdsp, 8);
2834
2835 65 ff_vp78dsp_init(&s->vp8dsp);
2836
2837 /* does not change for VP8 */
2838 65 memcpy(s->prob[0].scan, ff_zigzag_scan, sizeof(s->prob[0].scan));
2839 65 }
2840
2841 #if CONFIG_VP8_DECODER
2842 16392 static int vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
2843 int jobnr, int threadnr)
2844 {
2845 16392 return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
2846 }
2847
2848 15116 static void vp8_filter_mb_row(AVCodecContext *avctx, void *tdata,
2849 int jobnr, int threadnr)
2850 {
2851 15116 filter_mb_row(avctx, tdata, jobnr, threadnr, 0);
2852 15116 }
2853
2854 1109 static void vp8_warn_unsupported_webm_alpha(AVCodecContext *avctx,
2855 const AVPacket *avpkt)
2856 {
2857 1109 VP8Context *s = avctx->priv_data;
2858 const uint8_t *sd;
2859 size_t sd_size;
2860
2861 1109 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
2862 &sd_size);
2863
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1109 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1109 if (!sd || sd_size < 8 || AV_RB64(sd) != 1)
2864 1109 return;
2865
2866 ✗ av_log_once(avctx, AV_LOG_WARNING, AV_LOG_DEBUG,
2867 &s->webm_alpha_warned,
2868 "Ignoring unsupported WebM alpha channel side data; use the "
2869 "libvpx decoder to decode it.\n");
2870 }
2871
2872 1158 int ff_vp8_decode_frame(AVCodecContext *avctx, AVFrame *frame,
2873 int *got_frame, AVPacket *avpkt)
2874 {
2875 1158 return vp78_decode_frame(avctx, frame, got_frame, avpkt, IS_VP8);
2876 }
2877
2878 1109 static int vp8_decode_frame(AVCodecContext *avctx, AVFrame *frame,
2879 int *got_frame, AVPacket *avpkt)
2880 {
2881 1109 vp8_warn_unsupported_webm_alpha(avctx, avpkt);
2882
2883 1109 return ff_vp8_decode_frame(avctx, frame, got_frame, avpkt);
2884 }
2885
2886 62 av_cold int ff_vp8_decode_init(AVCodecContext *avctx)
2887 {
2888 62 VP8Context *s = avctx->priv_data;
2889
2890 62 vp78_decode_init(avctx);
2891 62 ff_h264_pred_init(&s->hpc, AV_CODEC_ID_VP8, 8, 1);
2892 62 ff_vp8dsp_init(&s->vp8dsp);
2893 62 s->decode_mb_row_no_filter = vp8_decode_mb_row_no_filter;
2894 62 s->filter_mb_row = vp8_filter_mb_row;
2895
2896 62 return 0;
2897 }
2898
2899 #if HAVE_THREADS
2900 ✗ static void vp8_replace_frame(VP8Frame *dst, const VP8Frame *src)
2901 {
2902 ✗ ff_progress_frame_replace(&dst->tf, &src->tf);
2903 ✗ av_refstruct_replace(&dst->seg_map, src->seg_map);
2904 ✗ av_refstruct_replace(&dst->hwaccel_picture_private,
2905 ✗ src->hwaccel_picture_private);
2906 ✗ }
2907
2908 #define REBASE(pic) ((pic) ? (pic) - &s_src->frames[0] + &s->frames[0] : NULL)
2909
2910 ✗ static int vp8_decode_update_thread_context(AVCodecContext *dst,
2911 const AVCodecContext *src)
2912 {
2913 ✗ VP8Context *s = dst->priv_data, *s_src = src->priv_data;
2914
2915 ✗ if (s->macroblocks_base &&
2916 ✗ (s_src->mb_width != s->mb_width || s_src->mb_height != s->mb_height)) {
2917 ✗ free_buffers(s);
2918 ✗ s->mb_width = s_src->mb_width;
2919 ✗ s->mb_height = s_src->mb_height;
2920 }
2921
2922 ✗ s->pix_fmt = s_src->pix_fmt;
2923 ✗ s->prob[0] = s_src->prob[!s_src->update_probabilities];
2924 ✗ s->segmentation = s_src->segmentation;
2925 ✗ s->lf_delta = s_src->lf_delta;
2926 ✗ s->webm_alpha_warned = s_src->webm_alpha_warned;
2927 ✗ memcpy(s->sign_bias, s_src->sign_bias, sizeof(s->sign_bias));
2928
2929 ✗ for (int i = 0; i < FF_ARRAY_ELEMS(s_src->frames); i++)
2930 ✗ vp8_replace_frame(&s->frames[i], &s_src->frames[i]);
2931
2932 ✗ s->framep[0] = REBASE(s_src->next_framep[0]);
2933 ✗ s->framep[1] = REBASE(s_src->next_framep[1]);
2934 ✗ s->framep[2] = REBASE(s_src->next_framep[2]);
2935 ✗ s->framep[3] = REBASE(s_src->next_framep[3]);
2936
2937 ✗ return 0;
2938 }
2939 #endif /* HAVE_THREADS */
2940 #endif /* CONFIG_VP8_DECODER */
2941
2942 #if CONFIG_VP7_DECODER
2943 352 static int vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
2944 int jobnr, int threadnr)
2945 {
2946 352 return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
2947 }
2948
2949 352 static void vp7_filter_mb_row(AVCodecContext *avctx, void *tdata,
2950 int jobnr, int threadnr)
2951 {
2952 352 filter_mb_row(avctx, tdata, jobnr, threadnr, 1);
2953 352 }
2954
2955 32 static int vp7_decode_frame(AVCodecContext *avctx, AVFrame *frame,
2956 int *got_frame, AVPacket *avpkt)
2957 {
2958 32 return vp78_decode_frame(avctx, frame, got_frame, avpkt, IS_VP7);
2959 }
2960
2961 3 av_cold static int vp7_decode_init(AVCodecContext *avctx)
2962 {
2963 3 VP8Context *s = avctx->priv_data;
2964
2965 3 vp78_decode_init(avctx);
2966 3 ff_h264_pred_init(&s->hpc, AV_CODEC_ID_VP7, 8, 1);
2967 3 ff_vp7dsp_init(&s->vp8dsp);
2968 3 s->decode_mb_row_no_filter = vp7_decode_mb_row_no_filter;
2969 3 s->filter_mb_row = vp7_filter_mb_row;
2970
2971 3 return 0;
2972 }
2973
2974 const FFCodec ff_vp7_decoder = {
2975 .p.name = "vp7",
2976 CODEC_LONG_NAME("On2 VP7"),
2977 .p.type = AVMEDIA_TYPE_VIDEO,
2978 .p.id = AV_CODEC_ID_VP7,
2979 .priv_data_size = sizeof(VP8Context),
2980 .init = vp7_decode_init,
2981 .close = ff_vp8_decode_free,
2982 FF_CODEC_DECODE_CB(vp7_decode_frame),
2983 .p.capabilities = AV_CODEC_CAP_DR1,
2984 .flush = vp8_decode_flush,
2985 .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES,
2986 };
2987 #endif /* CONFIG_VP7_DECODER */
2988
2989 #if CONFIG_VP8_DECODER
2990 const FFCodec ff_vp8_decoder = {
2991 .p.name = "vp8",
2992 CODEC_LONG_NAME("On2 VP8"),
2993 .p.type = AVMEDIA_TYPE_VIDEO,
2994 .p.id = AV_CODEC_ID_VP8,
2995 .priv_data_size = sizeof(VP8Context),
2996 .init = ff_vp8_decode_init,
2997 .close = ff_vp8_decode_free,
2998 FF_CODEC_DECODE_CB(vp8_decode_frame),
2999 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
3000 AV_CODEC_CAP_SLICE_THREADS,
3001 .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES,
3002 .flush = vp8_decode_flush,
3003 UPDATE_THREAD_CONTEXT(vp8_decode_update_thread_context),
3004 .hw_configs = (const AVCodecHWConfigInternal *const []) {
3005 #if CONFIG_VP8_VAAPI_HWACCEL
3006 HWACCEL_VAAPI(vp8),
3007 #endif
3008 #if CONFIG_VP8_NVDEC_HWACCEL
3009 HWACCEL_NVDEC(vp8),
3010 #endif
3011 #if CONFIG_VP8_NVDEC_CUARRAY_HWACCEL
3012 HWACCEL_NVDEC_CUARRAY(vp8),
3013 #endif
3014 NULL
3015 },
3016 };
3017 #endif /* CONFIG_VP8_DECODER */
3018