FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vp9lpf.c
Date: 2021-09-22 05:58:22
Exec Total Coverage
Lines: 112 112 100.0%
Branches: 60 60 100.0%

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 "vp9dec.h"
25
26 144708 static av_always_inline void filter_plane_cols(VP9Context *s, int col, int ss_h, int ss_v,
27 uint8_t *lvl, uint8_t (*mask)[4],
28 uint8_t *dst, ptrdiff_t ls)
29 {
30 144708 int y, x, bytesperpixel = s->bytesperpixel;
31
32 // filter edges between columns (e.g. block1 | block2)
33
2/2
✓ Branch 0 taken 389200 times.
✓ Branch 1 taken 144708 times.
533908 for (y = 0; y < 8; y += 2 << ss_v, dst += 16 * ls, lvl += 16 << ss_v) {
34 389200 uint8_t *ptr = dst, *l = lvl, *hmask1 = mask[y], *hmask2 = mask[y + 1 + ss_v];
35 389200 unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2], hm13 = hmask1[3];
36 389200 unsigned hm2 = hmask2[1] | hmask2[2], hm23 = hmask2[3];
37 389200 unsigned hm = hm1 | hm2 | hm13 | hm23;
38
39
2/2
✓ Branch 0 taken 1725401 times.
✓ Branch 1 taken 389200 times.
2114601 for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 8 * bytesperpixel >> ss_h) {
40
4/4
✓ Branch 0 taken 284351 times.
✓ Branch 1 taken 1441050 times.
✓ Branch 2 taken 231590 times.
✓ Branch 3 taken 52761 times.
1725401 if (col || x > 1) {
41
2/2
✓ Branch 0 taken 1136691 times.
✓ Branch 1 taken 535949 times.
1672640 if (hm1 & x) {
42 1136691 int L = *l, H = L >> 4;
43 1136691 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
44
45
2/2
✓ Branch 0 taken 329699 times.
✓ Branch 1 taken 806992 times.
1136691 if (hmask1[0] & x) {
46
2/2
✓ Branch 0 taken 328091 times.
✓ Branch 1 taken 1608 times.
329699 if (hmask2[0] & x) {
47 av_assert2(l[8 << ss_v] == L);
48 328091 s->dsp.loop_filter_16[0](ptr, ls, E, I, H);
49 } else {
50 1608 s->dsp.loop_filter_8[2][0](ptr, ls, E, I, H);
51 }
52
2/2
✓ Branch 0 taken 743429 times.
✓ Branch 1 taken 63563 times.
806992 } else if (hm2 & x) {
53 743429 L = l[8 << ss_v];
54 743429 H |= (L >> 4) << 8;
55 743429 E |= s->filter_lut.mblim_lut[L] << 8;
56 743429 I |= s->filter_lut.lim_lut[L] << 8;
57 743429 s->dsp.loop_filter_mix2[!!(hmask1[1] & x)]
58 743429 [!!(hmask2[1] & x)]
59 743429 [0](ptr, ls, E, I, H);
60 } else {
61 63563 s->dsp.loop_filter_8[!!(hmask1[1] & x)]
62 63563 [0](ptr, ls, E, I, H);
63 }
64
2/2
✓ Branch 0 taken 31642 times.
✓ Branch 1 taken 504307 times.
535949 } else if (hm2 & x) {
65 31642 int L = l[8 << ss_v], H = L >> 4;
66 31642 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
67
68 31642 s->dsp.loop_filter_8[!!(hmask2[1] & x)]
69 31642 [0](ptr + 8 * ls, ls, E, I, H);
70 }
71 }
72
2/2
✓ Branch 0 taken 837672 times.
✓ Branch 1 taken 887729 times.
1725401 if (ss_h) {
73
2/2
✓ Branch 0 taken 349932 times.
✓ Branch 1 taken 487740 times.
837672 if (x & 0xAA)
74 349932 l += 2;
75 } else {
76
2/2
✓ Branch 0 taken 112721 times.
✓ Branch 1 taken 775008 times.
887729 if (hm13 & x) {
77 112721 int L = *l, H = L >> 4;
78 112721 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
79
80
2/2
✓ Branch 0 taken 65900 times.
✓ Branch 1 taken 46821 times.
112721 if (hm23 & x) {
81 65900 L = l[8 << ss_v];
82 65900 H |= (L >> 4) << 8;
83 65900 E |= s->filter_lut.mblim_lut[L] << 8;
84 65900 I |= s->filter_lut.lim_lut[L] << 8;
85 65900 s->dsp.loop_filter_mix2[0][0][0](ptr + 4 * bytesperpixel, ls, E, I, H);
86 } else {
87 46821 s->dsp.loop_filter_8[0][0](ptr + 4 * bytesperpixel, ls, E, I, H);
88 }
89
2/2
✓ Branch 0 taken 38338 times.
✓ Branch 1 taken 736670 times.
775008 } else if (hm23 & x) {
90 38338 int L = l[8 << ss_v], H = L >> 4;
91 38338 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
92
93 38338 s->dsp.loop_filter_8[0][0](ptr + 8 * ls + 4 * bytesperpixel, ls, E, I, H);
94 }
95 887729 l++;
96 }
97 }
98 }
99 144708 }
100
101 144708 static av_always_inline void filter_plane_rows(VP9Context *s, int row, int ss_h, int ss_v,
102 uint8_t *lvl, uint8_t (*mask)[4],
103 uint8_t *dst, ptrdiff_t ls)
104 {
105 144708 int y, x, bytesperpixel = s->bytesperpixel;
106
107 // block1
108 // filter edges between rows (e.g. ------)
109 // block2
110
2/2
✓ Branch 0 taken 1157664 times.
✓ Branch 1 taken 144708 times.
1302372 for (y = 0; y < 8; y++, dst += 8 * ls >> ss_v) {
111 1157664 uint8_t *ptr = dst, *l = lvl, *vmask = mask[y];
112 1157664 unsigned vm = vmask[0] | vmask[1] | vmask[2], vm3 = vmask[3];
113
114
2/2
✓ Branch 0 taken 1338515 times.
✓ Branch 1 taken 1157664 times.
2496179 for (x = 1; vm & ~(x - 1); x <<= (2 << ss_h), ptr += 16 * bytesperpixel, l += 2 << ss_h) {
115
4/4
✓ Branch 0 taken 289757 times.
✓ Branch 1 taken 1048758 times.
✓ Branch 2 taken 222374 times.
✓ Branch 3 taken 67383 times.
1338515 if (row || y) {
116
2/2
✓ Branch 0 taken 1129385 times.
✓ Branch 1 taken 141747 times.
1271132 if (vm & x) {
117 1129385 int L = *l, H = L >> 4;
118 1129385 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
119
120
2/2
✓ Branch 0 taken 332376 times.
✓ Branch 1 taken 797009 times.
1129385 if (vmask[0] & x) {
121
2/2
✓ Branch 0 taken 332057 times.
✓ Branch 1 taken 319 times.
332376 if (vmask[0] & (x << (1 + ss_h))) {
122 av_assert2(l[1 + ss_h] == L);
123 332057 s->dsp.loop_filter_16[1](ptr, ls, E, I, H);
124 } else {
125 319 s->dsp.loop_filter_8[2][1](ptr, ls, E, I, H);
126 }
127
2/2
✓ Branch 0 taken 731086 times.
✓ Branch 1 taken 65923 times.
797009 } else if (vm & (x << (1 + ss_h))) {
128 731086 L = l[1 + ss_h];
129 731086 H |= (L >> 4) << 8;
130 731086 E |= s->filter_lut.mblim_lut[L] << 8;
131 731086 I |= s->filter_lut.lim_lut[L] << 8;
132 731086 s->dsp.loop_filter_mix2[!!(vmask[1] & x)]
133 731086 [!!(vmask[1] & (x << (1 + ss_h)))]
134 731086 [1](ptr, ls, E, I, H);
135 } else {
136 65923 s->dsp.loop_filter_8[!!(vmask[1] & x)]
137 65923 [1](ptr, ls, E, I, H);
138 }
139
2/2
✓ Branch 0 taken 34138 times.
✓ Branch 1 taken 107609 times.
141747 } else if (vm & (x << (1 + ss_h))) {
140 34138 int L = l[1 + ss_h], H = L >> 4;
141 34138 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
142
143 34138 s->dsp.loop_filter_8[!!(vmask[1] & (x << (1 + ss_h)))]
144 34138 [1](ptr + 8 * bytesperpixel, ls, E, I, H);
145 }
146 }
147
2/2
✓ Branch 0 taken 729973 times.
✓ Branch 1 taken 608542 times.
1338515 if (!ss_v) {
148
2/2
✓ Branch 0 taken 107657 times.
✓ Branch 1 taken 622316 times.
729973 if (vm3 & x) {
149 107657 int L = *l, H = L >> 4;
150 107657 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
151
152
2/2
✓ Branch 0 taken 64168 times.
✓ Branch 1 taken 43489 times.
107657 if (vm3 & (x << (1 + ss_h))) {
153 64168 L = l[1 + ss_h];
154 64168 H |= (L >> 4) << 8;
155 64168 E |= s->filter_lut.mblim_lut[L] << 8;
156 64168 I |= s->filter_lut.lim_lut[L] << 8;
157 64168 s->dsp.loop_filter_mix2[0][0][1](ptr + ls * 4, ls, E, I, H);
158 } else {
159 43489 s->dsp.loop_filter_8[0][1](ptr + ls * 4, ls, E, I, H);
160 }
161
2/2
✓ Branch 0 taken 41364 times.
✓ Branch 1 taken 580952 times.
622316 } else if (vm3 & (x << (1 + ss_h))) {
162 41364 int L = l[1 + ss_h], H = L >> 4;
163 41364 int E = s->filter_lut.mblim_lut[L], I = s->filter_lut.lim_lut[L];
164
165 41364 s->dsp.loop_filter_8[0][1](ptr + ls * 4 + 8 * bytesperpixel, ls, E, I, H);
166 }
167 }
168 }
169
2/2
✓ Branch 0 taken 758528 times.
✓ Branch 1 taken 399136 times.
1157664 if (ss_v) {
170
2/2
✓ Branch 0 taken 379264 times.
✓ Branch 1 taken 379264 times.
758528 if (y & 1)
171 379264 lvl += 16;
172 } else {
173 399136 lvl += 8;
174 }
175 }
176 144708 }
177
178 48236 void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl,
179 int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff)
180 {
181 48236 VP9Context *s = avctx->priv_data;
182 48236 AVFrame *f = s->s.frames[CUR_FRAME].tf.f;
183 48236 uint8_t *dst = f->data[0] + yoff;
184 48236 ptrdiff_t ls_y = f->linesize[0], ls_uv = f->linesize[1];
185 48236 uint8_t (*uv_masks)[8][4] = lflvl->mask[s->ss_h | s->ss_v];
186 int p;
187
188 /* FIXME: In how far can we interleave the v/h loopfilter calls? E.g.
189 * if you think of them as acting on a 8x8 block max, we can interleave
190 * each v/h within the single x loop, but that only works if we work on
191 * 8 pixel blocks, and we won't always do that (we want at least 16px
192 * to use SSE2 optimizations, perhaps 32 for AVX2) */
193
194 48236 filter_plane_cols(s, col, 0, 0, lflvl->level, lflvl->mask[0][0], dst, ls_y);
195 48236 filter_plane_rows(s, row, 0, 0, lflvl->level, lflvl->mask[0][1], dst, ls_y);
196
197
2/2
✓ Branch 0 taken 96472 times.
✓ Branch 1 taken 48236 times.
144708 for (p = 0; p < 2; p++) {
198 96472 dst = f->data[1 + p] + uvoff;
199 96472 filter_plane_cols(s, col, s->ss_h, s->ss_v, lflvl->level, uv_masks[0], dst, ls_uv);
200 96472 filter_plane_rows(s, row, s->ss_h, s->ss_v, lflvl->level, uv_masks[1], dst, ls_uv);
201 }
202 48236 }
203