FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vp9prob.c
Date: 2021-09-23 20:34:37
Exec Total Coverage
Lines: 169 169 100.0%
Branches: 68 68 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 "vp56.h"
25 #include "vp9.h"
26 #include "vp9data.h"
27 #include "vp9dec.h"
28
29 4081547 static av_always_inline void adapt_prob(uint8_t *p, unsigned ct0, unsigned ct1,
30 int max_count, int update_factor)
31 {
32 4081547 unsigned ct = ct0 + ct1, p2, p1;
33
34
2/2
✓ Branch 0 taken 3361133 times.
✓ Branch 1 taken 720414 times.
4081547 if (!ct)
35 3361133 return;
36
37 720414 update_factor = FASTDIV(update_factor * FFMIN(ct, max_count), max_count);
38 720414 p1 = *p;
39 720414 p2 = ((((int64_t) ct0) << 8) + (ct >> 1)) / ct;
40 720414 p2 = av_clip(p2, 1, 255);
41
42 // (p1 * (256 - update_factor) + p2 * update_factor + 128) >> 8
43 720414 *p = p1 + (((p2 - p1) * update_factor + 128) >> 8);
44 }
45
46 2244 void ff_vp9_adapt_probs(VP9Context *s)
47 {
48 int i, j, k, l, m;
49 2244 ProbContext *p = &s->prob_ctx[s->s.h.framectxid].p;
50
6/6
✓ Branch 0 taken 1783 times.
✓ Branch 1 taken 461 times.
✓ Branch 2 taken 1777 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1554 times.
✓ Branch 5 taken 223 times.
2244 int uf = (s->s.h.keyframe || s->s.h.intraonly || !s->last_keyframe) ? 112 : 128;
51
52 // coefficients
53
2/2
✓ Branch 0 taken 8976 times.
✓ Branch 1 taken 2244 times.
11220 for (i = 0; i < 4; i++)
54
2/2
✓ Branch 0 taken 17952 times.
✓ Branch 1 taken 8976 times.
26928 for (j = 0; j < 2; j++)
55
2/2
✓ Branch 0 taken 35904 times.
✓ Branch 1 taken 17952 times.
53856 for (k = 0; k < 2; k++)
56
2/2
✓ Branch 0 taken 215424 times.
✓ Branch 1 taken 35904 times.
251328 for (l = 0; l < 6; l++)
57
2/2
✓ Branch 0 taken 1220736 times.
✓ Branch 1 taken 179520 times.
1400256 for (m = 0; m < 6; m++) {
58 1220736 uint8_t *pp = s->prob_ctx[s->s.h.framectxid].coef[i][j][k][l][m];
59 1220736 unsigned *e = s->td[0].counts.eob[i][j][k][l][m];
60 1220736 unsigned *c = s->td[0].counts.coef[i][j][k][l][m];
61
62
4/4
✓ Branch 0 taken 143616 times.
✓ Branch 1 taken 1077120 times.
✓ Branch 2 taken 35904 times.
✓ Branch 3 taken 107712 times.
1220736 if (l == 0 && m >= 3) // dc only has 3 pt
63 35904 break;
64
65 1184832 adapt_prob(&pp[0], e[0], e[1], 24, uf);
66 1184832 adapt_prob(&pp[1], c[0], c[1] + c[2], 24, uf);
67 1184832 adapt_prob(&pp[2], c[1], c[2], 24, uf);
68 }
69
70
4/4
✓ Branch 0 taken 1783 times.
✓ Branch 1 taken 461 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 1777 times.
2244 if (s->s.h.keyframe || s->s.h.intraonly) {
71 467 memcpy(p->skip, s->prob.p.skip, sizeof(p->skip));
72 467 memcpy(p->tx32p, s->prob.p.tx32p, sizeof(p->tx32p));
73 467 memcpy(p->tx16p, s->prob.p.tx16p, sizeof(p->tx16p));
74 467 memcpy(p->tx8p, s->prob.p.tx8p, sizeof(p->tx8p));
75 467 return;
76 }
77
78 // skip flag
79
2/2
✓ Branch 0 taken 5331 times.
✓ Branch 1 taken 1777 times.
7108 for (i = 0; i < 3; i++)
80 5331 adapt_prob(&p->skip[i], s->td[0].counts.skip[i][0],
81 5331 s->td[0].counts.skip[i][1], 20, 128);
82
83 // intra/inter flag
84
2/2
✓ Branch 0 taken 7108 times.
✓ Branch 1 taken 1777 times.
8885 for (i = 0; i < 4; i++)
85 7108 adapt_prob(&p->intra[i], s->td[0].counts.intra[i][0],
86 7108 s->td[0].counts.intra[i][1], 20, 128);
87
88 // comppred flag
89
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 1469 times.
1777 if (s->s.h.comppredmode == PRED_SWITCHABLE) {
90
2/2
✓ Branch 0 taken 1540 times.
✓ Branch 1 taken 308 times.
1848 for (i = 0; i < 5; i++)
91 1540 adapt_prob(&p->comp[i], s->td[0].counts.comp[i][0],
92 1540 s->td[0].counts.comp[i][1], 20, 128);
93 }
94
95 // reference frames
96
2/2
✓ Branch 0 taken 310 times.
✓ Branch 1 taken 1467 times.
1777 if (s->s.h.comppredmode != PRED_SINGLEREF) {
97
2/2
✓ Branch 0 taken 1550 times.
✓ Branch 1 taken 310 times.
1860 for (i = 0; i < 5; i++)
98 1550 adapt_prob(&p->comp_ref[i], s->td[0].counts.comp_ref[i][0],
99 1550 s->td[0].counts.comp_ref[i][1], 20, 128);
100 }
101
102
2/2
✓ Branch 0 taken 1775 times.
✓ Branch 1 taken 2 times.
1777 if (s->s.h.comppredmode != PRED_COMPREF) {
103
2/2
✓ Branch 0 taken 8875 times.
✓ Branch 1 taken 1775 times.
10650 for (i = 0; i < 5; i++) {
104 8875 uint8_t *pp = p->single_ref[i];
105 8875 unsigned (*c)[2] = s->td[0].counts.single_ref[i];
106
107 8875 adapt_prob(&pp[0], c[0][0], c[0][1], 20, 128);
108 8875 adapt_prob(&pp[1], c[1][0], c[1][1], 20, 128);
109 }
110 }
111
112 // block partitioning
113
2/2
✓ Branch 0 taken 7108 times.
✓ Branch 1 taken 1777 times.
8885 for (i = 0; i < 4; i++)
114
2/2
✓ Branch 0 taken 28432 times.
✓ Branch 1 taken 7108 times.
35540 for (j = 0; j < 4; j++) {
115 28432 uint8_t *pp = p->partition[i][j];
116 28432 unsigned *c = s->td[0].counts.partition[i][j];
117
118 28432 adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
119 28432 adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
120 28432 adapt_prob(&pp[2], c[2], c[3], 20, 128);
121 }
122
123 // tx size
124
2/2
✓ Branch 0 taken 1306 times.
✓ Branch 1 taken 471 times.
1777 if (s->s.h.txfmmode == TX_SWITCHABLE) {
125
2/2
✓ Branch 0 taken 2612 times.
✓ Branch 1 taken 1306 times.
3918 for (i = 0; i < 2; i++) {
126 2612 unsigned *c16 = s->td[0].counts.tx16p[i], *c32 = s->td[0].counts.tx32p[i];
127
128 2612 adapt_prob(&p->tx8p[i], s->td[0].counts.tx8p[i][0],
129 2612 s->td[0].counts.tx8p[i][1], 20, 128);
130 2612 adapt_prob(&p->tx16p[i][0], c16[0], c16[1] + c16[2], 20, 128);
131 2612 adapt_prob(&p->tx16p[i][1], c16[1], c16[2], 20, 128);
132 2612 adapt_prob(&p->tx32p[i][0], c32[0], c32[1] + c32[2] + c32[3], 20, 128);
133 2612 adapt_prob(&p->tx32p[i][1], c32[1], c32[2] + c32[3], 20, 128);
134 2612 adapt_prob(&p->tx32p[i][2], c32[2], c32[3], 20, 128);
135 }
136 }
137
138 // interpolation filter
139
2/2
✓ Branch 0 taken 1308 times.
✓ Branch 1 taken 469 times.
1777 if (s->s.h.filtermode == FILTER_SWITCHABLE) {
140
2/2
✓ Branch 0 taken 5232 times.
✓ Branch 1 taken 1308 times.
6540 for (i = 0; i < 4; i++) {
141 5232 uint8_t *pp = p->filter[i];
142 5232 unsigned *c = s->td[0].counts.filter[i];
143
144 5232 adapt_prob(&pp[0], c[0], c[1] + c[2], 20, 128);
145 5232 adapt_prob(&pp[1], c[1], c[2], 20, 128);
146 }
147 }
148
149 // inter modes
150
2/2
✓ Branch 0 taken 12439 times.
✓ Branch 1 taken 1777 times.
14216 for (i = 0; i < 7; i++) {
151 12439 uint8_t *pp = p->mv_mode[i];
152 12439 unsigned *c = s->td[0].counts.mv_mode[i];
153
154 12439 adapt_prob(&pp[0], c[2], c[1] + c[0] + c[3], 20, 128);
155 12439 adapt_prob(&pp[1], c[0], c[1] + c[3], 20, 128);
156 12439 adapt_prob(&pp[2], c[1], c[3], 20, 128);
157 }
158
159 // mv joints
160 {
161 1777 uint8_t *pp = p->mv_joint;
162 1777 unsigned *c = s->td[0].counts.mv_joint;
163
164 1777 adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
165 1777 adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
166 1777 adapt_prob(&pp[2], c[2], c[3], 20, 128);
167 }
168
169 // mv components
170
2/2
✓ Branch 0 taken 3554 times.
✓ Branch 1 taken 1777 times.
5331 for (i = 0; i < 2; i++) {
171 uint8_t *pp;
172 unsigned *c, (*c2)[2], sum;
173
174 3554 adapt_prob(&p->mv_comp[i].sign, s->td[0].counts.mv_comp[i].sign[0],
175 3554 s->td[0].counts.mv_comp[i].sign[1], 20, 128);
176
177 3554 pp = p->mv_comp[i].classes;
178 3554 c = s->td[0].counts.mv_comp[i].classes;
179 3554 sum = c[1] + c[2] + c[3] + c[4] + c[5] +
180 3554 c[6] + c[7] + c[8] + c[9] + c[10];
181 3554 adapt_prob(&pp[0], c[0], sum, 20, 128);
182 3554 sum -= c[1];
183 3554 adapt_prob(&pp[1], c[1], sum, 20, 128);
184 3554 sum -= c[2] + c[3];
185 3554 adapt_prob(&pp[2], c[2] + c[3], sum, 20, 128);
186 3554 adapt_prob(&pp[3], c[2], c[3], 20, 128);
187 3554 sum -= c[4] + c[5];
188 3554 adapt_prob(&pp[4], c[4] + c[5], sum, 20, 128);
189 3554 adapt_prob(&pp[5], c[4], c[5], 20, 128);
190 3554 sum -= c[6];
191 3554 adapt_prob(&pp[6], c[6], sum, 20, 128);
192 3554 adapt_prob(&pp[7], c[7] + c[8], c[9] + c[10], 20, 128);
193 3554 adapt_prob(&pp[8], c[7], c[8], 20, 128);
194 3554 adapt_prob(&pp[9], c[9], c[10], 20, 128);
195
196 3554 adapt_prob(&p->mv_comp[i].class0, s->td[0].counts.mv_comp[i].class0[0],
197 3554 s->td[0].counts.mv_comp[i].class0[1], 20, 128);
198 3554 pp = p->mv_comp[i].bits;
199 3554 c2 = s->td[0].counts.mv_comp[i].bits;
200
2/2
✓ Branch 0 taken 35540 times.
✓ Branch 1 taken 3554 times.
39094 for (j = 0; j < 10; j++)
201 35540 adapt_prob(&pp[j], c2[j][0], c2[j][1], 20, 128);
202
203
2/2
✓ Branch 0 taken 7108 times.
✓ Branch 1 taken 3554 times.
10662 for (j = 0; j < 2; j++) {
204 7108 pp = p->mv_comp[i].class0_fp[j];
205 7108 c = s->td[0].counts.mv_comp[i].class0_fp[j];
206 7108 adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
207 7108 adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
208 7108 adapt_prob(&pp[2], c[2], c[3], 20, 128);
209 }
210 3554 pp = p->mv_comp[i].fp;
211 3554 c = s->td[0].counts.mv_comp[i].fp;
212 3554 adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
213 3554 adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
214 3554 adapt_prob(&pp[2], c[2], c[3], 20, 128);
215
216
2/2
✓ Branch 0 taken 2808 times.
✓ Branch 1 taken 746 times.
3554 if (s->s.h.highprecisionmvs) {
217 2808 adapt_prob(&p->mv_comp[i].class0_hp,
218 2808 s->td[0].counts.mv_comp[i].class0_hp[0],
219 2808 s->td[0].counts.mv_comp[i].class0_hp[1], 20, 128);
220 2808 adapt_prob(&p->mv_comp[i].hp, s->td[0].counts.mv_comp[i].hp[0],
221 2808 s->td[0].counts.mv_comp[i].hp[1], 20, 128);
222 }
223 }
224
225 // y intra modes
226
2/2
✓ Branch 0 taken 7108 times.
✓ Branch 1 taken 1777 times.
8885 for (i = 0; i < 4; i++) {
227 7108 uint8_t *pp = p->y_mode[i];
228 7108 unsigned *c = s->td[0].counts.y_mode[i], sum, s2;
229
230 7108 sum = c[0] + c[1] + c[3] + c[4] + c[5] + c[6] + c[7] + c[8] + c[9];
231 7108 adapt_prob(&pp[0], c[DC_PRED], sum, 20, 128);
232 7108 sum -= c[TM_VP8_PRED];
233 7108 adapt_prob(&pp[1], c[TM_VP8_PRED], sum, 20, 128);
234 7108 sum -= c[VERT_PRED];
235 7108 adapt_prob(&pp[2], c[VERT_PRED], sum, 20, 128);
236 7108 s2 = c[HOR_PRED] + c[DIAG_DOWN_RIGHT_PRED] + c[VERT_RIGHT_PRED];
237 7108 sum -= s2;
238 7108 adapt_prob(&pp[3], s2, sum, 20, 128);
239 7108 s2 -= c[HOR_PRED];
240 7108 adapt_prob(&pp[4], c[HOR_PRED], s2, 20, 128);
241 7108 adapt_prob(&pp[5], c[DIAG_DOWN_RIGHT_PRED], c[VERT_RIGHT_PRED],
242 20, 128);
243 7108 sum -= c[DIAG_DOWN_LEFT_PRED];
244 7108 adapt_prob(&pp[6], c[DIAG_DOWN_LEFT_PRED], sum, 20, 128);
245 7108 sum -= c[VERT_LEFT_PRED];
246 7108 adapt_prob(&pp[7], c[VERT_LEFT_PRED], sum, 20, 128);
247 7108 adapt_prob(&pp[8], c[HOR_DOWN_PRED], c[HOR_UP_PRED], 20, 128);
248 }
249
250 // uv intra modes
251
2/2
✓ Branch 0 taken 17770 times.
✓ Branch 1 taken 1777 times.
19547 for (i = 0; i < 10; i++) {
252 17770 uint8_t *pp = p->uv_mode[i];
253 17770 unsigned *c = s->td[0].counts.uv_mode[i], sum, s2;
254
255 17770 sum = c[0] + c[1] + c[3] + c[4] + c[5] + c[6] + c[7] + c[8] + c[9];
256 17770 adapt_prob(&pp[0], c[DC_PRED], sum, 20, 128);
257 17770 sum -= c[TM_VP8_PRED];
258 17770 adapt_prob(&pp[1], c[TM_VP8_PRED], sum, 20, 128);
259 17770 sum -= c[VERT_PRED];
260 17770 adapt_prob(&pp[2], c[VERT_PRED], sum, 20, 128);
261 17770 s2 = c[HOR_PRED] + c[DIAG_DOWN_RIGHT_PRED] + c[VERT_RIGHT_PRED];
262 17770 sum -= s2;
263 17770 adapt_prob(&pp[3], s2, sum, 20, 128);
264 17770 s2 -= c[HOR_PRED];
265 17770 adapt_prob(&pp[4], c[HOR_PRED], s2, 20, 128);
266 17770 adapt_prob(&pp[5], c[DIAG_DOWN_RIGHT_PRED], c[VERT_RIGHT_PRED],
267 20, 128);
268 17770 sum -= c[DIAG_DOWN_LEFT_PRED];
269 17770 adapt_prob(&pp[6], c[DIAG_DOWN_LEFT_PRED], sum, 20, 128);
270 17770 sum -= c[VERT_LEFT_PRED];
271 17770 adapt_prob(&pp[7], c[VERT_LEFT_PRED], sum, 20, 128);
272 17770 adapt_prob(&pp[8], c[HOR_DOWN_PRED], c[HOR_UP_PRED], 20, 128);
273 }
274 }
275