| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * VP9 compatible video decoder | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com> | ||
| 5 | * Copyright (C) 2013 Clément Bœsch <u pkh me> | ||
| 6 | * | ||
| 7 | * This file is part of FFmpeg. | ||
| 8 | * | ||
| 9 | * FFmpeg is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with FFmpeg; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include "avcodec.h" | ||
| 25 | #include "vp9dec.h" | ||
| 26 | |||
| 27 | 150018 | static av_always_inline void filter_plane_cols(VP9Context *s, int col, int ss_h, int ss_v, | |
| 28 | uint8_t *lvl, uint8_t (*mask)[4], | ||
| 29 | uint8_t *dst, ptrdiff_t ls) | ||
| 30 | { | ||
| 31 | 150018 | int y, x, bytesperpixel = s->bytesperpixel; | |
| 32 | |||
| 33 | // filter edges between columns (e.g. block1 | block2) | ||
| 34 |
2/2✓ Branch 0 taken 403360 times.
✓ Branch 1 taken 150018 times.
|
553378 | for (y = 0; y < 8; y += 2 << ss_v, dst += 16 * ls, lvl += 16 << ss_v) { |
| 35 | 403360 | uint8_t *ptr = dst, *l = lvl, *hmask1 = mask[y], *hmask2 = mask[y + 1 + ss_v]; | |
| 36 | 403360 | unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2], hm13 = hmask1[3]; | |
| 37 | 403360 | unsigned hm2 = hmask2[1] | hmask2[2], hm23 = hmask2[3]; | |
| 38 | 403360 | unsigned hm = hm1 | hm2 | hm13 | hm23; | |
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 1801292 times.
✓ Branch 1 taken 403360 times.
|
2204652 | for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 8 * bytesperpixel >> ss_h) { |
| 41 |
4/4✓ Branch 0 taken 289152 times.
✓ Branch 1 taken 1512140 times.
✓ Branch 2 taken 235449 times.
✓ Branch 3 taken 53703 times.
|
1801292 | if (col || x > 1) { |
| 42 |
2/2✓ Branch 0 taken 1183787 times.
✓ Branch 1 taken 563802 times.
|
1747589 | if (hm1 & x) { |
| 43 | 1183787 | int L = *l, H = L >> 4; | |
| 44 | 1183787 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 348316 times.
✓ Branch 1 taken 835471 times.
|
1183787 | if (hmask1[0] & x) { |
| 47 |
2/2✓ Branch 0 taken 346528 times.
✓ Branch 1 taken 1788 times.
|
348316 | if (hmask2[0] & x) { |
| 48 | av_assert2(l[8 << ss_v] == L); | ||
| 49 | 346528 | s->dsp.loop_filter_16[0](ptr, ls, E, I, H); | |
| 50 | } else { | ||
| 51 | 1788 | s->dsp.loop_filter_8[2][0](ptr, ls, E, I, H); | |
| 52 | } | ||
| 53 |
2/2✓ Branch 0 taken 769344 times.
✓ Branch 1 taken 66127 times.
|
835471 | } else if (hm2 & x) { |
| 54 | 769344 | L = l[8 << ss_v]; | |
| 55 | 769344 | H |= (L >> 4) << 8; | |
| 56 | 769344 | E |= s->filter_lut.mblim_lut[L] << 8; | |
| 57 | 769344 | I |= s->filter_lut.lim_lut[L] << 8; | |
| 58 | 769344 | s->dsp.loop_filter_mix2[!!(hmask1[1] & x)] | |
| 59 | 769344 | [!!(hmask2[1] & x)] | |
| 60 | 769344 | [0](ptr, ls, E, I, H); | |
| 61 | } else { | ||
| 62 | 66127 | s->dsp.loop_filter_8[!!(hmask1[1] & x)] | |
| 63 | 66127 | [0](ptr, ls, E, I, H); | |
| 64 | } | ||
| 65 |
2/2✓ Branch 0 taken 33532 times.
✓ Branch 1 taken 530270 times.
|
563802 | } else if (hm2 & x) { |
| 66 | 33532 | int L = l[8 << ss_v], H = L >> 4; | |
| 67 | 33532 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 68 | |||
| 69 | 33532 | s->dsp.loop_filter_8[!!(hmask2[1] & x)] | |
| 70 | 33532 | [0](ptr + 8 * ls, ls, E, I, H); | |
| 71 | } | ||
| 72 | } | ||
| 73 |
2/2✓ Branch 0 taken 873114 times.
✓ Branch 1 taken 928178 times.
|
1801292 | if (ss_h) { |
| 74 |
2/2✓ Branch 0 taken 365030 times.
✓ Branch 1 taken 508084 times.
|
873114 | if (x & 0xAA) |
| 75 | 365030 | l += 2; | |
| 76 | } else { | ||
| 77 |
2/2✓ Branch 0 taken 115223 times.
✓ Branch 1 taken 812955 times.
|
928178 | if (hm13 & x) { |
| 78 | 115223 | int L = *l, H = L >> 4; | |
| 79 | 115223 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 80 | |||
| 81 |
2/2✓ Branch 0 taken 66821 times.
✓ Branch 1 taken 48402 times.
|
115223 | if (hm23 & x) { |
| 82 | 66821 | L = l[8 << ss_v]; | |
| 83 | 66821 | H |= (L >> 4) << 8; | |
| 84 | 66821 | E |= s->filter_lut.mblim_lut[L] << 8; | |
| 85 | 66821 | I |= s->filter_lut.lim_lut[L] << 8; | |
| 86 | 66821 | s->dsp.loop_filter_mix2[0][0][0](ptr + 4 * bytesperpixel, ls, E, I, H); | |
| 87 | } else { | ||
| 88 | 48402 | s->dsp.loop_filter_8[0][0](ptr + 4 * bytesperpixel, ls, E, I, H); | |
| 89 | } | ||
| 90 |
2/2✓ Branch 0 taken 39533 times.
✓ Branch 1 taken 773422 times.
|
812955 | } else if (hm23 & x) { |
| 91 | 39533 | int L = l[8 << ss_v], H = L >> 4; | |
| 92 | 39533 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 93 | |||
| 94 | 39533 | s->dsp.loop_filter_8[0][0](ptr + 8 * ls + 4 * bytesperpixel, ls, E, I, H); | |
| 95 | } | ||
| 96 | 928178 | l++; | |
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | 150018 | } | |
| 101 | |||
| 102 | 150018 | static av_always_inline void filter_plane_rows(VP9Context *s, int row, int ss_h, int ss_v, | |
| 103 | uint8_t *lvl, uint8_t (*mask)[4], | ||
| 104 | uint8_t *dst, ptrdiff_t ls) | ||
| 105 | { | ||
| 106 | 150018 | int y, x, bytesperpixel = s->bytesperpixel; | |
| 107 | |||
| 108 | // block1 | ||
| 109 | // filter edges between rows (e.g. ------) | ||
| 110 | // block2 | ||
| 111 |
2/2✓ Branch 0 taken 1200144 times.
✓ Branch 1 taken 150018 times.
|
1350162 | for (y = 0; y < 8; y++, dst += 8 * ls >> ss_v) { |
| 112 | 1200144 | uint8_t *ptr = dst, *l = lvl, *vmask = mask[y]; | |
| 113 | 1200144 | unsigned vm = vmask[0] | vmask[1] | vmask[2], vm3 = vmask[3]; | |
| 114 | |||
| 115 |
2/2✓ Branch 0 taken 1392115 times.
✓ Branch 1 taken 1200144 times.
|
2592259 | for (x = 1; vm & ~(x - 1); x <<= (2 << ss_h), ptr += 16 * bytesperpixel, l += 2 << ss_h) { |
| 116 |
4/4✓ Branch 0 taken 294592 times.
✓ Branch 1 taken 1097523 times.
✓ Branch 2 taken 225765 times.
✓ Branch 3 taken 68827 times.
|
1392115 | if (row || y) { |
| 117 |
2/2✓ Branch 0 taken 1175981 times.
✓ Branch 1 taken 147307 times.
|
1323288 | if (vm & x) { |
| 118 | 1175981 | int L = *l, H = L >> 4; | |
| 119 | 1175981 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 120 | |||
| 121 |
2/2✓ Branch 0 taken 350697 times.
✓ Branch 1 taken 825284 times.
|
1175981 | if (vmask[0] & x) { |
| 122 |
2/2✓ Branch 0 taken 350378 times.
✓ Branch 1 taken 319 times.
|
350697 | if (vmask[0] & (x << (1 + ss_h))) { |
| 123 | av_assert2(l[1 + ss_h] == L); | ||
| 124 | 350378 | s->dsp.loop_filter_16[1](ptr, ls, E, I, H); | |
| 125 | } else { | ||
| 126 | 319 | s->dsp.loop_filter_8[2][1](ptr, ls, E, I, H); | |
| 127 | } | ||
| 128 |
2/2✓ Branch 0 taken 757655 times.
✓ Branch 1 taken 67629 times.
|
825284 | } else if (vm & (x << (1 + ss_h))) { |
| 129 | 757655 | L = l[1 + ss_h]; | |
| 130 | 757655 | H |= (L >> 4) << 8; | |
| 131 | 757655 | E |= s->filter_lut.mblim_lut[L] << 8; | |
| 132 | 757655 | I |= s->filter_lut.lim_lut[L] << 8; | |
| 133 | 757655 | s->dsp.loop_filter_mix2[!!(vmask[1] & x)] | |
| 134 | 757655 | [!!(vmask[1] & (x << (1 + ss_h)))] | |
| 135 | 757655 | [1](ptr, ls, E, I, H); | |
| 136 | } else { | ||
| 137 | 67629 | s->dsp.loop_filter_8[!!(vmask[1] & x)] | |
| 138 | 67629 | [1](ptr, ls, E, I, H); | |
| 139 | } | ||
| 140 |
2/2✓ Branch 0 taken 35358 times.
✓ Branch 1 taken 111949 times.
|
147307 | } else if (vm & (x << (1 + ss_h))) { |
| 141 | 35358 | int L = l[1 + ss_h], H = L >> 4; | |
| 142 | 35358 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 143 | |||
| 144 | 35358 | s->dsp.loop_filter_8[!!(vmask[1] & (x << (1 + ss_h)))] | |
| 145 | 35358 | [1](ptr + 8 * bytesperpixel, ls, E, I, H); | |
| 146 | } | ||
| 147 | } | ||
| 148 |
2/2✓ Branch 0 taken 757725 times.
✓ Branch 1 taken 634390 times.
|
1392115 | if (!ss_v) { |
| 149 |
2/2✓ Branch 0 taken 110039 times.
✓ Branch 1 taken 647686 times.
|
757725 | if (vm3 & x) { |
| 150 | 110039 | int L = *l, H = L >> 4; | |
| 151 | 110039 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 152 | |||
| 153 |
2/2✓ Branch 0 taken 65543 times.
✓ Branch 1 taken 44496 times.
|
110039 | if (vm3 & (x << (1 + ss_h))) { |
| 154 | 65543 | L = l[1 + ss_h]; | |
| 155 | 65543 | H |= (L >> 4) << 8; | |
| 156 | 65543 | E |= s->filter_lut.mblim_lut[L] << 8; | |
| 157 | 65543 | I |= s->filter_lut.lim_lut[L] << 8; | |
| 158 | 65543 | s->dsp.loop_filter_mix2[0][0][1](ptr + ls * 4, ls, E, I, H); | |
| 159 | } else { | ||
| 160 | 44496 | s->dsp.loop_filter_8[0][1](ptr + ls * 4, ls, E, I, H); | |
| 161 | } | ||
| 162 |
2/2✓ Branch 0 taken 42225 times.
✓ Branch 1 taken 605461 times.
|
647686 | } else if (vm3 & (x << (1 + ss_h))) { |
| 163 | 42225 | int L = l[1 + ss_h], H = L >> 4; | |
| 164 | 42225 | int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L]; | |
| 165 | |||
| 166 | 42225 | s->dsp.loop_filter_8[0][1](ptr + ls * 4 + 8 * bytesperpixel, ls, E, I, H); | |
| 167 | } | ||
| 168 | } | ||
| 169 | } | ||
| 170 |
2/2✓ Branch 0 taken 786848 times.
✓ Branch 1 taken 413296 times.
|
1200144 | if (ss_v) { |
| 171 |
2/2✓ Branch 0 taken 393424 times.
✓ Branch 1 taken 393424 times.
|
786848 | if (y & 1) |
| 172 | 393424 | lvl += 16; | |
| 173 | } else { | ||
| 174 | 413296 | lvl += 8; | |
| 175 | } | ||
| 176 | } | ||
| 177 | 150018 | } | |
| 178 | |||
| 179 | 50006 | void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl, | |
| 180 | int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff) | ||
| 181 | { | ||
| 182 | 50006 | VP9Context *s = avctx->priv_data; | |
| 183 | 50006 | AVFrame *f = s->s.frames[CUR_FRAME].tf.f; | |
| 184 | 50006 | uint8_t *dst = f->data[0] + yoff; | |
| 185 | 50006 | ptrdiff_t ls_y = f->linesize[0], ls_uv = f->linesize[1]; | |
| 186 | 50006 | uint8_t (*uv_masks)[8][4] = lflvl->mask[s->ss_h | s->ss_v]; | |
| 187 | int p; | ||
| 188 | |||
| 189 | /* FIXME: In how far can we interleave the v/h loopfilter calls? E.g. | ||
| 190 | * if you think of them as acting on a 8x8 block max, we can interleave | ||
| 191 | * each v/h within the single x loop, but that only works if we work on | ||
| 192 | * 8 pixel blocks, and we won't always do that (we want at least 16px | ||
| 193 | * to use SSE2 optimizations, perhaps 32 for AVX2) */ | ||
| 194 | |||
| 195 | 50006 | filter_plane_cols(s, col, 0, 0, lflvl->level, lflvl->mask[0][0], dst, ls_y); | |
| 196 | 50006 | filter_plane_rows(s, row, 0, 0, lflvl->level, lflvl->mask[0][1], dst, ls_y); | |
| 197 | |||
| 198 |
2/2✓ Branch 0 taken 100012 times.
✓ Branch 1 taken 50006 times.
|
150018 | for (p = 0; p < 2; p++) { |
| 199 | 100012 | dst = f->data[1 + p] + uvoff; | |
| 200 | 100012 | filter_plane_cols(s, col, s->ss_h, s->ss_v, lflvl->level, uv_masks[0], dst, ls_uv); | |
| 201 | 100012 | filter_plane_rows(s, row, s->ss_h, s->ss_v, lflvl->level, uv_masks[1], dst, ls_uv); | |
| 202 | } | ||
| 203 | 50006 | } | |
| 204 |