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